Class: Ketchup::API
Overview
The direct interface with Ketchup’s RESTful API. You should generally not have any need to use this class yourself, unless you’re playing around with the internals. That said, it’s a simple class - with get, post, put and delete instance methods for matching HTTP requests, that automatically include the access token.
For pure access to the API, without any implicit authentication, use the class level methods, which are provided by the mixed-in HTTParty module.
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
Instance Method Summary collapse
-
#delete(path, data = {}) ⇒ Object
Execute a DELETE request to the API server using the stored access token.
-
#get(path, data = {}) ⇒ Object
Execute a GET request to the API server using the stored access token.
-
#initialize(email, password) ⇒ API
constructor
Creates a new API instance for the given profile, as determined by the email and password.
-
#post(path, data = {}) ⇒ Object
Execute a POST request to the API server using the stored access token.
-
#put(path, data = {}) ⇒ Object
Execute a PUT request to the API server using the stored access token.
Constructor Details
#initialize(email, password) ⇒ API
Creates a new API instance for the given profile, as determined by the email and password. This API object can then be used by all other objects to interact with the API without having to re-authenticate.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ketchup/api.rb', line 28 def initialize(email, password) response = self.class.get '/profile.json', :basic_auth => { :username => email, :password => password } if response == 'Access Denied' raise Ketchup::AccessDenied else @access_token = response['single_access_token'] end end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
18 19 20 |
# File 'lib/ketchup/api.rb', line 18 def access_token @access_token end |
Instance Method Details
#delete(path, data = {}) ⇒ Object
Execute a DELETE request to the API server using the stored access token.
77 78 79 |
# File 'lib/ketchup/api.rb', line 77 def delete(path, data = {}) self.class.delete path, :body => data.merge(:u => access_token) end |
#get(path, data = {}) ⇒ Object
Execute a GET request to the API server using the stored access token.
47 48 49 |
# File 'lib/ketchup/api.rb', line 47 def get(path, data = {}) self.class.get path, :query => data.merge(:u => access_token) end |
#post(path, data = {}) ⇒ Object
Execute a POST request to the API server using the stored access token.
57 58 59 |
# File 'lib/ketchup/api.rb', line 57 def post(path, data = {}) self.class.post path, :body => data.merge(:u => access_token) end |
#put(path, data = {}) ⇒ Object
Execute a PUT request to the API server using the stored access token.
67 68 69 |
# File 'lib/ketchup/api.rb', line 67 def put(path, data = {}) self.class.put path, :body => data.merge(:u => access_token) end |