Class: HappyApps::APIClient

Inherits:
Object
  • Object
show all
Defined in:
lib/happyapps/api_client.rb

Direct Known Subclasses

ChecksInterface

Class Method Summary collapse

Instance Method Summary collapse

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.authorize(username,password,client_id='ha-customer',base_url='https://api.happyapps.io/')
	authorize_response = RestClient.post "#{base_url}oauth/token", {grant_type: 'password', scope:'write', client_id: client_id, username: username, password: password}

	credentials = JSON.parse(authorize_response.to_s)

	return self.new(credentials['access_token'],credentials['refresh_token'],credentials['expires_at'], base_url)
end

Instance Method Details

#checksObject



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