Class: Twilio::REST::Version
- Inherits:
-
Object
- Object
- Twilio::REST::Version
show all
- Defined in:
- lib/twilio-ruby/framework/version.rb
Direct Known Subclasses
Accounts::V1, Api::V2010, Chat::V1, Chat::V2, Fax::V1, IpMessaging::V1, IpMessaging::V2, Lookups::V1, Messaging::V1, Monitor::V1, Notify::V1, Preview::AccSecurity, Preview::BulkExports, Preview::DeployedDevices, Preview::HostedNumbers, Preview::Marketplace, Preview::Proxy, Preview::Studio, Preview::Sync, Preview::Understand, Preview::Wireless, Pricing::V1, Proxy::V1, Studio::V1, Sync::V1, Taskrouter::V1, Trunking::V1, Twilio::REST::Video::V1, Wireless::V1
Defined Under Namespace
Classes: RecordStream
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#absolute_url(uri) ⇒ Object
-
#create(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil) ⇒ Object
-
#delete(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) ⇒ Object
-
#exception(response, header) ⇒ Object
-
#fetch(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) ⇒ Object
-
#initialize(domain) ⇒ Version
constructor
A new instance of Version.
-
#page(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) ⇒ Object
-
#read_limits(limit = nil, page_size = nil) ⇒ Object
-
#relative_uri(uri) ⇒ Object
-
#request(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) ⇒ Object
-
#stream(page, limit: nil, page_limit: nil) ⇒ Object
-
#update(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil) ⇒ Object
Constructor Details
#initialize(domain) ⇒ Version
Returns a new instance of Version.
34
35
36
37
|
# File 'lib/twilio-ruby/framework/version.rb', line 34
def initialize(domain)
@domain = domain
@version = nil
end
|
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
4
5
6
|
# File 'lib/twilio-ruby/framework/version.rb', line 4
def domain
@domain
end
|
Instance Method Details
#absolute_url(uri) ⇒ Object
39
40
41
|
# File 'lib/twilio-ruby/framework/version.rb', line 39
def absolute_url(uri)
@domain.absolute_url(relative_uri(uri))
end
|
#create(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil) ⇒ Object
153
154
155
156
157
158
159
160
161
|
# File 'lib/twilio-ruby/framework/version.rb', line 153
def create(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
response = request(method, uri, params, data, , auth, timeout)
if response.status_code < 200 || response.status_code >= 300
raise exception(response, 'Unable to create record')
end
response.body
end
|
#delete(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/twilio-ruby/framework/version.rb', line 103
def delete(method, uri, params = {}, data = {}, = {}, auth = nil, timeout = nil)
response = request(
method,
uri,
params,
data,
,
auth,
timeout
)
if response.status_code < 200 || response.status_code >= 300
raise exception(response, 'Unable to delete record')
end
response.status_code == 204
end
|
#exception(response, header) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/twilio-ruby/framework/version.rb', line 54
def exception(response, )
message =
code = response.status_code
if response.body.key?('message')
message += ": #{response.body['message']}"
end
code = response.body['code'] if response.body.key?('code')
Twilio::REST::RestError.new(message, code, response.status_code)
end
|
#fetch(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/twilio-ruby/framework/version.rb', line 67
def fetch(method, uri, params = {}, data = {}, = {}, auth = nil, timeout = nil)
response = request(
method,
uri,
params,
data,
,
auth,
timeout
)
if response.status_code < 200 || response.status_code >= 300
raise exception(response, 'Unable to fetch record')
end
response.body
end
|
#page(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/twilio-ruby/framework/version.rb', line 137
def page(method, uri, params = {}, data = {}, = {}, auth = nil, timeout = nil)
request(
method,
uri,
params,
data,
,
auth,
timeout
)
end
|
#read_limits(limit = nil, page_size = nil) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/twilio-ruby/framework/version.rb', line 121
def read_limits(limit = nil, page_size = nil)
page_limit = nil
unless limit.nil?
page_size = limit
page_limit = (limit / page_size.to_f).ceil
end
{
limit: limit || nil,
page_size: page_size || nil,
page_limit: page_limit
}
end
|
#relative_uri(uri) ⇒ Object
43
44
45
|
# File 'lib/twilio-ruby/framework/version.rb', line 43
def relative_uri(uri)
"#{@version.chomp('/').gsub(/^\//, '')}/#{uri.chomp('/').gsub(/^\//, '')}"
end
|
#request(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/twilio-ruby/framework/version.rb', line 47
def request(method, uri, params = {}, data = {}, = {}, auth = nil, timeout = nil)
url = relative_uri(uri)
params = params.delete_if { |_k, v| v.nil? }
data = data
@domain.request(method, url, params, data, , auth, timeout)
end
|
#stream(page, limit: nil, page_limit: nil) ⇒ Object
149
150
151
|
# File 'lib/twilio-ruby/framework/version.rb', line 149
def stream(page, limit: nil, page_limit: nil)
RecordStream.new(page, limit: limit, page_limit: page_limit)
end
|
#update(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/twilio-ruby/framework/version.rb', line 85
def update(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
response = request(
method,
uri,
params,
data,
,
auth,
timeout
)
if response.status_code < 200 || response.status_code >= 300
raise exception(response, 'Unable to update record')
end
response.body
end
|