Class: HappyApps::APIClient
- Inherits:
-
Object
- Object
- HappyApps::APIClient
- Defined in:
- lib/happyapps/api_client.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #checks ⇒ Object
-
#initialize(access_token, refresh_token, expires_in = nil, base_url = nil) ⇒ APIClient
constructor
A new instance of APIClient.
Constructor Details
#initialize(access_token, refresh_token, expires_in = nil, base_url = nil) ⇒ APIClient
Returns a new instance of APIClient.
5 6 7 8 9 10 11 12 |
# File 'lib/happyapps/api_client.rb', line 5 def initialize(access_token, refresh_token,expires_in = nil, base_url=nil) @access_token = access_token @refresh_token = refresh_token @base_url = base_url if expires_in != nil @expires_at = DateTime.now + expires_in.seconds end end |
Class Method Details
.authorize(username, password, client_id = 'ha-customer', base_url = 'https://api.happyapps.io/') ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/happyapps/api_client.rb', line 14 def self.(username,password,client_id='ha-customer',base_url='https://api.happyapps.io/') = RestClient.post "#{base_url}oauth/token", {grant_type: 'password', scope:'write', client_id: client_id, username: username, password: password} credentials = JSON.parse(.to_s) return self.new(credentials['access_token'],credentials['refresh_token'],credentials['expires_at'], base_url) end |
Instance Method Details
#checks ⇒ Object
23 24 25 |
# File 'lib/happyapps/api_client.rb', line 23 def checks HappyApps::ChecksInterface.new(@access_token, @refresh_token, @expires_at, @base_url) end |