Class: RIQ::Client
- Inherits:
-
Object
- Object
- RIQ::Client
- Defined in:
- lib/riq/client.rb
Overview
Utility class to perform HTTP requests. This shouldn’t be instantiated directly but used by children of RIQObject instead.
HTTP client responsible for actually handling the HTTP requests.
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
Instance Method Summary collapse
-
#delete(endpoint, options: nil) ⇒ Object
Makes a DELETE request, used for deleting existing objects.
-
#get(endpoint, options: nil) ⇒ Object
Makes a GET request, used for fetching existing objects.
-
#initialize(key, secret) ⇒ Client
constructor
A new instance of Client.
-
#post(endpoint, body, options: nil) ⇒ Object
Makes a POST request, used for creating new objects.
-
#put(endpoint, body, options: nil) ⇒ Object
Makes a PUT request, used for updating existing objects.
Constructor Details
#initialize(key, secret) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/riq/client.rb', line 12 def initialize(key, secret) raise 'Missing credentials' if key.nil? || secret.nil? @root_url = 'https://api.salesforceiq.com/v2' @auth = {username: key, password: secret} @headers = { 'Content-type' => 'application/json', 'Accept' => 'application/json' } @cache = {} end |
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
10 11 12 |
# File 'lib/riq/client.rb', line 10 def cache @cache end |
Instance Method Details
#delete(endpoint, options: nil) ⇒ Object
Makes a DELETE request, used for deleting existing objects.
50 51 52 |
# File 'lib/riq/client.rb', line 50 def delete(endpoint, options: nil) request(endpoint, :delete, nil, ) end |
#get(endpoint, options: nil) ⇒ Object
Makes a GET request, used for fetching existing objects.
32 33 34 |
# File 'lib/riq/client.rb', line 32 def get(endpoint, options: nil) request(endpoint, :get, nil, ) end |
#post(endpoint, body, options: nil) ⇒ Object
Makes a POST request, used for creating new objects.
38 39 40 |
# File 'lib/riq/client.rb', line 38 def post(endpoint, body, options: nil) request(endpoint, :post, body, ) end |
#put(endpoint, body, options: nil) ⇒ Object
Makes a PUT request, used for updating existing objects.
44 45 46 |
# File 'lib/riq/client.rb', line 44 def put(endpoint, body, options: nil) request(endpoint, :put, body, ) end |