Class: Booker::BusinessClient

Inherits:
Client
  • Object
show all
Includes:
BusinessREST
Defined in:
lib/booker/business_client.rb

Constant Summary

Constants included from CommonREST

CommonREST::DEFAULT_PAGINATION_PARAMS

Constants inherited from Client

Client::TimeZone

Instance Attribute Summary collapse

Attributes inherited from Client

#base_url, #client_id, #client_secret, #temp_access_token, #temp_access_token_expires_at, #token_store, #token_store_callback_method

Instance Method Summary collapse

Methods included from BusinessREST

#create_special, #find_appointments, #find_customers, #find_employees, #find_locations, #find_treatments, #get_location, #get_logged_in_user

Methods included from CommonREST

#confirm_appointment, #get_online_booking_settings

Methods inherited from Client

#access_token, #get, #get_booker_resources, #handle_errors!, #log_issue, #paginated_request, #post, #put

Constructor Details

#initialize(options = {}) ⇒ BusinessClient

Returns a new instance of BusinessClient.



7
8
9
10
# File 'lib/booker/business_client.rb', line 7

def initialize(options={})
  self.base_url = ENV['BOOKER_BUSINESS_SERVICE_URL'] || 'https://apicurrent-app.booker.ninja/webservice4/json/BusinessService.svc'
  super
end

Instance Attribute Details

#booker_account_name ⇒ Object

Returns the value of attribute booker_account_name.



5
6
7
# File 'lib/booker/business_client.rb', line 5

def 
  
end

#booker_password ⇒ Object

Returns the value of attribute booker_password.



5
6
7
# File 'lib/booker/business_client.rb', line 5

def booker_password
  @booker_password
end

#booker_username ⇒ Object

Returns the value of attribute booker_username.



5
6
7
# File 'lib/booker/business_client.rb', line 5

def booker_username
  @booker_username
end

Instance Method Details

#get_access_token ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/booker/business_client.rb', line 12

def get_access_token
  http_options = {
    client_id: self.client_id,
    client_secret: self.client_secret,
    'AccountName' => self.,
    'UserName' => self.booker_username,
    'Password' => self.booker_password
  }
  response = post('/accountlogin', http_options, nil).parsed_response

  raise Booker::InvalidApiCredentials.new(http_options, response) unless response.present?

  self.temp_access_token_expires_at = Time.now + response['expires_in'].to_i.seconds
  self.temp_access_token = response['access_token']

  update_token_store

  self.temp_access_token
end