Class: WellRested::CAPI

Inherits:
API
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WellRested

#logger

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

#clientObject

Returns the value of attribute client.



13
14
15
# File 'lib/well_rested/capi.rb', line 13

def client
  @client
end

#default_path_parametersObject

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_responseObject (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

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/well_rested/capi.rb', line 11

def password
  @password
end

#unique_idObject

Returns the value of attribute unique_id.



15
16
17
# File 'lib/well_rested/capi.rb', line 15

def unique_id
  @unique_id
end

#userObject

Returns the value of attribute user.



10
11
12
# File 'lib/well_rested/capi.rb', line 10

def user
  @user
end

#versionObject

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_headersObject

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