Class: Lucid::Shopify::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(bulk_request: Container[:bulk_request], send_request: Container[:send_request], send_throttled_request: Container[:send_throttled_request], throttling: true) ⇒ Client

Returns a new instance of Client.

Parameters:

  • bulk_request (#call) (defaults to: Container[:bulk_request])
  • send_request (#call) (defaults to: Container[:send_request])
  • send_throttled_request (#call) (defaults to: Container[:send_throttled_request])
  • throttling (Boolean) (defaults to: true)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lucid/shopify/client.rb', line 14

def initialize(bulk_request: Container[:bulk_request],
               send_request: Container[:send_request],
               send_throttled_request: Container[:send_throttled_request],
               throttling: true)
  @bulk_request = bulk_request
  @send_request = send_request
  @send_throttled_request = send_throttled_request
  @throttling = throttling

  @params = {
    bulk_request: @bulk_request,
    send_request: @send_request,
    send_throttled_request: @send_throttled_request
  }
end

Instance Method Details

#authenticate(credentials) ⇒ AuthenticatedClient

Parameters:

Returns:



61
62
63
# File 'lib/lucid/shopify/client.rb', line 61

def authenticate(credentials)
  AuthenticatedClient.new(self, credentials)
end

#bulk(*args, &block) ⇒ Object

If called with a block, calls BulkRequest::Operation#call immediately, else, returns the BulkRequest::Operation.



70
71
72
73
74
# File 'lib/lucid/shopify/client.rb', line 70

def bulk(*args, &block)
  op = @bulk_request.(self, *args)

  block ? op.(&block) : op
end

#delete(*args) ⇒ Object



77
78
79
# File 'lib/lucid/shopify/client.rb', line 77

def delete(*args)
  send_request.(DeleteRequest.new(*args))
end

#get(*args) ⇒ Object



82
83
84
# File 'lib/lucid/shopify/client.rb', line 82

def get(*args)
  send_request.(GetRequest.new(*args))
end

#post_graphql(*args) ⇒ Object



87
88
89
# File 'lib/lucid/shopify/client.rb', line 87

def post_graphql(*args)
  send_request.(GraphQLPostRequest.new(*args))
end

#post_json(*args) ⇒ Object



92
93
94
# File 'lib/lucid/shopify/client.rb', line 92

def post_json(*args)
  send_request.(PostRequest.new(*args))
end

#put_json(*args) ⇒ Object



97
98
99
# File 'lib/lucid/shopify/client.rb', line 97

def put_json(*args)
  send_request.(PutRequest.new(*args))
end

#throttledClient, self

Returns a new instance with throttling enabled, or self.

Returns:



43
44
45
46
47
# File 'lib/lucid/shopify/client.rb', line 43

def throttled
  return self if throttled?

  self.class.new(**@params, throttling: true)
end

#throttled?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/lucid/shopify/client.rb', line 36

def throttled?
  @throttling
end

#unthrottledClient, self

Returns a new instance with throttling disabled, or self.

Returns:



52
53
54
55
56
# File 'lib/lucid/shopify/client.rb', line 52

def unthrottled
  return self unless throttled?

  self.class.new(**@params, throttling: false)
end