Class: WellRested::CAPI
- Includes:
- WellRested, Utils
- Defined in:
- lib/well_rested/capi.rb
Overview
All REST requests are made through an API object. API objects store cross-resource settings such as user and password (for HTTP basic auth).
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#default_path_parameters ⇒ Object
Returns the value of attribute default_path_parameters.
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
-
#password ⇒ Object
Returns the value of attribute password.
-
#unique_id ⇒ Object
Returns the value of attribute unique_id.
-
#user ⇒ Object
Returns the value of attribute user.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.request_headers(unique_id, version) ⇒ Object
Return the default headers sent with all HTTP requests.
Instance Method Summary collapse
-
#initialize(path_params = {}, session_params = {}, version = "") ⇒ CAPI
constructor
A new instance of CAPI.
-
#request_headers ⇒ Object
Convenience method.
Methods included from WellRested
Methods inherited from API
#create, #delete, fill_path, #find, #find_many, #get, #post, #put, #request, #save, #url_for
Constructor Details
#initialize(path_params = {}, session_params = {}, version = "") ⇒ CAPI
Returns a new instance of CAPI.
18 19 20 21 22 23 |
# File 'lib/well_rested/capi.rb', line 18 def initialize(path_params = {}, session_params = {}, version = "") self.default_path_parameters = path_params.with_indifferent_access self.client = RestClient self.unique_id = session_params.try(:id) || 'unauthorized' self.version = version end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
13 14 15 |
# File 'lib/well_rested/capi.rb', line 13 def client @client end |
#default_path_parameters ⇒ Object
Returns the value of attribute default_path_parameters.
12 13 14 |
# File 'lib/well_rested/capi.rb', line 12 def default_path_parameters @default_path_parameters end |
#last_response ⇒ Object (readonly)
Returns the value of attribute last_response.
14 15 16 |
# File 'lib/well_rested/capi.rb', line 14 def last_response @last_response end |
#password ⇒ Object
Returns the value of attribute password.
11 12 13 |
# File 'lib/well_rested/capi.rb', line 11 def password @password end |
#unique_id ⇒ Object
Returns the value of attribute unique_id.
15 16 17 |
# File 'lib/well_rested/capi.rb', line 15 def unique_id @unique_id end |
#user ⇒ Object
Returns the value of attribute user.
10 11 12 |
# File 'lib/well_rested/capi.rb', line 10 def user @user end |
#version ⇒ Object
Returns the value of attribute version.
16 17 18 |
# File 'lib/well_rested/capi.rb', line 16 def version @version end |
Class Method Details
.request_headers(unique_id, version) ⇒ Object
Return the default headers sent with all HTTP requests.
31 32 33 34 35 36 37 38 39 |
# File 'lib/well_rested/capi.rb', line 31 def self.request_headers(unique_id, version) # Accept necessary for fetching results by result ID, but not in most places. { :content_type => 'application/json', :accept => 'application/json', "Authentication" => unique_id, :version => version } end |
Instance Method Details
#request_headers ⇒ Object
Convenience method. Also allows request_headers to be can be set on a per-instance basis.
26 27 28 |
# File 'lib/well_rested/capi.rb', line 26 def request_headers self.class.request_headers(self.unique_id, self.version) end |