Class: Plivo::RestClient
- Inherits:
-
Object
- Object
- Plivo::RestClient
- Defined in:
- lib/plivo/rest_client.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Resources.
-
#addresses ⇒ Object
readonly
Returns the value of attribute addresses.
-
#applications ⇒ Object
readonly
Returns the value of attribute applications.
-
#auth_credentials ⇒ Object
readonly
Base stuff.
-
#calls ⇒ Object
readonly
Returns the value of attribute calls.
-
#conferences ⇒ Object
readonly
Returns the value of attribute conferences.
-
#endpoints ⇒ Object
readonly
Returns the value of attribute endpoints.
-
#headers ⇒ Object
readonly
Base stuff.
-
#identities ⇒ Object
readonly
Returns the value of attribute identities.
-
#messages ⇒ Object
readonly
Resources.
-
#numbers ⇒ Object
readonly
Returns the value of attribute numbers.
-
#phone_numbers ⇒ Object
readonly
Returns the value of attribute phone_numbers.
-
#pricings ⇒ Object
readonly
Returns the value of attribute pricings.
-
#recordings ⇒ Object
readonly
Resources.
-
#subaccounts ⇒ Object
readonly
Resources.
Instance Method Summary collapse
- #auth_id ⇒ Object
-
#initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout = 5) ⇒ RestClient
constructor
A new instance of RestClient.
- #process_response(method, response) ⇒ Object
- #send_request(resource_path, method = 'GET', data = {}, timeout = nil, use_multipart_conn = false) ⇒ Object
Constructor Details
#initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout = 5) ⇒ RestClient
Returns a new instance of RestClient.
23 24 25 26 27 28 29 30 |
# File 'lib/plivo/rest_client.rb', line 23 def initialize(auth_id = nil, auth_token = nil, = nil, timeout=5) configure_credentials(auth_id, auth_token) configure_proxies() configure_timeout(timeout) configure_headers configure_connection configure_interfaces end |
Instance Attribute Details
#account ⇒ Object (readonly)
Resources
18 19 20 |
# File 'lib/plivo/rest_client.rb', line 18 def account @account end |
#addresses ⇒ Object (readonly)
Returns the value of attribute addresses.
21 22 23 |
# File 'lib/plivo/rest_client.rb', line 21 def addresses @addresses end |
#applications ⇒ Object (readonly)
Returns the value of attribute applications.
20 21 22 |
# File 'lib/plivo/rest_client.rb', line 20 def applications @applications end |
#auth_credentials ⇒ Object (readonly)
Base stuff
15 16 17 |
# File 'lib/plivo/rest_client.rb', line 15 def auth_credentials @auth_credentials end |
#calls ⇒ Object (readonly)
Returns the value of attribute calls.
19 20 21 |
# File 'lib/plivo/rest_client.rb', line 19 def calls @calls end |
#conferences ⇒ Object (readonly)
Returns the value of attribute conferences.
19 20 21 |
# File 'lib/plivo/rest_client.rb', line 19 def conferences @conferences end |
#endpoints ⇒ Object (readonly)
Returns the value of attribute endpoints.
20 21 22 |
# File 'lib/plivo/rest_client.rb', line 20 def endpoints @endpoints end |
#headers ⇒ Object (readonly)
Base stuff
15 16 17 |
# File 'lib/plivo/rest_client.rb', line 15 def headers @headers end |
#identities ⇒ Object (readonly)
Returns the value of attribute identities.
21 22 23 |
# File 'lib/plivo/rest_client.rb', line 21 def identities @identities end |
#messages ⇒ Object (readonly)
Resources
18 19 20 |
# File 'lib/plivo/rest_client.rb', line 18 def @messages end |
#numbers ⇒ Object (readonly)
Returns the value of attribute numbers.
19 20 21 |
# File 'lib/plivo/rest_client.rb', line 19 def numbers @numbers end |
#phone_numbers ⇒ Object (readonly)
Returns the value of attribute phone_numbers.
20 21 22 |
# File 'lib/plivo/rest_client.rb', line 20 def phone_numbers @phone_numbers end |
#pricings ⇒ Object (readonly)
Returns the value of attribute pricings.
19 20 21 |
# File 'lib/plivo/rest_client.rb', line 19 def pricings @pricings end |
#recordings ⇒ Object (readonly)
Resources
18 19 20 |
# File 'lib/plivo/rest_client.rb', line 18 def recordings @recordings end |
#subaccounts ⇒ Object (readonly)
Resources
18 19 20 |
# File 'lib/plivo/rest_client.rb', line 18 def subaccounts @subaccounts end |
Instance Method Details
#auth_id ⇒ Object
32 33 34 |
# File 'lib/plivo/rest_client.rb', line 32 def auth_id @auth_credentials[:auth_id] end |
#process_response(method, response) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/plivo/rest_client.rb', line 36 def process_response(method, response) handle_response_exceptions(response) if method == 'DELETE' if response[:status] != 204 raise Exceptions::PlivoRESTError, "Resource at #{response[:url]} "\ 'couldn\'t be deleted' end elsif !([200, 201, 202].include? response[:status]) raise Exceptions::PlivoRESTError, "Received #{response[:status]} for #{method}" end response[:body] end |
#send_request(resource_path, method = 'GET', data = {}, timeout = nil, use_multipart_conn = false) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/plivo/rest_client.rb', line 50 def send_request(resource_path, method = 'GET', data = {}, timeout = nil, use_multipart_conn = false) timeout ||= @timeout response = case method when 'GET' then send_get(resource_path, data, timeout) when 'POST' then send_post(resource_path, data, timeout, use_multipart_conn) when 'DELETE' then send_delete(resource_path, timeout) else raise_invalid_request("#{method} not supported by Plivo, yet") end process_response(method, response.to_hash) end |