Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/say8425/sens_sms

๐Ÿ“ฉ Send SMS with Ncloud Sens
https://github.com/say8425/sens_sms

Last synced: 3 months ago
JSON representation

๐Ÿ“ฉ Send SMS with Ncloud Sens

Awesome Lists containing this project

README

        

# Ncloud Sens SMS Gem

[![gem version](https://img.shields.io/gem/v/sens_sms?color=cc342d&logo=ruby&logoColor=cc342d)](https://rubygems.org/gems/sens_sms)
[![GitHub Actions Test](https://github.com/say8425/sens_sms/workflows/Test/badge.svg)](https://github.com/say8425/sens_sms/actions?query=workflow%3ATest)
[![GitHub Actions Release](https://github.com/say8425/sens_sms/workflows/Release/badge.svg)](https://github.com/say8425/sens_sms/actions?query=workflow%3ARelease)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/say8425/sens_sms/blob/master/LICENSE)

Send your SMS with [Ncloud Sens](https://www.ncloud.com/product/applicationService/sens) in Ruby.

ํ•œ๊ตญ์–ด ๋ฌธ์„œ๋ฅผ ์ฝ๊ณ ์‹ถ๋‹ค๋ฉด, [์—ฌ๊ธฐ](https://github.com/say8425/sens_sms/blob/master/README.ko.md)๋ฅผ ํด๋ฆญํ•˜์„ธ์š”

## Installation

### Rails

Add this line to your application's Gemfile:

```ruby
gem 'sens_sms'
```

Then execute:

```shell script
$ bundle
```

Finally, run the generator:

```shell script
$ 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`.

```ruby
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](https://docs.ncloud.com/en/sens/sens-1-2.html).

### Sinatra or Plain ol' Ruby

Install the gem:

```shell script
$ 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

```ruby
# SMS
SensSms::Client.new
.deliver(type: :sms,
from_number: '01012345678',
to_numbers: '01098765432',
message: '์ „ ์„ธ๊ณ„์— ์•Œ๋ ค์ง„ ํŽญ๊ท„์˜ ์ข…๋ฅ˜๋Š” 17์ข… ํ˜น์€ 18์ข…์ด๋‹ค.')
```

```ruby
# 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](https://docs.ncloud.com/en/sens/sens-1-3.html#register-view-caller-id).

### 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](https://docs.ncloud.com/en/sens/sens-1-3.html#send-sms-messages)

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](https://docs.ncloud.com/en/sens/sens-1-3.html#send-lms-messages)

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](https://opensource.org/licenses/MIT).