Class: Automation::API::Client

Overview

Automation::API::Client

Constant Summary collapse

LOCAL_URL =
'http://admin.127.0.0.1.xip.io:3000'
MOCK_URL =
'http://localhost:1234'
URL =
'https://api.getshopkeep.com'
USERNAME =
'8ec7225ad7aead3ef09265456f8de02c'
PASSWORD =
'X'
AUTH_TOKEN =
'OGVjNzIyNWFkN2FlYWQzZWYwOTI2NTQ1NmY4ZGUwMmM6WA=='
CONTENT_HEADERS =
{ content_type: :json, accept: :json }.freeze
DEFAULT_ARCHETYPE =
'complex'
DEFAULT_PROCESSOR =
'tgate_dev'
DEFAULT_OPTIONS =
{ archetype: DEFAULT_ARCHETYPE,
processor: DEFAULT_PROCESSOR }.freeze

Constants included from Requests::AppSync

Requests::AppSync::GRAPHQL_DELETE, Requests::AppSync::GRAPHQL_ENDPOINT, Requests::AppSync::GRAPHQL_SEARCH

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Requests::Tenders

#disable_tenders, #enable_tenders, #tenders, #update_tenders

Methods included from Requests::TaxRateServiceTaxes

#trs_create_tax, #trs_delete_tax, #trs_tax, #trs_taxes, #trs_update_tax

Methods included from Requests::Taxes

#create_tax, #delete_tax, #tax, #taxes, #update_tax

Methods included from Requests::StockItems

#create_stock_item, #delete_stock_item, #stock_item, #stock_items, #update_stock_item

Methods included from Requests::Settings

#settings, #update_settings

Methods included from Requests::SalesRestrictions

#create_sales_restriction, #delete_sales_restriction, #sales_restriction, #sales_restrictions, #update_sales_restriction

Methods included from Requests::Sales

#sale, #sales

Methods included from Requests::Registers

#create_register, #deactivate_register, #register, #registers

Methods included from Requests::OnlineOrders

#enable_online_ordering

Methods included from Requests::NamedDiscounts

#create_named_discount, #delete_named_discount, #named_discount, #named_discounts, #update_named_discount

Methods included from Requests::Modifiers

#create_modifier, #delete_modifier, #modifier, #modifiers, #update_modifier

Methods included from Requests::MatrixProducts

#create_matrix_product, #delete_matrix_product, #matrix_product, #matrix_products, #update_matrix_product

Methods included from Requests::LoyaltyProvisioning

#deprovision, #provision

Methods included from Requests::LocationPreferences

#location_preferences, #update_location_preferences

Methods included from Requests::Features

#activate_feature, #deactivate_feature, #update_features

Methods included from Requests::Entitlements

#activate_entitlement, #deactivate_entitlement, #update_entitlements

Methods included from Requests::Employees

#create_employee, #delete_employee, #employee, #employees, #update_employee

Methods included from Requests::Departments

#create_department, #delete_department, #department, #departments, #update_department

Methods included from Requests::Customers

#create_customer, #customer, #customers, #delete_customer, #update_customer

Methods included from Requests::Categories

#categories, #category, #create_category, #delete_category, #update_category

Methods included from Requests::Buttons

#button, #buttons, #create_button, #delete_button, #update_button

Methods included from Requests::ButtonPages

#button_page, #button_pages, #create_button_page, #delete_button_page, #update_button_page

Methods included from Requests::AppSync

#delete_check, #search_checks

Methods included from Requests::AccountOwner

#account_owner, #update_account_owner

Constructor Details

#initialize(uuid:, store: '', login: '', password: '', url: URL) ⇒ Client

Returns a new instance of Client.



88
89
90
91
92
93
94
95
# File 'lib/automation/api/client.rb', line 88

def initialize(uuid:, store: '', login: '', password: '', url: URL)
  @uuid     = uuid
  @store    = store
  @login    = 
  @password = password
  @base_uri = "#{url}/dev/test/store/#{uuid}"
  @trs_uri  = "#{url}/tax-rates-service/stores/#{uuid}"
end

Instance Attribute Details

#loginObject (readonly)

Returns the value of attribute login.



86
87
88
# File 'lib/automation/api/client.rb', line 86

def 
  @login
end

#passwordObject (readonly)

Returns the value of attribute password.



86
87
88
# File 'lib/automation/api/client.rb', line 86

def password
  @password
end

#storeObject (readonly)

Returns the value of attribute store.



86
87
88
# File 'lib/automation/api/client.rb', line 86

def store
  @store
end

#uuidObject (readonly)

Returns the value of attribute uuid.



86
87
88
# File 'lib/automation/api/client.rb', line 86

def uuid
  @uuid
end

Class Method Details

.create(options = DEFAULT_OPTIONS) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/automation/api/client.rb', line 55

def self.create(options = DEFAULT_OPTIONS)
  store_data = generate_store(options)

  pp store_data

  store_settings(subdomain: store_data['subdomain'],
                 processor: options['processor'])

  new(uuid: store_data['uuid'])
end

.generate_store(options) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/automation/api/client.rb', line 66

def self.generate_store(options)
  response = RestClient.post("#{URL}/dev/test/generate_store",
                             options.to_json,
                             content_type: :json,
                             accept: :json,
                             authorization: "Basic #{AUTH_TOKEN}")

  JSON.parse(response.body)
end

.store_settings(settings) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/automation/api/client.rb', line 76

def self.store_settings(settings)
  response = RestClient.post("#{URL}/dev/test/store_settings",
                             settings.to_json,
                             content_type: :json,
                             accept: :json,
                             authorization: "Basic #{AUTH_TOKEN}")

  JSON.parse(response.body)
end

Instance Method Details

#dev_headersObject



97
98
99
# File 'lib/automation/api/client.rb', line 97

def dev_headers
  @dev_headers ||= CONTENT_HEADERS.merge(authorization: "Basic #{AUTH_TOKEN}")
end

#jwt_headersObject



101
102
103
# File 'lib/automation/api/client.rb', line 101

def jwt_headers
  @jwt_headers ||= CONTENT_HEADERS.merge(authorization: "Token token=#{jwt_token}")
end