bandwidth-sdk 0.1.0 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +27 -27
  3. data/README.md +115 -1
  4. data/lib/bandwidth.rb +39 -37
  5. data/lib/bandwidth/api_helper.rb +280 -280
  6. data/lib/bandwidth/client.rb +41 -32
  7. data/lib/bandwidth/configuration.rb +130 -111
  8. data/lib/bandwidth/exceptions/api_exception.rb +20 -20
  9. data/lib/bandwidth/http/api_response.rb +36 -36
  10. data/lib/bandwidth/http/auth/messaging_basic_auth.rb +22 -0
  11. data/lib/bandwidth/http/auth/voice_basic_auth.rb +22 -22
  12. data/lib/bandwidth/http/faraday_client.rb +64 -64
  13. data/lib/bandwidth/http/http_call_back.rb +24 -24
  14. data/lib/bandwidth/http/http_client.rb +104 -104
  15. data/lib/bandwidth/http/http_method_enum.rb +13 -13
  16. data/lib/bandwidth/http/http_request.rb +50 -50
  17. data/lib/bandwidth/http/http_response.rb +29 -29
  18. data/lib/bandwidth/messaging_lib/messaging.rb +23 -0
  19. data/lib/bandwidth/messaging_lib/messaging/client.rb +40 -0
  20. data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +406 -0
  21. data/lib/bandwidth/messaging_lib/messaging/controllers/base_controller.rb +49 -0
  22. data/lib/bandwidth/messaging_lib/messaging/exceptions/generic_client_exception.rb +46 -0
  23. data/lib/bandwidth/messaging_lib/messaging/exceptions/path_client_exception.rb +49 -0
  24. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_callback_message.rb +80 -0
  25. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb +125 -0
  26. data/lib/bandwidth/messaging_lib/messaging/models/deferred_result.rb +44 -0
  27. data/lib/bandwidth/messaging_lib/messaging/models/field_error.rb +44 -0
  28. data/lib/bandwidth/messaging_lib/messaging/models/media.rb +123 -0
  29. data/lib/bandwidth/messaging_lib/messaging/models/message_request.rb +80 -0
  30. data/lib/bandwidth/messaging_lib/messaging/models/tag.rb +44 -0
  31. data/lib/bandwidth/models/base_model.rb +36 -36
  32. data/lib/bandwidth/voice_lib/bxml/bxml.rb +40 -0
  33. data/lib/bandwidth/voice_lib/bxml/verbs/forward.rb +19 -0
  34. data/lib/bandwidth/voice_lib/bxml/verbs/gather.rb +38 -0
  35. data/lib/bandwidth/voice_lib/bxml/verbs/hangup.rb +15 -0
  36. data/lib/bandwidth/voice_lib/bxml/verbs/pause.rb +16 -0
  37. data/lib/bandwidth/voice_lib/bxml/verbs/phone_number.rb +19 -0
  38. data/lib/bandwidth/voice_lib/bxml/verbs/play_audio.rb +18 -0
  39. data/lib/bandwidth/voice_lib/bxml/verbs/redirect.rb +21 -0
  40. data/lib/bandwidth/voice_lib/bxml/verbs/send_dtmf.rb +14 -0
  41. data/lib/bandwidth/voice_lib/bxml/verbs/speak_sentence.rb +19 -0
  42. data/lib/bandwidth/voice_lib/bxml/verbs/transfer.rb +38 -0
  43. data/lib/bandwidth/voice_lib/bxml/verbs/xml_verb.rb +27 -0
  44. data/lib/bandwidth/voice_lib/voice.rb +27 -23
  45. data/lib/bandwidth/voice_lib/voice/client.rb +40 -36
  46. data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +184 -0
  47. data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +49 -49
  48. data/lib/bandwidth/voice_lib/voice/exceptions/bandwidth_exception.rb +51 -0
  49. data/lib/bandwidth/voice_lib/voice/exceptions/bandwidth_not_found_exception.rb +49 -0
  50. data/lib/bandwidth/voice_lib/voice/exceptions/bandwidth_rate_limit_error_exception.rb +56 -0
  51. data/lib/bandwidth/voice_lib/voice/models/answer_method_enum.rb +35 -35
  52. data/lib/bandwidth/voice_lib/voice/models/api_call_response.rb +116 -116
  53. data/lib/bandwidth/voice_lib/voice/models/api_create_call_request.rb +125 -125
  54. data/lib/bandwidth/voice_lib/voice/models/api_modify_call_request.rb +80 -80
  55. data/lib/bandwidth/voice_lib/voice/models/bandwidth_callback_message_voice.rb +98 -98
  56. data/lib/bandwidth/voice_lib/voice/models/disconnect_method_enum.rb +35 -35
  57. data/lib/bandwidth/voice_lib/voice/models/field_error.rb +44 -0
  58. data/lib/bandwidth/voice_lib/voice/models/redirect_method_enum.rb +35 -35
  59. data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +17 -17
  60. metadata +36 -47
  61. data/lib/bandwidth/voice_lib/voice/bxml/bxml.rb +0 -36
  62. data/lib/bandwidth/voice_lib/voice/bxml/verbs/forward.rb +0 -19
  63. data/lib/bandwidth/voice_lib/voice/bxml/verbs/gather.rb +0 -37
  64. data/lib/bandwidth/voice_lib/voice/bxml/verbs/hangup.rb +0 -14
  65. data/lib/bandwidth/voice_lib/voice/bxml/verbs/pause.rb +0 -15
  66. data/lib/bandwidth/voice_lib/voice/bxml/verbs/phone_number.rb +0 -18
  67. data/lib/bandwidth/voice_lib/voice/bxml/verbs/play_audio.rb +0 -17
  68. data/lib/bandwidth/voice_lib/voice/bxml/verbs/redirect.rb +0 -20
  69. data/lib/bandwidth/voice_lib/voice/bxml/verbs/send_dtmf.rb +0 -12
  70. data/lib/bandwidth/voice_lib/voice/bxml/verbs/speak_sentence.rb +0 -18
  71. data/lib/bandwidth/voice_lib/voice/bxml/verbs/transfer.rb +0 -37
  72. data/lib/bandwidth/voice_lib/voice/bxml/verbs/xml_verb.rb +0 -26
  73. data/lib/bandwidth/voice_lib/voice/controllers/calls_controller.rb +0 -88
@@ -0,0 +1,27 @@
1
+
2
+ module Bandwidth
3
+ module Voice
4
+ module XmlVerb
5
+ def initialize(data = nil)
6
+ @data = (data || {}).clone()
7
+ end
8
+
9
+ def method_missing(name, *args, &block)
10
+ if name[name.size - 1] == '='
11
+ @data[name[0..-2].to_sym] = args[0]
12
+ else
13
+ @data[name]
14
+ end
15
+ end
16
+
17
+ def compact_hash(hash)
18
+ hash.inject({}) do |new_hash, (k,v)|
19
+ if !v.nil?
20
+ new_hash[k] = v.class == Hash ? compact_hash(v) : v
21
+ end
22
+ new_hash
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,23 +1,27 @@
1
- # bandwidth
2
- #
3
- # This file was automatically generated by APIMATIC v2.0
4
- # ( https://apimatic.io ).
5
-
6
-
7
- require_relative 'voice/client.rb'
8
-
9
- # Models
10
- require_relative 'voice/models/api_call_response.rb'
11
- require_relative 'voice/models/api_create_call_request.rb'
12
- require_relative 'voice/models/api_modify_call_request.rb'
13
- require_relative 'voice/models/bandwidth_callback_message_voice.rb'
14
- require_relative 'voice/models/answer_method_enum.rb'
15
- require_relative 'voice/models/disconnect_method_enum.rb'
16
- require_relative 'voice/models/redirect_method_enum.rb'
17
- require_relative 'voice/models/state_enum.rb'
18
-
19
- require_relative 'voice/bxml/bxml.rb'
20
-
21
- # Controllers
22
- require_relative 'voice/controllers/base_controller.rb'
23
- require_relative 'voice/controllers/calls_controller.rb'
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+
7
+ require_relative 'voice/client.rb'
8
+
9
+ # Models
10
+ require_relative 'voice/models/field_error.rb'
11
+ require_relative 'voice/models/api_call_response.rb'
12
+ require_relative 'voice/models/api_create_call_request.rb'
13
+ require_relative 'voice/models/api_modify_call_request.rb'
14
+ require_relative 'voice/models/bandwidth_callback_message_voice.rb'
15
+ require_relative 'voice/models/answer_method_enum.rb'
16
+ require_relative 'voice/models/disconnect_method_enum.rb'
17
+ require_relative 'voice/models/redirect_method_enum.rb'
18
+ require_relative 'voice/models/state_enum.rb'
19
+
20
+ # Exceptions
21
+ require_relative 'voice/exceptions/bandwidth_exception.rb'
22
+ require_relative 'voice/exceptions/bandwidth_not_found_exception.rb'
23
+ require_relative 'voice/exceptions/bandwidth_rate_limit_error_exception.rb'
24
+ # Controllers
25
+ require_relative 'voice/controllers/base_controller.rb'
26
+ require_relative 'voice/controllers/api_controller.rb'
27
+ require_relative 'bxml/bxml.rb'
@@ -1,36 +1,40 @@
1
- # bandwidth
2
- #
3
- # This file was automatically generated by APIMATIC v2.0
4
- # ( https://apimatic.io ).
5
-
6
- module Bandwidth
7
- module Voice
8
- # bandwidth client class.
9
- class Client
10
- attr_reader :config
11
-
12
- # Access to calls controller.
13
- # @return [CallsController] Returns the controller instance.
14
- def calls
15
- @calls ||= CallsController.new config
16
- end
17
-
18
- def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
19
- backoff_factor: 1, environment: Environment::PRODUCTION,
20
- voice_basic_auth_user_name: 'TODO: Replace',
21
- voice_basic_auth_password: 'TODO: Replace', config: nil)
22
- @config = if config.nil?
23
- Configuration.new(timeout: timeout,
24
- max_retries: max_retries,
25
- retry_interval: retry_interval,
26
- backoff_factor: backoff_factor,
27
- environment: environment,
28
- voice_basic_auth_user_name: voice_basic_auth_user_name,
29
- voice_basic_auth_password: voice_basic_auth_password)
30
- else
31
- config
32
- end
33
- end
34
- end
35
- end
36
- end
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ module Voice
8
+ # bandwidth client class.
9
+ class Client
10
+ attr_reader :config
11
+
12
+ # Access to client controller.
13
+ # @return [APIController] Returns the controller instance.
14
+ def client
15
+ @client ||= APIController.new config
16
+ end
17
+
18
+ def initialize(timeout: 0, max_retries: 0, retry_interval: 1,
19
+ backoff_factor: 1, environment: Environment::PRODUCTION,
20
+ messaging_basic_auth_user_name: 'TODO: Replace',
21
+ messaging_basic_auth_password: 'TODO: Replace',
22
+ voice_basic_auth_user_name: 'TODO: Replace',
23
+ voice_basic_auth_password: 'TODO: Replace', config: nil)
24
+ @config = if config.nil?
25
+ Configuration.new(timeout: timeout,
26
+ max_retries: max_retries,
27
+ retry_interval: retry_interval,
28
+ backoff_factor: backoff_factor,
29
+ environment: environment,
30
+ messaging_basic_auth_user_name: messaging_basic_auth_user_name,
31
+ messaging_basic_auth_password: messaging_basic_auth_password,
32
+ voice_basic_auth_user_name: voice_basic_auth_user_name,
33
+ voice_basic_auth_password: voice_basic_auth_password)
34
+ else
35
+ config
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,184 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ module Voice
8
+ # APIController
9
+ class APIController < BaseController
10
+ def initialize(config, http_call_back: nil)
11
+ super(config, http_call_back: http_call_back)
12
+ end
13
+
14
+ # Creates a call request
15
+ # @param [String] account_id Required parameter: Example:
16
+ # @param [ApiCreateCallRequest] body Optional parameter: Example:
17
+ # @return [ApiCallResponse] response from the API call
18
+ def create_call(account_id,
19
+ body: nil)
20
+ # Prepare query url.
21
+ _query_builder = config.get_base_uri(Server::VOICEDEFAULT)
22
+ _query_builder << '/accounts/{accountId}/calls'
23
+ _query_builder = APIHelper.append_url_with_template_parameters(
24
+ _query_builder,
25
+ 'accountId' => account_id
26
+ )
27
+ _query_url = APIHelper.clean_url _query_builder
28
+
29
+ # Prepare headers.
30
+ _headers = {
31
+ 'accept' => 'application/json',
32
+ 'content-type' => 'application/json; charset=utf-8'
33
+ }
34
+
35
+ # Prepare and execute HttpRequest.
36
+ _request = config.http_client.post(
37
+ _query_url,
38
+ headers: _headers,
39
+ parameters: body.to_json
40
+ )
41
+ VoiceBasicAuth.apply(config, _request)
42
+ _response = execute_request(_request)
43
+
44
+ # Validate response against endpoint and global error codes.
45
+ if _response.status_code == 400
46
+ raise BandwidthException.new(
47
+ '400 request is malformed or invalid',
48
+ _response
49
+ )
50
+ elsif _response.status_code == 401
51
+ raise BandwidthException.new(
52
+ '401 The specified user does not have access to the account',
53
+ _response
54
+ )
55
+ elsif _response.status_code == 403
56
+ raise BandwidthException.new(
57
+ '403 The user does not have access to the API',
58
+ _response
59
+ )
60
+ elsif _response.status_code == 404
61
+ raise BandwidthNotFoundException.new(
62
+ '404 he call-id is no longer active, or the path is not found',
63
+ _response
64
+ )
65
+ elsif _response.status_code == 409
66
+ raise BandwidthException.new(
67
+ '409 Error when modifying a call that is unable to be modified',
68
+ _response
69
+ )
70
+ elsif _response.status_code == 415
71
+ raise BandwidthException.new(
72
+ '415 The content-type of the request is incorrect',
73
+ _response
74
+ )
75
+ elsif _response.status_code == 429
76
+ raise BandwidthRateLimitErrorException.new(
77
+ '429 The rate limit has been reached',
78
+ _response
79
+ )
80
+ elsif _response.status_code == 500
81
+ raise BandwidthException.new(
82
+ '500 Unknown server error',
83
+ _response
84
+ )
85
+ elsif _response.status_code == 503
86
+ raise BandwidthException.new(
87
+ '503 The service is unavailable for some reason',
88
+ _response
89
+ )
90
+ end
91
+ validate_response(_response)
92
+
93
+ # Return appropriate response type.
94
+ decoded = APIHelper.json_deserialize(_response.raw_body)
95
+ ApiResponse.new(_response, data: ApiCallResponse.from_hash(decoded))
96
+ end
97
+
98
+ # Creates a call request
99
+ # @param [String] account_id Required parameter: Example:
100
+ # @param [String] call_id Required parameter: Example:
101
+ # @param [ApiModifyCallRequest] body Optional parameter: Example:
102
+ # @return [void] response from the API call
103
+ def modify_call(account_id,
104
+ call_id,
105
+ body: nil)
106
+ # Prepare query url.
107
+ _query_builder = config.get_base_uri(Server::VOICEDEFAULT)
108
+ _query_builder << '/accounts/{accountId}/calls/{callId}'
109
+ _query_builder = APIHelper.append_url_with_template_parameters(
110
+ _query_builder,
111
+ 'accountId' => account_id,
112
+ 'callId' => call_id
113
+ )
114
+ _query_url = APIHelper.clean_url _query_builder
115
+
116
+ # Prepare headers.
117
+ _headers = {
118
+ 'content-type' => 'application/json; charset=utf-8'
119
+ }
120
+
121
+ # Prepare and execute HttpRequest.
122
+ _request = config.http_client.post(
123
+ _query_url,
124
+ headers: _headers,
125
+ parameters: body.to_json
126
+ )
127
+ VoiceBasicAuth.apply(config, _request)
128
+ _response = execute_request(_request)
129
+
130
+ # Validate response against endpoint and global error codes.
131
+ if _response.status_code == 400
132
+ raise BandwidthException.new(
133
+ '400 request is malformed or invalid',
134
+ _response
135
+ )
136
+ elsif _response.status_code == 401
137
+ raise BandwidthException.new(
138
+ '401 The specified user does not have access to the account',
139
+ _response
140
+ )
141
+ elsif _response.status_code == 403
142
+ raise BandwidthException.new(
143
+ '403 The user does not have access to the API',
144
+ _response
145
+ )
146
+ elsif _response.status_code == 404
147
+ raise BandwidthNotFoundException.new(
148
+ '404 he call-id is no longer active, or the path is not found',
149
+ _response
150
+ )
151
+ elsif _response.status_code == 409
152
+ raise BandwidthException.new(
153
+ '409 Error when modifying a call that is unable to be modified',
154
+ _response
155
+ )
156
+ elsif _response.status_code == 415
157
+ raise BandwidthException.new(
158
+ '415 The content-type of the request is incorrect',
159
+ _response
160
+ )
161
+ elsif _response.status_code == 429
162
+ raise BandwidthRateLimitErrorException.new(
163
+ '429 The rate limit has been reached',
164
+ _response
165
+ )
166
+ elsif _response.status_code == 500
167
+ raise BandwidthException.new(
168
+ '500 Unknown server error',
169
+ _response
170
+ )
171
+ elsif _response.status_code == 503
172
+ raise BandwidthException.new(
173
+ '503 The service is unavailable for some reason',
174
+ _response
175
+ )
176
+ end
177
+ validate_response(_response)
178
+
179
+ # Return appropriate response type.
180
+ ApiResponse.new(_response)
181
+ end
182
+ end
183
+ end
184
+ end
@@ -1,49 +1,49 @@
1
- # bandwidth
2
- #
3
- # This file was automatically generated by APIMATIC v2.0
4
- # ( https://apimatic.io ).
5
-
6
- module Bandwidth
7
- # BaseController.
8
- class BaseController
9
- attr_accessor :config, :http_call_back
10
-
11
- def initialize(config, http_call_back: nil)
12
- @config = config
13
- @http_call_back = http_call_back
14
-
15
- @global_headers = {
16
- 'user-agent' => 'APIMATIC 2.0'
17
- }
18
- end
19
-
20
- def validate_parameters(args)
21
- args.each do |_name, value|
22
- if value.nil?
23
- raise ArgumentError, "Required parameter #{_name} cannot be nil."
24
- end
25
- end
26
- end
27
-
28
- def execute_request(request, binary: false)
29
- @http_call_back.on_before_request(request) if @http_call_back
30
-
31
- APIHelper.clean_hash(request.headers)
32
- request.headers = @global_headers.clone.merge(request.headers)
33
-
34
- response = if binary
35
- config.http_client.execute_as_binary(request)
36
- else
37
- config.http_client.execute_as_string(request)
38
- end
39
- @http_call_back.on_after_response(response) if @http_call_back
40
-
41
- response
42
- end
43
-
44
- def validate_response(response)
45
- raise APIException.new 'HTTP Response Not OK', response unless
46
- response.status_code.between?(200, 208) # [200,208] = HTTP OK
47
- end
48
- end
49
- end
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ # BaseController.
8
+ class BaseController
9
+ attr_accessor :config, :http_call_back
10
+
11
+ def initialize(config, http_call_back: nil)
12
+ @config = config
13
+ @http_call_back = http_call_back
14
+
15
+ @global_headers = {
16
+ 'user-agent' => 'APIMATIC 2.0'
17
+ }
18
+ end
19
+
20
+ def validate_parameters(args)
21
+ args.each do |_name, value|
22
+ if value.nil?
23
+ raise ArgumentError, "Required parameter #{_name} cannot be nil."
24
+ end
25
+ end
26
+ end
27
+
28
+ def execute_request(request, binary: false)
29
+ @http_call_back.on_before_request(request) if @http_call_back
30
+
31
+ APIHelper.clean_hash(request.headers)
32
+ request.headers = @global_headers.clone.merge(request.headers)
33
+
34
+ response = if binary
35
+ config.http_client.execute_as_binary(request)
36
+ else
37
+ config.http_client.execute_as_string(request)
38
+ end
39
+ @http_call_back.on_after_response(response) if @http_call_back
40
+
41
+ response
42
+ end
43
+
44
+ def validate_response(response)
45
+ raise APIException.new 'HTTP Response Not OK', response unless
46
+ response.status_code.between?(200, 208) # [200,208] = HTTP OK
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,51 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ # BandwidthException class.
8
+ class BandwidthException < APIException
9
+ # TODO: Write general description for this method
10
+ # @return [String]
11
+ attr_accessor :type
12
+
13
+ # TODO: Write general description for this method
14
+ # @return [String]
15
+ attr_accessor :description
16
+
17
+ # TODO: Write general description for this method
18
+ # @return [String]
19
+ attr_accessor :id
20
+
21
+ # TODO: Write general description for this method
22
+ # @return [List of FieldError]
23
+ attr_accessor :field_errors
24
+
25
+ # The constructor.
26
+ # @param [String] The reason for raising an exception.
27
+ # @param [HttpResponse] The HttpReponse of the API call.
28
+ def initialize(reason, response)
29
+ super(reason, response)
30
+ hash = APIHelper.json_deserialize(@response.raw_body)
31
+ unbox(hash)
32
+ end
33
+
34
+ # Populates this object by extracting properties from a hash.
35
+ # @param [Hash] The deserialized response sent by the server in the
36
+ # response body.
37
+ def unbox(hash)
38
+ @type = hash['type']
39
+ @description = hash['description']
40
+ @id = hash['id']
41
+ # Parameter is an array, so we need to iterate through it
42
+ @field_errors = nil
43
+ unless hash['fieldErrors'].nil?
44
+ @field_errors = []
45
+ hash['fieldErrors'].each do |structure|
46
+ @field_errors << (FieldError.from_hash(structure) if structure)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end