Class: Idsimple::Rack::Api
- Inherits:
-
Object
- Object
- Idsimple::Rack::Api
- Defined in:
- lib/idsimple/rack/api.rb
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
-
#http_client ⇒ Object
TODO: - incorporate API secret.
-
#initialize(base_url, base_path, api_key) ⇒ Api
constructor
A new instance of Api.
- #refresh_token(token_id) ⇒ Object
- #use_token(token_id) ⇒ Object
Constructor Details
#initialize(base_url, base_path, api_key) ⇒ Api
Returns a new instance of Api.
9 10 11 12 13 |
# File 'lib/idsimple/rack/api.rb', line 9 def initialize(base_url, base_path, api_key) @base_url = base_url @base_path = base_path @api_key = api_key end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
7 8 9 |
# File 'lib/idsimple/rack/api.rb', line 7 def base_path @base_path end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
7 8 9 |
# File 'lib/idsimple/rack/api.rb', line 7 def base_url @base_url end |
Instance Method Details
#http_client ⇒ Object
TODO:
-
incorporate API secret
17 18 19 20 21 22 23 24 |
# File 'lib/idsimple/rack/api.rb', line 17 def http_client @http_client ||= begin uri = URI.parse(base_url) client = Net::HTTP.new(uri.host, uri.port) client.use_ssl = base_url.start_with?("https") client end end |
#refresh_token(token_id) ⇒ Object
31 32 33 34 |
# File 'lib/idsimple/rack/api.rb', line 31 def refresh_token(token_id) response = http_client.patch("#{base_path}/access_tokens/#{token_id}/refresh", "", headers) Result.new(response) end |
#use_token(token_id) ⇒ Object
26 27 28 29 |
# File 'lib/idsimple/rack/api.rb', line 26 def use_token(token_id) response = http_client.patch("#{base_path}/access_tokens/#{token_id}/use", "", headers) Result.new(response) end |