food_info 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.markdown +3 -0
- data/lib/food_info/adapters/fat_secret.rb +11 -3
- data/lib/food_info/version.rb +1 -1
- metadata +8 -8
data/HISTORY.markdown
CHANGED
@@ -10,6 +10,7 @@ module FoodInfo
|
|
10
10
|
module Adapters
|
11
11
|
class FatSecret
|
12
12
|
include HTTParty
|
13
|
+
RETRY_INVALID_TIMESTAMP = 1 # Only retry once to avoid huge pileup if concurrent
|
13
14
|
|
14
15
|
def initialize(opts = {})
|
15
16
|
raise AuthorizationError.new("Missing required argument :key") unless @key = opts[:key]
|
@@ -36,11 +37,18 @@ module FoodInfo
|
|
36
37
|
|
37
38
|
protected
|
38
39
|
|
39
|
-
def query(method, opts = {})
|
40
|
+
def query(method, opts = {}, retried = 0)
|
40
41
|
query_url = Request.new(method, {:key => @key, :secret => @secret}, opts).signed_request
|
41
|
-
data = self.class.get( query_url )
|
42
|
-
raise DataSourceException.new(data['error']['message']) if data['error']
|
42
|
+
data = self.class.get( query_url )
|
43
43
|
|
44
|
+
if data['error'] # Invalid timestamp can happen if more than one request/second. Allow retrying once.
|
45
|
+
if data['error']['message'] =~ 'Invalid/expired timestamp' && retried < RETRY_INVALID_TIMESTAMP
|
46
|
+
return query(method, opts, retried + 1)
|
47
|
+
else
|
48
|
+
raise DataSourceException.new(data['error']['message'])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
44
52
|
return data
|
45
53
|
end
|
46
54
|
|
data/lib/food_info/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: food_info
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-10-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement: &
|
16
|
+
requirement: &70256719087420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.7.7
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70256719087420
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hashie
|
27
|
-
requirement: &
|
27
|
+
requirement: &70256719086900 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.1.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70256719086900
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: ruby-hmac
|
38
|
-
requirement: &
|
38
|
+
requirement: &70256719086520 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70256719086520
|
47
47
|
description: Generic Ruby interface to look up nutritional information on food. Design
|
48
48
|
is modular so other adapters can be plugged in, but only data source currently implemented
|
49
49
|
is FatSecret.
|