Class: Vis::Api
- Inherits:
-
Object
- Object
- Vis::Api
- Defined in:
- lib/vis/api.rb
Instance Method Summary collapse
- #get(path) ⇒ Object
-
#initialize(server_url: "https://identity.dhamma.org", client_id:, client_secret:) ⇒ Api
constructor
A new instance of Api.
- #post(path, post_params_hash) ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(server_url: "https://identity.dhamma.org", client_id:, client_secret:) ⇒ Api
Returns a new instance of Api.
5 6 7 8 9 10 |
# File 'lib/vis/api.rb', line 5 def initialize(server_url: "https://identity.dhamma.org", client_id:, client_secret:) @client_id = client_id @client_secret = client_secret @vis_app_url = server_url @use_ssl = !Rails.env.development? end |
Instance Method Details
#get(path) ⇒ Object
40 41 42 43 44 |
# File 'lib/vis/api.rb', line 40 def get(path) http_client, uri = http_client_and_uri path response = http_client.get(uri, headers) return_response(response) end |
#post(path, post_params_hash) ⇒ Object
46 47 48 49 50 |
# File 'lib/vis/api.rb', line 46 def post(path, post_params_hash) http_client, uri = http_client_and_uri path response = http_client.post(uri, post_params_hash.to_json, headers) return_response(response) end |
#token ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/vis/api.rb', line 12 def token return @token if @token && @expiry && Time.now.utc < @expiry response = token_post result = JSON.parse(response.body) check_error!(response.code, result) @expiry = (Time.now.utc + result["expires_in"] - 1) @token = result["access_token"] end |