sens_sms

๐Ÿ“ฉ Send SMS with Ncloud Sens

MIT License

Downloads
2.1K
Stars
7

Ncloud Sens SMS Gem

Send your SMS with Ncloud Sens in Ruby.

ํ•œ๊ตญ์–ด ๋ฌธ์„œ๋ฅผ ์ฝ๊ณ ์‹ถ๋‹ค๋ฉด, ์—ฌ๊ธฐ๋ฅผ ํด๋ฆญํ•˜์„ธ์š”

Installation

Rails

Add this line to your application's Gemfile:

gem 'sens_sms'

Then execute:

$ bundle

Finally, run the generator:

$ rails generate sens_sms:install

At this point, you can find a sens_sms configuration file located at YOUR_PROJECT/config/initializers/sens_sms.rb.

require 'sens_sms'

SensSms::Client.configure do |config|
  config.access_key = ENV['NCLOUD_ACCESS_KEY']
  config.secret_key = ENV['NCLOUD_SECRET_KEY']
  config.service_id = ENV['NCLOUD_SERVICE_ID']
end

You can set your Ncloud access keys here, but we recommend to use Environment Values. Generating access keys guide is here.

Sinatra or Plain ol' Ruby

Install the gem:

$ gem install sens_sms

If you plan to use sens_sms gem in plain Ruby project, then you should call require 'sens_sms' and SensSms::Client.configure block to set access keys before calling deliver method like rails generator do it.

Usage

# SMS
SensSms::Client.new
               .deliver(type: :sms,
                        from_number: '01012345678',
                        to_numbers: '01098765432',
                        message: '์ „ ์„ธ๊ณ„์— ์•Œ๋ ค์ง„ ํŽญ๊ท„์˜ ์ข…๋ฅ˜๋Š” 17์ข… ํ˜น์€ 18์ข…์ด๋‹ค.')
# LMS
SensSms::Client.new
               .deliver(type: :lms,
                        from_number: '01012345678',
                        to_numbers: '01098765432',
                        title: 'ํŽญ๊ท„',
                        message: '์ „ ์„ธ๊ณ„์— ์•Œ๋ ค์ง„ ํŽญ๊ท„์˜ ์ข…๋ฅ˜๋Š” 17์ข… ํ˜น์€ 18์ข…์ด๋‹ค. (์‡ ํ‘ธ๋ฅธํŽญ๊ท„๊ณผ ํฐ๋‚ ๊ฐœํŽญ๊ท„์ด
                                  ์‹๋ณ„๋˜๋Š”์ง€ ์•„๋‹Œ์ง€์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์ง„๋‹ค.) ๋ชจ๋“  ํŽญ๊ท„ ์ข…์˜ ๊ณ ํ–ฅ์ด ๋‚จ๋ฐ˜๊ตฌ์ด๊ธฐ๋Š” ํ•˜์ง€๋งŒ,
                                  ํ†ต๋…๊ณผ ๋‹ฌ๋ฆฌ, ๋‚จ๊ทน๊ณผ ๊ฐ™์ด ์ถ”์šด ๊ธฐํ›„์—์„œ๋งŒ ์„œ์‹ํ•˜์ง€๋Š” ์•Š๋Š”๋‹ค. ์‹ค์ œ๋กœ๋Š” ๋ช‡๋ช‡ ์ข…๋งŒ์ด
                                  ๊ทน์ง€๋ฐฉ์— ์‚ฐ๋‹ค. 3์ข…์€ ์—ด๋Œ€ ์ง€๋ฐฉ์— ์‚ด๋ฉฐ, ๊ทธ ๊ฐ€์šด๋ฐ ๊ฐˆ๋ผํŒŒ๊ณ ์Šค ์ œ๋„์— ์‚ฌ๋Š” ํ•œ ์ข…์€ ๋จน์ด๋ฅผ
                                  ์ฐพ๋‹ค๊ฐ€ ์ ๋„๋ฅผ ๊ฑด๋„ˆ๊ธฐ๋„ ํ•œ๋‹ค. ๊ฐ€์žฅ ํฐ ์ข…์€ ํ™ฉ์ œํŽญ๊ท„์œผ๋กœ, ๋‹ค ์ž๋ผ๋ฉด ํ‚ค๊ฐ€ ์•ฝ 1.1๋ฏธํ„ฐ,
                                  ๋ฌด๊ฒŒ๊ฐ€ ์•ฝ 35ํ‚ฌ๋กœ๊ทธ๋žจ ์ด์ƒ์ด๋‹ค. ๊ฐ€์žฅ ์ž‘์€ ์ข…์€ ์‡ ํ‘ธ๋ฅธํŽญ๊ท„์œผ๋กœ, ํ‚ค๋Š” ์•ฝ 40์„ผํ‹ฐ๋ฏธํ„ฐ์—
                                  ๋ชธ๋ฌด๊ฒŒ๊ฐ€ 1ํ‚ฌ๋กœ๊ทธ๋žจ์— ๋ถˆ๊ณผํ•˜๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ํŽญ๊ท„์€ ๋ฉ์น˜๊ฐ€ ํด์ˆ˜๋ก ์—ด์„ ์ž˜ ๋ณด๊ด€ํ•ด์„œ
                                  ์ถ”์šด ์ง€๋ฐฉ์— ์‚ด๊ณ , ์ž‘์€ ํŽญ๊ท„๋“ค์€ ์˜จ๋Œ€๋‚˜ ์‹ฌ์ง€์–ด ์—ด๋Œ€์—์„œ ๋ฐœ๊ฒฌ๋œ๋‹ค.')

After calling configure method, use SensSms::Client.new.deliver with below arguments.

From Number

You can use from_number key to set sender number registered at Ncloud SENS console.

To Number

You can use to_numbers key to set receiver number. Also to_numbers can be set multiple numbers with Array type. (eg. ['01012345678', '01009876543'] )

Type

You can use type key to choose message type.

SMS Type

SMS can send short message with up to 80 bytes and this type cannot use title. However, sending title key will do not raise any error, it'll be just ignored.

LMS Type

LMS type can send title and super long text message with up to 2,000 bytes.

Title

Basically, This key is optional used by LMS message type for title. Of course, this key can be used in SMS message type, but nothing will be happened.

Message

Text message.

Contributing

Bug reports and pull requests are welcome.

License

The gem is available as open source under the terms of the MIT License.