Class: Bookafy::BaseService

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/bookafy/base_service.rb

Direct Known Subclasses

Appointment, Company, Customer

Constant Summary collapse

API_VERSION =
'v1'

Instance Method Summary collapse

Constructor Details

#initializeBaseService

Returns a new instance of BaseService.



9
10
11
12
13
# File 'lib/bookafy/base_service.rb', line 9

def initialize
  url = Bookafy.base_url || 'http://bookafydev.com'
  @domain = "#{url}/api/#{API_VERSION}/"
  @client_token = Bookafy.client_token
end

Instance Method Details

#access_tokenObject



19
20
21
# File 'lib/bookafy/base_service.rb', line 19

def access_token
  @client_token
end

#bookafy_api_urlObject



15
16
17
# File 'lib/bookafy/base_service.rb', line 15

def bookafy_api_url
  @domain
end

#get(url, options = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/bookafy/base_service.rb', line 23

def get(url, options={})
  default_options = {token: @client_token, page: 1}.merge(options)
  api_url = "#{@domain}#{url}"
  response = HTTParty.get(api_url, {query: default_options, headers: {'Authorization' => "Bearer #{Bookafy.access_token}"}})
  response
end