semantics3 0.02 → 0.03

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +5 -5
  2. data/Changes +6 -0
  3. data/lib/semantics3.rb +27 -24
  4. data/semantics3.gemspec +2 -2
  5. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA512:
3
- data.tar.gz: 7a35268c671e071cb8442871430c4573b62bf4b7a2fcf16a17640e929b7d75b8df3c0fe220a4cb0b6998f00ab96341a940589c1073eda17364a6da6807c34f40
4
- metadata.gz: 6980c9b8e8606a08867f22e720ef7f0c6ca8c4da9ccd279236bef74df4c3bd54a879db1dbdc525cd045e3f6f41a7e383d14b8f930859ce6555f16476f13f32f4
5
2
  SHA1:
6
- data.tar.gz: 6ce0854ae901345ab17388a2a9082a51f57fe2c7
7
- metadata.gz: e19b3c953692d377067b882776fc4d43b6d1e6e8
3
+ data.tar.gz: 94cd2416099186ac9473a42d472f9a6e87688adc
4
+ metadata.gz: 2d2546ddf78dd461a0bb92224a0786df0ed7a3d4
5
+ SHA512:
6
+ data.tar.gz: 7ab76290fea5adb2da17155f8369dc0931a1cb95a39d8347d8f2396599236fa9f990c8f7bbfe567a95da7a7b329a91fabc7f4b40bb581b1d521ec4c2d4429840
7
+ metadata.gz: 57b29c4925b1d2bb272c4fc6c84f4b06d0cfe0115fd9d94a6e41dd9eba05d85a2fd264b3053288ff1e4c45ca33b31b3f5c67b89915da2145ce8bb111510ff266
data/Changes CHANGED
@@ -1,5 +1,11 @@
1
1
  Revision history for semantics3-ruby
2
2
 
3
+ 0.03 07-02-2014
4
+ Made library thread safe [Thanks to Mark Evans/ShopGenius App (mark@shopgeniusapp.com)]
5
+
6
+ 0.02 13-01-2014
7
+ Bumped json min. requirements.
8
+
3
9
  0.01 31-01-2013
4
10
  First version, released on an unsuspecting world.
5
11
 
data/lib/semantics3.rb CHANGED
@@ -41,8 +41,11 @@ module Semantics3
41
41
  end
42
42
 
43
43
  class Products < Base
44
- @@data_query = {}
45
- @@query_result = {}
44
+
45
+ def initialize api_key, api_secret
46
+ super
47
+ clear()
48
+ end
46
49
 
47
50
  MAX_LIMIT = 10
48
51
 
@@ -77,17 +80,17 @@ module Semantics3
77
80
  end
78
81
 
79
82
  def all_products
80
- if not @@query_result.has_key?(results)
83
+ if not @query_result.has_key?(results)
81
84
  raise Error.new('Undefined Query','Query result is undefined. You need to run a query first.')
82
85
  end
83
- @@query_result['results']
86
+ @query_result['results']
84
87
  end
85
88
 
86
89
  def iterate_products
87
90
  limit = MAX_LIMIT
88
- prodRef = @@data_query['products']
91
+ prodRef = @data_query['products']
89
92
 
90
- if (not ( @@query_result.has_key?('total_results_count') ) ) or ( @@query_result['offset'] >= @@query_result['total_results_count'] )
93
+ if (not ( @query_result.has_key?('total_results_count') ) ) or ( @query_result['offset'] >= @query_result['total_results_count'] )
91
94
  return
92
95
  end
93
96
 
@@ -113,11 +116,11 @@ module Semantics3
113
116
  raise Error.new('Undefined Endpoint','Query Endpoint was not defined. You need to provide one. Eg: products','endpoint')
114
117
  end
115
118
 
116
- if not @@data_query.has_key?(endpoint)
117
- @@data_query[endpoint] = {}
119
+ if not @data_query.has_key?(endpoint)
120
+ @data_query[endpoint] = {}
118
121
  end
119
122
 
120
- prodRef = @@data_query[endpoint]
123
+ prodRef = @data_query[endpoint]
121
124
 
122
125
  for i in 1..(fields.length - 1)
123
126
  if not prodRef.has_key?(fields[i-1])
@@ -131,7 +134,7 @@ module Semantics3
131
134
  end
132
135
 
133
136
  #-- To be removed
134
- #puts @@data_query.inspect
137
+ #puts @data_query.inspect
135
138
 
136
139
  end
137
140
 
@@ -146,7 +149,7 @@ module Semantics3
146
149
  prodRef = {}
147
150
  arrayCt = 0
148
151
 
149
- if @@data_query.has_key?(endpoint)
152
+ if @data_query.has_key?(endpoint)
150
153
  prodRef = data_query[endpoint]
151
154
  arrayCt = fields.length-1
152
155
  valid = 1
@@ -169,35 +172,35 @@ module Semantics3
169
172
  end
170
173
 
171
174
  #-- To be removed
172
- #puts @@data_query.inspect
175
+ #puts @data_query.inspect
173
176
 
174
177
  end
175
178
 
176
179
  def get_query(endpoint)
177
- if not @@data_query.has_key?(endpoint)
180
+ if not @data_query.has_key?(endpoint)
178
181
  raise Error.new('Undefined Endpoint','Query Endpoint was not defined. You need to provide one. Eg: products', 'endpoint')
179
182
  end
180
- @@data_query[endpoint]
183
+ @data_query[endpoint]
181
184
  end
182
185
 
183
186
  def get_query_json(endpoint)
184
- if not @@data_query.has_key?(endpoint)
187
+ if not @data_query.has_key?(endpoint)
185
188
  raise Error.new('Undefined Endpoint','Query Endpoint was not defined. You need to provide one. Eg: products', 'endpoint')
186
189
  end
187
- @@data_query[endpoint].to_json
190
+ @data_query[endpoint].to_json
188
191
  end
189
192
 
190
193
  def get_results
191
- @@query_result
194
+ @query_result
192
195
  end
193
196
 
194
197
  def get_results_json
195
- @@query_result.to_json
198
+ @query_result.to_json
196
199
  end
197
200
 
198
201
  def clear
199
- @@data_query={}
200
- @@query_result={}
202
+ @data_query={}
203
+ @query_result={}
201
204
  end
202
205
 
203
206
  def run_query(endpoint,*params)
@@ -210,7 +213,7 @@ module Semantics3
210
213
  data = params[0]
211
214
 
212
215
  if data == nil
213
- @@query_result = _make_request(endpoint,@@data_query[endpoint].to_json)
216
+ @query_result = _make_request(endpoint,@data_query[endpoint].to_json)
214
217
  else
215
218
  if not data.is_a?(Hash) and not data.is_a?(String)
216
219
  #-- Throw error - neither string nor hash
@@ -218,19 +221,19 @@ module Semantics3
218
221
  else
219
222
  #-- Data is Hash ref. Great just send it.
220
223
  if data.is_a?(Hash)
221
- @@query_result = _make_request(endpoint,data.to_json)
224
+ @query_result = _make_request(endpoint,data.to_json)
222
225
  #-- Data is string
223
226
  elsif data.is_a?(String)
224
227
  #-- Check if it's valid JSON
225
228
  if JSON.is_json?(data)
226
- @@query_result = _make_request(endpoint,data)
229
+ @query_result = _make_request(endpoint,data)
227
230
  else
228
231
  raise Error.new('Invalid Input','You submitted an invalid JSON query string')
229
232
  end
230
233
  end
231
234
  end
232
235
  end
233
- @@query_result
236
+ @query_result
234
237
  end
235
238
 
236
239
  end
data/semantics3.gemspec CHANGED
@@ -2,9 +2,9 @@ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
2
 
3
3
  spec = Gem::Specification.new do |s|
4
4
  s.name = 'semantics3'
5
- s.version = '0.02'
5
+ s.version = '0.03'
6
6
  s.summary = 'Ruby bindings for the Semantics3 API'
7
- s.description = 'Get access to a constantly updated database of product and price ifnormations. See https://semantics3.com/ for more information.'
7
+ s.description = 'Get access to a constantly updated database of product and price data. See https://semantics3.com/ for more information.'
8
8
  s.authors = ['Sivamani Varun']
9
9
  s.email = ['varun@semantics3.com']
10
10
  s.homepage = 'https://semantics3.com'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantics3
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.02"
4
+ version: "0.03"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sivamani Varun
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2014-01-14 00:00:00 Z
12
+ date: 2014-02-08 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -37,7 +37,7 @@ dependencies:
37
37
  version: 0.4.6
38
38
  type: :runtime
39
39
  version_requirements: *id002
40
- description: Get access to a constantly updated database of product and price ifnormations. See https://semantics3.com/ for more information.
40
+ description: Get access to a constantly updated database of product and price data. See https://semantics3.com/ for more information.
41
41
  email:
42
42
  - varun@semantics3.com
43
43
  executables: []
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  requirements: []
78
78
 
79
79
  rubyforge_project:
80
- rubygems_version: 2.2.1
80
+ rubygems_version: 2.2.2
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: Ruby bindings for the Semantics3 API