Class: Cellsynt
- Inherits:
-
Object
- Object
- Cellsynt
- Defined in:
- lib/cellsynt.rb
Overview
Object for interacting with the api
Constant Summary collapse
- SMS_CHAR_LIMIT =
160- SMS_CONCAT_CHAR_LIMIT =
153- SMS_CONCAT_HARD_LIMIT =
153 * 6
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
Instance Method Summary collapse
- #adjust_concat(message) ⇒ Object
- #format_destination(number) ⇒ Object
- #format_originator(number) ⇒ Object
-
#initialize(username = nil, password = nil) ⇒ Cellsynt
constructor
A new instance of Cellsynt.
- #send ⇒ Object
Constructor Details
#initialize(username = nil, password = nil) ⇒ Cellsynt
Returns a new instance of Cellsynt.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cellsynt.rb', line 12 def initialize(username = nil, password = nil) @endpoint = 'https://se-1.cellsynt.net/sms.php' @auth = { username: username || ENV['cellsyntUser'], password: password || ENV['cellsyntPass'] } @config = { destination: nil, allowconcat: nil, # Values: 1 - 6 originator: nil, # Values: numeric, shortcode & alpha expiry: nil, # Value: Unix timestamp text: nil, # Type: String udh: nil, # Type: Hex originatortype: 'numeric', # Values: numeric, shortcode & alpha charset: 'UTF-8', # Values: ISO-8859-1 & UTF-8, Standard: ISO-8859-1 type: 'text', # Values: text, binary & unicode, Standard: text flash: false, # Values: true, false class: 1, # Values: 0 - 3, Standard: 1 pid: 00 # Type: Hex, Standard: 00 }.compact end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
10 11 12 |
# File 'lib/cellsynt.rb', line 10 def config @config end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
10 11 12 |
# File 'lib/cellsynt.rb', line 10 def endpoint @endpoint end |
Instance Method Details
#adjust_concat(message) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cellsynt.rb', line 37 def adjust_concat() return nil if .chars.length > SMS_CONCAT_HARD_LIMIT if .chars.length > SMS_CHAR_LIMIT = .chars.length (1..6).each do |index| if (index * SMS_CONCAT_CHAR_LIMIT) >= return index end end end end |
#format_destination(number) ⇒ Object
51 52 53 54 |
# File 'lib/cellsynt.rb', line 51 def format_destination(number) number.delete_prefix('0') number.dup.prepend('0046') end |
#format_originator(number) ⇒ Object
56 57 58 59 |
# File 'lib/cellsynt.rb', line 56 def format_originator(number) number.delete_prefix('0') number.dup.prepend('46') end |
#send ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cellsynt.rb', line 61 def send uri = URI(@endpoint) req = Net::HTTP::Post.new(uri) config[:allowconcat] = adjust_concat(@config[:text]) config[:destination] = format_destination(@config[:destination]) config[:originator] = format_originator(@config[:originator]) form_data = @auth.merge(@config) req.set_form_data(form_data) res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, timeout: 300) do |packet| packet.request(req) end res.body end |