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 +4 -4
- data/README.md +85 -70
- data/lib/bandwidth.rb +3 -0
- data/lib/bandwidth/http/faraday_client.rb +2 -6
- data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +15 -5
- data/lib/bandwidth/utilities/file_wrapper.rb +17 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/phone_number.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b03c113c9fff659a7bbc0d7c174b59a0f0bd3ac6e5ae83801bd7f412cf1bcf9
|
4
|
+
data.tar.gz: 2dcf6a85620d519d62ba6192adcfa241ad8dfc70cf3e1f2fae5102c188640e69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94e42d80d90c7211fb629ba2f68d68685185a6f9bd9cdb85049742c78757bd7402021ab30da2ed7d71eeb1269d87406ad466c0a4bab799510988bff664f7d973
|
7
|
+
data.tar.gz: 38163d3789373e3efe9180c37204136cd1047442828b63a7543a1e84814e9266b60fb5e0151a4c2027b2e90356a2d4aa003b9cfa9271a2c2b5e1874e14d53131
|
data/README.md
CHANGED
@@ -1,70 +1,85 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
Bandwidth's
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
```
|
10
|
-
gem install bandwidth-sdk
|
11
|
-
```
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
```ruby
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
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
|
+
```
|
data/lib/bandwidth.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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 [
|
202
|
-
# @param [String] content_type Optional parameter:
|
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:
|
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:
|
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.
|
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
|
+
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
|