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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b46ee6ef36dc71fd56c9eb489c752888c9bc540b
4
- data.tar.gz: 18b13fe4160681fc262b41e24fd770682475f334
3
+ metadata.gz: 5190b45ea661721139ce27889e32faf90a8849ec
4
+ data.tar.gz: fbf8feb37324ec7e2a2cd328cc12cd32bc8cdd61
5
5
  SHA512:
6
- metadata.gz: b840ea663d3d4a78d82cc88c4db90c5a5a82cdfeba18acea43e2e454d484a01130c918342f7551d0675e9503d1935b758570bce6aad8708c3cb187b760b3a837
7
- data.tar.gz: 3f74ddd7261045b492ab2297553a01b9c95aea4b12ba252964c287f76c012f0be69d9d7480a1d6872af63cad7506d05b42ea916cfc4c2088ab77ddd9713fa338
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
@@ -9,9 +9,7 @@ class Jet::Client::Files
9
9
  end
10
10
 
11
11
  def upload_token
12
- headers = @client.token
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
- headers = @client.token
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
@@ -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
- response = RestClient.get("#{Jet::Client::API_URL}/orders/#{query_status}", headers)
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
- headers = @client.token
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
- headers = @client.token
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
- headers = @client.token
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
- headers = @client.token
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
- headers = @client.token
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
@@ -7,51 +7,35 @@ class Jet::Client::Products
7
7
  end
8
8
 
9
9
  def update_inventory(merchant_sku, body = {})
10
- headers = @client.token
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
- headers = @client.token
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
- headers = @client.token
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
- headers = @client.token
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
- headers = @client.token
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
- headers = @client.token
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
- headers = @client.token
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
- headers = @client.token
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
 
@@ -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
- response = RestClient.get("#{Jet::Client::API_URL}/returns/#{query_status}", headers)
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
- headers = @client.token
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
- headers = @client.token
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
- headers = @client.token
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
- headers = @client.token
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
@@ -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
- response = RestClient.get("#{Jet::Client::API_URL}/taxonomy/links/#{version}", headers.merge({ params: params }))
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
- headers = @client.token
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
- headers = @client.token
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-jet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Wells