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.
Instance Method Summary collapse
- #authorize ⇒ Object
- #conn ⇒ Object
- #get(url, params = {}) ⇒ Object
-
#initialize(cn, password, site, auth_url) ⇒ BasicApiClient
constructor
A new instance of BasicApiClient.
- #post(url, params = {}) ⇒ Object
Constructor Details
#initialize(cn, password, site, auth_url) ⇒ BasicApiClient
Returns a new instance of BasicApiClient.
10 11 12 13 14 15 |
# File 'lib/basic_api_client.rb', line 10 def initialize(cn, password, site, auth_url) @cn = cn @password = password @site = site @auth_url = auth_url 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 |
Instance Method Details
#authorize ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/basic_api_client.rb', line 31 def res = conn.post do |req| req.url @auth_url req.params['cn'] = @cn req.params['password'] = @password end handle_response(res) end |
#conn ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/basic_api_client.rb', line 21 def conn @conn ||= begin Faraday.new(url: @site) do |faraday| faraday.request :url_encoded faraday.response :logger faraday.adapter Faraday.default_adapter end end end |
#get(url, params = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/basic_api_client.rb', line 41 def get(url, params = {}) unless auth_headers? res = conn.get do |req| req.url url req.params = params.merge(req.params) req.headers = headers end handle_response(res) end |
#post(url, params = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/basic_api_client.rb', line 53 def post(url, params = {}) unless auth_headers? res = conn.post do |req| req.url url req.params = params.merge(req.params) req.headers = headers end handle_response(res) end |