Class: SmsApi

Inherits:
Object show all
Defined in:
lib/sms_api.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_secret) ⇒ SmsApi

apiInvoker = APIInvoker



7
8
9
10
11
12
13
14
15
# File 'lib/sms_api.rb', line 7

def initialize(api_key, api_secret)
  @api_key = api_key
  @api_secret = api_secret
  @sms_api = SmsApi

  @api_key_secret = create_api_key_secret()

  config_swagger()
end

Instance Method Details

#cancel_sms(id = nil, opts = {}) ⇒ Object

Cancel a message you have scheduled to be sent in the future.

Parameters:

  • id (defaults to: nil)

    Message ID

Returns:

  • void



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/sms_api.rb', line 36

def cancel_sms (id = nil, opts={})
  query_param_keys = [:id]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'id' => id
    
  }.merge(opts)

  #resource path
  path = "/cancel-sms.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#config_swaggerObject



22
23
24
25
26
27
28
29
# File 'lib/sms_api.rb', line 22

def config_swagger()
  Swagger.configure do |config|
    config.host = "https://api.transmitsms.com/".gsub("http://", "").gsub("https://", "").gsub("/", "")
    config.base_path = "/"
    config.format = "x-www-form-urlencoded"
    config.camelize_params = false
  end
end

#create_api_key_secretObject



17
18
19
20
# File 'lib/sms_api.rb', line 17

def create_api_key_secret()
  api_key_secret = Base64.strict_encode64("#{@api_key}:#{@api_secret}")
  "Basic #{api_key_secret}"
end

#format_number(msisdn = nil, countrycode = nil, opts = {}) ⇒ Object

Format and validate a given number.

Parameters:

  • msisdn (defaults to: nil)

    The number to check

  • countrycode (defaults to: nil)

    2 Letter countrycode to validate number against

Returns:

  • void



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/sms_api.rb', line 88

def format_number (msisdn = nil, countrycode = nil, opts={})
  query_param_keys = [:msisdn,:countrycode]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'msisdn' => msisdn,
    :'countrycode' => countrycode
    
  }.merge(opts)

  #resource path
  path = "/format-number.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#get_message_log(message_id = nil, mobile = nil, opts = {}) ⇒ Object

get-message-log Format and validate a given number.

Parameters:

  • message_id (defaults to: nil)

    The message to retrieve

  • mobile (defaults to: nil)

    The mobile used in message

Returns:

  • void



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/sms_api.rb', line 141

def get_message_log (message_id = nil, mobile = nil, opts={})
  query_param_keys = [:message_id,:mobile]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'message_id' => message_id,
    :'mobile' => mobile
    
  }.merge(opts)

  #resource path
  path = "/get-message-log.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#get_sms(message_id = nil, opts = {}) ⇒ Object

Get information about a message you have sent.

Parameters:

  • message_id (defaults to: nil)

    Message ID

Returns:

  • void



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/sms_api.rb', line 317

def get_sms (message_id = nil, opts={})
  query_param_keys = [:message_id]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'message_id' => message_id
    
  }.merge(opts)

  #resource path
  path = "/get-sms.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#get_sms_responses(message_id = nil, keyword_id = nil, keyword = nil, number = nil, msisdn = nil, page = nil, max = nil, include_original = nil, opts = {}) ⇒ Object

Pick up responses to messages you have sent. Filter by keyword or for just one phone number.

Parameters:

  • message_id (defaults to: nil)

    Message ID

  • keyword_id (defaults to: nil)

    Keyword ID

  • keyword (defaults to: nil)

    Keyword

  • number (defaults to: nil)

    Filter results by response number

  • msisdn (defaults to: nil)

    Filter results by a particular mobile number

  • page (defaults to: nil)

    Page number, for pagination

  • max (defaults to: nil)

    Maximum results returned per page

  • include_original (defaults to: nil)

    include text of original message

Returns:

  • void



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/sms_api.rb', line 200

def get_sms_responses (message_id = nil, keyword_id = nil, keyword = nil, number = nil, msisdn = nil, page = nil, max = nil, include_original = nil, opts={})
  query_param_keys = [:message_id,:keyword_id,:keyword,:number,:msisdn,:page,:max,:include_original]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'message_id' => message_id,
    :'keyword_id' => keyword_id,
    :'keyword' => keyword,
    :'number' => number,
    :'msisdn' => msisdn,
    :'page' => page,
    :'max' => max,
    :'include_original' => include_original
    
  }.merge(opts)

  #resource path
  path = "/get-sms-responses.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#get_sms_sent(message_id = nil, optouts = nil, page = nil, max = nil, delivery = nil, opts = {}) ⇒ Object

Get a list of recipients from a message send. Get up to date information such as opt-out status and delivery status.

Parameters:

  • message_id (defaults to: nil)

    Message ID's are made up of digits

  • optouts (defaults to: nil)

    Whether to include optouts. Valid options are: only - only get optouts, omit - do not get optouts, include - get all recipients including optouts (default)

  • page (defaults to: nil)

    Page number, for pagination

  • max (defaults to: nil)

    Maximum results returned per page

  • delivery (defaults to: nil)

    Only show messages with requested delivery status. Valid options are: delivered - only show delivered messages, failed - only show failed messages, pending - only show pending messages

Returns:

  • void



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/sms_api.rb', line 262

def get_sms_sent (message_id = nil, optouts = nil, page = nil, max = nil, delivery = nil, opts={})
  query_param_keys = [:message_id,:optouts,:page,:max,:delivery]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'message_id' => message_id,
    :'optouts' => optouts,
    :'page' => page,
    :'max' => max,
    :'delivery' => delivery
    
  }.merge(opts)

  #resource path
  path = "/get-sms-sent.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#get_user_sms_responses(start = nil, enddate = nil, page = nil, max = nil, keywords = nil, include_original = nil, opts = {}) ⇒ Object

Pick up responses to messages you have sent. Instead of setting message ID, you should provide a time frame.

Parameters:

  • start (defaults to: nil)

    A timestamp to start the report from

  • enddate (defaults to: nil)

    A timestamp to end the report at

  • page (defaults to: nil)

    Page number, for pagination

  • max (defaults to: nil)

    Maximum results returned per page

  • keywords (defaults to: nil)

    Filter if keyword responses should be included. Can be: ‘only’ - only keyword responses will be included‘omit’ - only regular campaign responses will be included. ‘both’ - both keyword and campaign responses will be included (default)

  • include_original (defaults to: nil)

    include text of original message

Returns:

  • void



373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/sms_api.rb', line 373

def get_user_sms_responses (start = nil, enddate = nil, page = nil, max = nil, keywords = nil, include_original = nil, opts={})
  query_param_keys = [:start,:enddate,:page,:max,:keywords,:include_original]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'start' => start,
    :'enddate' => enddate,
    :'page' => page,
    :'max' => max,
    :'keywords' => keywords,
    :'include_original' => include_original
    
  }.merge(opts)

  #resource path
  path = "/get-user-sms-responses.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#message_reply(message = nil, from = nil, to = nil, opts = {}) ⇒ Object

Reply to a message message-reply

Parameters:

  • message (defaults to: nil)

    Message text

  • from (defaults to: nil)

    Set the alphanumeric Caller ID

  • to (defaults to: nil)

    Number or set of up to 10,000 numbers to send the SMS to. If your number set has some invalid numbers, they won’t cause validation error, but will be returned as ‘fails’ parameter of the response (see example 3).

Returns:

  • void



431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'lib/sms_api.rb', line 431

def message_reply (message = nil, from = nil, to = nil, opts={})
  query_param_keys = [:message,:from,:to]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'message' => message,
    :'from' => from,
    :'to' => to
    
  }.merge(opts)

  #resource path
  path = "/message-reply.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#send(message = nil, to = nil, from = nil, send_at = nil, list_id = nil, dlr_callback = nil, reply_callback = nil, validity = nil, replies_to_email = nil, from_shared = nil, countrycode = nil, opts = {}) ⇒ Object

Sends sms to the given number or list id

Parameters:

  • message (defaults to: nil)

    Message text

  • to (defaults to: nil)

    Number or set of up to 10,000 numbers to send the SMS to. If your number set has some invalid numbers, they won’t cause validation error, but will be returned as ‘fails’ parameter of the response (see example 3).

  • from (defaults to: nil)

    Set the alphanumeric Caller ID

  • send_at (defaults to: nil)

    A time in the future to send the message

  • list_id (defaults to: nil)

    This ID is the numerical reference to one of your recipient lists

  • dlr_callback (defaults to: nil)

    A URL on your system which we can call to notify you of Delivery Receipts. If required, this Parameter can be different for each message sent and will take precedence over the DLR Callback URL supplied by you in the API Settings.

  • reply_callback (defaults to: nil)

    A URL on your system which we can call to notify you of incoming messages. If required, this parameter can be different and will take precedence over the Reply Callback URL supplied by you on the API Settings.

  • validity (defaults to: nil)

    Specify the maximum time to attempt to deliver. In minutes, 0 (zero) implies no limit.

  • replies_to_email (defaults to: nil)

    Specify an email address to send responses to this message. NOTE: specified email must be authorised to send messages via add-email or in your account under the 'Email SMS' section.

  • from_shared (defaults to: nil)

    Forces sending via the shared number when you have virtual numbers

  • countrycode (defaults to: nil)

    Formats the numbers given in to as internation format for this 2 letter country code.

Returns:

  • void



494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'lib/sms_api.rb', line 494

def send (message = nil, to = nil, from = nil, send_at = nil, list_id = nil, dlr_callback = nil, reply_callback = nil, validity = nil, replies_to_email = nil, from_shared = nil, countrycode = nil, opts={})
  query_param_keys = [:message,:to,:from,:send_at,:list_id,:dlr_callback,:reply_callback,:validity,:replies_to_email,:from_shared,:countrycode]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'message' => message,
    :'to' => to,
    :'from' => from,
    :'send_at' => send_at,
    :'list_id' => list_id,
    :'dlr_callback' => dlr_callback,
    :'reply_callback' => reply_callback,
    :'validity' => validity,
    :'replies_to_email' => replies_to_email,
    :'from_shared' => from_shared,
    :'countrycode' => countrycode
    
  }.merge(opts)

  #resource path
  path = "/send-sms.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end