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,19 @@
1
+ require_relative 'xml_verb'
2
+
3
+ module Bandwidth
4
+ module Voice
5
+ class Forward
6
+ include XmlVerb
7
+
8
+ def to_xml(xml)
9
+ xml.Forward(compact_hash({
10
+ 'to' => to,
11
+ 'from' => from,
12
+ 'callTimeout' => call_timeout,
13
+ 'diversionTreatment' => diversion_treatment,
14
+ 'diversionReason' => diversion_reason
15
+ }))
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'xml_verb'
2
+
3
+ module Bandwidth
4
+ module Voice
5
+ # The Gather verb is used to collect digits for some period of time
6
+ class Gather
7
+ include XmlVerb
8
+
9
+ def to_xml(xml)
10
+ xml.Gather(compact_hash({
11
+ 'gatherUrl' => gather_url,
12
+ 'gatherMethod' => gather_method,
13
+ 'terminatingDigits' => terminating_digits,
14
+ 'tag' => tag,
15
+ 'maxDigits' => max_digits,
16
+ 'interDigitTimeout' => inter_digit_timeout,
17
+ 'username' => username,
18
+ 'password' => password,
19
+ 'firstDigitTimeout' => first_digit_timeout,
20
+ 'repeatCount' => repeat_count
21
+ })) do
22
+ def embedded_xml(xml, property, type)
23
+ if property
24
+ s = if property.is_a?(type)
25
+ then property
26
+ else type.new(property)
27
+ end
28
+ s.to_xml(xml)
29
+ end
30
+ end
31
+ embedded_xml(xml, speak_sentence, SpeakSentence)
32
+ embedded_xml(xml, play_audio, PlayAudio)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'xml_verb'
2
+
3
+ module Bandwidth
4
+ module Voice
5
+ # The Hangup verb is used to hangup current call
6
+ class Hangup
7
+ include XmlVerb
8
+
9
+ def to_xml(xml)
10
+ xml.Hangup()
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'xml_verb'
2
+
3
+ module Bandwidth
4
+ module Voice
5
+ class Pause
6
+ include XmlVerb
7
+
8
+ def to_xml(xml)
9
+ xml.Pause(compact_hash({
10
+ 'duration' => duration
11
+ }))
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'xml_verb'
2
+
3
+ module Bandwidth
4
+ module Voice
5
+ class PhoneNumber
6
+ include XmlVerb
7
+ def to_xml(xml)
8
+ xml.PhoneNumber(number, compact_hash({
9
+ 'transferAnswerUrl' => transfer_answer_url,
10
+ 'transferAnswerMethod' => transfer_answer_method,
11
+ 'username' => username,
12
+ 'password' => password,
13
+ 'tag' => tag
14
+ }))
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'xml_verb'
2
+
3
+ module Bandwidth
4
+ module Voice
5
+ # The PlayAudio verb is used to play an audio file in the call
6
+ class PlayAudio
7
+ include XmlVerb
8
+
9
+ def to_xml(xml)
10
+ xml.PlayAudio(url, compact_hash({
11
+ 'username' => username,
12
+ 'password' => password
13
+ }))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'xml_verb'
2
+
3
+ module Bandwidth
4
+ module Voice
5
+ # The Redirect verb is used to redirect the current XML execution to another URL
6
+ class Redirect
7
+ include XmlVerb
8
+
9
+ def to_xml(xml)
10
+ xml.Redirect(compact_hash({
11
+ 'redirectUrl' => redirect_url,
12
+ 'redirectMethod' => redirect_method,
13
+ 'tag' => tag,
14
+ 'username' => username,
15
+ 'password' => password
16
+ }))
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ require_relative 'xml_verb'
2
+ module Bandwidth
3
+ module Voice
4
+ class SendDtmf
5
+ include XmlVerb
6
+
7
+ def to_xml(xml)
8
+ xml.SendDtmf(dtmf)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'xml_verb'
2
+
3
+ module Bandwidth
4
+ module Voice
5
+ # The SpeakSentence verb is used to convert any text into speak for the caller
6
+ class SpeakSentence
7
+ include XmlVerb
8
+
9
+ def to_xml(xml)
10
+ xml.SpeakSentence(sentence, compact_hash({
11
+ 'voice' => voice,
12
+ 'locale' => locale,
13
+ 'gender' => gender
14
+ }))
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'xml_verb'
2
+
3
+ module Bandwidth
4
+ module Voice
5
+ # The Transfer verb is used to transfer the call to another number
6
+ class Transfer
7
+ include XmlVerb
8
+
9
+ def to_xml(xml)
10
+ xml.Transfer(compact_hash({
11
+ 'transferCallerId' => transfer_caller_id,
12
+ 'callTimeout' => call_timeout,
13
+ 'tag' => tag,
14
+ 'transferCompleteUrl' => transfer_complete_url,
15
+ 'transferCompleteMethod' => transfer_complete_method,
16
+ 'username' => username,
17
+ 'password' => password,
18
+ 'diversionTreatment' => diversion_treatment,
19
+ 'diversionReason' => diversion_reason
20
+ })) do
21
+ def embedded_xml(xml, property, type)
22
+ if property
23
+ s = if property.is_a?(type)
24
+ then property
25
+ else type.new(property)
26
+ end
27
+ s.to_xml(xml)
28
+ end
29
+ end
30
+ phone_numbers.each do |number|
31
+ embedded_xml(xml, number, PhoneNumber)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ module Bandwidth
2
+ module Voice
3
+ module XmlVerb
4
+ def initialize(data = nil)
5
+ @data = (data || {}).clone()
6
+ end
7
+
8
+ def method_missing(name, *args, &block)
9
+ if name[name.size - 1] == '='
10
+ @data[name[0..-2].to_sym] = args[0]
11
+ else
12
+ @data[name]
13
+ end
14
+ end
15
+
16
+ def compact_hash(hash)
17
+ hash.inject({}) do |new_hash, (k,v)|
18
+ if !v.nil?
19
+ new_hash[k] = v.class == Hash ? compact_hash(v) : v
20
+ end
21
+ new_hash
22
+ end
23
+ end
24
+ end
25
+ end
26
+ 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
+ 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
@@ -0,0 +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
@@ -0,0 +1,88 @@
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
+ # CallsController
9
+ class CallsController < 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 << '/api/v2/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
+ validate_response(_response)
44
+
45
+ # Return appropriate response type.
46
+ decoded = APIHelper.json_deserialize(_response.raw_body)
47
+ ApiResponse.new(_response, data: ApiCallResponse.from_hash(decoded))
48
+ end
49
+
50
+ # Creates a call request
51
+ # @param [String] account_id Required parameter: Example:
52
+ # @param [String] call_id Required parameter: Example:
53
+ # @param [ApiModifyCallRequest] body Optional parameter: Example:
54
+ # @return [void] response from the API call
55
+ def modify_call(account_id,
56
+ call_id,
57
+ body: nil)
58
+ # Prepare query url.
59
+ _query_builder = config.get_base_uri(Server::VOICEDEFAULT)
60
+ _query_builder << '/api/v2/accounts/{accountId}/calls/{callId}'
61
+ _query_builder = APIHelper.append_url_with_template_parameters(
62
+ _query_builder,
63
+ 'accountId' => account_id,
64
+ 'callId' => call_id
65
+ )
66
+ _query_url = APIHelper.clean_url _query_builder
67
+
68
+ # Prepare headers.
69
+ _headers = {
70
+ 'content-type' => 'application/json; charset=utf-8'
71
+ }
72
+
73
+ # Prepare and execute HttpRequest.
74
+ _request = config.http_client.post(
75
+ _query_url,
76
+ headers: _headers,
77
+ parameters: body.to_json
78
+ )
79
+ VoiceBasicAuth.apply(config, _request)
80
+ _response = execute_request(_request)
81
+ validate_response(_response)
82
+
83
+ # Return appropriate response type.
84
+ ApiResponse.new(_response)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,35 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ # AnswerMethod.
8
+ class AnswerMethodEnum
9
+ ANSWER_METHOD_ENUM = [
10
+ # TODO: Write general description for GET
11
+ GET = 'GET'.freeze,
12
+
13
+ # TODO: Write general description for HEAD
14
+ HEAD = 'HEAD'.freeze,
15
+
16
+ # TODO: Write general description for POST
17
+ POST = 'POST'.freeze,
18
+
19
+ # TODO: Write general description for PUT
20
+ PUT = 'PUT'.freeze,
21
+
22
+ # TODO: Write general description for PATCH
23
+ PATCH = 'PATCH'.freeze,
24
+
25
+ # TODO: Write general description for DELETE
26
+ DELETE = 'DELETE'.freeze,
27
+
28
+ # TODO: Write general description for OPTIONS
29
+ OPTIONS = 'OPTIONS'.freeze,
30
+
31
+ # TODO: Write general description for TRACE
32
+ TRACE = 'TRACE'.freeze
33
+ ].freeze
34
+ end
35
+ end