indix-api-client 0.0.1
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/lib/exceptions.rb +12 -0
- data/lib/http_client.rb +90 -0
- data/lib/indix_api_client.rb +205 -0
- data/lib/models.rb +36 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 11cc7291d0e2490961013b4657f583df7c596095
|
4
|
+
data.tar.gz: c4001e25aafaf019f46a26acf91e9ba64c44024b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eb20938c99608b30516fd9e25772e25986268d76448246fb8cc294351d56cf9e0cc1624437992b09e30a5325eba1cdd506854213932b7fb96d4cd3f4e219f34f
|
7
|
+
data.tar.gz: eca83230a94399a7ef811c3db08777e60a1035906e0e20c7bda7f9e34c24b92fe1b68e9f3ae8a86b9aab2c53cabbde2bf9b9078d944c7a1f52ab53a186e73201
|
data/lib/exceptions.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
class RuntimeException < StandardError;
|
2
|
+
end
|
3
|
+
class ResourceNotFound < StandardError;
|
4
|
+
end
|
5
|
+
class BadRequest < StandardError;
|
6
|
+
end
|
7
|
+
class UnAuthorizedException < StandardError;
|
8
|
+
end
|
9
|
+
class RequestTimeoutException < StandardError;
|
10
|
+
end
|
11
|
+
class ResponseError < StandardError;
|
12
|
+
end
|
data/lib/http_client.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'exceptions'
|
2
|
+
require 'rest_client'
|
3
|
+
require 'uri'
|
4
|
+
require 'hashie'
|
5
|
+
require 'active_support'
|
6
|
+
|
7
|
+
class HttpClient
|
8
|
+
attr_accessor :host, :protocol, :headers
|
9
|
+
|
10
|
+
def initialize(host, protocol = 'https')
|
11
|
+
@host = host
|
12
|
+
@protocol = protocol
|
13
|
+
@headers = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_headers(hash)
|
17
|
+
@headers = @headers.merge(hash)
|
18
|
+
end
|
19
|
+
|
20
|
+
def request(method, path, request_params = {}, payload = {}, extra_options = {})
|
21
|
+
response = nil
|
22
|
+
path = url(method, path, request_params)
|
23
|
+
begin
|
24
|
+
case method
|
25
|
+
when 'get'
|
26
|
+
response = self.get(path)
|
27
|
+
when 'post'
|
28
|
+
payload = build_query(payload) if extra_options[:multipart] != true
|
29
|
+
response = self.post(path, payload)
|
30
|
+
end
|
31
|
+
rescue RestClient::BadRequest => e
|
32
|
+
raise BadRequest.new(JSON.parse(e.http_body)["statusMessage"])
|
33
|
+
rescue RestClient::ResourceNotFound => e
|
34
|
+
raise ResourceNotFound.new(e.message)
|
35
|
+
rescue RestClient::Unauthorized => e
|
36
|
+
raise UnAuthorizedException.new(e.message)
|
37
|
+
rescue Exception => e
|
38
|
+
raise e
|
39
|
+
end
|
40
|
+
|
41
|
+
unless extra_options[:stream] == true
|
42
|
+
unless response.empty?
|
43
|
+
response = ::ActiveSupport::JSON.decode(response)
|
44
|
+
response = to_hashie(response)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
response
|
48
|
+
end
|
49
|
+
|
50
|
+
def get(path)
|
51
|
+
RestClient::Request.execute(:method => :get, :url => path, :headers => @headers, :verify_ssl => false)
|
52
|
+
end
|
53
|
+
|
54
|
+
def post(path, data)
|
55
|
+
RestClient::Request.execute(:method => :post, :url => path, :payload => data, :headers => @headers)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def url(method, path, options = {})
|
61
|
+
query_string = build_query(options)
|
62
|
+
uri_hash = {:host => @host, :path => URI::encode(path), :query => query_string}
|
63
|
+
uri = @protocol == 'http' ? URI::HTTP.build(uri_hash) : URI::HTTPS.build(uri_hash)
|
64
|
+
uri.to_s
|
65
|
+
end
|
66
|
+
|
67
|
+
def escape_string(str)
|
68
|
+
URI.escape(str, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
69
|
+
end
|
70
|
+
|
71
|
+
def build_query(options)
|
72
|
+
return nil if options.nil? or options.empty?
|
73
|
+
options = options.collect do |name, value|
|
74
|
+
if value.is_a? Array
|
75
|
+
value.collect { |v| "#{name}=#{v.class.to_s != 'Fixnum' ? escape_string(v.to_s) : v}" }.join('&')
|
76
|
+
else
|
77
|
+
"#{name}=#{!value.nil? ? (value.class.to_s != 'Fixnum' ? escape_string(value.to_s) : value) : ''}"
|
78
|
+
end
|
79
|
+
end.join('&')
|
80
|
+
options
|
81
|
+
end
|
82
|
+
|
83
|
+
def to_hashie json
|
84
|
+
if json.is_a? Array
|
85
|
+
json.collect! { |x| x.is_a?(Hash) ? Hashie::Mash.new(x) : x }
|
86
|
+
else
|
87
|
+
Hashie::Mash.new(json)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
require 'http_client'
|
2
|
+
require 'models'
|
3
|
+
|
4
|
+
class IndixApiClient < ParamsBase
|
5
|
+
attr_accessor :app_id, :app_key, :host, :protocol, :http_client, :api_version
|
6
|
+
|
7
|
+
def initialize(app_id, app_key, host = "api.indix.com", protocol = "https")
|
8
|
+
@app_id = app_id
|
9
|
+
@app_key = app_key
|
10
|
+
@host = host
|
11
|
+
@protocol = protocol
|
12
|
+
@http_client = get_http_client
|
13
|
+
@api_version = "v2"
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_stores(query)
|
17
|
+
params = query.to_hash
|
18
|
+
params.merge!(get_api_params)
|
19
|
+
self.http_client.request("get", "/#{self.api_version}/stores", params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_brands(query)
|
23
|
+
params = query.to_hash
|
24
|
+
params.merge!(get_api_params)
|
25
|
+
self.http_client.request("get", "/#{self.api_version}/brands", params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_categories
|
29
|
+
params = self.to_hash
|
30
|
+
self.http_client.request("get", "/#{self.api_version}/categories", params)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_summary_products(query)
|
34
|
+
get_products(query, 'summary')
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_offers_standard_products(query)
|
38
|
+
get_products(query, 'offersStandard')
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_offers_premium_products(query)
|
42
|
+
get_products(query, 'offersPremium')
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_catalog_standard_products(query)
|
46
|
+
get_products(query, 'catalogStandard')
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_catalog_premium_products(query)
|
50
|
+
get_products(query, 'catalogPremium')
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_universal_products(query)
|
54
|
+
get_products(query, 'universal')
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_summary_product_detail(product_id, countryCode)
|
58
|
+
get_product_detail(product_id, countryCode, 'summary')
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_offers_standard_product_detail(product_id, countryCode)
|
62
|
+
get_product_detail(product_id, countryCode, 'offersStandard')
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_offers_premium_product_detail(product_id, countryCode)
|
66
|
+
get_product_detail(product_id, countryCode, 'offersPremium')
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_catalog_standard_product_detail(product_id, countryCode)
|
70
|
+
get_product_detail(product_id, countryCode, 'catalogStandard')
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_catalog_premium_product_detail(product_id, countryCode)
|
74
|
+
get_product_detail(product_id, countryCode, 'catalogPremium')
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_universal_product_detail(product_id, countryCode)
|
78
|
+
get_product_detail(product_id, countryCode, 'universal')
|
79
|
+
end
|
80
|
+
|
81
|
+
def post_bulk_summary_products(query)
|
82
|
+
post_bulk_search_job(query, 'summary')
|
83
|
+
end
|
84
|
+
|
85
|
+
def post_bulk_offers_standard_products(query)
|
86
|
+
post_bulk_search_job(query, 'offersStandard')
|
87
|
+
end
|
88
|
+
|
89
|
+
def post_bulk_offers_premium_products(query)
|
90
|
+
post_bulk_search_job(query, 'offersPremium')
|
91
|
+
end
|
92
|
+
|
93
|
+
def post_bulk_catalog_standard_products(query)
|
94
|
+
post_bulk_search_job(query, 'catalogStandard')
|
95
|
+
end
|
96
|
+
|
97
|
+
def post_bulk_catalog_premium_products(query)
|
98
|
+
post_bulk_search_job(query, 'catalogPremium')
|
99
|
+
end
|
100
|
+
|
101
|
+
def post_bulk_universal_products(query)
|
102
|
+
post_bulk_search_job(query, 'universal')
|
103
|
+
end
|
104
|
+
|
105
|
+
def post_bulk_summary_product_lookup(query)
|
106
|
+
post_bulk_lookup_job(query, 'summary')
|
107
|
+
end
|
108
|
+
|
109
|
+
def post_bulk_offers_standard_product_lookup(query)
|
110
|
+
post_bulk_lookup_job(query, 'offersStandard')
|
111
|
+
end
|
112
|
+
|
113
|
+
def post_bulk_offers_premium_product_lookup(query)
|
114
|
+
post_bulk_lookup_job(query, 'offersPremium')
|
115
|
+
end
|
116
|
+
|
117
|
+
def post_bulk_catalog_standard_product_lookup(query)
|
118
|
+
post_bulk_lookup_job(query, 'catalogStandard')
|
119
|
+
end
|
120
|
+
|
121
|
+
def post_bulk_catalog_premium_product_lookup(query)
|
122
|
+
post_bulk_lookup_job(query, 'catalogPremium')
|
123
|
+
end
|
124
|
+
|
125
|
+
def post_bulk_universal_product_lookup(query)
|
126
|
+
post_bulk_lookup_job(query, 'universal')
|
127
|
+
end
|
128
|
+
|
129
|
+
def get_bulk_job_status(job_id)
|
130
|
+
params = get_api_params
|
131
|
+
self.http_client.request("get", "/#{self.api_version}/bulk/jobs/#{job_id}", params)
|
132
|
+
end
|
133
|
+
|
134
|
+
def get_bulk_job_output(job_id)
|
135
|
+
params = get_api_params
|
136
|
+
extra_options = {:stream => true}
|
137
|
+
self.http_client.request("get", "/#{self.api_version}/bulk/jobs/#{job_id}/download", params, {}, extra_options)
|
138
|
+
end
|
139
|
+
|
140
|
+
def post_advanced_search_bulk_job(query)
|
141
|
+
payload = query.to_hash
|
142
|
+
payload.merge!(get_api_params)
|
143
|
+
extra_options = {:multipart => true}
|
144
|
+
self.http_client.request("post", "/#{self.api_version}/universal/bulk/ase", {}, payload, extra_options)
|
145
|
+
end
|
146
|
+
|
147
|
+
def get_advanced_search_bulk_job_status(job_id)
|
148
|
+
params = get_api_params
|
149
|
+
self.http_client.request("get", "/#{self.api_version}/bulk/ase/#{job_id}", params)
|
150
|
+
end
|
151
|
+
|
152
|
+
def get_advanced_search_bulk_job_output(job_id)
|
153
|
+
params = get_api_params
|
154
|
+
extra_options = {:stream => true}
|
155
|
+
self.http_client.request("get", "/#{self.api_version}/bulk/ase/#{job_id}", params, {}, extra_options)
|
156
|
+
end
|
157
|
+
|
158
|
+
def get_api_params
|
159
|
+
{"app_id" => self.app_id, "app_key" => self.app_key}
|
160
|
+
end
|
161
|
+
|
162
|
+
def get_suggestions(country_code, q)
|
163
|
+
params = get_api_params
|
164
|
+
params.merge!({"countryCode" => country_code, "q" => q})
|
165
|
+
self.http_client.request("get", "/#{self.api_version}/bulk/ase/#{job_id}", params)
|
166
|
+
end
|
167
|
+
|
168
|
+
def get_product_price_history(pid, query)
|
169
|
+
params = query.to_hash
|
170
|
+
params.merge!(get_api_params)
|
171
|
+
self.http_client.request("get", "/#{self.api_version}/history/products/#{pid}", params)
|
172
|
+
end
|
173
|
+
|
174
|
+
private
|
175
|
+
|
176
|
+
def get_products(query, type = 'summary')
|
177
|
+
params = query.to_hash
|
178
|
+
params.merge!(get_api_params)
|
179
|
+
self.http_client.request("get", "/#{self.api_version}/#{type}/products", params)
|
180
|
+
end
|
181
|
+
|
182
|
+
def get_product_detail(product_id, country_code, type = 'summary')
|
183
|
+
params = {"countryCode" => country_code}
|
184
|
+
params.merge!(get_api_params)
|
185
|
+
self.http_client.request("get", "/#{self.api_version}/#{type}/products/#{product_id}", params)
|
186
|
+
end
|
187
|
+
|
188
|
+
def post_bulk_search_job(query, type = 'summary')
|
189
|
+
payload = query.to_hash
|
190
|
+
payload.merge!(get_api_params)
|
191
|
+
self.http_client.request("post", "/#{self.api_version}/#{type}/bulk/products", {}, payload)
|
192
|
+
end
|
193
|
+
|
194
|
+
def post_bulk_lookup_job(query, type = 'summary')
|
195
|
+
payload = query.to_hash
|
196
|
+
payload.merge!(get_api_params)
|
197
|
+
extra_options = {:multipart => true}
|
198
|
+
self.http_client.request("post", "/#{self.api_version}/#{type}/bulk/lookup", {}, payload, extra_options)
|
199
|
+
end
|
200
|
+
|
201
|
+
def get_http_client
|
202
|
+
HttpClient.new(self.host, self.protocol)
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
data/lib/models.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
class ParamsBase
|
2
|
+
def initialize params
|
3
|
+
params.each { |k, v| send "#{k}=", v }
|
4
|
+
end
|
5
|
+
|
6
|
+
def to_hash
|
7
|
+
hash = {}
|
8
|
+
self.instance_variables.each do |var|
|
9
|
+
hash[var.to_s.delete("@")] = self.instance_variable_get(var)
|
10
|
+
end
|
11
|
+
hash
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class BCSQueryParams < ParamsBase
|
16
|
+
attr_accessor :q
|
17
|
+
end
|
18
|
+
|
19
|
+
class BulkProductLookupParams < ParamsBase
|
20
|
+
attr_accessor :countryCode, :file
|
21
|
+
end
|
22
|
+
|
23
|
+
class BulkProductSearchParams < ParamsBase
|
24
|
+
attr_accessor :countryCode, :storeId, :alsoSoldAt, :brandId, :categoryId
|
25
|
+
attr_accessor :startPrice, :endPrice, :availability, :priceHistoryAvailable, :priceChange
|
26
|
+
attr_accessor :onPromotion, :lastRecordedIn, :storesCount, :applyFiltersTo, :selectOffersFrom
|
27
|
+
end
|
28
|
+
|
29
|
+
class SearchParams < BulkProductSearchParams
|
30
|
+
attr_accessor :q, :url, :upc, :mpn, :sku
|
31
|
+
attr_accessor :sortBy, :facetBy, :pageNumber, :pageSize
|
32
|
+
end
|
33
|
+
|
34
|
+
class PriceHistoryParams < ParamsBase
|
35
|
+
attr_accessor :countryCode, :storeId
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: indix-api-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeevan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: hashie
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.4.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.4.0
|
69
|
+
description: Indix API Client library to interact with indix apis using ruby
|
70
|
+
email: jeevan@indix.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- lib/exceptions.rb
|
76
|
+
- lib/http_client.rb
|
77
|
+
- lib/indix_api_client.rb
|
78
|
+
- lib/models.rb
|
79
|
+
homepage: http://indix.com
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.6
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Indix API Client library to interact with indix apis using ruby
|
103
|
+
test_files: []
|