Class: Twilio::REST::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/twilio-ruby/framework/rest/version.rb

Defined Under Namespace

Classes: RecordStream

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain) ⇒ Version

Returns a new instance of Version.


36
37
38
39
# File 'lib/twilio-ruby/framework/rest/version.rb', line 36

def initialize(domain)
  @domain = domain
  @version = nil
end

Instance Attribute Details

#domainObject

Returns the value of attribute domain


6
7
8
# File 'lib/twilio-ruby/framework/rest/version.rb', line 6

def domain
  @domain
end

Instance Method Details

#absolute_url(uri) ⇒ Object


41
42
43
# File 'lib/twilio-ruby/framework/rest/version.rb', line 41

def absolute_url(uri)
  @domain.absolute_url(relative_uri(uri))
end

#create(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil) ⇒ Object


142
143
144
145
146
147
148
149
150
# File 'lib/twilio-ruby/framework/rest/version.rb', line 142

def create(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
  response = request(method, uri, params, data, headers, 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


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/twilio-ruby/framework/rest/version.rb', line 97

def delete(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
  response = request(
    method,
    uri,
    params,
    data,
    headers,
    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


56
57
58
# File 'lib/twilio-ruby/framework/rest/version.rb', line 56

def exception(response, header)
  Twilio::REST::RestError.new(header, response)
end

#fetch(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil) ⇒ Object


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/twilio-ruby/framework/rest/version.rb', line 60

def fetch(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
  response = request(
    method,
    uri,
    params,
    data,
    headers,
    auth,
    timeout
  )

  # Note that 3XX response codes are allowed for fetches.
  if response.status_code < 200 || response.status_code >= 400
    raise exception(response, 'Unable to fetch record')
  end

  response.body
end

#page(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil) ⇒ Object


126
127
128
129
130
131
132
133
134
135
136
# File 'lib/twilio-ruby/framework/rest/version.rb', line 126

def page(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
  request(
    method,
    uri,
    params,
    data,
    headers,
    auth,
    timeout
  )
end

#read_limits(limit = nil, page_size = nil) ⇒ Object


115
116
117
118
119
120
121
122
123
124
# File 'lib/twilio-ruby/framework/rest/version.rb', line 115

def read_limits(limit = nil, page_size = nil)
  unless limit.nil? || page_size
    page_size = limit
  end

  {
    limit: limit || nil,
    page_size: page_size || nil
  }
end

#relative_uri(uri) ⇒ Object


45
46
47
# File 'lib/twilio-ruby/framework/rest/version.rb', line 45

def relative_uri(uri)
  "#{@version.chomp('/').gsub(/^\//, '')}/#{uri.chomp('/').gsub(/^\//, '')}"
end

#request(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) ⇒ Object


49
50
51
52
53
54
# File 'lib/twilio-ruby/framework/rest/version.rb', line 49

def request(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil)
  url = relative_uri(uri)
  params = params.delete_if { |_k, v| v.nil? }
  data = data
  @domain.request(method, url, params, data, headers, auth, timeout)
end

#stream(page, limit: nil, page_limit: nil) ⇒ Object


138
139
140
# File 'lib/twilio-ruby/framework/rest/version.rb', line 138

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


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/twilio-ruby/framework/rest/version.rb', line 79

def update(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
  response = request(
    method,
    uri,
    params,
    data,
    headers,
    auth,
    timeout
  )

  if response.status_code < 200 || response.status_code >= 300
    raise exception(response, 'Unable to update record')
  end

  response.body
end