ruby-jet 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jet/client.rb +13 -0
- data/lib/jet/client/files.rb +2 -6
- data/lib/jet/client/orders.rb +6 -18
- data/lib/jet/client/products.rb +8 -24
- data/lib/jet/client/returns.rb +5 -15
- data/lib/jet/client/taxonomy.rb +3 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5190b45ea661721139ce27889e32faf90a8849ec
|
4
|
+
data.tar.gz: fbf8feb37324ec7e2a2cd328cc12cd32bc8cdd61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c720821aa867dc50127be31fd02898bbbbb9a5f6b17547cd5853204c743d0475f98052202d52fc1c08d8256521659f9cd7d63950d2f5b6e157c9d4961bbc7238
|
7
|
+
data.tar.gz: d46c4d94597545aad8314813b0ac93d27c007813382567867fa7de689ddac6cd03ab37d0810fc9c09d6eb8e88c1093f9a459b71b3010439f618c60288ad5e8bb
|
data/lib/jet/client.rb
CHANGED
@@ -26,6 +26,19 @@ class Jet::Client
|
|
26
26
|
{ Authorization: "#{@token_type} #{@id_token}" }
|
27
27
|
end
|
28
28
|
|
29
|
+
def rest_get_with_token(path, query_params = {})
|
30
|
+
headers = token
|
31
|
+
headers.merge!({ params: query_params }) unless query_params.empty?
|
32
|
+
response = RestClient.get("#{API_URL}#{path}", headers)
|
33
|
+
JSON.parse(response.body) if response.code == 200
|
34
|
+
end
|
35
|
+
|
36
|
+
def rest_put_with_token(path, body = {})
|
37
|
+
headers = token
|
38
|
+
response = RestClient.put("#{API_URL}#{path}", body.to_json, headers)
|
39
|
+
JSON.parse(response.body) if response.code == 200
|
40
|
+
end
|
41
|
+
|
29
42
|
def orders
|
30
43
|
Orders.new(self)
|
31
44
|
end
|
data/lib/jet/client/files.rb
CHANGED
@@ -9,9 +9,7 @@ class Jet::Client::Files
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def upload_token
|
12
|
-
|
13
|
-
response = RestClient.get("#{Jet::Client::API_URL}/files/uploadToken", headers)
|
14
|
-
JSON.parse(response.body) if response.code == 200
|
12
|
+
@client.rest_get_with_token('/files/uploadToken')
|
15
13
|
end
|
16
14
|
|
17
15
|
def file_upload(url, body)
|
@@ -33,8 +31,6 @@ class Jet::Client::Files
|
|
33
31
|
end
|
34
32
|
|
35
33
|
def jet_file_id(file_id)
|
36
|
-
|
37
|
-
response = RestClient.get("#{Jet::Client::API_URL}/files/#{file_id}", headers)
|
38
|
-
JSON.parse(response.body) if response.code == 200
|
34
|
+
@client.rest_get_with_token("/files/#{file_id}")
|
39
35
|
end
|
40
36
|
end
|
data/lib/jet/client/orders.rb
CHANGED
@@ -16,39 +16,27 @@ class Jet::Client::Orders
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def get_orders(status = :ready)
|
19
|
-
headers = @client.token
|
20
19
|
query_status = STATUSES[status]
|
21
|
-
|
22
|
-
JSON.parse(response.body) if response.code == 200
|
20
|
+
@client.rest_get_with_token("/orders/#{query_status}")
|
23
21
|
end
|
24
22
|
|
25
23
|
def get_order(order_url)
|
26
|
-
|
27
|
-
response = RestClient.get("#{Jet::Client::API_URL}#{order_url}", headers)
|
28
|
-
JSON.parse(response.body) if response.code == 200
|
24
|
+
@client.rest_get_with_token(order_url)
|
29
25
|
end
|
30
26
|
|
31
27
|
def get_order_by_id(order_id)
|
32
|
-
|
33
|
-
response = RestClient.get("#{Jet::Client::API_URL}/orders/withoutShipmentDetail/#{order_id}", headers)
|
34
|
-
JSON.parse(response.body) if response.code == 200
|
28
|
+
@client.rest_get_with_token("/orders/withoutShipmentDetail/#{order_id}")
|
35
29
|
end
|
36
30
|
|
37
31
|
def acknowledge_order(order_id, body = {})
|
38
|
-
|
39
|
-
response = RestClient.put("#{Jet::Client::API_URL}/orders/#{order_id}/acknowledge", body.to_json, headers)
|
40
|
-
JSON.parse(response.body) if response.code == 200
|
32
|
+
@client.rest_put_with_token("/orders/#{order_id}/acknowledge", body)
|
41
33
|
end
|
42
34
|
|
43
35
|
def ship_order(order_id, body = {})
|
44
|
-
|
45
|
-
response = RestClient.put("#{Jet::Client::API_URL}/orders/#{order_id}/shipped", body.to_json, headers)
|
46
|
-
JSON.parse(response.body) if response.code == 200
|
36
|
+
@client.rest_put_with_token("/orders/#{order_id}/shipped", body)
|
47
37
|
end
|
48
38
|
|
49
39
|
def get_directed_cancel
|
50
|
-
|
51
|
-
response = RestClient.get("#{Jet::Client::API_URL}/orders/directedCancel", headers)
|
52
|
-
JSON.parse(response.body) if response.code == 200
|
40
|
+
@client.rest_get_with_token('/orders/directedCancel')
|
53
41
|
end
|
54
42
|
end
|
data/lib/jet/client/products.rb
CHANGED
@@ -7,51 +7,35 @@ class Jet::Client::Products
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def update_inventory(merchant_sku, body = {})
|
10
|
-
|
11
|
-
response = RestClient.put("#{Jet::Client::API_URL}/merchant-skus/#{merchant_sku}/inventory", body.to_json, headers)
|
12
|
-
JSON.parse(response.body) if response.code == 200
|
10
|
+
@client.rest_put_with_token("/merchant-skus/#{merchant_sku}/inventory", body)
|
13
11
|
end
|
14
12
|
|
15
13
|
def get_inventory(merchant_sku)
|
16
|
-
|
17
|
-
response = RestClient.get("#{Jet::Client::API_URL}/merchant-skus/#{merchant_sku}/inventory", headers)
|
18
|
-
JSON.parse(response.body) if response.code == 200
|
14
|
+
@client.rest_get_with_token("/merchant-skus/#{merchant_sku}/inventory")
|
19
15
|
end
|
20
16
|
|
21
17
|
def update_product(merchant_sku, body = {})
|
22
|
-
|
23
|
-
response = RestClient.put("#{Jet::Client::API_URL}/merchant-skus/#{merchant_sku}", body.to_json, headers)
|
24
|
-
JSON.parse(response.body) if response.code == 200
|
18
|
+
@client.rest_put_with_token("/merchant-skus/#{merchant_sku}", body)
|
25
19
|
end
|
26
20
|
|
27
21
|
def get_product(merchant_sku)
|
28
|
-
|
29
|
-
response = RestClient.get("#{Jet::Client::API_URL}/merchant-skus/#{merchant_sku}", headers)
|
30
|
-
JSON.parse(response.body) if response.code == 200
|
22
|
+
@client.rest_get_with_token("/merchant-skus/#{merchant_sku}")
|
31
23
|
end
|
32
24
|
|
33
25
|
def update_price(merchant_sku, body = {})
|
34
|
-
|
35
|
-
response = RestClient.put("#{Jet::Client::API_URL}/merchant-skus/#{merchant_sku}/price", body.to_json, headers)
|
36
|
-
JSON.parse(response.body) if response.code == 200
|
26
|
+
@client.rest_put_with_token("/merchant-skus/#{merchant_sku}/price", body)
|
37
27
|
end
|
38
28
|
|
39
29
|
def get_price(merchant_sku)
|
40
|
-
|
41
|
-
response = RestClient.get("#{Jet::Client::API_URL}/merchant-skus/#{merchant_sku}/price", headers)
|
42
|
-
JSON.parse(response.body) if response.code == 200
|
30
|
+
@client.rest_get_with_token("/merchant-skus/#{merchant_sku}/price")
|
43
31
|
end
|
44
32
|
|
45
33
|
def update_image(merchant_sku, body = {})
|
46
|
-
|
47
|
-
response = RestClient.put("#{Jet::Client::API_URL}/merchant-skus/#{merchant_sku}/image", body.to_json, headers)
|
48
|
-
JSON.parse(response.body) if response.code == 200
|
34
|
+
@client.rest_put_with_token("/merchant-skus/#{merchant_sku}/image", body)
|
49
35
|
end
|
50
36
|
|
51
37
|
def get_products(params = {})
|
52
|
-
|
53
|
-
response = RestClient.get("#{Jet::Client::API_URL}/merchant-skus", headers.merge({ params: params }))
|
54
|
-
JSON.parse(response.body) if response.code == 200
|
38
|
+
@client.rest_get_with_token('/merchant-skus', params)
|
55
39
|
end
|
56
40
|
end
|
57
41
|
|
data/lib/jet/client/returns.rb
CHANGED
@@ -15,33 +15,23 @@ class Jet::Client::Returns
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def get_returns(status = :created)
|
18
|
-
headers = @client.token
|
19
18
|
query_status = STATUSES[status]
|
20
|
-
|
21
|
-
JSON.parse(response.body) if response.code == 200
|
19
|
+
@client.rest_get_with_token("/returns/#{query_status}")
|
22
20
|
end
|
23
21
|
|
24
22
|
def get_return(return_url)
|
25
|
-
|
26
|
-
response = RestClient.get("#{Jet::Client::API_URL}#{return_url}", headers)
|
27
|
-
JSON.parse(response.body) if response.code == 200
|
23
|
+
@client.rest_get_with_token(return_url)
|
28
24
|
end
|
29
25
|
|
30
26
|
def get_return_by_id(return_id)
|
31
|
-
|
32
|
-
response = RestClient.get("#{Jet::Client::API_URL}/returns/state/#{return_id}", headers)
|
33
|
-
JSON.parse(response.body) if response.code == 200
|
27
|
+
@client.rest_get_with_token("/returns/state/#{return_id}")
|
34
28
|
end
|
35
29
|
|
36
30
|
def acknowledge_return(return_id, body = {})
|
37
|
-
|
38
|
-
response = RestClient.put("#{Jet::Client::API_URL}/returns/#{return_id}/acknowledge", body.to_json, headers)
|
39
|
-
JSON.parse(response.body) if response.code == 200
|
31
|
+
@client.rest_put_with_token("/returns/#{return_id}/acknowledge", body)
|
40
32
|
end
|
41
33
|
|
42
34
|
def complete_return(return_id, body = {})
|
43
|
-
|
44
|
-
response = RestClient.put("#{Jet::Client::API_URL}/returns/#{return_id}/complete", body.to_json, headers)
|
45
|
-
JSON.parse(response.body) if response.code == 200
|
35
|
+
@client.rest_put_with_token("/returns/#{return_id}/complete", body)
|
46
36
|
end
|
47
37
|
end
|
data/lib/jet/client/taxonomy.rb
CHANGED
@@ -7,21 +7,15 @@ class Jet::Client::Taxonomy
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def get_links(limit, offset, version = "v1")
|
10
|
-
headers = @client.token
|
11
10
|
params = { limit: limit, offset: offset }
|
12
|
-
|
13
|
-
JSON.parse(response.body) if response.code == 200
|
11
|
+
@client.rest_get_with_token("/taxonomy/links/#{version}", params)
|
14
12
|
end
|
15
13
|
|
16
14
|
def get_node(node_url)
|
17
|
-
|
18
|
-
response = RestClient.get("#{Jet::Client::API_URL}#{node_url}", headers)
|
19
|
-
JSON.parse(response.body) if response.code == 200
|
15
|
+
@client.rest_get_with_token(node_url)
|
20
16
|
end
|
21
17
|
|
22
18
|
def get_node_attributes(node_url)
|
23
|
-
|
24
|
-
response = RestClient.get("#{Jet::Client::API_URL}#{node_url}/attributes", headers)
|
25
|
-
JSON.parse(response.body) if response.code == 200
|
19
|
+
@client.rest_get_with_token("#{node_url}/attributes")
|
26
20
|
end
|
27
21
|
end
|