bandwidth-sdk 0.1.0 → 1.0.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/LICENSE +27 -27
- data/README.md +115 -1
- data/lib/bandwidth.rb +39 -37
- data/lib/bandwidth/api_helper.rb +280 -280
- data/lib/bandwidth/client.rb +41 -32
- data/lib/bandwidth/configuration.rb +130 -111
- data/lib/bandwidth/exceptions/api_exception.rb +20 -20
- data/lib/bandwidth/http/api_response.rb +36 -36
- data/lib/bandwidth/http/auth/messaging_basic_auth.rb +22 -0
- data/lib/bandwidth/http/auth/voice_basic_auth.rb +22 -22
- data/lib/bandwidth/http/faraday_client.rb +64 -64
- data/lib/bandwidth/http/http_call_back.rb +24 -24
- data/lib/bandwidth/http/http_client.rb +104 -104
- data/lib/bandwidth/http/http_method_enum.rb +13 -13
- data/lib/bandwidth/http/http_request.rb +50 -50
- data/lib/bandwidth/http/http_response.rb +29 -29
- data/lib/bandwidth/messaging_lib/messaging.rb +23 -0
- data/lib/bandwidth/messaging_lib/messaging/client.rb +40 -0
- data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +406 -0
- data/lib/bandwidth/messaging_lib/messaging/controllers/base_controller.rb +49 -0
- data/lib/bandwidth/messaging_lib/messaging/exceptions/generic_client_exception.rb +46 -0
- data/lib/bandwidth/messaging_lib/messaging/exceptions/path_client_exception.rb +49 -0
- data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_callback_message.rb +80 -0
- data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb +125 -0
- data/lib/bandwidth/messaging_lib/messaging/models/deferred_result.rb +44 -0
- data/lib/bandwidth/messaging_lib/messaging/models/field_error.rb +44 -0
- data/lib/bandwidth/messaging_lib/messaging/models/media.rb +123 -0
- data/lib/bandwidth/messaging_lib/messaging/models/message_request.rb +80 -0
- data/lib/bandwidth/messaging_lib/messaging/models/tag.rb +44 -0
- data/lib/bandwidth/models/base_model.rb +36 -36
- data/lib/bandwidth/voice_lib/bxml/bxml.rb +40 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/forward.rb +19 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/gather.rb +38 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/hangup.rb +15 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/pause.rb +16 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/phone_number.rb +19 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/play_audio.rb +18 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/redirect.rb +21 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/send_dtmf.rb +14 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/speak_sentence.rb +19 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/transfer.rb +38 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/xml_verb.rb +27 -0
- data/lib/bandwidth/voice_lib/voice.rb +27 -23
- data/lib/bandwidth/voice_lib/voice/client.rb +40 -36
- data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +184 -0
- data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +49 -49
- data/lib/bandwidth/voice_lib/voice/exceptions/bandwidth_exception.rb +51 -0
- data/lib/bandwidth/voice_lib/voice/exceptions/bandwidth_not_found_exception.rb +49 -0
- data/lib/bandwidth/voice_lib/voice/exceptions/bandwidth_rate_limit_error_exception.rb +56 -0
- data/lib/bandwidth/voice_lib/voice/models/answer_method_enum.rb +35 -35
- data/lib/bandwidth/voice_lib/voice/models/api_call_response.rb +116 -116
- data/lib/bandwidth/voice_lib/voice/models/api_create_call_request.rb +125 -125
- data/lib/bandwidth/voice_lib/voice/models/api_modify_call_request.rb +80 -80
- data/lib/bandwidth/voice_lib/voice/models/bandwidth_callback_message_voice.rb +98 -98
- data/lib/bandwidth/voice_lib/voice/models/disconnect_method_enum.rb +35 -35
- data/lib/bandwidth/voice_lib/voice/models/field_error.rb +44 -0
- data/lib/bandwidth/voice_lib/voice/models/redirect_method_enum.rb +35 -35
- data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +17 -17
- metadata +36 -47
- data/lib/bandwidth/voice_lib/voice/bxml/bxml.rb +0 -36
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/forward.rb +0 -19
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/gather.rb +0 -37
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/hangup.rb +0 -14
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/pause.rb +0 -15
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/phone_number.rb +0 -18
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/play_audio.rb +0 -17
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/redirect.rb +0 -20
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/send_dtmf.rb +0 -12
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/speak_sentence.rb +0 -18
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/transfer.rb +0 -37
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/xml_verb.rb +0 -26
- data/lib/bandwidth/voice_lib/voice/controllers/calls_controller.rb +0 -88
@@ -0,0 +1,80 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# MessageRequest Model.
|
8
|
+
class MessageRequest < BaseModel
|
9
|
+
# TODO: Write general description for this method
|
10
|
+
# @return [String]
|
11
|
+
attr_accessor :application_id
|
12
|
+
|
13
|
+
# TODO: Write general description for this method
|
14
|
+
# @return [List of String]
|
15
|
+
attr_accessor :to
|
16
|
+
|
17
|
+
# TODO: Write general description for this method
|
18
|
+
# @return [String]
|
19
|
+
attr_accessor :from
|
20
|
+
|
21
|
+
# TODO: Write general description for this method
|
22
|
+
# @return [String]
|
23
|
+
attr_accessor :text
|
24
|
+
|
25
|
+
# TODO: Write general description for this method
|
26
|
+
# @return [List of String]
|
27
|
+
attr_accessor :media
|
28
|
+
|
29
|
+
# TODO: Write general description for this method
|
30
|
+
# @return [String]
|
31
|
+
attr_accessor :tag
|
32
|
+
|
33
|
+
# A mapping from model property names to API property names.
|
34
|
+
def self.names
|
35
|
+
@_hash = {} if @_hash.nil?
|
36
|
+
@_hash['application_id'] = 'applicationId'
|
37
|
+
@_hash['to'] = 'to'
|
38
|
+
@_hash['from'] = 'from'
|
39
|
+
@_hash['text'] = 'text'
|
40
|
+
@_hash['media'] = 'media'
|
41
|
+
@_hash['tag'] = 'tag'
|
42
|
+
@_hash
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize(application_id = nil,
|
46
|
+
to = nil,
|
47
|
+
from = nil,
|
48
|
+
text = nil,
|
49
|
+
media = nil,
|
50
|
+
tag = nil)
|
51
|
+
@application_id = application_id
|
52
|
+
@to = to
|
53
|
+
@from = from
|
54
|
+
@text = text
|
55
|
+
@media = media
|
56
|
+
@tag = tag
|
57
|
+
end
|
58
|
+
|
59
|
+
# Creates an instance of the object from a hash.
|
60
|
+
def self.from_hash(hash)
|
61
|
+
return nil unless hash
|
62
|
+
|
63
|
+
# Extract variables from the hash.
|
64
|
+
application_id = hash['applicationId']
|
65
|
+
to = hash['to']
|
66
|
+
from = hash['from']
|
67
|
+
text = hash['text']
|
68
|
+
media = hash['media']
|
69
|
+
tag = hash['tag']
|
70
|
+
|
71
|
+
# Create object from extracted values.
|
72
|
+
MessageRequest.new(application_id,
|
73
|
+
to,
|
74
|
+
from,
|
75
|
+
text,
|
76
|
+
media,
|
77
|
+
tag)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# Tag Model.
|
8
|
+
class Tag < BaseModel
|
9
|
+
# TODO: Write general description for this method
|
10
|
+
# @return [String]
|
11
|
+
attr_accessor :key
|
12
|
+
|
13
|
+
# TODO: Write general description for this method
|
14
|
+
# @return [String]
|
15
|
+
attr_accessor :value
|
16
|
+
|
17
|
+
# A mapping from model property names to API property names.
|
18
|
+
def self.names
|
19
|
+
@_hash = {} if @_hash.nil?
|
20
|
+
@_hash['key'] = 'key'
|
21
|
+
@_hash['value'] = 'value'
|
22
|
+
@_hash
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(key = nil,
|
26
|
+
value = nil)
|
27
|
+
@key = key
|
28
|
+
@value = value
|
29
|
+
end
|
30
|
+
|
31
|
+
# Creates an instance of the object from a hash.
|
32
|
+
def self.from_hash(hash)
|
33
|
+
return nil unless hash
|
34
|
+
|
35
|
+
# Extract variables from the hash.
|
36
|
+
key = hash['key']
|
37
|
+
value = hash['value']
|
38
|
+
|
39
|
+
# Create object from extracted values.
|
40
|
+
Tag.new(key,
|
41
|
+
value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,36 +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
|
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,40 @@
|
|
1
|
+
|
2
|
+
require 'builder'
|
3
|
+
Dir[File.dirname(__FILE__) + '/verbs/*'].each {|file|
|
4
|
+
require_relative file
|
5
|
+
}
|
6
|
+
|
7
|
+
SSML_REGEX = /<([a-zA-Z\/\/].*?)>/
|
8
|
+
SPEAK_SENTENCE_REGEX = /<SpeakSentence.*?>.*?<\/SpeakSentence>/
|
9
|
+
|
10
|
+
module Bandwidth
|
11
|
+
module Voice
|
12
|
+
class Response
|
13
|
+
# Initializer
|
14
|
+
# @param verbs [Array] optional list of verbs to include into response
|
15
|
+
def initialize(verbs = nil)
|
16
|
+
@verbs = verbs || []
|
17
|
+
end
|
18
|
+
|
19
|
+
# Return BXML representaion of this response
|
20
|
+
def to_bxml()
|
21
|
+
xml = Builder::XmlMarkup.new()
|
22
|
+
xml.instruct!(:xml, :version=>'1.0', :encoding=>'UTF-8')
|
23
|
+
xml.Response do
|
24
|
+
@verbs.each {|verb| verb.to_bxml(xml)}
|
25
|
+
end
|
26
|
+
xml.target!().gsub(SPEAK_SENTENCE_REGEX){|s|s.gsub(SSML_REGEX, '<\1>')}
|
27
|
+
end
|
28
|
+
|
29
|
+
# Add one or more verbs to this response
|
30
|
+
def push(*verbs)
|
31
|
+
@verbs.push(*verbs)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Add a verb to this response
|
35
|
+
def <<(verb)
|
36
|
+
@verbs << verb
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
require_relative 'xml_verb'
|
3
|
+
|
4
|
+
module Bandwidth
|
5
|
+
module Voice
|
6
|
+
class Forward
|
7
|
+
include XmlVerb
|
8
|
+
def to_bxml(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,38 @@
|
|
1
|
+
|
2
|
+
require_relative 'xml_verb'
|
3
|
+
|
4
|
+
module Bandwidth
|
5
|
+
module Voice
|
6
|
+
# The Gather verb is used to collect digits for some period of time
|
7
|
+
class Gather
|
8
|
+
include XmlVerb
|
9
|
+
|
10
|
+
def to_bxml(xml)
|
11
|
+
xml.Gather(compact_hash({
|
12
|
+
'gatherUrl' => gather_url,
|
13
|
+
'gatherMethod' => gather_method,
|
14
|
+
'terminatingDigits' => terminating_digits,
|
15
|
+
'tag' => tag,
|
16
|
+
'maxDigits' => max_digits,
|
17
|
+
'interDigitTimeout' => inter_digit_timeout,
|
18
|
+
'username' => username,
|
19
|
+
'password' => password,
|
20
|
+
'firstDigitTimeout' => first_digit_timeout,
|
21
|
+
'repeatCount' => repeat_count
|
22
|
+
})) do
|
23
|
+
def embedded_xml(xml, property, type)
|
24
|
+
if property
|
25
|
+
s = if property.is_a?(type)
|
26
|
+
then property
|
27
|
+
else type.new(property)
|
28
|
+
end
|
29
|
+
s.to_bxml(xml)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
embedded_xml(xml, speak_sentence, SpeakSentence)
|
33
|
+
embedded_xml(xml, play_audio, PlayAudio)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
require_relative 'xml_verb'
|
3
|
+
|
4
|
+
module Bandwidth
|
5
|
+
module Voice
|
6
|
+
class PhoneNumber
|
7
|
+
include XmlVerb
|
8
|
+
def to_bxml(xml)
|
9
|
+
xml.PhoneNumber(number, compact_hash({
|
10
|
+
'transferAnswerUrl' => transfer_answer_url,
|
11
|
+
'transferAnswerMethod' => transfer_answer_method,
|
12
|
+
'username' => username,
|
13
|
+
'password' => password,
|
14
|
+
'tag' => tag
|
15
|
+
}))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
require_relative 'xml_verb'
|
3
|
+
|
4
|
+
module Bandwidth
|
5
|
+
module Voice
|
6
|
+
# The PlayAudio verb is used to play an audio file in the call
|
7
|
+
class PlayAudio
|
8
|
+
include XmlVerb
|
9
|
+
|
10
|
+
def to_bxml(xml)
|
11
|
+
xml.PlayAudio(url, compact_hash({
|
12
|
+
'username' => username,
|
13
|
+
'password' => password
|
14
|
+
}))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
require_relative 'xml_verb'
|
3
|
+
|
4
|
+
module Bandwidth
|
5
|
+
module Voice
|
6
|
+
# The Redirect verb is used to redirect the current XML execution to another URL
|
7
|
+
class Redirect
|
8
|
+
include XmlVerb
|
9
|
+
|
10
|
+
def to_bxml(xml)
|
11
|
+
xml.Redirect(compact_hash({
|
12
|
+
'redirectUrl' => redirect_url,
|
13
|
+
'redirectMethod' => redirect_method,
|
14
|
+
'tag' => tag,
|
15
|
+
'username' => username,
|
16
|
+
'password' => password
|
17
|
+
}))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
require_relative 'xml_verb'
|
3
|
+
|
4
|
+
module Bandwidth
|
5
|
+
module Voice
|
6
|
+
# The SpeakSentence verb is used to convert any text into speak for the caller
|
7
|
+
class SpeakSentence
|
8
|
+
include XmlVerb
|
9
|
+
|
10
|
+
def to_bxml(xml)
|
11
|
+
xml.SpeakSentence(sentence, compact_hash({
|
12
|
+
'voice' => voice,
|
13
|
+
'locale' => locale,
|
14
|
+
'gender' => gender
|
15
|
+
}))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
require_relative 'xml_verb'
|
3
|
+
|
4
|
+
module Bandwidth
|
5
|
+
module Voice
|
6
|
+
# The Transfer verb is used to transfer the call to another number
|
7
|
+
class Transfer
|
8
|
+
include XmlVerb
|
9
|
+
|
10
|
+
def to_bxml(xml)
|
11
|
+
xml.Transfer(compact_hash({
|
12
|
+
'transferCallerId' => transfer_caller_id,
|
13
|
+
'callTimeout' => call_timeout,
|
14
|
+
'tag' => tag,
|
15
|
+
'transferCompleteUrl' => transfer_complete_url,
|
16
|
+
'transferCompleteMethod' => transfer_complete_method,
|
17
|
+
'username' => username,
|
18
|
+
'password' => password,
|
19
|
+
'diversionTreatment' => diversion_treatment,
|
20
|
+
'diversionReason' => diversion_reason
|
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_bxml(xml)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
phone_numbers.each do |number|
|
32
|
+
embedded_xml(xml, number, PhoneNumber)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|