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 CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.6 October 21, 2011
4
+ * FatSecret: Retry once if timestamp invalid (API only supports single request/second)
5
+
3
6
  ## 0.0.5 September 26, 2011
4
7
  * Bugfix: missing 'return' was wreaking havoc with FoodInfo.search
5
8
 
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module FoodInfo
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
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.5
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-09-26 00:00:00.000000000Z
12
+ date: 2011-10-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &70296305209760 !ruby/object:Gem::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: *70296305209760
24
+ version_requirements: *70256719087420
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hashie
27
- requirement: &70296305209140 !ruby/object:Gem::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: *70296305209140
35
+ version_requirements: *70256719086900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ruby-hmac
38
- requirement: &70296305208640 !ruby/object:Gem::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: *70296305208640
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.