Class: Lightspeed::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/lightspeed/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oauth_token: nil) ⇒ Client

Returns a new instance of Client.



11
12
13
14
# File 'lib/lightspeed/client.rb', line 11

def initialize(oauth_token: nil)
  @oauth_token = oauth_token
  @throttler = Lightspeed::RequestThrottler.new
end

Instance Attribute Details

#oauth_tokenObject

Returns the value of attribute oauth_token.



9
10
11
# File 'lib/lightspeed/client.rb', line 9

def oauth_token
  @oauth_token
end

#throttlerObject

Returns the value of attribute throttler.



9
10
11
# File 'lib/lightspeed/client.rb', line 9

def throttler
  @throttler
end

Instance Method Details

#accountsObject

Returns a list of accounts that you have access to.



17
18
19
# File 'lib/lightspeed/client.rb', line 17

def accounts
  @accounts ||= Lightspeed::Accounts.new(context: self)
end

#delete(**args) ⇒ Object



41
42
43
# File 'lib/lightspeed/client.rb', line 41

def delete(**args)
  perform_request(args.merge(method: :delete))
end

#get(**args) ⇒ Object



29
30
31
# File 'lib/lightspeed/client.rb', line 29

def get(**args)
  perform_request(args.merge(method: :get))
end

#load_json(json) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/lightspeed/client.rb', line 21

def load_json(json)
  data = JSON.parse(json)
  Array.wrap(data).map do |resource|
    resource = resource_class.new(context: self, attributes: resource)
    @resources[resource.id] = resource
  end
end

#post(**args) ⇒ Object



33
34
35
# File 'lib/lightspeed/client.rb', line 33

def post(**args)
  perform_request(args.merge(method: :post))
end

#put(**args) ⇒ Object



37
38
39
# File 'lib/lightspeed/client.rb', line 37

def put(**args)
  perform_request(args.merge(method: :put))
end