bandwidth-sdk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +28 -0
  3. data/README.md +1 -0
  4. data/lib/bandwidth.rb +37 -0
  5. data/lib/bandwidth/api_helper.rb +280 -0
  6. data/lib/bandwidth/client.rb +32 -0
  7. data/lib/bandwidth/configuration.rb +111 -0
  8. data/lib/bandwidth/exceptions/api_exception.rb +20 -0
  9. data/lib/bandwidth/http/api_response.rb +36 -0
  10. data/lib/bandwidth/http/auth/voice_basic_auth.rb +22 -0
  11. data/lib/bandwidth/http/faraday_client.rb +64 -0
  12. data/lib/bandwidth/http/http_call_back.rb +24 -0
  13. data/lib/bandwidth/http/http_client.rb +104 -0
  14. data/lib/bandwidth/http/http_method_enum.rb +13 -0
  15. data/lib/bandwidth/http/http_request.rb +50 -0
  16. data/lib/bandwidth/http/http_response.rb +29 -0
  17. data/lib/bandwidth/models/base_model.rb +36 -0
  18. data/lib/bandwidth/voice_lib/voice.rb +23 -0
  19. data/lib/bandwidth/voice_lib/voice/bxml/bxml.rb +36 -0
  20. data/lib/bandwidth/voice_lib/voice/bxml/verbs/forward.rb +19 -0
  21. data/lib/bandwidth/voice_lib/voice/bxml/verbs/gather.rb +37 -0
  22. data/lib/bandwidth/voice_lib/voice/bxml/verbs/hangup.rb +14 -0
  23. data/lib/bandwidth/voice_lib/voice/bxml/verbs/pause.rb +15 -0
  24. data/lib/bandwidth/voice_lib/voice/bxml/verbs/phone_number.rb +18 -0
  25. data/lib/bandwidth/voice_lib/voice/bxml/verbs/play_audio.rb +17 -0
  26. data/lib/bandwidth/voice_lib/voice/bxml/verbs/redirect.rb +20 -0
  27. data/lib/bandwidth/voice_lib/voice/bxml/verbs/send_dtmf.rb +12 -0
  28. data/lib/bandwidth/voice_lib/voice/bxml/verbs/speak_sentence.rb +18 -0
  29. data/lib/bandwidth/voice_lib/voice/bxml/verbs/transfer.rb +37 -0
  30. data/lib/bandwidth/voice_lib/voice/bxml/verbs/xml_verb.rb +26 -0
  31. data/lib/bandwidth/voice_lib/voice/client.rb +36 -0
  32. data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +49 -0
  33. data/lib/bandwidth/voice_lib/voice/controllers/calls_controller.rb +88 -0
  34. data/lib/bandwidth/voice_lib/voice/models/answer_method_enum.rb +35 -0
  35. data/lib/bandwidth/voice_lib/voice/models/api_call_response.rb +116 -0
  36. data/lib/bandwidth/voice_lib/voice/models/api_create_call_request.rb +125 -0
  37. data/lib/bandwidth/voice_lib/voice/models/api_modify_call_request.rb +80 -0
  38. data/lib/bandwidth/voice_lib/voice/models/bandwidth_callback_message_voice.rb +98 -0
  39. data/lib/bandwidth/voice_lib/voice/models/disconnect_method_enum.rb +35 -0
  40. data/lib/bandwidth/voice_lib/voice/models/redirect_method_enum.rb +35 -0
  41. data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +17 -0
  42. metadata +181 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dda3a64e6345a2b4b57ff3e2ef4925b1aa325dd6
4
+ data.tar.gz: 579af4d2e8973ebf0577bcb86be0a1cea0186dcc
5
+ SHA512:
6
+ metadata.gz: ec54ff2a4c0da9ca4e0da7125ef1ea4eb5ba480eccbb2bdfb53ae5336a18ddb177d1a8e4416f2f4db01fafc257fa9b2205dd797f2c6f8e77148b021416b2d906
7
+ data.tar.gz: da2b2fed5ae62674e1b6cfdd47df80157f599d61c7abfb139e07b1bce1f38944c15b5d296e42aa390113461fff47d3f91e2de2e663807eea6afcfa051ad27102
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ License:
2
+ ========
3
+ The MIT License (MIT)
4
+ http://opensource.org/licenses/MIT
5
+
6
+ Copyright (c) 2014 - 2016 APIMATIC Limited
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
25
+
26
+ Trade Mark:
27
+ ==========
28
+ APIMATIC is a trade mark for APIMATIC Limited
@@ -0,0 +1 @@
1
+ # Bandwidth's Ruby SDK
@@ -0,0 +1,37 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ require 'date'
7
+ require 'json'
8
+ require 'faraday'
9
+ require 'certifi'
10
+ require 'logging'
11
+
12
+ require_relative 'bandwidth/api_helper.rb'
13
+ require_relative 'bandwidth/client.rb'
14
+
15
+ # Http
16
+ require_relative 'bandwidth/http/api_response.rb'
17
+ require_relative 'bandwidth/http/http_call_back.rb'
18
+ require_relative 'bandwidth/http/http_client.rb'
19
+ require_relative 'bandwidth/http/faraday_client.rb'
20
+ require_relative 'bandwidth/http/http_method_enum.rb'
21
+ require_relative 'bandwidth/http/http_request.rb'
22
+ require_relative 'bandwidth/http/http_response.rb'
23
+
24
+ # Models
25
+ require_relative 'bandwidth/models/base_model.rb'
26
+
27
+ # Exceptions
28
+ require_relative 'bandwidth/exceptions/api_exception.rb'
29
+
30
+ require_relative 'bandwidth/configuration.rb'
31
+
32
+ # Namespaces
33
+ require_relative 'bandwidth/voice_lib/voice'
34
+ require_relative 'bandwidth/http/auth/voice_basic_auth.rb'
35
+
36
+
37
+ # Controllers
@@ -0,0 +1,280 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ # API utility class
8
+ class APIHelper
9
+ # Serializes an array parameter (creates key value pairs).
10
+ # @param [String] The name of the parameter.
11
+ # @param [Array] The value of the parameter.
12
+ # @param [String] The format of the serialization.
13
+ def self.serialize_array(key, array, formatting: 'indexed')
14
+ tuples = []
15
+
16
+ if formatting == 'unindexed'
17
+ tuples += array.map { |element| ["#{key}[]", element] }
18
+ elsif formatting == 'indexed'
19
+ tuples += array.map.with_index do |element, index|
20
+ ["#{key}[#{index}]", element]
21
+ end
22
+ elsif formatting == 'plain'
23
+ tuples += array.map { |element| [key, element] }
24
+ else
25
+ raise ArgumentError, 'Invalid format provided.'
26
+ end
27
+ tuples
28
+ end
29
+
30
+ # Replaces template parameters in the given url.
31
+ # @param [String] The query string builder to replace the template
32
+ # parameters.
33
+ # @param [Hash] The parameters to replace in the url.
34
+ def self.append_url_with_template_parameters(query_builder, parameters)
35
+ # perform parameter validation
36
+ unless query_builder.instance_of? String
37
+ raise ArgumentError, 'Given value for parameter \"query_builder\" is
38
+ invalid.'
39
+ end
40
+
41
+ # Return if there are no parameters to replace.
42
+ return query_builder if parameters.nil?
43
+
44
+ # Iterate and append parameters.
45
+ parameters.each do |key, value|
46
+ replace_value = ''
47
+
48
+ if value.nil?
49
+ replace_value = ''
50
+ elsif value.instance_of? Array
51
+ value.map! { |element| CGI.escape(element.to_s) }
52
+ replace_value = value.join('/')
53
+ else
54
+ replace_value = CGI.escape(value.to_s)
55
+ end
56
+
57
+ # Find the template parameter and replace it with its value.
58
+ query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
59
+ end
60
+ query_builder
61
+ end
62
+
63
+ # Appends the given set of parameters to the given query string.
64
+ # @param [String] The query string builder to add the query parameters to.
65
+ # @param [Hash] The parameters to append.
66
+ # @param [String] The format of array parameter serialization.
67
+ def self.append_url_with_query_parameters(query_builder, parameters,
68
+ array_serialization: 'indexed')
69
+ # Perform parameter validation.
70
+ unless query_builder.instance_of? String
71
+ raise ArgumentError, 'Given value for parameter \"query_builder\"
72
+ is invalid.'
73
+ end
74
+
75
+ # Return if there are no parameters to replace.
76
+ return query_builder if parameters.nil?
77
+
78
+ parameters.each do |key, value|
79
+ seperator = query_builder.include?('?') ? '&' : '?'
80
+ unless value.nil?
81
+ if value.instance_of? Array
82
+ value.compact!
83
+ query_builder += if array_serialization == 'csv'
84
+ "#{seperator}#{key}=#{value.map do |element|
85
+ CGI.escape(element.to_s)
86
+ end.join(',')}"
87
+ elsif array_serialization == 'psv'
88
+ "#{seperator}#{key}=#{value.map do |element|
89
+ CGI.escape(element.to_s)
90
+ end.join('|')}"
91
+ elsif array_serialization == 'tsv'
92
+ "#{seperator}#{key}=#{value.map do |element|
93
+ CGI.escape(element.to_s)
94
+ end.join("\t")}"
95
+ else
96
+ "#{seperator}#{APIHelper.serialize_array(
97
+ key, value, formatting: array_serialization
98
+ ).map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }
99
+ .join('&')}"
100
+ end
101
+ else
102
+ query_builder += "#{seperator}#{key}=#{CGI.escape(value.to_s)}"
103
+ end
104
+ end
105
+ end
106
+ query_builder
107
+ end
108
+
109
+ # Validates and processes the given Url.
110
+ # @param [String] The given Url to process.
111
+ # @return [String] Pre-processed Url as string.
112
+ def self.clean_url(url)
113
+ # Perform parameter validation.
114
+ raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
115
+
116
+ # Ensure that the urls are absolute.
117
+ matches = url.match(%r{^(https?:\/\/[^\/]+)})
118
+ raise ArgumentError, 'Invalid Url format.' if matches.nil?
119
+
120
+ # Get the http protocol match.
121
+ protocol = matches[1]
122
+
123
+ # Check if parameters exist.
124
+ index = url.index('?')
125
+
126
+ # Remove redundant forward slashes.
127
+ query = url[protocol.length...(!index.nil? ? index : url.length)]
128
+ query.gsub!(%r{\/\/+}, '/')
129
+
130
+ # Get the parameters.
131
+ parameters = !index.nil? ? url[url.index('?')...url.length] : ''
132
+
133
+ # Return processed url.
134
+ protocol + query + parameters
135
+ end
136
+
137
+ # Parses JSON string.
138
+ # @param [String] A JSON string.
139
+ def self.json_deserialize(json)
140
+ return JSON.parse(json)
141
+ rescue StandardError
142
+ raise TypeError, 'Server responded with invalid JSON.'
143
+ end
144
+
145
+ # Removes elements with empty values from a hash.
146
+ # @param [Hash] The hash to clean.
147
+ def self.clean_hash(hash)
148
+ hash.delete_if { |_key, value| value.to_s.strip.empty? }
149
+ end
150
+
151
+ # Form encodes a hash of parameters.
152
+ # @param [Hash] The hash of parameters to encode.
153
+ # @return [Hash] A hash with the same parameters form encoded.
154
+ def self.form_encode_parameters(form_parameters,
155
+ array_serialization: 'indexed')
156
+ encoded = {}
157
+ form_parameters.each do |key, value|
158
+ encoded.merge!(APIHelper.form_encode(value, key, formatting:
159
+ array_serialization))
160
+ end
161
+ encoded
162
+ end
163
+
164
+ def self.custom_merge(a, b)
165
+ x = {}
166
+ a.each do |key, value_a|
167
+ b.each do |k, value_b|
168
+ next unless key == k
169
+ x[k] = []
170
+ if value_a.instance_of? Array
171
+ value_a.each do |v|
172
+ x[k].push(v)
173
+ end
174
+ else
175
+ x[k].push(value_a)
176
+ end
177
+ if value_b.instance_of? Array
178
+ value_b.each do |v|
179
+ x[k].push(v)
180
+ end
181
+ else
182
+ x[k].push(value_b)
183
+ end
184
+ a.delete(k)
185
+ b.delete(k)
186
+ end
187
+ end
188
+ x.merge!(a)
189
+ x.merge!(b)
190
+ x
191
+ end
192
+
193
+ # Form encodes an object.
194
+ # @param [Dynamic] An object to form encode.
195
+ # @param [String] The name of the object.
196
+ # @return [Hash] A form encoded representation of the object in the form
197
+ # of a hash.
198
+ def self.form_encode(obj, instance_name, formatting: 'indexed')
199
+ retval = {}
200
+
201
+ serializable_types = [String, Numeric, TrueClass,
202
+ FalseClass, Date, DateTime]
203
+
204
+ # If this is a structure, resolve it's field names.
205
+ obj = obj.to_hash if obj.is_a? BaseModel
206
+
207
+ # Create a form encoded hash for this object.
208
+ if obj.nil?
209
+ nil
210
+ elsif obj.instance_of? Array
211
+ if formatting == 'indexed'
212
+ obj.each_with_index do |value, index|
213
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
214
+ index.to_s + ']'))
215
+ end
216
+ elsif serializable_types.map { |x| obj[0].is_a? x }.any?
217
+ obj.each do |value|
218
+ abc = if formatting == 'unindexed'
219
+ APIHelper.form_encode(value, instance_name + '[]',
220
+ formatting: formatting)
221
+ else
222
+ APIHelper.form_encode(value, instance_name,
223
+ formatting: formatting)
224
+ end
225
+ retval = APIHelper.custom_merge(retval, abc)
226
+ end
227
+ else
228
+ obj.each_with_index do |value, index|
229
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
230
+ index.to_s + ']', formatting: formatting))
231
+ end
232
+ end
233
+ elsif obj.instance_of? Hash
234
+ obj.each do |key, value|
235
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
236
+ key.to_s + ']', formatting: formatting))
237
+ end
238
+ else
239
+ retval[instance_name] = obj
240
+ end
241
+ retval
242
+ end
243
+
244
+ # Retrieves a field from a Hash/Array based on an Array of keys/indexes
245
+ # @param [Hash, Array] The hash to extract data from
246
+ # @param [Array<String, Integer>] The keys/indexes to use
247
+ # @return [Object] The extracted value
248
+ def self.map_response(obj, keys)
249
+ val = obj
250
+ begin
251
+ keys.each do |key|
252
+ val = if val.is_a? Array
253
+ if key.to_i.to_s == key
254
+ val[key.to_i]
255
+ else
256
+ val = nil
257
+ end
258
+ else
259
+ val.fetch(key.to_sym)
260
+ end
261
+ end
262
+ rescue NoMethodError, TypeError, IndexError
263
+ val = nil
264
+ end
265
+ val
266
+ end
267
+
268
+ # Safely converts a string into an rfc3339 DateTime object
269
+ # @param [String] The datetime string
270
+ # @return [DateTime] A DateTime object of rfc3339 format
271
+ def self.rfc3339(date_time)
272
+ # missing timezone information
273
+ if date_time.end_with?('Z') || date_time.index('+')
274
+ DateTime.rfc3339(date_time)
275
+ else
276
+ DateTime.rfc3339(date_time + 'Z')
277
+ end
278
+ end
279
+ end
280
+ end
@@ -0,0 +1,32 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ # bandwidth client class.
8
+ class Client
9
+ attr_reader :config
10
+ # Access to voice_client controller.
11
+ # @return [Voice::Client] Returns the client instance.
12
+ def voice_client
13
+ @voice_client ||= Voice::Client.new(config: config)
14
+ end
15
+
16
+ def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
17
+ backoff_factor: 1, environment: Environment::PRODUCTION,
18
+ voice_basic_auth_user_name: 'TODO: Replace',
19
+ voice_basic_auth_password: 'TODO: Replace', config: nil)
20
+ @config = if config.nil?
21
+ Configuration.new(timeout: timeout, max_retries: max_retries,
22
+ retry_interval: retry_interval,
23
+ backoff_factor: backoff_factor,
24
+ environment: environment,
25
+ voice_basic_auth_user_name: voice_basic_auth_user_name,
26
+ voice_basic_auth_password: voice_basic_auth_password)
27
+ else
28
+ config
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,111 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ # An enum for SDK environments.
8
+ class Environment
9
+ ENVIRONMENT = [
10
+ PRODUCTION = 'production'.freeze
11
+ ].freeze
12
+ end
13
+
14
+ # An enum for API servers.
15
+ class Server
16
+ SERVER = [
17
+ DEFAULT = 'default'.freeze,
18
+ VOICEDEFAULT = 'VoiceDefault'.freeze
19
+ ].freeze
20
+ end
21
+
22
+ # All configuration including auth info and base URI for the API access
23
+ # are configured in this class.
24
+ class Configuration
25
+ # The attribute readers for properties.
26
+ attr_reader :http_client
27
+ attr_reader :timeout
28
+ attr_reader :max_retries
29
+ attr_reader :retry_interval
30
+ attr_reader :backoff_factor
31
+ attr_reader :environment
32
+ attr_reader :voice_basic_auth_user_name
33
+ attr_reader :voice_basic_auth_password
34
+
35
+ class << self
36
+ attr_reader :environments
37
+ end
38
+
39
+ def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
40
+ backoff_factor: 1, environment: Environment::PRODUCTION,
41
+ voice_basic_auth_user_name: 'TODO: Replace',
42
+ voice_basic_auth_password: 'TODO: Replace')
43
+ # The value to use for connection timeout
44
+ @timeout = timeout
45
+
46
+ # The number of times to retry an endpoint call if it fails
47
+ @max_retries = max_retries
48
+
49
+ # Pause in seconds between retries
50
+ @retry_interval = retry_interval
51
+
52
+ # The amount to multiply each successive retry's interval amount
53
+ # by in order to provide backoff
54
+ @backoff_factor = backoff_factor
55
+
56
+ # Current API environment
57
+ @environment = environment
58
+
59
+ # The username to use with basic authentication
60
+ @voice_basic_auth_user_name = voice_basic_auth_user_name
61
+
62
+ # The password to use with basic authentication
63
+ @voice_basic_auth_password = voice_basic_auth_password
64
+
65
+ # The Http Client to use for making requests.
66
+ @http_client = create_http_client
67
+ end
68
+
69
+ def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
70
+ backoff_factor: nil, environment: nil,
71
+ voice_basic_auth_user_name: nil,
72
+ voice_basic_auth_password: nil)
73
+ timeout ||= self.timeout
74
+ max_retries ||= self.max_retries
75
+ retry_interval ||= self.retry_interval
76
+ backoff_factor ||= self.backoff_factor
77
+ environment ||= self.environment
78
+ voice_basic_auth_user_name ||= self.voice_basic_auth_user_name
79
+ voice_basic_auth_password ||= self.voice_basic_auth_password
80
+
81
+ Configuration.new(timeout: timeout, max_retries: max_retries,
82
+ retry_interval: retry_interval,
83
+ backoff_factor: backoff_factor,
84
+ environment: environment,
85
+ voice_basic_auth_user_name: voice_basic_auth_user_name,
86
+ voice_basic_auth_password: voice_basic_auth_password)
87
+ end
88
+
89
+ def create_http_client
90
+ FaradayClient.new(timeout: timeout, max_retries: max_retries,
91
+ retry_interval: retry_interval,
92
+ backoff_factor: backoff_factor)
93
+ end
94
+
95
+ # All the environments the SDK can run in.
96
+ @environments = {
97
+ Environment::PRODUCTION => {
98
+ Server::DEFAULT => 'api.bandwidth.com',
99
+ Server::VOICEDEFAULT => 'https://voice.bandwidth.com'
100
+ }
101
+ }
102
+
103
+ # Generates the appropriate base URI for the environment and the server.
104
+ # @param [Configuration::Server] The server enum for which the base URI is
105
+ # required.
106
+ # @return [String] The base URI.
107
+ def get_base_uri(server = Server::DEFAULT)
108
+ self.class.environments[environment][server].clone
109
+ end
110
+ end
111
+ end