Class: BasicApiClient
- Inherits:
-
Object
- Object
- BasicApiClient
- Defined in:
- lib/basic_api_client.rb
Constant Summary collapse
- AUTH_HEADERS =
%w{ access-token token-type uid expiry client }.sort
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#last_response ⇒ Object
Returns the value of attribute last_response.
-
#last_return ⇒ Object
Returns the value of attribute last_return.
Instance Method Summary collapse
- #authorize ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(cn, password, site, auth_path) ⇒ BasicApiClient
constructor
A new instance of BasicApiClient.
- #post(path, params = {}) ⇒ Object
Constructor Details
#initialize(cn, password, site, auth_path) ⇒ BasicApiClient
Returns a new instance of BasicApiClient.
10 11 12 13 14 15 16 |
# File 'lib/basic_api_client.rb', line 10 def initialize(cn, password, site, auth_path) @cn = cn @password = password @site = site @site.sub!(/\/+$/, '') @auth_url = url_for(auth_path) end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
7 8 9 |
# File 'lib/basic_api_client.rb', line 7 def headers @headers end |
#last_response ⇒ Object
Returns the value of attribute last_response.
8 9 10 |
# File 'lib/basic_api_client.rb', line 8 def last_response @last_response end |
#last_return ⇒ Object
Returns the value of attribute last_return.
8 9 10 |
# File 'lib/basic_api_client.rb', line 8 def last_return @last_return end |
Instance Method Details
#authorize ⇒ Object
22 23 24 25 26 27 |
# File 'lib/basic_api_client.rb', line 22 def @headers = {} params = { cn: @cn, password: @password } Curl.post(@auth_url, params, &method(:setup_request)) last_return end |
#get(path, params = {}) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/basic_api_client.rb', line 29 def get(path, params = {}) unless auth_headers? url = url_for(path) Curl.get(url, params, &method(:setup_request)) last_return end |
#post(path, params = {}) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/basic_api_client.rb', line 37 def post(path, params = {}) unless auth_headers? url = url_for(path) Curl.post(url, params, &method(:setup_request)) last_return end |