foodnutritionix 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +24 -0
- data/Gemfile.lock +85 -0
- data/LICENSE.md +21 -0
- data/README.md +3 -0
- data/Rakefile +38 -0
- data/config/credentials.yml.example +3 -0
- data/foodnutritionix.gemspec +33 -0
- data/lib/foodnutritionix/food.rb +31 -0
- data/lib/foodnutritionix/foodnutrix_api.rb +31 -0
- data/lib/foodnutritionix/version.rb +5 -0
- data/lib/foodnutritionix.rb +4 -0
- data/spec/foodnutritionix/food_spec.rb +17 -0
- data/spec/foodnutritionix/foodnutrix_api_spec.rb +16 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/support/cassettes/food_spec_should_return_Foods_that_contain_specific_tags.yml +50 -0
- data/spec/support/cassettes/foodnutrix_api_spec_should_return_foods_information_that_contain_specific_tags.yml +50 -0
- data/spec/test.rb +14 -0
- metadata +236 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 40e99db47659732f428493c72855282be855fe34
|
4
|
+
data.tar.gz: 731cbf9742f3e89dd78108f59004112e487b9458
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dcee281d72c859ee3684b61973feeee960f38450489ab081135982d9c76573253b462799a59e7d6a0a0a38eb7ff1f5eae0eef8305a063f6342347abb2d93d1af
|
7
|
+
data.tar.gz: 662a6f546166360f2b64f8f3ee8150710c82823afd3326d44757f80e05e5300a47f5029f417b486c382461517d8dba3147eed4ba18c064eca3f8738d09ccf213
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
ruby '2.3.1'
|
3
|
+
|
4
|
+
source 'https://rubygems.org'
|
5
|
+
|
6
|
+
gem 'dotenv'
|
7
|
+
|
8
|
+
gem 'flog'
|
9
|
+
gem 'flay'
|
10
|
+
|
11
|
+
gem 'httparty'
|
12
|
+
|
13
|
+
gem 'minitest'
|
14
|
+
gem 'minitest-rg'
|
15
|
+
|
16
|
+
gem 'pry-coolline'
|
17
|
+
|
18
|
+
gem 'rake'
|
19
|
+
gem 'rubocop'
|
20
|
+
|
21
|
+
gem 'vcr'
|
22
|
+
gem 'webmock'
|
23
|
+
|
24
|
+
gem 'simplecov'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.5.0)
|
5
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
6
|
+
ast (2.3.0)
|
7
|
+
coolline (0.5.0)
|
8
|
+
unicode_utils (~> 1.4)
|
9
|
+
crack (0.4.3)
|
10
|
+
safe_yaml (~> 1.0.0)
|
11
|
+
docile (1.1.5)
|
12
|
+
dotenv (2.1.1)
|
13
|
+
erubis (2.7.0)
|
14
|
+
flay (2.8.1)
|
15
|
+
erubis (~> 2.7.0)
|
16
|
+
path_expander (~> 1.0)
|
17
|
+
ruby_parser (~> 3.0)
|
18
|
+
sexp_processor (~> 4.0)
|
19
|
+
flog (4.4.0)
|
20
|
+
path_expander (~> 1.0)
|
21
|
+
ruby_parser (~> 3.1, > 3.1.0)
|
22
|
+
sexp_processor (~> 4.4)
|
23
|
+
hashdiff (0.3.0)
|
24
|
+
httparty (0.14.0)
|
25
|
+
multi_xml (>= 0.5.2)
|
26
|
+
json (2.0.2)
|
27
|
+
minitest (5.9.1)
|
28
|
+
minitest-rg (5.2.0)
|
29
|
+
minitest (~> 5.0)
|
30
|
+
multi_xml (0.5.5)
|
31
|
+
parser (2.3.2.0)
|
32
|
+
ast (~> 2.2)
|
33
|
+
path_expander (1.0.0)
|
34
|
+
powerpack (0.1.1)
|
35
|
+
pry-coolline (0.2.5)
|
36
|
+
coolline (~> 0.5)
|
37
|
+
public_suffix (2.0.3)
|
38
|
+
rainbow (2.1.0)
|
39
|
+
rake (11.3.0)
|
40
|
+
rubocop (0.45.0)
|
41
|
+
parser (>= 2.3.1.1, < 3.0)
|
42
|
+
powerpack (~> 0.1)
|
43
|
+
rainbow (>= 1.99.1, < 3.0)
|
44
|
+
ruby-progressbar (~> 1.7)
|
45
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
46
|
+
ruby-progressbar (1.8.1)
|
47
|
+
ruby_parser (3.8.3)
|
48
|
+
sexp_processor (~> 4.1)
|
49
|
+
safe_yaml (1.0.4)
|
50
|
+
sexp_processor (4.7.0)
|
51
|
+
simplecov (0.12.0)
|
52
|
+
docile (~> 1.1.0)
|
53
|
+
json (>= 1.8, < 3)
|
54
|
+
simplecov-html (~> 0.10.0)
|
55
|
+
simplecov-html (0.10.0)
|
56
|
+
unicode-display_width (1.1.1)
|
57
|
+
unicode_utils (1.4.0)
|
58
|
+
vcr (3.0.3)
|
59
|
+
webmock (2.1.0)
|
60
|
+
addressable (>= 2.3.6)
|
61
|
+
crack (>= 0.3.2)
|
62
|
+
hashdiff
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
ruby
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
dotenv
|
69
|
+
flay
|
70
|
+
flog
|
71
|
+
httparty
|
72
|
+
minitest
|
73
|
+
minitest-rg
|
74
|
+
pry-coolline
|
75
|
+
rake
|
76
|
+
rubocop
|
77
|
+
simplecov
|
78
|
+
vcr
|
79
|
+
webmock
|
80
|
+
|
81
|
+
RUBY VERSION
|
82
|
+
ruby 2.3.1p112
|
83
|
+
|
84
|
+
BUNDLED WITH
|
85
|
+
1.13.6
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 NoBetterThan97
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'base64'
|
3
|
+
require 'dotenv'
|
4
|
+
require 'httparty'
|
5
|
+
require 'rake/testtask'
|
6
|
+
|
7
|
+
Dotenv.load
|
8
|
+
|
9
|
+
# rake test
|
10
|
+
Rake::TestTask.new do |task|
|
11
|
+
task.pattern = 'spec/**/*_spec.rb'
|
12
|
+
end
|
13
|
+
|
14
|
+
namespace :util do
|
15
|
+
desc 'deletes cassettes'
|
16
|
+
task :delete_cassettes do
|
17
|
+
sh 'rm -r spec/support/cassettes'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
namespace :quality do
|
22
|
+
LIB_DIR = 'lib'
|
23
|
+
|
24
|
+
desc 'perform all quality checks'
|
25
|
+
task default: [:rubocop, :flay, :flog]
|
26
|
+
|
27
|
+
desc 'linting code'
|
28
|
+
task(:rubocop) { sh "bundle exec rubocop #{LIB_DIR}" }
|
29
|
+
|
30
|
+
desc 'flay'
|
31
|
+
task(:flay) { sh "bundle exec flay #{LIB_DIR}" }
|
32
|
+
|
33
|
+
desc 'flog'
|
34
|
+
task(:flog) { sh "bundle exec flog #{LIB_DIR}" }
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'runs all quality tasks'
|
38
|
+
task quality: ['quality:default']
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'foodnutritionix/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'foodnutritionix'
|
7
|
+
s.version = FoodNutritionix::VERSION
|
8
|
+
|
9
|
+
s.summary = 'Get foods nutrients by search it name'
|
10
|
+
s.description = 'Get name, search time, unit, qty, weight, nutrients, calories, photo'
|
11
|
+
s.authors = ['Leo Lee']
|
12
|
+
s.email = ['leo.li@iss.nthu.edu.tw']
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
16
|
+
|
17
|
+
s.add_runtime_dependency 'httparty', '~> 0.14'
|
18
|
+
|
19
|
+
s.add_development_dependency 'dotenv', '~> 2.1'
|
20
|
+
s.add_development_dependency 'minitest', '~> 5.9'
|
21
|
+
s.add_development_dependency 'minitest-rg', '~> 5.2'
|
22
|
+
s.add_development_dependency 'rake', '~> 11.3'
|
23
|
+
s.add_development_dependency 'vcr', '~> 3.0'
|
24
|
+
s.add_development_dependency 'webmock', '~> 2.1'
|
25
|
+
s.add_development_dependency 'simplecov', '~> 0.12'
|
26
|
+
s.add_development_dependency 'flog', '~> 4.4'
|
27
|
+
s.add_development_dependency 'flay', '~> 2.8'
|
28
|
+
s.add_development_dependency 'rubocop', '~> 0.42'
|
29
|
+
s.add_development_dependency 'httparty', '~> 0.14'
|
30
|
+
|
31
|
+
s.homepage = 'https://github.com/NoBetterThan97/FoodNutritionix'
|
32
|
+
s.license = 'MIT'
|
33
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module FoodNutritionix
|
3
|
+
class Food
|
4
|
+
attr_reader :food_name, :consumed_at, :serving_qty, :serving_unit, :serving_weight_grams, :nf_calories, :nf_total_fat, :nf_saturated_fat, :nf_cholesterol, :nf_sodium, :nf_total_carbohydrate, :nf_dietary_fiber, :nf_sugars, :nf_protein, :nf_potassium, :photo
|
5
|
+
|
6
|
+
def initialize(data)
|
7
|
+
@food_name = data['food_name']
|
8
|
+
@consumed_at = DateTime.parse(data['consumed_at'])
|
9
|
+
@serving_qty = data['serving_qty']
|
10
|
+
@serving_unit = data['serving_unit']
|
11
|
+
@serving_weight_grams = data['serving_weight_grams']
|
12
|
+
@nf_calories = data['nf_calories']
|
13
|
+
@nf_total_fat = data['nf_total_fat']
|
14
|
+
@nf_saturated_fat = data['nf_saturated_fat']
|
15
|
+
@nf_cholesterol = data['nf_cholesterol']
|
16
|
+
@nf_sodium = data['nf_sodium']
|
17
|
+
@nf_total_carbohydrate = data['nf_total_carbohydrate']
|
18
|
+
@nf_dietary_fiber = data['nf_dietary_fiber']
|
19
|
+
@nf_sugars = data['nf_sugars']
|
20
|
+
@nf_protein = data['nf_protein']
|
21
|
+
@nf_potassium = data['nf_potassium']
|
22
|
+
@consumed_at = data['consumed_at']
|
23
|
+
@photo = data['photo']
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.search(*tags)
|
27
|
+
data = FoodNutrixClient.search_foods(tags)
|
28
|
+
new(data)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'yaml'
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module FoodNutritionix
|
6
|
+
class FoodNutrixClient
|
7
|
+
API_BASE = 'https://trackapi.nutritionix.com/'
|
8
|
+
API_VERSION = 'v2/'
|
9
|
+
SEARCH_FOOD_ENDPOINT = URI.join(API_BASE, API_VERSION, 'natural/nutrients')
|
10
|
+
|
11
|
+
def self.config=(conf)
|
12
|
+
@config ? @config.update(conf) : (@config = conf)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.config
|
16
|
+
return @config if @config
|
17
|
+
@config ||= { x_app_id: ENV['X_APP_ID'], x_app_key: ENV['X_APP_KEY'] }
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.search_foods(*foods)
|
21
|
+
HTTParty.post(SEARCH_FOOD_ENDPOINT,
|
22
|
+
headers: authorization_header,
|
23
|
+
body: { 'query': foods.join(' ') })
|
24
|
+
.parsed_response['foods'][0]
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.authorization_header
|
28
|
+
@authorization_header ||= { 'x-app-id': "#{config[:x_app_id]}", 'x-app-key': "#{config[:x_app_key]}" }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative '../spec_helper.rb'
|
3
|
+
|
4
|
+
describe 'FoodNutritionix::Food::search' do
|
5
|
+
before do
|
6
|
+
VCR.insert_cassette(cassette_name(__FILE__, name), record: :new_episodes)
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
VCR.eject_cassette
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should return Foods that contain specific tags' do
|
14
|
+
foods = FoodNutritionix::Food.search(FOODS)
|
15
|
+
foods.wont_be_nil
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative '../spec_helper.rb'
|
3
|
+
|
4
|
+
describe 'FoodNutritionix::FoodNutrixClient::search_foods' do
|
5
|
+
before do
|
6
|
+
VCR.insert_cassette(cassette_name(__FILE__, name), record: :new_episodes)
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
VCR.eject_cassette
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should return foods information that contain specific tags' do
|
14
|
+
FoodNutritionix::FoodNutrixClient.search_foods(FOODS).wont_be_nil
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start
|
4
|
+
|
5
|
+
require 'vcr'
|
6
|
+
require 'yaml'
|
7
|
+
require 'dotenv'
|
8
|
+
require 'webmock'
|
9
|
+
require 'minitest/rg'
|
10
|
+
require 'minitest/autorun'
|
11
|
+
|
12
|
+
require_relative '../lib/foodnutritionix.rb'
|
13
|
+
|
14
|
+
Dotenv.load
|
15
|
+
|
16
|
+
CASSETTES_FOLDER = 'spec/support/cassettes'
|
17
|
+
FOODS = ['pizza']
|
18
|
+
|
19
|
+
VCR.configure do |config|
|
20
|
+
config.cassette_library_dir = CASSETTES_FOLDER
|
21
|
+
config.hook_into :webmock
|
22
|
+
config.allow_http_connections_when_no_cassette = true
|
23
|
+
config.filter_sensitive_data('<X_APP_ID>') { ENV['X_APP_ID'] }
|
24
|
+
config.filter_sensitive_data('<X_APP_KEY>') { ENV['X_APP_KEY'] }
|
25
|
+
end
|
26
|
+
|
27
|
+
def cassette_name(path_to_spec, description)
|
28
|
+
spec_filename = File.basename(path_to_spec, '.*')
|
29
|
+
spec_description = description.gsub(/^test_[0-9]+_/, '')
|
30
|
+
|
31
|
+
"#{spec_filename} #{spec_description}"
|
32
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://trackapi.nutritionix.com/v2/natural/nutrients
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: query=pizza
|
9
|
+
headers:
|
10
|
+
X-App-Id:
|
11
|
+
- "<X_APP_ID>"
|
12
|
+
X-App-Key:
|
13
|
+
- "<X_APP_KEY>"
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Access-Control-Allow-Origin:
|
20
|
+
- "*"
|
21
|
+
Cache-Control:
|
22
|
+
- no-store, no-cache, must-revalidate, proxy-revalidate
|
23
|
+
Content-Type:
|
24
|
+
- application/json; charset=utf-8
|
25
|
+
Date:
|
26
|
+
- Sun, 27 Nov 2016 05:01:11 GMT
|
27
|
+
Etag:
|
28
|
+
- W/"13a7-c+n02oZDUpZ+c/UvIr2M0w"
|
29
|
+
Expires:
|
30
|
+
- '0'
|
31
|
+
Pragma:
|
32
|
+
- no-cache
|
33
|
+
Server:
|
34
|
+
- nginx/1.8.0
|
35
|
+
Status:
|
36
|
+
- 200 OK
|
37
|
+
Surrogate-Control:
|
38
|
+
- no-store
|
39
|
+
X-Powered-By:
|
40
|
+
- Phusion Passenger 5.0.16
|
41
|
+
Content-Length:
|
42
|
+
- '5031'
|
43
|
+
Connection:
|
44
|
+
- keep-alive
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: '{"foods":[{"food_name":"pizza","brand_name":null,"serving_qty":1,"serving_unit":"slice","serving_weight_grams":107,"nf_calories":284.62,"nf_total_fat":10.37,"nf_saturated_fat":4.78,"nf_cholesterol":18.19,"nf_sodium":639.86,"nf_total_carbohydrate":35.66,"nf_dietary_fiber":2.46,"nf_sugars":3.83,"nf_protein":12.19,"nf_potassium":184.04,"nf_p":231.12,"full_nutrients":[{"attr_id":255,"value":46.1919},{"attr_id":208,"value":284.62},{"attr_id":268,"value":1190.91},{"attr_id":203,"value":12.1873},{"attr_id":204,"value":10.3683},{"attr_id":207,"value":2.5787},{"attr_id":205,"value":35.6631},{"attr_id":291,"value":2.461},{"attr_id":269,"value":3.8306},{"attr_id":210,"value":0.214},{"attr_id":211,"value":0.8346},{"attr_id":212,"value":1.07},{"attr_id":213,"value":0.4494},{"attr_id":214,"value":1.1235},{"attr_id":287,"value":0.1391},{"attr_id":209,"value":28.8365},{"attr_id":301,"value":201.16},{"attr_id":303,"value":2.6536},{"attr_id":304,"value":25.68},{"attr_id":305,"value":231.12},{"attr_id":306,"value":184.04},{"attr_id":307,"value":639.86},{"attr_id":309,"value":1.4338},{"attr_id":312,"value":0.1124},{"attr_id":315,"value":0.3852},{"attr_id":317,"value":21.293},{"attr_id":401,"value":1.498},{"attr_id":404,"value":0.4173},{"attr_id":405,"value":0.2087},{"attr_id":406,"value":4.0928},{"attr_id":415,"value":0.0856},{"attr_id":417,"value":99.51},{"attr_id":431,"value":55.64},{"attr_id":432,"value":42.8},{"attr_id":435,"value":138.03},{"attr_id":421,"value":17.548},{"attr_id":454,"value":29.746},{"attr_id":418,"value":0.4494},{"attr_id":320,"value":73.83},{"attr_id":319,"value":65.27},{"attr_id":321,"value":98.44},{"attr_id":322,"value":0},{"attr_id":334,"value":0},{"attr_id":318,"value":383.06},{"attr_id":337,"value":2049.05},{"attr_id":338,"value":62.06},{"attr_id":323,"value":0.8881},{"attr_id":341,"value":0.0535},{"attr_id":342,"value":1.2733},{"attr_id":343,"value":0.3638},{"attr_id":344,"value":0.0642},{"attr_id":345,"value":0},{"attr_id":346,"value":0},{"attr_id":347,"value":0},{"attr_id":328,"value":0},{"attr_id":324,"value":0},{"attr_id":430,"value":7.169},{"attr_id":429,"value":0},{"attr_id":606,"value":4.7776},{"attr_id":607,"value":0.1081},{"attr_id":608,"value":0.0856},{"attr_id":609,"value":0.0589},{"attr_id":610,"value":0.1509},{"attr_id":611,"value":0.1873},{"attr_id":612,"value":0.6441},{"attr_id":652,"value":0.0685},{"attr_id":613,"value":2.4589},{"attr_id":653,"value":0.046},{"attr_id":614,"value":0.9181},{"attr_id":615,"value":0.0225},{"attr_id":624,"value":0.015},{"attr_id":654,"value":0.0086},{"attr_id":645,"value":2.7906},{"attr_id":625,"value":0.0514},{"attr_id":697,"value":0},{"attr_id":626,"value":0.1252},{"attr_id":673,"value":0.1006},{"attr_id":662,"value":0.0235},{"attr_id":687,"value":0.0161},{"attr_id":617,"value":2.5552},{"attr_id":674,"value":2.3829},{"attr_id":663,"value":0.1723},{"attr_id":628,"value":0.0396},{"attr_id":630,"value":0.0021},{"attr_id":676,"value":0.0021},{"attr_id":664,"value":0},{"attr_id":671,"value":0.0011},{"attr_id":646,"value":1.7987},{"attr_id":618,"value":1.5654},{"attr_id":675,"value":1.4627},{"attr_id":670,"value":0.0417},{"attr_id":619,"value":0.1894},{"attr_id":851,"value":0.1873},{"attr_id":685,"value":0.0032},{"attr_id":627,"value":0.0021},{"attr_id":672,"value":0.0032},{"attr_id":689,"value":0.0107},{"attr_id":852,"value":0},{"attr_id":853,"value":0.0096},{"attr_id":620,"value":0.0128},{"attr_id":629,"value":0.0043},{"attr_id":858,"value":0.0043},{"attr_id":631,"value":0.0043},{"attr_id":621,"value":0},{"attr_id":605,"value":0.2579},{"attr_id":693,"value":0.1958},{"attr_id":695,"value":0.061},{"attr_id":601,"value":18.19},{"attr_id":502,"value":0.4387},{"attr_id":503,"value":0.6035},{"attr_id":504,"value":1.2187},{"attr_id":505,"value":0.8239},{"attr_id":506,"value":0.2825},{"attr_id":507,"value":0.1744},{"attr_id":508,"value":0.7105},{"attr_id":509,"value":0.5585},{"attr_id":510,"value":0.7704},{"attr_id":511,"value":0.52},{"attr_id":512,"value":0.3799},{"attr_id":513,"value":0.4483},{"attr_id":514,"value":0.8977},{"attr_id":515,"value":3.7825},{"attr_id":516,"value":0.3649},{"attr_id":517,"value":1.452},{"attr_id":518,"value":0.749},{"attr_id":521,"value":0},{"attr_id":221,"value":0},{"attr_id":262,"value":0},{"attr_id":263,"value":0}],"nix_brand_name":null,"nix_brand_id":null,"nix_item_name":null,"nix_item_id":null,"upc":null,"consumed_at":"2016-11-27T05:01:11+00:00","metadata":{},"source":1,"ndb_no":21299,"tags":{"item":"pizza","measure":null,"quantity":"1.0","tag_id":1060},"alt_measures":[{"serving_weight":853,"measure":"pizza","seq":2,"qty":1},{"serving_weight":107,"measure":"slice","seq":1,"qty":1},{"serving_weight":853,"measure":"entire","seq":80,"qty":1},{"serving_weight":853,"measure":"whole","seq":81,"qty":1},{"serving_weight":107,"measure":"piece","seq":82,"qty":1}],"lat":null,"lng":null,"meal_type":5,"photo":{"thumb":"https://d2xdmhkmkbyw75.cloudfront.net/1060_thumb.jpg","highres":"https://d2xdmhkmkbyw75.cloudfront.net/1060_highres.jpg"}}],"unmatched":null,"errors":null}'
|
48
|
+
http_version:
|
49
|
+
recorded_at: Sun, 27 Nov 2016 05:01:11 GMT
|
50
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,50 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://trackapi.nutritionix.com/v2/natural/nutrients
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: query=pizza
|
9
|
+
headers:
|
10
|
+
X-App-Id:
|
11
|
+
- "<X_APP_ID>"
|
12
|
+
X-App-Key:
|
13
|
+
- "<X_APP_KEY>"
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Access-Control-Allow-Origin:
|
20
|
+
- "*"
|
21
|
+
Cache-Control:
|
22
|
+
- no-store, no-cache, must-revalidate, proxy-revalidate
|
23
|
+
Content-Type:
|
24
|
+
- application/json; charset=utf-8
|
25
|
+
Date:
|
26
|
+
- Sun, 27 Nov 2016 05:01:12 GMT
|
27
|
+
Etag:
|
28
|
+
- W/"13a7-IO9Q0qd5va+71EiD8f+UFg"
|
29
|
+
Expires:
|
30
|
+
- '0'
|
31
|
+
Pragma:
|
32
|
+
- no-cache
|
33
|
+
Server:
|
34
|
+
- nginx/1.8.0
|
35
|
+
Status:
|
36
|
+
- 200 OK
|
37
|
+
Surrogate-Control:
|
38
|
+
- no-store
|
39
|
+
X-Powered-By:
|
40
|
+
- Phusion Passenger 5.0.16
|
41
|
+
Content-Length:
|
42
|
+
- '5031'
|
43
|
+
Connection:
|
44
|
+
- keep-alive
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: '{"foods":[{"food_name":"pizza","brand_name":null,"serving_qty":1,"serving_unit":"slice","serving_weight_grams":107,"nf_calories":284.62,"nf_total_fat":10.37,"nf_saturated_fat":4.78,"nf_cholesterol":18.19,"nf_sodium":639.86,"nf_total_carbohydrate":35.66,"nf_dietary_fiber":2.46,"nf_sugars":3.83,"nf_protein":12.19,"nf_potassium":184.04,"nf_p":231.12,"full_nutrients":[{"attr_id":255,"value":46.1919},{"attr_id":208,"value":284.62},{"attr_id":268,"value":1190.91},{"attr_id":203,"value":12.1873},{"attr_id":204,"value":10.3683},{"attr_id":207,"value":2.5787},{"attr_id":205,"value":35.6631},{"attr_id":291,"value":2.461},{"attr_id":269,"value":3.8306},{"attr_id":210,"value":0.214},{"attr_id":211,"value":0.8346},{"attr_id":212,"value":1.07},{"attr_id":213,"value":0.4494},{"attr_id":214,"value":1.1235},{"attr_id":287,"value":0.1391},{"attr_id":209,"value":28.8365},{"attr_id":301,"value":201.16},{"attr_id":303,"value":2.6536},{"attr_id":304,"value":25.68},{"attr_id":305,"value":231.12},{"attr_id":306,"value":184.04},{"attr_id":307,"value":639.86},{"attr_id":309,"value":1.4338},{"attr_id":312,"value":0.1124},{"attr_id":315,"value":0.3852},{"attr_id":317,"value":21.293},{"attr_id":401,"value":1.498},{"attr_id":404,"value":0.4173},{"attr_id":405,"value":0.2087},{"attr_id":406,"value":4.0928},{"attr_id":415,"value":0.0856},{"attr_id":417,"value":99.51},{"attr_id":431,"value":55.64},{"attr_id":432,"value":42.8},{"attr_id":435,"value":138.03},{"attr_id":421,"value":17.548},{"attr_id":454,"value":29.746},{"attr_id":418,"value":0.4494},{"attr_id":320,"value":73.83},{"attr_id":319,"value":65.27},{"attr_id":321,"value":98.44},{"attr_id":322,"value":0},{"attr_id":334,"value":0},{"attr_id":318,"value":383.06},{"attr_id":337,"value":2049.05},{"attr_id":338,"value":62.06},{"attr_id":323,"value":0.8881},{"attr_id":341,"value":0.0535},{"attr_id":342,"value":1.2733},{"attr_id":343,"value":0.3638},{"attr_id":344,"value":0.0642},{"attr_id":345,"value":0},{"attr_id":346,"value":0},{"attr_id":347,"value":0},{"attr_id":328,"value":0},{"attr_id":324,"value":0},{"attr_id":430,"value":7.169},{"attr_id":429,"value":0},{"attr_id":606,"value":4.7776},{"attr_id":607,"value":0.1081},{"attr_id":608,"value":0.0856},{"attr_id":609,"value":0.0589},{"attr_id":610,"value":0.1509},{"attr_id":611,"value":0.1873},{"attr_id":612,"value":0.6441},{"attr_id":652,"value":0.0685},{"attr_id":613,"value":2.4589},{"attr_id":653,"value":0.046},{"attr_id":614,"value":0.9181},{"attr_id":615,"value":0.0225},{"attr_id":624,"value":0.015},{"attr_id":654,"value":0.0086},{"attr_id":645,"value":2.7906},{"attr_id":625,"value":0.0514},{"attr_id":697,"value":0},{"attr_id":626,"value":0.1252},{"attr_id":673,"value":0.1006},{"attr_id":662,"value":0.0235},{"attr_id":687,"value":0.0161},{"attr_id":617,"value":2.5552},{"attr_id":674,"value":2.3829},{"attr_id":663,"value":0.1723},{"attr_id":628,"value":0.0396},{"attr_id":630,"value":0.0021},{"attr_id":676,"value":0.0021},{"attr_id":664,"value":0},{"attr_id":671,"value":0.0011},{"attr_id":646,"value":1.7987},{"attr_id":618,"value":1.5654},{"attr_id":675,"value":1.4627},{"attr_id":670,"value":0.0417},{"attr_id":619,"value":0.1894},{"attr_id":851,"value":0.1873},{"attr_id":685,"value":0.0032},{"attr_id":627,"value":0.0021},{"attr_id":672,"value":0.0032},{"attr_id":689,"value":0.0107},{"attr_id":852,"value":0},{"attr_id":853,"value":0.0096},{"attr_id":620,"value":0.0128},{"attr_id":629,"value":0.0043},{"attr_id":858,"value":0.0043},{"attr_id":631,"value":0.0043},{"attr_id":621,"value":0},{"attr_id":605,"value":0.2579},{"attr_id":693,"value":0.1958},{"attr_id":695,"value":0.061},{"attr_id":601,"value":18.19},{"attr_id":502,"value":0.4387},{"attr_id":503,"value":0.6035},{"attr_id":504,"value":1.2187},{"attr_id":505,"value":0.8239},{"attr_id":506,"value":0.2825},{"attr_id":507,"value":0.1744},{"attr_id":508,"value":0.7105},{"attr_id":509,"value":0.5585},{"attr_id":510,"value":0.7704},{"attr_id":511,"value":0.52},{"attr_id":512,"value":0.3799},{"attr_id":513,"value":0.4483},{"attr_id":514,"value":0.8977},{"attr_id":515,"value":3.7825},{"attr_id":516,"value":0.3649},{"attr_id":517,"value":1.452},{"attr_id":518,"value":0.749},{"attr_id":521,"value":0},{"attr_id":221,"value":0},{"attr_id":262,"value":0},{"attr_id":263,"value":0}],"nix_brand_name":null,"nix_brand_id":null,"nix_item_name":null,"nix_item_id":null,"upc":null,"consumed_at":"2016-11-27T05:01:12+00:00","metadata":{},"source":1,"ndb_no":21299,"tags":{"item":"pizza","measure":null,"quantity":"1.0","tag_id":1060},"alt_measures":[{"serving_weight":853,"measure":"pizza","seq":2,"qty":1},{"serving_weight":107,"measure":"slice","seq":1,"qty":1},{"serving_weight":853,"measure":"entire","seq":80,"qty":1},{"serving_weight":853,"measure":"whole","seq":81,"qty":1},{"serving_weight":107,"measure":"piece","seq":82,"qty":1}],"lat":null,"lng":null,"meal_type":5,"photo":{"thumb":"https://d2xdmhkmkbyw75.cloudfront.net/1060_thumb.jpg","highres":"https://d2xdmhkmkbyw75.cloudfront.net/1060_highres.jpg"}}],"unmatched":null,"errors":null}'
|
48
|
+
http_version:
|
49
|
+
recorded_at: Sun, 27 Nov 2016 05:01:12 GMT
|
50
|
+
recorded_with: VCR 3.0.3
|
data/spec/test.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'vcr'
|
2
|
+
require 'yaml'
|
3
|
+
require 'dotenv'
|
4
|
+
require 'webmock'
|
5
|
+
require 'minitest/rg'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
|
8
|
+
require_relative '../lib/foodnutritionix.rb'
|
9
|
+
|
10
|
+
Dotenv.load
|
11
|
+
|
12
|
+
puts FoodNutritionix::FoodNutrixClient.search_foods
|
13
|
+
puts ENV['x_app_id']
|
14
|
+
puts ENV['x_app_key']
|
metadata
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foodnutritionix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Leo Lee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.14'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dotenv
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-rg
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '11.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '11.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.1'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.1'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.12'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.12'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: flog
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '4.4'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '4.4'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: flay
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '2.8'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '2.8'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0.42'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0.42'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: httparty
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.14'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0.14'
|
181
|
+
description: Get name, search time, unit, qty, weight, nutrients, calories, photo
|
182
|
+
email:
|
183
|
+
- leo.li@iss.nthu.edu.tw
|
184
|
+
executables: []
|
185
|
+
extensions: []
|
186
|
+
extra_rdoc_files: []
|
187
|
+
files:
|
188
|
+
- ".gitignore"
|
189
|
+
- Gemfile
|
190
|
+
- Gemfile.lock
|
191
|
+
- LICENSE.md
|
192
|
+
- README.md
|
193
|
+
- Rakefile
|
194
|
+
- config/credentials.yml.example
|
195
|
+
- foodnutritionix.gemspec
|
196
|
+
- lib/foodnutritionix.rb
|
197
|
+
- lib/foodnutritionix/food.rb
|
198
|
+
- lib/foodnutritionix/foodnutrix_api.rb
|
199
|
+
- lib/foodnutritionix/version.rb
|
200
|
+
- spec/foodnutritionix/food_spec.rb
|
201
|
+
- spec/foodnutritionix/foodnutrix_api_spec.rb
|
202
|
+
- spec/spec_helper.rb
|
203
|
+
- spec/support/cassettes/food_spec_should_return_Foods_that_contain_specific_tags.yml
|
204
|
+
- spec/support/cassettes/foodnutrix_api_spec_should_return_foods_information_that_contain_specific_tags.yml
|
205
|
+
- spec/test.rb
|
206
|
+
homepage: https://github.com/NoBetterThan97/FoodNutritionix
|
207
|
+
licenses:
|
208
|
+
- MIT
|
209
|
+
metadata: {}
|
210
|
+
post_install_message:
|
211
|
+
rdoc_options: []
|
212
|
+
require_paths:
|
213
|
+
- lib
|
214
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
215
|
+
requirements:
|
216
|
+
- - ">="
|
217
|
+
- !ruby/object:Gem::Version
|
218
|
+
version: '0'
|
219
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
220
|
+
requirements:
|
221
|
+
- - ">="
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
version: '0'
|
224
|
+
requirements: []
|
225
|
+
rubyforge_project:
|
226
|
+
rubygems_version: 2.5.1
|
227
|
+
signing_key:
|
228
|
+
specification_version: 4
|
229
|
+
summary: Get foods nutrients by search it name
|
230
|
+
test_files:
|
231
|
+
- spec/foodnutritionix/food_spec.rb
|
232
|
+
- spec/foodnutritionix/foodnutrix_api_spec.rb
|
233
|
+
- spec/spec_helper.rb
|
234
|
+
- spec/support/cassettes/food_spec_should_return_Foods_that_contain_specific_tags.yml
|
235
|
+
- spec/support/cassettes/foodnutrix_api_spec_should_return_foods_information_that_contain_specific_tags.yml
|
236
|
+
- spec/test.rb
|