-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexamples.rb
134 lines (115 loc) · 3.89 KB
/
examples.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
require File.dirname(__FILE__) + '/app/models/spree/printfulclient'
require 'pp'
#
# Replace this with your API key
#
key = 'thkdrylg-da0m-2b90:c1tb-cqp9kpovds9y'
pf = PrintfulClient.new(key)
begin
#
#Uncomment any of the following examples to test it
#
#Get information about the store
#pp pf.get('store')
#Get product list
#pp pf.get('products')
#Get variants for product 10
#pp pf.get('products/10')
#Get information about Variant 1007
#pp pf.get('products/variant/1007')
#Select 10 latest orders and get the total number of orders
#pp pf.get('orders',['limit'=>10])
#puts "Total orders available: %i" % [pf.item_count]
#Select order with ID 12345 (Replace with your order's ID)
#pp pf.get('orders/12345')
#Select order with External ID 9900999 (Replace with your order's External ID)
#pp pf.get('orders/@9900999')
#Confirm order with ID 12345 (Replace with your order's ID)
#pp pf.post('orders/12345/confirm')
#Cancel order with ID 12345 (Replace with your order's ID)
#pp pf.delete('orders/12345')
#Create an order
=begin
pp pf.post('orders',
{
recipient: {
name: 'John Doe',
address1: '172 W Providencia Ave #105',
city: 'Burbank',
state_code: 'CA',
country_code: 'US',
zip: '91502'
},
items: [
{
variant_id: 1, #Small poster
name: 'Niagara Falls poster', #Display name
retail_price: '19.99', #Retail price for packing slip
quantity: 1,
files: [
{url: 'http://example.com/files/posters/poster_1.jpg'}
]
},
{
variant_id: 1118,
quantity: 2,
name: 'Grand Canyon T-Shirt', #Display name
retail_price: '29.99', #Retail price for packing slip
files: [
{url: 'http://example.com/files/tshirts/shirt_front.ai'}, #Front print
{type: 'back', url: 'http://example.com/files/tshirts/shirt_back.ai'}, #Back print
{type: 'preview', url: 'http://example.com/files/tshirts/shirt_mockup.jpg'} #Mockup image
],
options: [ #Additional options
{id: 'remove_labels', value: true}
]
}
]
}
)
=end
#Create an order and confirm immediately
pp pf.post('orders',
{
recipient: {
name: 'John Doe',
address1: '172 W Providencia Ave #105',
city: 'Burbank',
state_code: 'CA',
country_code: 'US',
zip: '91502'
},
items: [
{
variant_id: 1, #Small poster
name: 'Niagara Falls poster', #Display name
retail_price: '19.99', #Retail price for packing slip
quantity: 1,
files: [
{url: 'http://example.com/files/posters/poster_1.jpg'}
]
}
]
},
{confirm: 1}
)
#Calculate shipping rates for an order
=begin
pp pf.post('shipping/rates',{
recipient: {
country_code: 'US',
state_code: 'CA'
},
items: [
{variant_id: 1, quantity: 1}, #Small poster
{variant_id: 1118, quantity: 2} #Alternative T-Shirt
]
})
=end
rescue PrintfulApiException => e
#Error code from the API
puts 'API exception: %i %s' % [e.code, e.message]
rescue PrintfulException => e
#Error while doing the request
puts 'Printful exception: ' + e.message
end