bandwidth-sdk 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37ac6cedf8f46960bdc51af5b2c1cb7084f303ba4b757373538186ca932997ba
4
- data.tar.gz: 1bac73b1c867feec6a21b3b985bbe15b3a163c3319538313453928e39a66806a
3
+ metadata.gz: 9b03c113c9fff659a7bbc0d7c174b59a0f0bd3ac6e5ae83801bd7f412cf1bcf9
4
+ data.tar.gz: 2dcf6a85620d519d62ba6192adcfa241ad8dfc70cf3e1f2fae5102c188640e69
5
5
  SHA512:
6
- metadata.gz: 7883069c08c868dcddd095be404121878adacd67dce7adbab68cc3e2af858d7534f2bd16410b64786a496372f0d1f81b6ffe456ea0b4c6434b4594cb997b0fb3
7
- data.tar.gz: f32337f52e22bad320f06fa789cfcd8618a4973fea80155ac626cef225c9c063cc2d27c7927354e14ed4f50b6185d139c303b0690d325f6d8dcb4c9514fbb484
6
+ metadata.gz: 94e42d80d90c7211fb629ba2f68d68685185a6f9bd9cdb85049742c78757bd7402021ab30da2ed7d71eeb1269d87406ad466c0a4bab799510988bff664f7d973
7
+ data.tar.gz: 38163d3789373e3efe9180c37204136cd1047442828b63a7543a1e84814e9266b60fb5e0151a4c2027b2e90356a2d4aa003b9cfa9271a2c2b5e1874e14d53131
data/README.md CHANGED
@@ -1,70 +1,85 @@
1
- # Getting Started with bandwidth
2
-
3
- Bandwidth's set of APIs
4
-
5
- ## Install the Package
6
-
7
- Install the gem from the command line:
8
-
9
- ```ruby
10
- gem install bandwidth-sdk -v 2.2.0
11
- ```
12
-
13
- Or add the gem to your Gemfile and run `bundle`:
14
-
15
- ```ruby
16
- gem 'bandwidth-sdk', '2.2.0'
17
- ```
18
-
19
- For additional gem details, see the [RubyGems page for the bandwidth-sdk gem](https://rubygems.org/gems/bandwidth-sdk/versions/2.2.0).
20
-
21
- ## Initialize the API Client
22
-
23
- The following parameters are configurable for the API Client.
24
-
25
- | Parameter | Type | Description |
26
- | --- | --- | --- |
27
- | `messaging_basic_auth_user_name` | `String` | The username to use with basic authentication |
28
- | `messaging_basic_auth_password` | `String` | The password to use with basic authentication |
29
- | `voice_basic_auth_user_name` | `String` | The username to use with basic authentication |
30
- | `voice_basic_auth_password` | `String` | The password to use with basic authentication |
31
- | `environment` | Environment | The API environment. <br> **Default: `Environment.PRODUCTION`** |
32
- | `timeout` | `Float` | The value to use for connection timeout. <br> **Default: 60** |
33
- | `max_retries` | `Integer` | The number of times to retry an endpoint call if it fails. <br> **Default: 0** |
34
- | `retry_interval` | `Float` | Pause in seconds between retries. <br> **Default: 1** |
35
- | `backoff_factor` | `Float` | The amount to multiply each successive retry's interval amount by in order to provide backoff. <br> **Default: 1** |
36
-
37
- The API client can be initialized as following.
38
-
39
- ```ruby
40
- client = Bandwidth::Client.new(
41
- messaging_basic_auth_user_name: 'MessagingBasicAuthUserName',
42
- messaging_basic_auth_password: 'MessagingBasicAuthPassword',
43
- voice_basic_auth_user_name: 'VoiceBasicAuthUserName',
44
- voice_basic_auth_password: 'VoiceBasicAuthPassword',
45
- environment: Environment::PRODUCTION,
46
- )
47
- ```
48
-
49
- API calls return an `ApiResponse` object that includes the following fields:
50
-
51
- | Field | Description |
52
- | --- | --- |
53
- | `status_code` | Status code of the HTTP response |
54
- | `reason_phrase` | Reason phrase of the HTTP response |
55
- | `headers` | Headers of the HTTP response as a Hash |
56
- | `raw_body` | The body of the HTTP response as a String |
57
- | `request` | HTTP request info |
58
- | `errors` | Errors, if they exist |
59
- | `data` | The deserialized body of the HTTP response |
60
-
61
- ## Authorization
62
-
63
- This API does not require authentication.
64
-
65
- ## API Reference
66
-
67
- ### List of APIs
68
-
69
- *
70
-
1
+ # Bandwidth Ruby SDK
2
+
3
+ Bandwidth's API docs can be found at https://dev.bandwidth.com
4
+
5
+ Ruby specific docs can be found at https://dev.bandwidth.com/sdks/ruby.html
6
+
7
+ ## Download & Install
8
+
9
+ ```
10
+ gem install bandwidth-sdk
11
+ ```
12
+
13
+ ## Initialize Bandwidth Client
14
+
15
+ ```ruby
16
+ require 'bandwidth'
17
+
18
+ include Bandwidth
19
+ include Bandwidth::Voice
20
+ include Bandwidth::Messaging
21
+
22
+ bandwidth_client = Bandwidth::Client.new(
23
+ voice_basic_auth_user_name: 'username',
24
+ voice_basic_auth_password: 'password',
25
+ messaging_basic_auth_user_name: 'token',
26
+ messaging_basic_auth_password: 'secret',
27
+ )
28
+ ```
29
+
30
+ ## Create Phone Call
31
+
32
+ ```ruby
33
+ voice_client = bandwidth_client.voice_client.client
34
+
35
+ account_id = '1'
36
+ body = ApiCreateCallRequest.new
37
+ body.from = '+16666666666'
38
+ body.to = '+17777777777'
39
+ body.answer_url = 'https://test.com'
40
+ body.application_id = '3-d-4-b-5'
41
+
42
+ begin
43
+ response = voice_client.create_call(account_id,:body => body)
44
+ puts response.data.call_id #c-d45a41e5-bcb12581-b18e-4bdc-9874-6r3235dfweao
45
+ puts response.status_code #201
46
+ rescue Bandwidth::ErrorResponseException => e
47
+ puts e.description #Invalid to: must be an E164 telephone number
48
+ puts e.response_code #400
49
+ end
50
+ ```
51
+
52
+ ## Generate BXML
53
+
54
+ ```ruby
55
+ response = Bandwidth::Voice::Response.new()
56
+ hangup = Bandwidth::Voice::Hangup.new()
57
+
58
+ response.push(hangup)
59
+ puts response.to_bxml()
60
+ ```
61
+
62
+ ## Send Text Message
63
+
64
+ ```ruby
65
+ messaging_client = bandwidth_client.messaging_client.client
66
+
67
+ account_id = '1'
68
+ body = MessageRequest.new
69
+ body.application_id = '1-2-3'
70
+ body.to = ['+17777777777']
71
+ body.from = '+18888888888'
72
+ body.text = 'Hello from Bandwidth'
73
+
74
+ begin
75
+ response = messaging_client.create_message(account_id, :body => body)
76
+ puts response.data.id #1570740275373xbn7mbhsfewasdr
77
+ puts response.status_code #202
78
+ rescue Bandwidth::GenericClientException => e
79
+ puts e.description #Access is denied
80
+ puts e.response_code #403
81
+ rescue Bandwidth::PathClientException => e
82
+ puts e.message #Your request could not be accepted.
83
+ puts e.response_code #400
84
+ end
85
+ ```
@@ -12,6 +12,9 @@ require 'logging'
12
12
  require_relative 'bandwidth/api_helper.rb'
13
13
  require_relative 'bandwidth/client.rb'
14
14
 
15
+ # Utilities
16
+ require_relative 'bandwidth/utilities/file_wrapper.rb'
17
+
15
18
  # Http
16
19
  require_relative 'bandwidth/http/api_response.rb'
17
20
  require_relative 'bandwidth/http/http_call_back.rb'
@@ -34,9 +34,7 @@ module Bandwidth
34
34
  http_request.query_url
35
35
  ) do |request|
36
36
  request.headers = http_request.headers
37
- unless http_request.parameters.empty?
38
- request.body = http_request.parameters
39
- end
37
+ request.body = http_request.parameters
40
38
  end
41
39
  convert_response(response, http_request)
42
40
  end
@@ -48,9 +46,7 @@ module Bandwidth
48
46
  http_request.query_url
49
47
  ) do |request|
50
48
  request.headers = http_request.headers
51
- unless http_request.parameters.empty?
52
- request.body = http_request.parameters
53
- end
49
+ request.body = http_request.parameters
54
50
  end
55
51
  convert_response(response, http_request)
56
52
  end
@@ -198,15 +198,16 @@ module Messaging
198
198
  # @param [String] user_id Required parameter: Example:
199
199
  # @param [String] media_id Required parameter: Example:
200
200
  # @param [Long] content_length Required parameter: Example:
201
- # @param [String] body Required parameter: Example:
202
- # @param [String] content_type Optional parameter: Example:
201
+ # @param [File | UploadIO] body Required parameter: Example:
202
+ # @param [String] content_type Optional parameter:
203
+ # Example:application/octet-stream
203
204
  # @param [String] cache_control Optional parameter: Example:
204
205
  # @return [void] response from the API call
205
206
  def upload_media(user_id,
206
207
  media_id,
207
208
  content_length,
208
209
  body,
209
- content_type: nil,
210
+ content_type: 'application/octet-stream',
210
211
  cache_control: nil)
211
212
  # Prepare query url.
212
213
  _query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
@@ -218,10 +219,19 @@ module Messaging
218
219
  )
219
220
  _query_url = APIHelper.clean_url _query_builder
220
221
 
222
+ if body.is_a? FileWrapper
223
+ body_wrapper = body.file
224
+ body_content_type = body.content_type
225
+ else
226
+ body_wrapper = body
227
+ body_content_type = content_type
228
+ end
229
+
221
230
  # Prepare headers.
222
231
  _headers = {
232
+ 'content-type' => body_content_type,
233
+ 'content-length' => body_wrapper.size.to_s,
223
234
  'Content-Length' => content_length,
224
- 'Content-Type' => content_type,
225
235
  'Cache-Control' => cache_control
226
236
  }
227
237
 
@@ -229,7 +239,7 @@ module Messaging
229
239
  _request = config.http_client.put(
230
240
  _query_url,
231
241
  headers: _headers,
232
- parameters: body
242
+ parameters: body_wrapper
233
243
  )
234
244
  MessagingBasicAuth.apply(config, _request)
235
245
  _response = execute_request(_request)
@@ -0,0 +1,17 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ # A utility to allow users to set the content-type for files
8
+ class FileWrapper
9
+ attr_reader :content_type
10
+ attr_reader :file
11
+
12
+ def initialize(file, content_type: 'application/octet-stream')
13
+ @file = file
14
+ @content_type = content_type
15
+ end
16
+ end
17
+ end
@@ -8,6 +8,8 @@ module Bandwidth
8
8
  xml.PhoneNumber(number, compact_hash({
9
9
  'transferAnswerUrl' => transfer_answer_url,
10
10
  'transferAnswerMethod' => transfer_answer_method,
11
+ 'transferDisconnectUrl' => transfer_disconnect_url,
12
+ 'transferDisconnectMethod' => transfer_disconnect_method,
11
13
  'username' => username,
12
14
  'password' => password,
13
15
  'tag' => tag
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bandwidth-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - APIMatic SDK Generator
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-11 00:00:00.000000000 Z
11
+ date: 2020-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logging
@@ -116,6 +116,7 @@ files:
116
116
  - lib/bandwidth/messaging_lib/messaging/models/message_request.rb
117
117
  - lib/bandwidth/messaging_lib/messaging/models/tag.rb
118
118
  - lib/bandwidth/models/base_model.rb
119
+ - lib/bandwidth/utilities/file_wrapper.rb
119
120
  - lib/bandwidth/voice_lib/bxml/bxml.rb
120
121
  - lib/bandwidth/voice_lib/bxml/verbs/forward.rb
121
122
  - lib/bandwidth/voice_lib/bxml/verbs/gather.rb