bluepark 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bluepark.gemspec +19 -0
- data/lib/bluepark.rb +7 -0
- data/lib/bluepark/client.rb +115 -0
- data/lib/bluepark/client/orders.rb +35 -0
- data/lib/bluepark/client/products.rb +35 -0
- data/lib/bluepark/client/sales.rb +36 -0
- data/lib/bluepark/client/skus.rb +31 -0
- data/lib/bluepark/client/taxonomies.rb +15 -0
- data/lib/bluepark/errors/bluepark_error.rb +5 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 99c6f3389d00ea62394dfb7c00e80acce35d0da4
|
4
|
+
data.tar.gz: 20aec909198796a00e236313bf2217a9f1227115
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a8cb33b8bfe8646393bea26fc6a2ecc851b93387ec53ff5275af526519b0afd1807238f01a3368b956af2b820e9845efd174373764cfda4bc9679a666bc3f7bf
|
7
|
+
data.tar.gz: fb9c99b37581c4533ca7f3058399e8d3355bdb02dc27c98d37de6f122ef821babcf861001dce8964f0f56668fce143f0b2d59df0361caf6397141bc7ce7211a8
|
data/bluepark.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'bluepark'
|
6
|
+
s.version = '1.0.0'
|
7
|
+
s.date = '2017-07-10'
|
8
|
+
s.summary = "Ruby client library for the Bluepark API"
|
9
|
+
s.description = "A simple client created to help with Bluepark integration"
|
10
|
+
s.authors = ["Andriy Byalyk"]
|
11
|
+
s.email = ['rewrite.andriy@gmail.com', 'andriy.b@coaxsoft.com']
|
12
|
+
s.require_paths = ['lib']
|
13
|
+
s.files = Dir['lib/**/*','bluepark.gemspec']
|
14
|
+
s.license = 'MIT'
|
15
|
+
s.add_development_dependency 'bundler'
|
16
|
+
s.add_development_dependency 'rake'
|
17
|
+
s.add_dependency 'oj', '~> 3.3.1'
|
18
|
+
s.add_dependency 'rest-client', '~> 2.0.2'
|
19
|
+
end
|
data/lib/bluepark.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'oj'
|
3
|
+
|
4
|
+
class Bluepark::Client
|
5
|
+
attr_accessor :bluepark_token, :user_name, :bluepark_api_uri
|
6
|
+
STATUS_CODES = { 200 => 'success',
|
7
|
+
304 => 'not_modified',
|
8
|
+
400 => 'bad_request',
|
9
|
+
401 => 'unauthorized',
|
10
|
+
403 => 'forbidden',
|
11
|
+
404 => 'not_found',
|
12
|
+
405 => 'method_not_allowed',
|
13
|
+
406 => 'not_acceptable',
|
14
|
+
413 => 'too_large_request',
|
15
|
+
415 => 'unsupported_mediatype',
|
16
|
+
429 => 'too_many_requests',
|
17
|
+
500 => 'internal_server_error' }.freeze
|
18
|
+
|
19
|
+
def initialize(config = {})
|
20
|
+
@user_name = config[:user_name]
|
21
|
+
@bluepark_token = config[:bluepark_token]
|
22
|
+
@bluepark_api_uri = config[:bluepark_api_uri]
|
23
|
+
end
|
24
|
+
|
25
|
+
def encode_json(data)
|
26
|
+
Oj.dump(data, mode: :compat)
|
27
|
+
end
|
28
|
+
|
29
|
+
def decode_json(json)
|
30
|
+
Oj.load(json)
|
31
|
+
end
|
32
|
+
|
33
|
+
def decode_status(response)
|
34
|
+
if response.body.blank? || response.code >= 300
|
35
|
+
error = {
|
36
|
+
status: STATUS_CODES[response.code],
|
37
|
+
status_code: response.code
|
38
|
+
}.merge(decode_json(response.body).to_h)
|
39
|
+
raise BlueparkError, encode_json(error)
|
40
|
+
else
|
41
|
+
decode_json(response.body)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def api_call_with_token(action, path, options = {})
|
46
|
+
headers = { Authorization: "Basic #{token}" }
|
47
|
+
headers.merge!(options[:headers]) if options[:headers].is_a?(Hash)
|
48
|
+
headers[:Accept] = 'text/json'
|
49
|
+
headers[:"content-type"] = 'application/json'
|
50
|
+
args = ["#{@bluepark_api_uri}#{path}"]
|
51
|
+
args << encode_json(options[:body]) unless options[:body].nil?
|
52
|
+
args << headers
|
53
|
+
|
54
|
+
begin
|
55
|
+
response = RestClient.send(action, *args)
|
56
|
+
decode_status(response)
|
57
|
+
rescue RestClient::ExceptionWithResponse => e
|
58
|
+
decode_status(e.response)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def rest_get_with_token(path, query_params = {})
|
63
|
+
headers = query_params.empty? ? nil : { params: query_params }
|
64
|
+
api_call_with_token(:get, path, headers: headers)
|
65
|
+
end
|
66
|
+
|
67
|
+
def rest_put_with_token(path, body = {})
|
68
|
+
api_call_with_token(:put, path, body: body)
|
69
|
+
end
|
70
|
+
|
71
|
+
def rest_post_with_token(path, body = {})
|
72
|
+
api_call_with_token(:post, path, body: body)
|
73
|
+
end
|
74
|
+
|
75
|
+
def rest_delete_with_token(path)
|
76
|
+
api_call_with_token(:delete, path)
|
77
|
+
end
|
78
|
+
|
79
|
+
def orders
|
80
|
+
Orders.new(self)
|
81
|
+
end
|
82
|
+
|
83
|
+
def products
|
84
|
+
Products.new(self)
|
85
|
+
end
|
86
|
+
|
87
|
+
def skus
|
88
|
+
Skus.new(self)
|
89
|
+
end
|
90
|
+
|
91
|
+
def taxonomies
|
92
|
+
Taxonomies.new(self)
|
93
|
+
end
|
94
|
+
|
95
|
+
def sales(order_id)
|
96
|
+
Sales.new(self, order_id)
|
97
|
+
end
|
98
|
+
|
99
|
+
def company
|
100
|
+
rest_get_with_token('company')
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def token
|
106
|
+
Base64.encode64("#{@user_name}:#{@bluepark_token}").tr("\n", '')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
require 'bluepark/client/orders'
|
111
|
+
require 'bluepark/client/products'
|
112
|
+
require 'bluepark/client/skus'
|
113
|
+
require 'bluepark/client/taxonomies'
|
114
|
+
require 'bluepark/client/sales'
|
115
|
+
require 'bluepark/errors/bluepark_error'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
class Bluepark::Client::Orders
|
4
|
+
def initialize(client)
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_orders(params = {})
|
9
|
+
@client.rest_get_with_token('orders/', params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_order(order_id)
|
13
|
+
@client.rest_get_with_token("orders/#{order_id}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def count(params = {})
|
17
|
+
@client.rest_get_with_token('orders/count', params)['count']
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_order(order_params)
|
21
|
+
@client.rest_post_with_token('orders', order_params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_single_order(order_id, order_params)
|
25
|
+
@client.rest_put_with_token("orders/#{order_id}", order_params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete_order_by_id(order_id)
|
29
|
+
@client.rest_delete_with_token("orders/#{order_id}")
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete_all_orders
|
33
|
+
@client.rest_delete_with_token('orders/all')
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
class Bluepark::Client::Products
|
4
|
+
def initialize(client)
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_products(params = {})
|
9
|
+
@client.rest_get_with_token('products/', params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_product(product_id)
|
13
|
+
@client.rest_get_with_token("products/#{product_id}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def count(params = {})
|
17
|
+
@client.rest_get_with_token('products/count', params)['count']
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_product(product_params)
|
21
|
+
@client.rest_post_with_token('products', product_params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_single_product(product_id, product_params)
|
25
|
+
@client.rest_put_with_token("products/#{product_id}", product_params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete_product_by_id(product_id)
|
29
|
+
@client.rest_delete_with_token("products/#{product_id}")
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete_all_products
|
33
|
+
@client.rest_delete_with_token('products/all')
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
class Bluepark::Client::Sales
|
4
|
+
def initialize(client, order_id)
|
5
|
+
@client = client
|
6
|
+
@order_id = order_id
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_products(params = {})
|
10
|
+
@client.rest_get_with_token("orders/#{@order_id}/products/", params)
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_product(product_id)
|
14
|
+
@client.rest_get_with_token("orders/#{@order_id}/products/#{product_id}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def count(params = {})
|
18
|
+
@client.rest_get_with_token("orders/#{@order_id}/products/count", params)['count']
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_product(product_params)
|
22
|
+
@client.rest_post_with_token("orders/#{@order_id}/products", product_params)
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_single_product(product_id, product_params)
|
26
|
+
@client.rest_put_with_token("orders/#{@order_id}/products/#{product_id}", product_params)
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete_product_by_id(product_id)
|
30
|
+
@client.rest_delete_with_token("orders/#{@order_id}/products/#{product_id}")
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete_all_products
|
34
|
+
@client.rest_delete_with_token("orders/#{@order_id}/products/all")
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
class Bluepark::Client::Skus
|
4
|
+
def initialize(client)
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_skus(params = {})
|
9
|
+
@client.rest_get_with_token('skus/', params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_sku(sku_id)
|
13
|
+
@client.rest_get_with_token("skus/#{sku_id}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def count(params = {})
|
17
|
+
@client.rest_get_with_token('skus/count', params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def update_single_sku(sku_id, sku_params)
|
21
|
+
@client.rest_put_with_token("skus/#{sku_id}", sku_params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete_sku_by_id(sku_id)
|
25
|
+
@client.rest_delete_with_token("skus/#{sku_id}")
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete_all_skus
|
29
|
+
@client.rest_delete_with_token('skus/all')
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
class Bluepark::Client::Taxonomies
|
4
|
+
def initialize(client)
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
def retrieve_tree
|
9
|
+
@client.rest_get_with_token('taxonomy/')
|
10
|
+
end
|
11
|
+
|
12
|
+
def count
|
13
|
+
@client.rest_get_with_token('taxonomy/count')
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bluepark
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andriy Byalyk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: oj
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.3.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.3.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.2
|
69
|
+
description: A simple client created to help with Bluepark integration
|
70
|
+
email:
|
71
|
+
- rewrite.andriy@gmail.com
|
72
|
+
- andriy.b@coaxsoft.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- bluepark.gemspec
|
78
|
+
- lib/bluepark.rb
|
79
|
+
- lib/bluepark/client.rb
|
80
|
+
- lib/bluepark/client/orders.rb
|
81
|
+
- lib/bluepark/client/products.rb
|
82
|
+
- lib/bluepark/client/sales.rb
|
83
|
+
- lib/bluepark/client/skus.rb
|
84
|
+
- lib/bluepark/client/taxonomies.rb
|
85
|
+
- lib/bluepark/errors/bluepark_error.rb
|
86
|
+
homepage:
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.6.8
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Ruby client library for the Bluepark API
|
110
|
+
test_files: []
|