Class: NumbersApi

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

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_secret) ⇒ NumbersApi

apiInvoker = APIInvoker



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

#config_swaggerObject



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

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

#get_number(number = nil, opts = {}) ⇒ Object

Get detailed information about a response number you have leased.

Parameters:

  • number (defaults to: nil)

    The virtual number to retrieve

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/numbers_api.rb', line 36

def get_number (number = nil, opts={})
  query_param_keys = [:number]
  headerParams = {}

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

  #resource path
  path = "/get-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(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#get_numbers(filter = nil, page = nil, max = nil, opts = {}) ⇒ Object

Get a list of numbers either leased by you or available to be leased.

Parameters:

  • filter (defaults to: nil)

    Possible values are owned and available

  • page (defaults to: nil)

    Page number, for pagination

  • max (defaults to: nil)

    Maximum results returned per page

Returns:

  • void



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
135
136
# File 'lib/numbers_api.rb', line 89

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

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

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

#lease_number(number = nil, opts = {}) ⇒ Object

Lease a dedicated virtual number

Parameters:

  • number (defaults to: nil)

    The virtual number to lease. Omit this field to be given a random number. Use get-numbers to find out which numbers are currently available.

Returns:

  • void



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/numbers_api.rb', line 142

def lease_number (number = nil, opts={})
  query_param_keys = [:number]
  headerParams = {}

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

  #resource path
  path = "/lease-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(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end