printfulrb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.example +4 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +27 -0
- data/LICENSE.txt +21 -0
- data/README.md +191 -0
- data/Rakefile +4 -0
- data/bin/console +21 -0
- data/bin/setup +8 -0
- data/lib/printful/client.rb +68 -0
- data/lib/printful/collection.rb +17 -0
- data/lib/printful/error.rb +4 -0
- data/lib/printful/object.rb +19 -0
- data/lib/printful/objects/category.rb +5 -0
- data/lib/printful/objects/cost.rb +5 -0
- data/lib/printful/objects/file.rb +5 -0
- data/lib/printful/objects/mockup_printfile.rb +5 -0
- data/lib/printful/objects/mockup_task.rb +5 -0
- data/lib/printful/objects/mockup_template.rb +5 -0
- data/lib/printful/objects/order.rb +5 -0
- data/lib/printful/objects/product.rb +5 -0
- data/lib/printful/objects/product_size.rb +5 -0
- data/lib/printful/objects/product_template.rb +5 -0
- data/lib/printful/objects/shipping_rate.rb +5 -0
- data/lib/printful/objects/store.rb +5 -0
- data/lib/printful/objects/variant.rb +5 -0
- data/lib/printful/resource.rb +56 -0
- data/lib/printful/resources/catalog.rb +37 -0
- data/lib/printful/resources/files.rb +15 -0
- data/lib/printful/resources/mockup_generator.rb +25 -0
- data/lib/printful/resources/orders.rb +42 -0
- data/lib/printful/resources/product_templates.rb +21 -0
- data/lib/printful/resources/products.rb +33 -0
- data/lib/printful/resources/shipping_rates.rb +11 -0
- data/lib/printful/resources/stores.rb +16 -0
- data/lib/printful/resources/variants.rb +26 -0
- data/lib/printful/version.rb +3 -0
- data/lib/printful.rb +38 -0
- data/lib/printfulrb.rb +1 -0
- data/printfulrb.gemspec +32 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 17f3ca0aac0950b05c2b6ac29c47b4991f142da562d8ac5ef3f379efc5046b2d
|
4
|
+
data.tar.gz: a66829e9a74a13f58f61bd6f94b6883cb7803bd589bca38f217b8b0d235ec5e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 305e7533e1e635e8254f137601102091089d81168a26d8a9fd3652cbfdc13fe1318c829e9ea05222f9824e020b2af0e06dfac1def607dc98771e1a680bc56607
|
7
|
+
data.tar.gz: 7f2a9fdfef5edf1befc3ea55efbe3416f3028581ef4ff0e90707337a360abbfea77246cbb2e8df9664b2d7f66174eb0cd81d9163f21a322a6a3ed78c36e9a224
|
data/.env.example
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
printfulrb (0.1.0)
|
5
|
+
faraday (~> 2.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
dotenv (2.7.6)
|
11
|
+
faraday (2.6.0)
|
12
|
+
faraday-net_http (>= 2.0, < 3.1)
|
13
|
+
ruby2_keywords (>= 0.0.4)
|
14
|
+
faraday-net_http (3.0.1)
|
15
|
+
rake (13.0.6)
|
16
|
+
ruby2_keywords (0.0.5)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
x86_64-linux
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
dotenv
|
23
|
+
printfulrb!
|
24
|
+
rake (~> 13.0)
|
25
|
+
|
26
|
+
BUNDLED WITH
|
27
|
+
2.3.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Dean Perry
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
# PrintfulRB
|
2
|
+
|
3
|
+
**This library is a work in progress**
|
4
|
+
|
5
|
+
PrintfulRB is a Ruby library for interacting with the Printful API.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'printfulrb'
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Authentication
|
18
|
+
|
19
|
+
The Printful API requires authentication with an access token.
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
@client = Printful::Client.new(access_token: "abc123")
|
23
|
+
```
|
24
|
+
|
25
|
+
If you have an account level token, you can set a Store ID like so:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
@client = Printful::Client.new(store_id: 123, access_token: "abc123")
|
29
|
+
```
|
30
|
+
|
31
|
+
### Stores
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
# Retrieve a list of stores depending on token access
|
35
|
+
@client.stores.list
|
36
|
+
|
37
|
+
# Retrieve store info
|
38
|
+
@client.stores.retrieve id: 123
|
39
|
+
```
|
40
|
+
|
41
|
+
### Catalog
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
# Retrieve a list of Products available on Printful
|
45
|
+
@client.catalog.products
|
46
|
+
@client.catalog.products(category: 123)
|
47
|
+
|
48
|
+
# Retrieve a product by its ID
|
49
|
+
@client.catalog.product id: "123"
|
50
|
+
|
51
|
+
# Retrieve information for a variant
|
52
|
+
@client.catalog.variant id: "123"
|
53
|
+
|
54
|
+
# Retrieve information about size guides for a product
|
55
|
+
@client.catalog.product_sizes id: "123"
|
56
|
+
|
57
|
+
# Retrieve a list of Catalog Categories on Printful
|
58
|
+
@client.catalog.categories
|
59
|
+
|
60
|
+
# Retrieve a category by its ID
|
61
|
+
@client.catalog.category id: "123"
|
62
|
+
```
|
63
|
+
|
64
|
+
### Products
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
# Returns a list of products for a store
|
68
|
+
@client.products.list
|
69
|
+
|
70
|
+
# Retrieve a product
|
71
|
+
@client.products.retrieve id: 123123
|
72
|
+
|
73
|
+
# Create a product
|
74
|
+
# More info: https://developers.printful.com/docs/#operation/createSyncProduct
|
75
|
+
@client.products.create product: {name: "My Product"}, variants: [{variant_id: 4011, retail_price: "20.00", files: [{url: "http://myfileurl.com/file.png"}]}]
|
76
|
+
|
77
|
+
# Update a product
|
78
|
+
# More info: https://developers.printful.com/docs/#operation/updateSyncProduct
|
79
|
+
@client.products.update id: 123123, product: {name: "My Product"}, variants: [{variant_id: 4011, retail_price: "20.00", files: [{url: "http://myfileurl.com/file.png"}]}]
|
80
|
+
|
81
|
+
# Delete a product
|
82
|
+
@client.products.delete id: 123123
|
83
|
+
```
|
84
|
+
|
85
|
+
### Product Variants
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
# Retrieve a variant
|
89
|
+
@client.variants.retrieve id: 123123
|
90
|
+
|
91
|
+
# Create a variant
|
92
|
+
# ID would be the Product ID
|
93
|
+
# More info: https://developers.printful.com/docs/#operation/createSyncVariant
|
94
|
+
@client.variants.create id: 123123, variant_id: 4011, retail_price: "20.00", files: [{url: "http://myfileurl.com/file.png"}]
|
95
|
+
|
96
|
+
# Update a variant
|
97
|
+
# More info: https://developers.printful.com/docs/#operation/updateSyncVariant
|
98
|
+
@client.variants.update id: 123123, retail_price: "25.00"
|
99
|
+
|
100
|
+
# Delete a variant
|
101
|
+
@client.variants.delete id: 123123
|
102
|
+
```
|
103
|
+
|
104
|
+
### Product Templates
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
# List all product templates
|
108
|
+
@client.product_templates.list
|
109
|
+
|
110
|
+
# Retrieve a product template
|
111
|
+
@client.product_templates.retrieve id: 123123
|
112
|
+
|
113
|
+
# Delete a product template
|
114
|
+
@client.product_templates.delete id: 123123
|
115
|
+
```
|
116
|
+
|
117
|
+
### Orders
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
# List all orders
|
121
|
+
@client.orders.list
|
122
|
+
|
123
|
+
# Retrieve an order
|
124
|
+
@client.order.retrieve id: 123123
|
125
|
+
|
126
|
+
# Create an order
|
127
|
+
# More info: https://developers.printful.com/docs/#operation/createOrder
|
128
|
+
@client.orders.create recipient: {}, items: []
|
129
|
+
|
130
|
+
# Estimate order costs
|
131
|
+
# More info: https://developers.printful.com/docs/#operation/estimateOrderCosts
|
132
|
+
@client.orders.estimate recipient: {}, items: []
|
133
|
+
|
134
|
+
# Update an order
|
135
|
+
# More info: https://developers.printful.com/docs/#operation/updateOrderById
|
136
|
+
@client.orders.update id: 123123, recipient: {}, items: []
|
137
|
+
|
138
|
+
# Cancel an order
|
139
|
+
@client.orders.cancel id: 123123
|
140
|
+
|
141
|
+
# Confirm an order
|
142
|
+
@client.orders.confirm id: 123123
|
143
|
+
```
|
144
|
+
|
145
|
+
### Files
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
# Retrieve a file
|
149
|
+
@client.files.retrieve id: 123123
|
150
|
+
|
151
|
+
# Create a file
|
152
|
+
# More info: https://developers.printful.com/docs/#operation/addFile
|
153
|
+
@client.files.create url: "https://myfileurl.com/file.png"
|
154
|
+
```
|
155
|
+
|
156
|
+
### Shipping Rates
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
# Returns available shipping options and rates for a given list of products
|
160
|
+
# More info: https://developers.printful.com/docs/#operation/calculateShippingRates
|
161
|
+
@client.shipping_rates.calculate recipient: {}, items: []
|
162
|
+
```
|
163
|
+
|
164
|
+
## Mockup Generator
|
165
|
+
|
166
|
+
This API is complex and you'll need to read through the [API docs](https://developers.printful.com/docs/#tag/Mockup-Generator-API)
|
167
|
+
to learn how to use it properly.
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
# Retrieve a list of templates that can be used for client-side positioning
|
171
|
+
@client.mockup_generator.templates id: 123
|
172
|
+
|
173
|
+
# Retrieve a list of print files for a product
|
174
|
+
@client.mockup_generator.printfiles id: 123
|
175
|
+
|
176
|
+
# Create a Mockup Generator task
|
177
|
+
# This API is rate limited
|
178
|
+
# More info: https://developers.printful.com/docs/#operation/createGeneratorTask
|
179
|
+
@client.mockup_generator.create id: 123, variant_ids: [123], files: [{placement: "front", url: "https://host.com/file.png", position: {}}]
|
180
|
+
|
181
|
+
# Retrieve mockup generator task result
|
182
|
+
@client.mockup_generator.retrieve id: "abc123"
|
183
|
+
```
|
184
|
+
|
185
|
+
## Contributing
|
186
|
+
|
187
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/printfulrb.
|
188
|
+
|
189
|
+
## License
|
190
|
+
|
191
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "printful"
|
6
|
+
|
7
|
+
# Load environment variables from .env file
|
8
|
+
require 'dotenv/load'
|
9
|
+
|
10
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
11
|
+
# with your gem easier. You can also use a different console, if you like.
|
12
|
+
|
13
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
14
|
+
# require "pry"
|
15
|
+
# Pry.start
|
16
|
+
|
17
|
+
@client = Printful::Client.new(access_token: ENV["ACCESS_TOKEN"])
|
18
|
+
@client_store = Printful::Client.new(store_id: ENV["STORE_ID"], access_token: ENV["ACCESS_TOKEN"])
|
19
|
+
|
20
|
+
require "irb"
|
21
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
module Printful
|
2
|
+
class Client
|
3
|
+
attr_reader :access_token, :store_id, :adapter
|
4
|
+
|
5
|
+
def initialize(access_token:, store_id: nil, adapter: Faraday.default_adapter, stubs: nil)
|
6
|
+
@access_token = access_token
|
7
|
+
@store_id = store_id
|
8
|
+
@adapter = adapter
|
9
|
+
|
10
|
+
# Test stubs for requests
|
11
|
+
@stubs = stubs
|
12
|
+
end
|
13
|
+
|
14
|
+
def catalog
|
15
|
+
CatalogResource.new(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
def stores
|
19
|
+
StoresResource.new(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
def products
|
23
|
+
ProductsResource.new(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def variants
|
27
|
+
VariantsResource.new(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def product_templates
|
31
|
+
ProductTemplatesResource.new(self)
|
32
|
+
end
|
33
|
+
|
34
|
+
def orders
|
35
|
+
OrdersResource.new(self)
|
36
|
+
end
|
37
|
+
|
38
|
+
def files
|
39
|
+
FilesResource.new(self)
|
40
|
+
end
|
41
|
+
|
42
|
+
def shipping_rates
|
43
|
+
ShippingRatesResource.new(self)
|
44
|
+
end
|
45
|
+
|
46
|
+
def mockup_generator
|
47
|
+
MockupGeneratorResource.new(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
def connection
|
51
|
+
url = "https://api.printful.com"
|
52
|
+
|
53
|
+
@connection ||= Faraday.new(url) do |conn|
|
54
|
+
conn.request :authorization, :Bearer, access_token
|
55
|
+
conn.request :json
|
56
|
+
|
57
|
+
if store_id
|
58
|
+
conn.headers["X-PF-Store-Id"] = store_id
|
59
|
+
end
|
60
|
+
|
61
|
+
conn.response :json
|
62
|
+
|
63
|
+
conn.adapter adapter, @stubs
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Printful
|
2
|
+
class Collection
|
3
|
+
attr_reader :data, :count
|
4
|
+
|
5
|
+
def self.from_response(body:, type:)
|
6
|
+
new(
|
7
|
+
data: body.map { |attrs| type.new(attrs) },
|
8
|
+
count: body.count
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(data:, count:)
|
13
|
+
@data = data
|
14
|
+
@count = count
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
|
3
|
+
module Printful
|
4
|
+
class Object < OpenStruct
|
5
|
+
def initialize(attributes)
|
6
|
+
super to_ostruct(attributes)
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_ostruct(obj)
|
10
|
+
if obj.is_a?(Hash)
|
11
|
+
OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
|
12
|
+
elsif obj.is_a?(Array)
|
13
|
+
obj.map { |o| to_ostruct(o) }
|
14
|
+
else # Assumed to be a primitive value
|
15
|
+
obj
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Printful
|
2
|
+
class Resource
|
3
|
+
attr_reader :client
|
4
|
+
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def get_request(url, params: {}, headers: {})
|
12
|
+
handle_response client.connection.get(url, params, headers)
|
13
|
+
end
|
14
|
+
|
15
|
+
def post_request(url, body:, headers: {})
|
16
|
+
handle_response client.connection.post(url, body, headers)
|
17
|
+
end
|
18
|
+
|
19
|
+
def patch_request(url, body:, headers: {})
|
20
|
+
handle_response client.connection.patch(url, body, headers)
|
21
|
+
end
|
22
|
+
|
23
|
+
def put_request(url, body:, headers: {})
|
24
|
+
handle_response client.connection.put(url, body, headers)
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete_request(url, params: {}, headers: {})
|
28
|
+
handle_response client.connection.delete(url, params, headers)
|
29
|
+
end
|
30
|
+
|
31
|
+
def handle_response(response)
|
32
|
+
case response.status
|
33
|
+
when 400
|
34
|
+
raise Error, "Error 400: Your request was malformed. '#{response.body}'"
|
35
|
+
when 401
|
36
|
+
raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body}'"
|
37
|
+
when 403
|
38
|
+
raise Error, "Error 403: You are not allowed to perform that action. '#{response.body}'"
|
39
|
+
when 404
|
40
|
+
raise Error, "Error 404: No results were found for your request. '#{response.body}'"
|
41
|
+
when 409
|
42
|
+
raise Error, "Error 409: Your request was a conflict. '#{response.body}'"
|
43
|
+
when 422
|
44
|
+
raise Error, "Error 422: Unprocessable Entity. '#{response.body}'"
|
45
|
+
when 429
|
46
|
+
raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body}'"
|
47
|
+
when 500
|
48
|
+
raise Error, "Error 500: We were unable to perform the request due to server-side problems. '#{response.body}'"
|
49
|
+
when 503
|
50
|
+
raise Error, "Error 503: You have been rate limited for sending more than 20 requests per second. '#{response.body}'"
|
51
|
+
end
|
52
|
+
|
53
|
+
response
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Printful
|
2
|
+
class CatalogResource < Resource
|
3
|
+
|
4
|
+
def products(category: nil)
|
5
|
+
response = get_request("products?category_id=#{category}")
|
6
|
+
body = response.body["result"]
|
7
|
+
Collection.from_response(body: body, type: Product)
|
8
|
+
end
|
9
|
+
|
10
|
+
def categories
|
11
|
+
response = get_request("categories")
|
12
|
+
body = response.body["result"]["categories"]
|
13
|
+
Collection.from_response(body: body, type: Category)
|
14
|
+
end
|
15
|
+
|
16
|
+
def variant(id:)
|
17
|
+
response = get_request("products/variant/#{id}")
|
18
|
+
Variant.new(response.body["result"]["variant"])
|
19
|
+
end
|
20
|
+
|
21
|
+
def product(id:)
|
22
|
+
response = get_request("products/#{id}")
|
23
|
+
Product.new(response.body["result"])
|
24
|
+
end
|
25
|
+
|
26
|
+
def product_sizes(id:)
|
27
|
+
response = get_request("products/#{id}/sizes")
|
28
|
+
ProductSize.new(response.body["result"])
|
29
|
+
end
|
30
|
+
|
31
|
+
def category(id:)
|
32
|
+
response = get_request("categories/#{id}")
|
33
|
+
Category.new(response.body["result"]["category"])
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Printful
|
2
|
+
class FilesResource < Resource
|
3
|
+
|
4
|
+
def retrieve(id:)
|
5
|
+
response = get_request("files/#{id}")
|
6
|
+
File.new(response.body["result"])
|
7
|
+
end
|
8
|
+
|
9
|
+
def create(**params)
|
10
|
+
response = post_request("files", body: params)
|
11
|
+
File.new(response.body["result"])
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Printful
|
2
|
+
class MockupGeneratorResource < Resource
|
3
|
+
|
4
|
+
def printfiles(id:, **params)
|
5
|
+
response = get_request("mockup-generator/printfiles/#{id}", params: params)
|
6
|
+
MockupPrintfile.new(response.body["result"])
|
7
|
+
end
|
8
|
+
|
9
|
+
def templates(id:, **params)
|
10
|
+
response = get_request("mockup-generator/templates/#{id}", params: params)
|
11
|
+
MockupTemplate.new(response.body["result"])
|
12
|
+
end
|
13
|
+
|
14
|
+
def create(id:, **params)
|
15
|
+
response = post_request("mockup-generator/create-task/#{id}", body: params)
|
16
|
+
MockupTask.new(response.body["result"])
|
17
|
+
end
|
18
|
+
|
19
|
+
def retrieve(id:)
|
20
|
+
response = get_request("mockup-generator/task?task_key=#{id}")
|
21
|
+
MockupTask.new(response.body["result"])
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Printful
|
2
|
+
class OrdersResource < Resource
|
3
|
+
|
4
|
+
def list
|
5
|
+
response = get_request("orders")
|
6
|
+
body = response.body["result"]
|
7
|
+
Collection.from_response(body: body, type: Order)
|
8
|
+
end
|
9
|
+
|
10
|
+
def estimate(**params)
|
11
|
+
response = post_request("orders/estimate-costs", body: params)
|
12
|
+
Cost.new(response.body["result"])
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(**params)
|
16
|
+
# attributes = {sync_product: product, sync_variants: variants}
|
17
|
+
response = post_request("orders", body: params)
|
18
|
+
Order.new(response.body["result"])
|
19
|
+
end
|
20
|
+
|
21
|
+
def retrieve(id:)
|
22
|
+
response = get_request("orders/#{id}")
|
23
|
+
Order.new(response.body["result"])
|
24
|
+
end
|
25
|
+
|
26
|
+
def update(id:, **params)
|
27
|
+
response = put_request("orders/#{id}", body: params)
|
28
|
+
return true if response.success?
|
29
|
+
end
|
30
|
+
|
31
|
+
def cancel(id:)
|
32
|
+
response = delete_request("orders/#{id}")
|
33
|
+
return true if response.success?
|
34
|
+
end
|
35
|
+
|
36
|
+
def confirm(id:)
|
37
|
+
response = post_request("orders/#{id}/confirm", body: {})
|
38
|
+
Order.new(response.body["result"])
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Printful
|
2
|
+
class ProductTemplatesResource < Resource
|
3
|
+
|
4
|
+
def list
|
5
|
+
response = get_request("product-templates")
|
6
|
+
body = response.body["result"]["items"]
|
7
|
+
Collection.from_response(body: body, type: ProductTemplate)
|
8
|
+
end
|
9
|
+
|
10
|
+
def retrieve(id:)
|
11
|
+
response = get_request("product-templates/#{id}")
|
12
|
+
ProductTemplate.new(response.body["result"])
|
13
|
+
end
|
14
|
+
|
15
|
+
def delete(id:)
|
16
|
+
response = delete_request("product-templates/#{id}")
|
17
|
+
return true if response.success?
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Printful
|
2
|
+
class ProductsResource < Resource
|
3
|
+
|
4
|
+
def list
|
5
|
+
response = get_request("store/products")
|
6
|
+
body = response.body["result"]
|
7
|
+
Collection.from_response(body: body, type: Product)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(product:, variants:)
|
11
|
+
attributes = {sync_product: product, sync_variants: variants}
|
12
|
+
response = post_request("store/products", body: attributes)
|
13
|
+
Product.new(response.body["result"])
|
14
|
+
end
|
15
|
+
|
16
|
+
def retrieve(id:)
|
17
|
+
response = get_request("store/products/#{id}")
|
18
|
+
Product.new(response.body["result"])
|
19
|
+
end
|
20
|
+
|
21
|
+
def update(id:, product:, variants: nil)
|
22
|
+
attributes = {sync_product: product, sync_variants: variants}
|
23
|
+
response = put_request("store/products/#{id}", body: attributes)
|
24
|
+
return true if response.success?
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete(id:)
|
28
|
+
response = delete_request("store/products/#{id}")
|
29
|
+
return true if response.success?
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Printful
|
2
|
+
class StoresResource < Resource
|
3
|
+
|
4
|
+
def list
|
5
|
+
response = get_request("stores")
|
6
|
+
body = response.body["result"]
|
7
|
+
Collection.from_response(body: body, type: Store)
|
8
|
+
end
|
9
|
+
|
10
|
+
def retrieve(id:)
|
11
|
+
response = get_request("stores/#{id}")
|
12
|
+
Store.new(response.body["result"])
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Printful
|
2
|
+
class VariantsResource < Resource
|
3
|
+
|
4
|
+
def create(id:, **params)
|
5
|
+
# attributes = {sync_product: product, sync_variants: variants}
|
6
|
+
response = post_request("store/products/#{id}/variants", body: params)
|
7
|
+
Variant.new(response.body["result"])
|
8
|
+
end
|
9
|
+
|
10
|
+
def retrieve(id:)
|
11
|
+
response = get_request("store/variants/#{id}")
|
12
|
+
Variant.new(response.body["result"])
|
13
|
+
end
|
14
|
+
|
15
|
+
def update(id:, **params)
|
16
|
+
response = put_request("store/variants/#{id}", body: params)
|
17
|
+
return true if response.success?
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(id:)
|
21
|
+
response = delete_request("store/variants/#{id}")
|
22
|
+
return true if response.success?
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/printful.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
require_relative "printful/version"
|
5
|
+
|
6
|
+
module Printful
|
7
|
+
|
8
|
+
autoload :Client, "printful/client"
|
9
|
+
autoload :Collection, "printful/collection"
|
10
|
+
autoload :Error, "printful/error"
|
11
|
+
autoload :Resource, "printful/resource"
|
12
|
+
autoload :Object, "printful/object"
|
13
|
+
|
14
|
+
autoload :CatalogResource, "printful/resources/catalog"
|
15
|
+
autoload :StoresResource, "printful/resources/stores"
|
16
|
+
autoload :ProductsResource, "printful/resources/products"
|
17
|
+
autoload :VariantsResource, "printful/resources/variants"
|
18
|
+
autoload :ProductTemplatesResource, "printful/resources/product_templates"
|
19
|
+
autoload :OrdersResource, "printful/resources/orders"
|
20
|
+
autoload :FilesResource, "printful/resources/files"
|
21
|
+
autoload :ShippingRatesResource, "printful/resources/shipping_rates"
|
22
|
+
autoload :MockupGeneratorResource, "printful/resources/mockup_generator"
|
23
|
+
|
24
|
+
autoload :Product, "printful/objects/product"
|
25
|
+
autoload :ProductSize, "printful/objects/product_size"
|
26
|
+
autoload :Category, "printful/objects/category"
|
27
|
+
autoload :Variant, "printful/objects/variant"
|
28
|
+
autoload :Store, "printful/objects/store"
|
29
|
+
autoload :ProductTemplate, "printful/objects/product_template"
|
30
|
+
autoload :Order, "printful/objects/order"
|
31
|
+
autoload :Cost, "printful/objects/cost"
|
32
|
+
autoload :File, "printful/objects/file"
|
33
|
+
autoload :ShippingRate, "printful/objects/shipping_rate"
|
34
|
+
autoload :MockupTask, "printful/objects/mockup_task"
|
35
|
+
autoload :MockupPrintfile, "printful/objects/mockup_printfile"
|
36
|
+
autoload :MockupTemplate, "printful/objects/mockup_template"
|
37
|
+
|
38
|
+
end
|
data/lib/printfulrb.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "printful"
|
data/printfulrb.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/printful/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "printfulrb"
|
7
|
+
spec.version = Printful::VERSION
|
8
|
+
spec.authors = ["Dean Perry"]
|
9
|
+
spec.email = ["dean@deanpcmad.com"]
|
10
|
+
|
11
|
+
spec.summary = "A Ruby library for interacting with the Printful API"
|
12
|
+
spec.homepage = "https://deanpcmad.com"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/deanpcmad/printfulrb"
|
18
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_dependency "faraday", "~> 2.0"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: printfulrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dean Perry
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-10-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- dean@deanpcmad.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".env.example"
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
37
|
+
- LICENSE.txt
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- bin/console
|
41
|
+
- bin/setup
|
42
|
+
- lib/printful.rb
|
43
|
+
- lib/printful/client.rb
|
44
|
+
- lib/printful/collection.rb
|
45
|
+
- lib/printful/error.rb
|
46
|
+
- lib/printful/object.rb
|
47
|
+
- lib/printful/objects/category.rb
|
48
|
+
- lib/printful/objects/cost.rb
|
49
|
+
- lib/printful/objects/file.rb
|
50
|
+
- lib/printful/objects/mockup_printfile.rb
|
51
|
+
- lib/printful/objects/mockup_task.rb
|
52
|
+
- lib/printful/objects/mockup_template.rb
|
53
|
+
- lib/printful/objects/order.rb
|
54
|
+
- lib/printful/objects/product.rb
|
55
|
+
- lib/printful/objects/product_size.rb
|
56
|
+
- lib/printful/objects/product_template.rb
|
57
|
+
- lib/printful/objects/shipping_rate.rb
|
58
|
+
- lib/printful/objects/store.rb
|
59
|
+
- lib/printful/objects/variant.rb
|
60
|
+
- lib/printful/resource.rb
|
61
|
+
- lib/printful/resources/catalog.rb
|
62
|
+
- lib/printful/resources/files.rb
|
63
|
+
- lib/printful/resources/mockup_generator.rb
|
64
|
+
- lib/printful/resources/orders.rb
|
65
|
+
- lib/printful/resources/product_templates.rb
|
66
|
+
- lib/printful/resources/products.rb
|
67
|
+
- lib/printful/resources/shipping_rates.rb
|
68
|
+
- lib/printful/resources/stores.rb
|
69
|
+
- lib/printful/resources/variants.rb
|
70
|
+
- lib/printful/version.rb
|
71
|
+
- lib/printfulrb.rb
|
72
|
+
- printfulrb.gemspec
|
73
|
+
homepage: https://deanpcmad.com
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata:
|
77
|
+
homepage_uri: https://deanpcmad.com
|
78
|
+
source_code_uri: https://github.com/deanpcmad/printfulrb
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 2.6.0
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubygems_version: 3.3.7
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: A Ruby library for interacting with the Printful API
|
98
|
+
test_files: []
|