bandwidth-sdk 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +28 -0
- data/README.md +1 -0
- data/lib/bandwidth.rb +37 -0
- data/lib/bandwidth/api_helper.rb +280 -0
- data/lib/bandwidth/client.rb +32 -0
- data/lib/bandwidth/configuration.rb +111 -0
- data/lib/bandwidth/exceptions/api_exception.rb +20 -0
- data/lib/bandwidth/http/api_response.rb +36 -0
- data/lib/bandwidth/http/auth/voice_basic_auth.rb +22 -0
- data/lib/bandwidth/http/faraday_client.rb +64 -0
- data/lib/bandwidth/http/http_call_back.rb +24 -0
- data/lib/bandwidth/http/http_client.rb +104 -0
- data/lib/bandwidth/http/http_method_enum.rb +13 -0
- data/lib/bandwidth/http/http_request.rb +50 -0
- data/lib/bandwidth/http/http_response.rb +29 -0
- data/lib/bandwidth/models/base_model.rb +36 -0
- data/lib/bandwidth/voice_lib/voice.rb +23 -0
- data/lib/bandwidth/voice_lib/voice/bxml/bxml.rb +36 -0
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/forward.rb +19 -0
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/gather.rb +37 -0
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/hangup.rb +14 -0
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/pause.rb +15 -0
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/phone_number.rb +18 -0
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/play_audio.rb +17 -0
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/redirect.rb +20 -0
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/send_dtmf.rb +12 -0
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/speak_sentence.rb +18 -0
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/transfer.rb +37 -0
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/xml_verb.rb +26 -0
- data/lib/bandwidth/voice_lib/voice/client.rb +36 -0
- data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +49 -0
- data/lib/bandwidth/voice_lib/voice/controllers/calls_controller.rb +88 -0
- data/lib/bandwidth/voice_lib/voice/models/answer_method_enum.rb +35 -0
- data/lib/bandwidth/voice_lib/voice/models/api_call_response.rb +116 -0
- data/lib/bandwidth/voice_lib/voice/models/api_create_call_request.rb +125 -0
- data/lib/bandwidth/voice_lib/voice/models/api_modify_call_request.rb +80 -0
- data/lib/bandwidth/voice_lib/voice/models/bandwidth_callback_message_voice.rb +98 -0
- data/lib/bandwidth/voice_lib/voice/models/disconnect_method_enum.rb +35 -0
- data/lib/bandwidth/voice_lib/voice/models/redirect_method_enum.rb +35 -0
- data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +17 -0
- metadata +181 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# Class for exceptions when there is a network error, status code error, etc.
|
8
|
+
class APIException < StandardError
|
9
|
+
attr_reader :response, :response_code
|
10
|
+
|
11
|
+
# The constructor.
|
12
|
+
# @param [String] The reason for raising an exception.
|
13
|
+
# @param [HttpResponse] The HttpReponse of the API call.
|
14
|
+
def initialize(reason, response)
|
15
|
+
super(reason)
|
16
|
+
@response = response
|
17
|
+
@response_code = response.status_code
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# Http response received.
|
8
|
+
class ApiResponse
|
9
|
+
attr_reader(:status_code, :reason_phrase, :headers, :raw_body, :request,
|
10
|
+
:data, :errors)
|
11
|
+
|
12
|
+
# The constructor
|
13
|
+
# @param [HttpResponse] The original, raw response from the api.
|
14
|
+
# @param [Object] The data field specified for the response.
|
15
|
+
# @param [Array<String>] Any errors returned by the server.
|
16
|
+
def initialize(http_response,
|
17
|
+
data: nil,
|
18
|
+
errors: nil)
|
19
|
+
@status_code = http_response.status_code
|
20
|
+
@reason_phrase = http_response.reason_phrase
|
21
|
+
@headers = http_response.headers
|
22
|
+
@raw_body = http_response.raw_body
|
23
|
+
@request = http_response.request
|
24
|
+
@data = data
|
25
|
+
@errors = errors
|
26
|
+
end
|
27
|
+
|
28
|
+
def success?
|
29
|
+
status_code >= 200 && status_code < 300
|
30
|
+
end
|
31
|
+
|
32
|
+
def error?
|
33
|
+
status_code >= 400 && status_code < 600
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
require 'base64'
|
7
|
+
|
8
|
+
module Bandwidth
|
9
|
+
# Utility class for basic authorization.
|
10
|
+
class VoiceBasicAuth
|
11
|
+
# Add basic authentication to the request.
|
12
|
+
# @param [HttpRequest] The HttpRequest object to which authentication will
|
13
|
+
# be added.
|
14
|
+
def self.apply(config, http_request)
|
15
|
+
username = config.voice_basic_auth_user_name
|
16
|
+
password = config.voice_basic_auth_password
|
17
|
+
value = Base64.strict_encode64("#{username}:#{password}")
|
18
|
+
header_value = "Basic #{value}"
|
19
|
+
http_request.headers['Authorization'] = header_value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
require 'faraday/http_cache'
|
7
|
+
require 'faraday_middleware'
|
8
|
+
|
9
|
+
module Bandwidth
|
10
|
+
# An implementation of HttpClient.
|
11
|
+
class FaradayClient < HttpClient
|
12
|
+
# The constructor.
|
13
|
+
def initialize(timeout:, max_retries:, retry_interval:,
|
14
|
+
backoff_factor:, cache: false, verify: true)
|
15
|
+
@connection = Faraday.new do |faraday|
|
16
|
+
faraday.use Faraday::HttpCache, serializer: Marshal if cache
|
17
|
+
faraday.use FaradayMiddleware::FollowRedirects
|
18
|
+
faraday.request :multipart
|
19
|
+
faraday.request :url_encoded
|
20
|
+
faraday.ssl[:ca_file] = Certifi.where
|
21
|
+
faraday.ssl[:verify] = verify
|
22
|
+
faraday.request :retry, max: max_retries, interval: retry_interval,
|
23
|
+
backoff_factor: backoff_factor
|
24
|
+
faraday.adapter Faraday.default_adapter
|
25
|
+
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
|
26
|
+
faraday.options[:timeout] = timeout if timeout > 0
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Method overridden from HttpClient.
|
31
|
+
def execute_as_string(http_request)
|
32
|
+
response = @connection.send(
|
33
|
+
http_request.http_method.downcase,
|
34
|
+
http_request.query_url
|
35
|
+
) do |request|
|
36
|
+
request.headers = http_request.headers
|
37
|
+
unless http_request.parameters.empty?
|
38
|
+
request.body = http_request.parameters
|
39
|
+
end
|
40
|
+
end
|
41
|
+
convert_response(response, http_request)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Method overridden from HttpClient.
|
45
|
+
def execute_as_binary(http_request)
|
46
|
+
response = @connection.send(
|
47
|
+
http_request.http_method.downcase,
|
48
|
+
http_request.query_url
|
49
|
+
) do |request|
|
50
|
+
request.headers = http_request.headers
|
51
|
+
unless http_request.parameters.empty?
|
52
|
+
request.body = http_request.parameters
|
53
|
+
end
|
54
|
+
end
|
55
|
+
convert_response(response, http_request)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Method overridden from HttpClient.
|
59
|
+
def convert_response(response, http_request)
|
60
|
+
HttpResponse.new(response.status, response.reason_phrase,
|
61
|
+
response.headers, response.body, http_request)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# HttpCallBack allows defining callables for pre and post API calls.
|
8
|
+
class HttpCallBack
|
9
|
+
# A controller will call this method before making an HTTP Request.
|
10
|
+
# @param [HttpRequest] The HttpRequest object which the HttpClient
|
11
|
+
# will execute.
|
12
|
+
def on_before_request(_http_request)
|
13
|
+
raise NotImplementedError, 'This method needs
|
14
|
+
to be implemented in a child class.'
|
15
|
+
end
|
16
|
+
|
17
|
+
# A controller will call this method after making an HTTP Request.
|
18
|
+
# @param [HttpResponse] The HttpReponse of the API call.
|
19
|
+
def on_after_response(_http_response)
|
20
|
+
raise NotImplementedError, 'This method needs
|
21
|
+
to be implemented in a child class.'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# An interface for the methods that an HTTP Client must implement.
|
8
|
+
#
|
9
|
+
# This class should not be instantiated but should be used as a base class
|
10
|
+
# for HTTP Client classes.
|
11
|
+
class HttpClient
|
12
|
+
# Execute an HttpRequest when the response is expected to be a string.
|
13
|
+
# @param [HttpRequest] The HttpRequest to be executed.
|
14
|
+
def execute_as_string(_http_request)
|
15
|
+
raise NotImplementedError, 'This method needs
|
16
|
+
to be implemented in a child class.'
|
17
|
+
end
|
18
|
+
|
19
|
+
# Execute an HttpRequest when the response is expected to be binary.
|
20
|
+
# @param [HttpRequest] The HttpRequest to be executed.
|
21
|
+
def execute_as_binary(_http_request)
|
22
|
+
raise NotImplementedError, 'This method needs
|
23
|
+
to be implemented in a child class.'
|
24
|
+
end
|
25
|
+
|
26
|
+
# Converts the HTTP Response from the client to an HttpResponse object.
|
27
|
+
# @param [Dynamic] The response object received from the client.
|
28
|
+
def convert_response(_response)
|
29
|
+
raise NotImplementedError, 'This method needs
|
30
|
+
to be implemented in a child class.'
|
31
|
+
end
|
32
|
+
|
33
|
+
# Get a GET HttpRequest object.
|
34
|
+
# @param [String] The URL to send the request to.
|
35
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
36
|
+
def get(query_url,
|
37
|
+
headers: {})
|
38
|
+
HttpRequest.new(HttpMethodEnum::GET,
|
39
|
+
query_url,
|
40
|
+
headers: headers)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Get a HEAD HttpRequest object.
|
44
|
+
# @param [String] The URL to send the request to.
|
45
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
46
|
+
def head(query_url,
|
47
|
+
headers: {})
|
48
|
+
HttpRequest.new(HttpMethodEnum::HEAD,
|
49
|
+
query_url,
|
50
|
+
headers: headers)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Get a POST HttpRequest object.
|
54
|
+
# @param [String] The URL to send the request to.
|
55
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
56
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
57
|
+
def post(query_url,
|
58
|
+
headers: {},
|
59
|
+
parameters: {})
|
60
|
+
HttpRequest.new(HttpMethodEnum::POST,
|
61
|
+
query_url,
|
62
|
+
headers: headers,
|
63
|
+
parameters: parameters)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Get a PUT HttpRequest object.
|
67
|
+
# @param [String] The URL to send the request to.
|
68
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
69
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
70
|
+
def put(query_url,
|
71
|
+
headers: {},
|
72
|
+
parameters: {})
|
73
|
+
HttpRequest.new(HttpMethodEnum::PUT,
|
74
|
+
query_url,
|
75
|
+
headers: headers,
|
76
|
+
parameters: parameters)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Get a PATCH HttpRequest object.
|
80
|
+
# @param [String] The URL to send the request to.
|
81
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
82
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
83
|
+
def patch(query_url,
|
84
|
+
headers: {},
|
85
|
+
parameters: {})
|
86
|
+
HttpRequest.new(HttpMethodEnum::PATCH,
|
87
|
+
query_url,
|
88
|
+
headers: headers,
|
89
|
+
parameters: parameters)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Get a DELETE HttpRequest object.
|
93
|
+
# @param [String] The URL to send the request to.
|
94
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
95
|
+
def delete(query_url,
|
96
|
+
headers: {},
|
97
|
+
parameters: {})
|
98
|
+
HttpRequest.new(HttpMethodEnum::DELETE,
|
99
|
+
query_url,
|
100
|
+
headers: headers,
|
101
|
+
parameters: parameters)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# HTTP Methods Enumeration.
|
8
|
+
class HttpMethodEnum
|
9
|
+
HTTPMETHODENUM = [GET = 'GET'.freeze, POST = 'POST'.freeze,
|
10
|
+
PUT = 'PUT'.freeze, PATCH = 'PATCH'.freeze,
|
11
|
+
DELETE = 'DELETE'.freeze, HEAD = 'HEAD'.freeze].freeze
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# Represents a single Http Request.
|
8
|
+
class HttpRequest
|
9
|
+
attr_accessor :http_method, :query_url, :headers,
|
10
|
+
:parameters, :username, :password
|
11
|
+
|
12
|
+
# The constructor.
|
13
|
+
# @param [HttpMethodEnum] The HTTP method.
|
14
|
+
# @param [String] The URL to send the request to.
|
15
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
16
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
17
|
+
def initialize(http_method,
|
18
|
+
query_url,
|
19
|
+
headers: {},
|
20
|
+
parameters: {})
|
21
|
+
@http_method = http_method
|
22
|
+
@query_url = query_url
|
23
|
+
@headers = headers
|
24
|
+
@parameters = parameters
|
25
|
+
end
|
26
|
+
|
27
|
+
# Add a header to the HttpRequest.
|
28
|
+
# @param [String] The name of the header.
|
29
|
+
# @param [String] The value of the header.
|
30
|
+
def add_header(name, value)
|
31
|
+
@headers[name] = value
|
32
|
+
end
|
33
|
+
|
34
|
+
# Add a parameter to the HttpRequest.
|
35
|
+
# @param [String] The name of the parameter.
|
36
|
+
# @param [String] The value of the parameter.
|
37
|
+
def add_parameter(name, value)
|
38
|
+
@parameters[name] = value
|
39
|
+
end
|
40
|
+
|
41
|
+
# Add a query parameter to the HttpRequest.
|
42
|
+
# @param [String] The name of the query parameter.
|
43
|
+
# @param [String] The value of the query parameter.
|
44
|
+
def add_query_parameter(name, value)
|
45
|
+
@query_url = APIHelper.append_url_with_query_parameters(@query_url,
|
46
|
+
name => value)
|
47
|
+
@query_url = APIHelper.clean_url(@query_url)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# Http response received.
|
8
|
+
class HttpResponse
|
9
|
+
attr_reader :status_code, :reason_phrase, :headers, :raw_body, :request
|
10
|
+
|
11
|
+
# The constructor
|
12
|
+
# @param [Integer] The status code returned by the server.
|
13
|
+
# @param [String] The reason phrase returned by the server.
|
14
|
+
# @param [Hash] The headers sent by the server in the response.
|
15
|
+
# @param [String] The raw body of the response.
|
16
|
+
# @param [HttpRequest] The request that resulted in this response.
|
17
|
+
def initialize(status_code,
|
18
|
+
reason_phrase,
|
19
|
+
headers,
|
20
|
+
raw_body,
|
21
|
+
request)
|
22
|
+
@status_code = status_code
|
23
|
+
@reason_phrase = reason_phrase
|
24
|
+
@headers = headers
|
25
|
+
@raw_body = raw_body
|
26
|
+
@request = request
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# Base model.
|
8
|
+
class BaseModel
|
9
|
+
# Returns a Hash representation of the current object.
|
10
|
+
def to_hash
|
11
|
+
hash = {}
|
12
|
+
instance_variables.each do |name|
|
13
|
+
value = instance_variable_get(name)
|
14
|
+
name = name[1..-1]
|
15
|
+
key = self.class.names.key?(name) ? self.class.names[name] : name
|
16
|
+
if value.instance_of? Array
|
17
|
+
hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
|
18
|
+
elsif value.instance_of? Hash
|
19
|
+
hash[key] = {}
|
20
|
+
value.each do |k, v|
|
21
|
+
hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
|
22
|
+
end
|
23
|
+
else
|
24
|
+
hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
hash
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns a JSON representation of the curent object.
|
31
|
+
def to_json(options = {})
|
32
|
+
hash = to_hash.reject { |k, v| v.nil? }
|
33
|
+
hash.to_json(options)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
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'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'builder'
|
2
|
+
Dir[File.dirname(__FILE__) + '/verbs/*'].each {|file|
|
3
|
+
require_relative file
|
4
|
+
}
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
module Voice
|
8
|
+
class Response
|
9
|
+
# Initializer
|
10
|
+
# @param verbs [Array] optional list of verbs to include into response
|
11
|
+
def initialize(verbs = nil)
|
12
|
+
@verbs = verbs || []
|
13
|
+
end
|
14
|
+
|
15
|
+
# Return XML presentaion of this response
|
16
|
+
def to_xml()
|
17
|
+
xml = Builder::XmlMarkup.new()
|
18
|
+
xml.instruct!(:xml, :version=>'1.0', :encoding=>'UTF-8')
|
19
|
+
xml.Response do
|
20
|
+
@verbs.each {|verb| verb.to_xml(xml)}
|
21
|
+
end
|
22
|
+
xml.target!()
|
23
|
+
end
|
24
|
+
|
25
|
+
# Add one or more verbs to this response
|
26
|
+
def push(*verbs)
|
27
|
+
@verbs.push(*verbs)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Add a verb to this response
|
31
|
+
def <<(verb)
|
32
|
+
@verbs << verb
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|