bandwidth-sdk 0.1.0 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +27 -27
  3. data/README.md +115 -1
  4. data/lib/bandwidth.rb +39 -37
  5. data/lib/bandwidth/api_helper.rb +280 -280
  6. data/lib/bandwidth/client.rb +41 -32
  7. data/lib/bandwidth/configuration.rb +130 -111
  8. data/lib/bandwidth/exceptions/api_exception.rb +20 -20
  9. data/lib/bandwidth/http/api_response.rb +36 -36
  10. data/lib/bandwidth/http/auth/messaging_basic_auth.rb +22 -0
  11. data/lib/bandwidth/http/auth/voice_basic_auth.rb +22 -22
  12. data/lib/bandwidth/http/faraday_client.rb +64 -64
  13. data/lib/bandwidth/http/http_call_back.rb +24 -24
  14. data/lib/bandwidth/http/http_client.rb +104 -104
  15. data/lib/bandwidth/http/http_method_enum.rb +13 -13
  16. data/lib/bandwidth/http/http_request.rb +50 -50
  17. data/lib/bandwidth/http/http_response.rb +29 -29
  18. data/lib/bandwidth/messaging_lib/messaging.rb +23 -0
  19. data/lib/bandwidth/messaging_lib/messaging/client.rb +40 -0
  20. data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +406 -0
  21. data/lib/bandwidth/messaging_lib/messaging/controllers/base_controller.rb +49 -0
  22. data/lib/bandwidth/messaging_lib/messaging/exceptions/generic_client_exception.rb +46 -0
  23. data/lib/bandwidth/messaging_lib/messaging/exceptions/path_client_exception.rb +49 -0
  24. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_callback_message.rb +80 -0
  25. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb +125 -0
  26. data/lib/bandwidth/messaging_lib/messaging/models/deferred_result.rb +44 -0
  27. data/lib/bandwidth/messaging_lib/messaging/models/field_error.rb +44 -0
  28. data/lib/bandwidth/messaging_lib/messaging/models/media.rb +123 -0
  29. data/lib/bandwidth/messaging_lib/messaging/models/message_request.rb +80 -0
  30. data/lib/bandwidth/messaging_lib/messaging/models/tag.rb +44 -0
  31. data/lib/bandwidth/models/base_model.rb +36 -36
  32. data/lib/bandwidth/voice_lib/bxml/bxml.rb +40 -0
  33. data/lib/bandwidth/voice_lib/bxml/verbs/forward.rb +19 -0
  34. data/lib/bandwidth/voice_lib/bxml/verbs/gather.rb +38 -0
  35. data/lib/bandwidth/voice_lib/bxml/verbs/hangup.rb +15 -0
  36. data/lib/bandwidth/voice_lib/bxml/verbs/pause.rb +16 -0
  37. data/lib/bandwidth/voice_lib/bxml/verbs/phone_number.rb +19 -0
  38. data/lib/bandwidth/voice_lib/bxml/verbs/play_audio.rb +18 -0
  39. data/lib/bandwidth/voice_lib/bxml/verbs/redirect.rb +21 -0
  40. data/lib/bandwidth/voice_lib/bxml/verbs/send_dtmf.rb +14 -0
  41. data/lib/bandwidth/voice_lib/bxml/verbs/speak_sentence.rb +19 -0
  42. data/lib/bandwidth/voice_lib/bxml/verbs/transfer.rb +38 -0
  43. data/lib/bandwidth/voice_lib/bxml/verbs/xml_verb.rb +27 -0
  44. data/lib/bandwidth/voice_lib/voice.rb +27 -23
  45. data/lib/bandwidth/voice_lib/voice/client.rb +40 -36
  46. data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +184 -0
  47. data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +49 -49
  48. data/lib/bandwidth/voice_lib/voice/exceptions/bandwidth_exception.rb +51 -0
  49. data/lib/bandwidth/voice_lib/voice/exceptions/bandwidth_not_found_exception.rb +49 -0
  50. data/lib/bandwidth/voice_lib/voice/exceptions/bandwidth_rate_limit_error_exception.rb +56 -0
  51. data/lib/bandwidth/voice_lib/voice/models/answer_method_enum.rb +35 -35
  52. data/lib/bandwidth/voice_lib/voice/models/api_call_response.rb +116 -116
  53. data/lib/bandwidth/voice_lib/voice/models/api_create_call_request.rb +125 -125
  54. data/lib/bandwidth/voice_lib/voice/models/api_modify_call_request.rb +80 -80
  55. data/lib/bandwidth/voice_lib/voice/models/bandwidth_callback_message_voice.rb +98 -98
  56. data/lib/bandwidth/voice_lib/voice/models/disconnect_method_enum.rb +35 -35
  57. data/lib/bandwidth/voice_lib/voice/models/field_error.rb +44 -0
  58. data/lib/bandwidth/voice_lib/voice/models/redirect_method_enum.rb +35 -35
  59. data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +17 -17
  60. metadata +36 -47
  61. data/lib/bandwidth/voice_lib/voice/bxml/bxml.rb +0 -36
  62. data/lib/bandwidth/voice_lib/voice/bxml/verbs/forward.rb +0 -19
  63. data/lib/bandwidth/voice_lib/voice/bxml/verbs/gather.rb +0 -37
  64. data/lib/bandwidth/voice_lib/voice/bxml/verbs/hangup.rb +0 -14
  65. data/lib/bandwidth/voice_lib/voice/bxml/verbs/pause.rb +0 -15
  66. data/lib/bandwidth/voice_lib/voice/bxml/verbs/phone_number.rb +0 -18
  67. data/lib/bandwidth/voice_lib/voice/bxml/verbs/play_audio.rb +0 -17
  68. data/lib/bandwidth/voice_lib/voice/bxml/verbs/redirect.rb +0 -20
  69. data/lib/bandwidth/voice_lib/voice/bxml/verbs/send_dtmf.rb +0 -12
  70. data/lib/bandwidth/voice_lib/voice/bxml/verbs/speak_sentence.rb +0 -18
  71. data/lib/bandwidth/voice_lib/voice/bxml/verbs/transfer.rb +0 -37
  72. data/lib/bandwidth/voice_lib/voice/bxml/verbs/xml_verb.rb +0 -26
  73. data/lib/bandwidth/voice_lib/voice/controllers/calls_controller.rb +0 -88
@@ -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,46 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ # GenericClientException class.
8
+ class GenericClientException < APIException
9
+ # TODO: Write general description for this method
10
+ # @return [String]
11
+ attr_accessor :type
12
+
13
+ # TODO: Write general description for this method
14
+ # @return [String]
15
+ attr_accessor :description
16
+
17
+ # TODO: Write general description for this method
18
+ # @return [List of FieldError]
19
+ attr_accessor :field_errors
20
+
21
+ # The constructor.
22
+ # @param [String] The reason for raising an exception.
23
+ # @param [HttpResponse] The HttpReponse of the API call.
24
+ def initialize(reason, response)
25
+ super(reason, response)
26
+ hash = APIHelper.json_deserialize(@response.raw_body)
27
+ unbox(hash)
28
+ end
29
+
30
+ # Populates this object by extracting properties from a hash.
31
+ # @param [Hash] The deserialized response sent by the server in the
32
+ # response body.
33
+ def unbox(hash)
34
+ @type = hash['type']
35
+ @description = hash['description']
36
+ # Parameter is an array, so we need to iterate through it
37
+ @field_errors = nil
38
+ unless hash['fieldErrors'].nil?
39
+ @field_errors = []
40
+ hash['fieldErrors'].each do |structure|
41
+ @field_errors << (FieldError.from_hash(structure) if structure)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ 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
+ # PathClientException class.
8
+ class PathClientException < APIException
9
+ # TODO: Write general description for this method
10
+ # @return [String]
11
+ attr_accessor :timestamp
12
+
13
+ # TODO: Write general description for this method
14
+ # @return [Integer]
15
+ attr_accessor :status
16
+
17
+ # TODO: Write general description for this method
18
+ # @return [String]
19
+ attr_accessor :error
20
+
21
+ # TODO: Write general description for this method
22
+ # @return [String]
23
+ attr_accessor :message
24
+
25
+ # TODO: Write general description for this method
26
+ # @return [String]
27
+ attr_accessor :path
28
+
29
+ # The constructor.
30
+ # @param [String] The reason for raising an exception.
31
+ # @param [HttpResponse] The HttpReponse of the API call.
32
+ def initialize(reason, response)
33
+ super(reason, response)
34
+ hash = APIHelper.json_deserialize(@response.raw_body)
35
+ unbox(hash)
36
+ end
37
+
38
+ # Populates this object by extracting properties from a hash.
39
+ # @param [Hash] The deserialized response sent by the server in the
40
+ # response body.
41
+ def unbox(hash)
42
+ @timestamp = hash['timestamp']
43
+ @status = hash['status']
44
+ @error = hash['error']
45
+ @message = hash['message']
46
+ @path = hash['path']
47
+ end
48
+ end
49
+ end
@@ -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
+ # BandwidthCallbackMessage Model.
8
+ class BandwidthCallbackMessage < BaseModel
9
+ # TODO: Write general description for this method
10
+ # @return [String]
11
+ attr_accessor :time
12
+
13
+ # TODO: Write general description for this method
14
+ # @return [String]
15
+ attr_accessor :type
16
+
17
+ # TODO: Write general description for this method
18
+ # @return [String]
19
+ attr_accessor :to
20
+
21
+ # TODO: Write general description for this method
22
+ # @return [String]
23
+ attr_accessor :error_code
24
+
25
+ # TODO: Write general description for this method
26
+ # @return [String]
27
+ attr_accessor :description
28
+
29
+ # TODO: Write general description for this method
30
+ # @return [BandwidthMessage]
31
+ attr_accessor :message
32
+
33
+ # A mapping from model property names to API property names.
34
+ def self.names
35
+ @_hash = {} if @_hash.nil?
36
+ @_hash['time'] = 'time'
37
+ @_hash['type'] = 'type'
38
+ @_hash['to'] = 'to'
39
+ @_hash['error_code'] = 'errorCode'
40
+ @_hash['description'] = 'description'
41
+ @_hash['message'] = 'message'
42
+ @_hash
43
+ end
44
+
45
+ def initialize(time = nil,
46
+ type = nil,
47
+ to = nil,
48
+ error_code = nil,
49
+ description = nil,
50
+ message = nil)
51
+ @time = time
52
+ @type = type
53
+ @to = to
54
+ @error_code = error_code
55
+ @description = description
56
+ @message = message
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
+ time = hash['time']
65
+ type = hash['type']
66
+ to = hash['to']
67
+ error_code = hash['errorCode']
68
+ description = hash['description']
69
+ message = BandwidthMessage.from_hash(hash['message']) if hash['message']
70
+
71
+ # Create object from extracted values.
72
+ BandwidthCallbackMessage.new(time,
73
+ type,
74
+ to,
75
+ error_code,
76
+ description,
77
+ message)
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,125 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ # BandwidthMessage Model.
8
+ class BandwidthMessage < BaseModel
9
+ # TODO: Write general description for this method
10
+ # @return [String]
11
+ attr_accessor :id
12
+
13
+ # TODO: Write general description for this method
14
+ # @return [String]
15
+ attr_accessor :owner
16
+
17
+ # TODO: Write general description for this method
18
+ # @return [String]
19
+ attr_accessor :application_id
20
+
21
+ # TODO: Write general description for this method
22
+ # @return [String]
23
+ attr_accessor :time
24
+
25
+ # TODO: Write general description for this method
26
+ # @return [String]
27
+ attr_accessor :segment_count
28
+
29
+ # TODO: Write general description for this method
30
+ # @return [String]
31
+ attr_accessor :direction
32
+
33
+ # TODO: Write general description for this method
34
+ # @return [List of String]
35
+ attr_accessor :to
36
+
37
+ # TODO: Write general description for this method
38
+ # @return [String]
39
+ attr_accessor :from
40
+
41
+ # TODO: Write general description for this method
42
+ # @return [List of String]
43
+ attr_accessor :media
44
+
45
+ # TODO: Write general description for this method
46
+ # @return [String]
47
+ attr_accessor :text
48
+
49
+ # TODO: Write general description for this method
50
+ # @return [String]
51
+ attr_accessor :tag
52
+
53
+ # A mapping from model property names to API property names.
54
+ def self.names
55
+ @_hash = {} if @_hash.nil?
56
+ @_hash['id'] = 'id'
57
+ @_hash['owner'] = 'owner'
58
+ @_hash['application_id'] = 'applicationId'
59
+ @_hash['time'] = 'time'
60
+ @_hash['segment_count'] = 'segmentCount'
61
+ @_hash['direction'] = 'direction'
62
+ @_hash['to'] = 'to'
63
+ @_hash['from'] = 'from'
64
+ @_hash['media'] = 'media'
65
+ @_hash['text'] = 'text'
66
+ @_hash['tag'] = 'tag'
67
+ @_hash
68
+ end
69
+
70
+ def initialize(id = nil,
71
+ owner = nil,
72
+ application_id = nil,
73
+ time = nil,
74
+ segment_count = nil,
75
+ direction = nil,
76
+ to = nil,
77
+ from = nil,
78
+ media = nil,
79
+ text = nil,
80
+ tag = nil)
81
+ @id = id
82
+ @owner = owner
83
+ @application_id = application_id
84
+ @time = time
85
+ @segment_count = segment_count
86
+ @direction = direction
87
+ @to = to
88
+ @from = from
89
+ @media = media
90
+ @text = text
91
+ @tag = tag
92
+ end
93
+
94
+ # Creates an instance of the object from a hash.
95
+ def self.from_hash(hash)
96
+ return nil unless hash
97
+
98
+ # Extract variables from the hash.
99
+ id = hash['id']
100
+ owner = hash['owner']
101
+ application_id = hash['applicationId']
102
+ time = hash['time']
103
+ segment_count = hash['segmentCount']
104
+ direction = hash['direction']
105
+ to = hash['to']
106
+ from = hash['from']
107
+ media = hash['media']
108
+ text = hash['text']
109
+ tag = hash['tag']
110
+
111
+ # Create object from extracted values.
112
+ BandwidthMessage.new(id,
113
+ owner,
114
+ application_id,
115
+ time,
116
+ segment_count,
117
+ direction,
118
+ to,
119
+ from,
120
+ media,
121
+ text,
122
+ tag)
123
+ end
124
+ end
125
+ 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
+ # DeferredResult Model.
8
+ class DeferredResult < BaseModel
9
+ # TODO: Write general description for this method
10
+ # @return [Object]
11
+ attr_accessor :result
12
+
13
+ # TODO: Write general description for this method
14
+ # @return [Boolean]
15
+ attr_accessor :set_or_expired
16
+
17
+ # A mapping from model property names to API property names.
18
+ def self.names
19
+ @_hash = {} if @_hash.nil?
20
+ @_hash['result'] = 'result'
21
+ @_hash['set_or_expired'] = 'setOrExpired'
22
+ @_hash
23
+ end
24
+
25
+ def initialize(result = nil,
26
+ set_or_expired = nil)
27
+ @result = result
28
+ @set_or_expired = set_or_expired
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
+ result = hash['result']
37
+ set_or_expired = hash['setOrExpired']
38
+
39
+ # Create object from extracted values.
40
+ DeferredResult.new(result,
41
+ set_or_expired)
42
+ end
43
+ end
44
+ 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
+ # FieldError Model.
8
+ class FieldError < BaseModel
9
+ # TODO: Write general description for this method
10
+ # @return [String]
11
+ attr_accessor :field_name
12
+
13
+ # TODO: Write general description for this method
14
+ # @return [String]
15
+ attr_accessor :description
16
+
17
+ # A mapping from model property names to API property names.
18
+ def self.names
19
+ @_hash = {} if @_hash.nil?
20
+ @_hash['field_name'] = 'fieldName'
21
+ @_hash['description'] = 'description'
22
+ @_hash
23
+ end
24
+
25
+ def initialize(field_name = nil,
26
+ description = nil)
27
+ @field_name = field_name
28
+ @description = description
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
+ field_name = hash['fieldName']
37
+ description = hash['description']
38
+
39
+ # Create object from extracted values.
40
+ FieldError.new(field_name,
41
+ description)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,123 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ # Media Model.
8
+ class Media < BaseModel
9
+ # TODO: Write general description for this method
10
+ # @return [Object]
11
+ attr_accessor :input_stream
12
+
13
+ # TODO: Write general description for this method
14
+ # @return [String]
15
+ attr_accessor :content
16
+
17
+ # TODO: Write general description for this method
18
+ # @return [String]
19
+ attr_accessor :url
20
+
21
+ # TODO: Write general description for this method
22
+ # @return [String]
23
+ attr_accessor :content_length
24
+
25
+ # TODO: Write general description for this method
26
+ # @return [String]
27
+ attr_accessor :content_type
28
+
29
+ # TODO: Write general description for this method
30
+ # @return [List of Tag]
31
+ attr_accessor :tags
32
+
33
+ # TODO: Write general description for this method
34
+ # @return [String]
35
+ attr_accessor :user_id
36
+
37
+ # TODO: Write general description for this method
38
+ # @return [String]
39
+ attr_accessor :media_name
40
+
41
+ # TODO: Write general description for this method
42
+ # @return [String]
43
+ attr_accessor :media_id
44
+
45
+ # TODO: Write general description for this method
46
+ # @return [String]
47
+ attr_accessor :cache_control
48
+
49
+ # A mapping from model property names to API property names.
50
+ def self.names
51
+ @_hash = {} if @_hash.nil?
52
+ @_hash['input_stream'] = 'inputStream'
53
+ @_hash['content'] = 'content'
54
+ @_hash['url'] = 'url'
55
+ @_hash['content_length'] = 'contentLength'
56
+ @_hash['content_type'] = 'contentType'
57
+ @_hash['tags'] = 'tags'
58
+ @_hash['user_id'] = 'userId'
59
+ @_hash['media_name'] = 'mediaName'
60
+ @_hash['media_id'] = 'mediaId'
61
+ @_hash['cache_control'] = 'cacheControl'
62
+ @_hash
63
+ end
64
+
65
+ def initialize(input_stream = nil,
66
+ content = nil,
67
+ url = nil,
68
+ content_length = nil,
69
+ content_type = nil,
70
+ tags = nil,
71
+ user_id = nil,
72
+ media_name = nil,
73
+ media_id = nil,
74
+ cache_control = nil)
75
+ @input_stream = input_stream
76
+ @content = content
77
+ @url = url
78
+ @content_length = content_length
79
+ @content_type = content_type
80
+ @tags = tags
81
+ @user_id = user_id
82
+ @media_name = media_name
83
+ @media_id = media_id
84
+ @cache_control = cache_control
85
+ end
86
+
87
+ # Creates an instance of the object from a hash.
88
+ def self.from_hash(hash)
89
+ return nil unless hash
90
+
91
+ # Extract variables from the hash.
92
+ input_stream = hash['inputStream']
93
+ content = hash['content']
94
+ url = hash['url']
95
+ content_length = hash['contentLength']
96
+ content_type = hash['contentType']
97
+ # Parameter is an array, so we need to iterate through it
98
+ tags = nil
99
+ unless hash['tags'].nil?
100
+ tags = []
101
+ hash['tags'].each do |structure|
102
+ tags << (Tag.from_hash(structure) if structure)
103
+ end
104
+ end
105
+ user_id = hash['userId']
106
+ media_name = hash['mediaName']
107
+ media_id = hash['mediaId']
108
+ cache_control = hash['cacheControl']
109
+
110
+ # Create object from extracted values.
111
+ Media.new(input_stream,
112
+ content,
113
+ url,
114
+ content_length,
115
+ content_type,
116
+ tags,
117
+ user_id,
118
+ media_name,
119
+ media_id,
120
+ cache_control)
121
+ end
122
+ end
123
+ end