Class: Twilio::RestAccount
- Inherits:
-
Object
- Object
- Twilio::RestAccount
- Defined in:
- lib/twiliolib.rb
Overview
Twilio REST Helpers
Instance Method Summary collapse
-
#initialize(id, token) ⇒ Object
constructor
initialize a twilio account object.
-
#request(path, method = nil, vars = {}) ⇒ Object
sends a request and gets a response from the Twilio REST API.
Constructor Details
#initialize(id, token) ⇒ Object
initialize a twilio account object
46 47 48 49 |
# File 'lib/twiliolib.rb', line 46 def initialize(id, token) @id = id @token = token end |
Instance Method Details
#request(path, method = nil, vars = {}) ⇒ Object
sends a request and gets a response from the Twilio REST API
path, the URL (relative to the endpoint URL, after the /v1 method, the HTTP method to use, defaults to POST vars, for POST or PUT, a dict of data to send
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/twiliolib.rb', line 61 def request(path, method=nil, vars={}) if !path || path.length < 1 raise ArgumentError, 'Invalid path parameter' end if method && !['GET', 'POST', 'DELETE', 'PUT'].include?(method) raise NotImplementedError, 'HTTP %s not implemented' % method end if path[0, 1] == '/' uri = TWILIO_API_URL + path else uri = TWILIO_API_URL + '/' + path end return fetch(uri, vars, method) end |