Class: Pocus::Session
- Inherits:
-
Object
- Object
- Pocus::Session
- Defined in:
- lib/pocus/session.rb
Overview
Sends authenticated JSON requests to remote service using HTTPS.
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(host: 'api.invoc.us', app_id:, username:, password:, logger: Logger.new('/dev/null')) ⇒ Session
constructor
A new instance of Session.
-
#pro? ⇒ Boolean
‘Pro’ is legacy as moniker dropped.
-
#send_request(method, path, fields = {}) ⇒ Object
Accepts hash of fields to send.
Constructor Details
#initialize(host: 'api.invoc.us', app_id:, username:, password:, logger: Logger.new('/dev/null')) ⇒ Session
Returns a new instance of Session.
23 24 25 26 27 28 29 30 31 |
# File 'lib/pocus/session.rb', line 23 def initialize(host: 'api.invoc.us', app_id:, username:, password:, logger: Logger.new('/dev/null')) @base_url = "https://#{host}/icp".freeze @credentials = { 'API-AppId' => app_id, 'API-Username' => username, 'API-Password' => password } @logger = logger end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
19 20 21 |
# File 'lib/pocus/session.rb', line 19 def base_url @base_url end |
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
20 21 22 |
# File 'lib/pocus/session.rb', line 20 def credentials @credentials end |
#logger ⇒ Object
Returns the value of attribute logger.
21 22 23 |
# File 'lib/pocus/session.rb', line 21 def logger @logger end |
Instance Method Details
#pro? ⇒ Boolean
‘Pro’ is legacy as moniker dropped.
34 35 36 |
# File 'lib/pocus/session.rb', line 34 def pro? base_url =~ /invoc.us/ end |
#send_request(method, path, fields = {}) ⇒ Object
Accepts hash of fields to send. Returns parsed response body, always a hash.
40 41 42 43 44 |
# File 'lib/pocus/session.rb', line 40 def send_request(method, path, fields = {}) response = send_logged_request(URI(base_url + path), method, request_data(fields)) fail UnexpectedHttpResponse, response unless response.is_a? Net::HTTPSuccess JSON.parse(response.body) end |