Class: KeywordsApi

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

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_secret) ⇒ KeywordsApi

apiInvoker = APIInvoker



7
8
9
10
11
12
13
14
15
# File 'lib/keywords_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

#add_keyword(keyword = nil, number = nil, reference = nil, list_id = nil, welcome_message = nil, members_message = nil, activate = nil, forward_url = nil, forward_email = nil, forward_sms = nil, opts = {}) ⇒ Object

Add a keyword to an existing virtual number

Parameters:

  • keyword (defaults to: nil)

    The first word of a text message

  • number (defaults to: nil)

    The dedicated virtual number that the keyword belongs to

  • reference (defaults to: nil)

    Your own reference (up to 100 characters)

  • list_id (defaults to: nil)

    ID of a list to add respondents to, list ID's can be found in the title of a list or in the list page URL

  • welcome_message (defaults to: nil)

    SMS message to send to new members

  • members_message (defaults to: nil)

    SMS message to existing members

  • activate (defaults to: nil)

    Whether to make the keyword active immediately.

  • forward_url (defaults to: nil)

    Forward messages to a URL

  • forward_email (defaults to: nil)

    Forward messages to a set of email addresses

  • forward_sms (defaults to: nil)

    Forward messages to a set of msisdns

Returns:

  • void



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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/keywords_api.rb', line 45

def add_keyword (keyword = nil, number = nil, reference = nil, list_id = nil, welcome_message = nil, members_message = nil, activate = nil, forward_url = nil, forward_email = nil, forward_sms = nil, opts={})
  query_param_keys = [:keyword,:number,:reference,:list_id,:welcome_message,:members_message,:activate,:forward_url,:forward_email,:forward_sms]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'keyword' => keyword,
    :'number' => number,
    :'reference' => reference,
    :'list_id' => list_id,
    :'welcome_message' => welcome_message,
    :'members_message' => members_message,
    :'activate' => activate,
    :'forward_url' => forward_url,
    :'forward_email' => forward_email,
    :'forward_sms' => forward_sms
    
  }.merge(opts)

  #resource path
  path = "/add-keyword.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

#config_swaggerObject



22
23
24
25
26
27
28
29
# File 'lib/keywords_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/keywords_api.rb', line 17

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

#edit_keyword(keyword = nil, number = nil, reference = nil, list_id = nil, welcome_message = nil, members_message = nil, activate = nil, forward_url = nil, forward_email = nil, forward_sms = nil, opts = {}) ⇒ Object

Edit an existing keyword.

Parameters:

  • keyword (defaults to: nil)

    The first word of a text message

  • number (defaults to: nil)

    The dedicated virtual number that the keyword belongs to

  • reference (defaults to: nil)

    Your own reference (up to 100 characters)

  • list_id (defaults to: nil)

    ID of a list to add respondents to, list ID's can be found in the title of a list or in the list page URL

  • welcome_message (defaults to: nil)

    SMS message to send to new members

  • members_message (defaults to: nil)

    SMS message to existing members

  • activate (defaults to: nil)

    Whether to make the keyword active immediately.

  • forward_url (defaults to: nil)

    Forward messages to a URL

  • forward_email (defaults to: nil)

    Forward messages to a set of email addresses

  • forward_sms (defaults to: nil)

    Forward messages to a set of msisdns

Returns:

  • void



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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
# File 'lib/keywords_api.rb', line 114

def edit_keyword (keyword = nil, number = nil, reference = nil, list_id = nil, welcome_message = nil, members_message = nil, activate = nil, forward_url = nil, forward_email = nil, forward_sms = nil, opts={})
  query_param_keys = [:keyword,:number,:reference,:list_id,:welcome_message,:members_message,:activate,:forward_url,:forward_email,:forward_sms]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'keyword' => keyword,
    :'number' => number,
    :'reference' => reference,
    :'list_id' => list_id,
    :'welcome_message' => welcome_message,
    :'members_message' => members_message,
    :'activate' => activate,
    :'forward_url' => forward_url,
    :'forward_email' => forward_email,
    :'forward_sms' => forward_sms
    
  }.merge(opts)

  #resource path
  path = "/edit-keyword.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

#get_keywords(number = nil, page = nil, max = nil, opts = {}) ⇒ Object

Get a list of existing keywords.

Parameters:

  • number (defaults to: nil)

    Filter the list by virtual number

  • page (defaults to: nil)

    Page number, for pagination

  • max (defaults to: nil)

    Maximum results returned per page

Returns:

  • void



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/keywords_api.rb', line 176

def get_keywords (number = nil, page = nil, max = nil, opts={})
  query_param_keys = [:number,:page,:max]
  headerParams = {}

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

  #resource path
  path = "/get-keywords.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