Class: Printful::Client
- Inherits:
-
Object
- Object
- Printful::Client
- Defined in:
- lib/printful/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#store_id ⇒ Object
readonly
Returns the value of attribute store_id.
Instance Method Summary collapse
- #catalog ⇒ Object
- #connection ⇒ Object
- #files ⇒ Object
-
#initialize(access_token:, store_id: nil, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
constructor
A new instance of Client.
- #mockup_generator ⇒ Object
- #orders ⇒ Object
- #product_templates ⇒ Object
- #products ⇒ Object
- #shipping_rates ⇒ Object
- #stores ⇒ Object
- #variants ⇒ Object
Constructor Details
#initialize(access_token:, store_id: nil, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 |
# File 'lib/printful/client.rb', line 5 def initialize(access_token:, store_id: nil, adapter: Faraday.default_adapter, stubs: nil) @access_token = access_token @store_id = store_id @adapter = adapter # Test stubs for requests @stubs = stubs end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
3 4 5 |
# File 'lib/printful/client.rb', line 3 def access_token @access_token end |
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
3 4 5 |
# File 'lib/printful/client.rb', line 3 def adapter @adapter end |
#store_id ⇒ Object (readonly)
Returns the value of attribute store_id.
3 4 5 |
# File 'lib/printful/client.rb', line 3 def store_id @store_id end |
Instance Method Details
#catalog ⇒ Object
14 15 16 |
# File 'lib/printful/client.rb', line 14 def catalog CatalogResource.new(self) end |
#connection ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/printful/client.rb', line 50 def connection url = "https://api.printful.com" @connection ||= Faraday.new(url) do |conn| conn.request :authorization, :Bearer, access_token conn.request :json if store_id conn.headers["X-PF-Store-Id"] = store_id end conn.response :json conn.adapter adapter, @stubs end end |
#files ⇒ Object
38 39 40 |
# File 'lib/printful/client.rb', line 38 def files FilesResource.new(self) end |
#mockup_generator ⇒ Object
46 47 48 |
# File 'lib/printful/client.rb', line 46 def mockup_generator MockupGeneratorResource.new(self) end |
#orders ⇒ Object
34 35 36 |
# File 'lib/printful/client.rb', line 34 def orders OrdersResource.new(self) end |
#product_templates ⇒ Object
30 31 32 |
# File 'lib/printful/client.rb', line 30 def product_templates ProductTemplatesResource.new(self) end |
#products ⇒ Object
22 23 24 |
# File 'lib/printful/client.rb', line 22 def products ProductsResource.new(self) end |
#shipping_rates ⇒ Object
42 43 44 |
# File 'lib/printful/client.rb', line 42 def shipping_rates ShippingRatesResource.new(self) end |
#stores ⇒ Object
18 19 20 |
# File 'lib/printful/client.rb', line 18 def stores StoresResource.new(self) end |
#variants ⇒ Object
26 27 28 |
# File 'lib/printful/client.rb', line 26 def variants VariantsResource.new(self) end |