fat_secret 0.0.4 → 0.0.5

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.
@@ -14,11 +14,11 @@ module FatSecret
14
14
 
15
15
  params = default_parameters.merge(params).merge(method: method)
16
16
  uri = request_uri('GET', params)
17
- # response = Typhoeus.get(
18
- # "#{uri.scheme}://#{uri.host}:#{uri.port}#{uri.path}",
19
- # params: params, followlocation: true
20
- # )
21
- JSON.parse(uri.read)
17
+ response = uri.read
18
+ FatSecret.configuration.logger.debug(
19
+ "FatSecret Response: #{response}"
20
+ )
21
+ JSON.parse(response)
22
22
  end
23
23
 
24
24
  private
@@ -17,7 +17,9 @@ module FatSecret
17
17
 
18
18
  define_method "#{type}=" do |array|
19
19
  klass = "FatSecret::#{type.to_s.singularize.classify}".constantize
20
- servings = array[type.to_s.singularize].map do |attrs|
20
+ servings = array[type.to_s.singularize]
21
+ servings = [servings] unless servings.is_a?(Array)
22
+ servings = servings.map do |attrs|
21
23
  klass.new(attrs)
22
24
  end
23
25
  @servings = HasManyProxy.new(servings)
@@ -1,3 +1,3 @@
1
1
  module FatSecret
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -35,30 +35,49 @@ describe FatSecret::Food do
35
35
  describe '.get' do
36
36
  before { configure }
37
37
 
38
- subject do
39
- VCR.use_cassette('get_milk', match_requests_on: [ :host ], allow_playback_repeats: true) do
40
- FatSecret::Food.get(793)
38
+ context 'when there are multiple servings', :multiple_servings do
39
+ subject do
40
+ VCR.use_cassette('get_milk', match_requests_on: [ :host ], allow_playback_repeats: true) do
41
+ FatSecret::Food.get(793)
42
+ end
41
43
  end
42
- end
43
44
 
44
- it 'should return a food object' do
45
- subject.should be_instance_of(FatSecret::Food)
46
- end
45
+ it 'should return a food object' do
46
+ subject.should be_instance_of(FatSecret::Food)
47
+ end
47
48
 
48
- it 'should populate the food name' do
49
- subject.name.should eql('Milk')
50
- end
49
+ it 'should populate the food name' do
50
+ subject.name.should eql('Milk')
51
+ end
51
52
 
52
- it 'should populate the servings' do
53
- subject.servings.should_not be_blank
54
- end
53
+ it 'should populate the servings' do
54
+ subject.servings.should_not be_blank
55
+ end
55
56
 
56
- it 'should use serving objects in the servings relation' do
57
- subject.servings.first.should be_instance_of(FatSecret::Serving)
57
+ it 'should use serving objects in the servings relation' do
58
+ subject.servings.first.should be_instance_of(FatSecret::Serving)
59
+ end
60
+
61
+ it 'should add the serving data to the servings' do
62
+ subject.servings.first.saturated_fat.should eql(2.965)
63
+ end
58
64
  end
59
65
 
60
- it 'should add the serving data to the servings' do
61
- subject.servings.first.saturated_fat.should eql(2.965)
66
+ context 'when there is only 1 serving', :one_serving do
67
+ subject do
68
+ VCR.use_cassette(
69
+ 'get_steel_cut_oats', match_requests_on: [ :host ],
70
+ allow_playback_repeats: true
71
+ ) do
72
+ FatSecret::Food.get(2095870)
73
+ end
74
+ end
75
+
76
+ it { should be_instance_of(FatSecret::Food) }
77
+
78
+ it { subject.servings.count.should eql(1) }
79
+
80
+ it { subject.servings.first.calories.should eql(150.0) }
62
81
  end
63
82
  end
64
83
 
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://platform.fatsecret.com/rest/server.api?food_id=2095870&format=json&method=food.get&oauth_consumer_key=7ebedda1451640ecbd8db41ea22d1351&oauth_nonce=429e9d97ad3f4f51&oauth_signature=xxPMCPmw5CxkTpTo2RGpmevl5co%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1362913468&oauth_version=1.0
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ accept:
11
+ - ! '*/*'
12
+ user-agent:
13
+ - Ruby
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ cache-control:
20
+ - private
21
+ content-type:
22
+ - application/json; charset=utf-8
23
+ server:
24
+ - Microsoft-IIS/7.5
25
+ x-aspnet-version:
26
+ - 4.0.30319
27
+ x-powered-by:
28
+ - ASP.NET
29
+ date:
30
+ - Sun, 10 Mar 2013 11:04:27 GMT
31
+ content-length:
32
+ - '840'
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! '{ "food": {"brand_name": "Hodgson Mill", "food_id": "2095870", "food_name":
36
+ "Steel Cut Oats", "food_type": "Brand", "food_url": "http:\/\/www.fatsecret.com\/calories-nutrition\/hodgson-mill\/steel-cut-oats",
37
+ "servings": {"serving": {"calcium": "0", "calories": "150", "carbohydrate":
38
+ "27", "cholesterol": "0", "fat": "2.5", "fiber": "4", "iron": "10", "measurement_description":
39
+ "serving", "metric_serving_amount": "40.000", "metric_serving_unit": "g",
40
+ "monounsaturated_fat": "0", "number_of_units": "1.000", "polyunsaturated_fat":
41
+ "0", "potassium": "167", "protein": "5", "saturated_fat": "0.5", "serving_description":
42
+ "1\/4 cup", "serving_id": "2053719", "serving_url": "http:\/\/www.fatsecret.com\/calories-nutrition\/hodgson-mill\/steel-cut-oats",
43
+ "sodium": "0", "sugar": "1", "trans_fat": "0", "vitamin_a": "0", "vitamin_c":
44
+ "0" } } }}'
45
+ http_version: '1.1'
46
+ recorded_at: Sun, 10 Mar 2013 11:04:28 GMT
47
+ recorded_with: VCR 2.3.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fat_secret
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-02 00:00:00.000000000 Z
12
+ date: 2013-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: active_attr
@@ -128,6 +128,7 @@ files:
128
128
  - spec/support/vcr.rb
129
129
  - spec/vcr_cassettes/get_milk.yml
130
130
  - spec/vcr_cassettes/get_servings_association.yml
131
+ - spec/vcr_cassettes/get_steel_cut_oats.yml
131
132
  - spec/vcr_cassettes/search_for_milk.yml
132
133
  homepage: https://github.com/mattbeedle/FatSecret
133
134
  licenses: []
@@ -165,4 +166,5 @@ test_files:
165
166
  - spec/support/vcr.rb
166
167
  - spec/vcr_cassettes/get_milk.yml
167
168
  - spec/vcr_cassettes/get_servings_association.yml
169
+ - spec/vcr_cassettes/get_steel_cut_oats.yml
168
170
  - spec/vcr_cassettes/search_for_milk.yml