openfoodfacts 0.6.2 → 0.10.0
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.
- checksums.yaml +4 -4
- data/README.md +24 -3
- data/Rakefile +7 -5
- data/lib/openfoodfacts/additive.rb +9 -13
- data/lib/openfoodfacts/allergen.rb +4 -6
- data/lib/openfoodfacts/brand.rb +5 -7
- data/lib/openfoodfacts/category.rb +4 -6
- data/lib/openfoodfacts/city.rb +4 -6
- data/lib/openfoodfacts/contributor.rb +4 -6
- data/lib/openfoodfacts/country.rb +4 -6
- data/lib/openfoodfacts/entry_date.rb +5 -7
- data/lib/openfoodfacts/faq.rb +11 -16
- data/lib/openfoodfacts/ingredient.rb +31 -0
- data/lib/openfoodfacts/ingredient_that_may_be_from_palm_oil.rb +4 -6
- data/lib/openfoodfacts/label.rb +4 -6
- data/lib/openfoodfacts/language.rb +5 -7
- data/lib/openfoodfacts/last_edit_date.rb +5 -7
- data/lib/openfoodfacts/locale.rb +12 -14
- data/lib/openfoodfacts/manufacturing_place.rb +4 -6
- data/lib/openfoodfacts/mission.rb +20 -21
- data/lib/openfoodfacts/number_of_ingredients.rb +5 -7
- data/lib/openfoodfacts/nutrition_grade.rb +5 -7
- data/lib/openfoodfacts/origin.rb +4 -6
- data/lib/openfoodfacts/packager_code.rb +4 -6
- data/lib/openfoodfacts/packaging.rb +4 -6
- data/lib/openfoodfacts/period_after_opening.rb +31 -0
- data/lib/openfoodfacts/press.rb +16 -13
- data/lib/openfoodfacts/product.rb +132 -67
- data/lib/openfoodfacts/product_state.rb +5 -7
- data/lib/openfoodfacts/purchase_place.rb +4 -6
- data/lib/openfoodfacts/store.rb +4 -6
- data/lib/openfoodfacts/trace.rb +4 -6
- data/lib/openfoodfacts/user.rb +16 -15
- data/lib/openfoodfacts/version.rb +1 -1
- data/lib/openfoodfacts.rb +11 -2
- metadata +17 -18
- data/test/minitest_helper.rb +0 -18
- data/test/test_openfoodfacts.rb +0 -329
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc63c1f6cd6ee0102081119b885d7e9e14e2c7fb6b0cfc5a489f6930d564e693
|
4
|
+
data.tar.gz: 8f26b4e82235da0859d0d5c91832d72db1685364ac4534699d24ecd933fbad6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50d60b0512a1b70650e58a35a72efb4a7710478e051c02ea3293eee537a0bc61c6d82436fb414896707b19fe5f1f2ce8bfbea5c24951386449e723819a09c9bf
|
7
|
+
data.tar.gz: 04f97cf59df1b84d1105da46d155ff483c90a52fb93ca1e8ae09b117ed223a215edd5a36eddea2a24a63336822f1a4ba6818e7cd9a133d61eec5f60961a47ce1
|
data/README.md
CHANGED
@@ -1,11 +1,20 @@
|
|
1
|
-
# Open Food Facts
|
1
|
+
# Open Food Facts Ruby SDK
|
2
|
+
|
3
|
+
<picture>
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://static.openfoodfacts.org/images/logos/off-logo-horizontal-dark.png?refresh_github_cache=1">
|
5
|
+
<source media="(prefers-color-scheme: light)" srcset="https://static.openfoodfacts.org/images/logos/off-logo-horizontal-light.png?refresh_github_cache=1">
|
6
|
+
<img height="48" src="https://static.openfoodfacts.org/images/logos/off-logo-horizontal-light.svg"/>
|
7
|
+
</picture>
|
2
8
|
|
3
9
|
[](https://badge.fury.io/rb/openfoodfacts)
|
4
10
|
[](https://github.com/openfoodfacts/openfoodfacts-ruby/actions/workflows/ruby.yml)
|
5
11
|
[](https://github.com/openfoodfacts/openfoodfacts-ruby/actions/workflows/rubocop-analysis.yml)
|
6
12
|
[](https://inch-ci.org/github/openfoodfacts/openfoodfacts-ruby)
|
7
13
|
|
8
|
-
API Wrapper for [Open Food Facts](https://openfoodfacts.org/), the open database about food.
|
14
|
+
- API Wrapper for [Open Food Facts](https://openfoodfacts.org/), the open database about food.
|
15
|
+
- We [have a similar package for cosmetics](https://github.com/openfoodfacts/openbeautyfacts-ruby).
|
16
|
+
- Note: This package needs updates for the newest APIs.
|
17
|
+
- Please see on the wiki [how to join the community to help with the Ruby package](https://wiki.openfoodfacts.org/API/Ruby)
|
9
18
|
|
10
19
|
## Installation
|
11
20
|
|
@@ -104,7 +113,7 @@ Openfoodfacts::Locale.all
|
|
104
113
|
|
105
114
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
106
115
|
|
107
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and
|
116
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `lib/openfoodfacts/version.rb`, and push to the main branch. Releases are automated via GitHub Actions using Trusted Publishers for secure publishing to [rubygems.org](https://rubygems.org).
|
108
117
|
|
109
118
|
## Contributing
|
110
119
|
|
@@ -113,3 +122,15 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
113
122
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
114
123
|
4. Push to the branch (`git push origin my-new-feature`)
|
115
124
|
5. Create a new Pull Request
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
### Third party applications
|
129
|
+
|
130
|
+
* Feel [free to open a PR to add your application in this list](https://github.com/openfoodfacts/openfoodfacts-ruby/edit/main/REUSERS.md).
|
131
|
+
* Please get in touch at reuse@openfoodfacts.org
|
132
|
+
* We are very interested in learning what the Open Food Facts data is used for. It is not mandatory, but we would very much appreciate it if you tell us about your re-uses (https://forms.gle/hwaeqBfs8ywwhbTg8) so that we can share them with the Open Food Facts community. You can also fill this form to get a chance to get your app featured: https://forms.gle/hwaeqBfs8ywwhbTg8
|
133
|
+
* Make sure you comply with the OdBL licence, mentioning the Source of your data, and ensuring to avoid combining non free data you can't release legally as open data. Another requirement is contributing back any product you add using this SDK.
|
134
|
+
|
135
|
+
## Authors
|
136
|
+
|
data/Rakefile
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
2
4
|
require 'rake/testtask'
|
3
|
-
|
5
|
+
|
4
6
|
Rake::TestTask.new do |task|
|
5
|
-
task.libs <<
|
6
|
-
task.libs <<
|
7
|
-
task.pattern =
|
7
|
+
task.libs << 'lib'
|
8
|
+
task.libs << 'test'
|
9
|
+
task.pattern = 'test/test_*.rb'
|
8
10
|
end
|
9
11
|
|
10
12
|
task default: :test
|
@@ -16,4 +18,4 @@ task :console do
|
|
16
18
|
require File.join(__FILE__, '../lib/openfoodfacts')
|
17
19
|
ARGV.clear
|
18
20
|
IRB.start
|
19
|
-
end
|
21
|
+
end
|
@@ -1,44 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hashie'
|
2
4
|
|
3
5
|
module Openfoodfacts
|
4
6
|
class Additive < Hashie::Mash
|
5
|
-
|
6
7
|
# TODO: Add more locales
|
7
8
|
LOCALE_PATHS = {
|
8
9
|
'fr' => 'additifs',
|
9
10
|
'uk' => 'additives',
|
10
11
|
'us' => 'additives',
|
11
12
|
'world' => 'additives'
|
12
|
-
}
|
13
|
+
}.freeze
|
13
14
|
|
14
15
|
class << self
|
15
|
-
|
16
16
|
# Get additives
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
|
-
if path = LOCALE_PATHS[locale]
|
20
|
-
page_url = "https://#{locale}.#{domain}/#{path}"
|
19
|
+
if (path = LOCALE_PATHS[locale])
|
20
|
+
page_url = "https://#{locale}.#{domain}/facets/#{path}"
|
21
21
|
|
22
22
|
Product.tags_from_page(self, page_url) do |tag|
|
23
23
|
columns = tag.css('td')
|
24
24
|
|
25
25
|
link = tag.css('a').first
|
26
26
|
attributes = {
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
'name' => link.text.strip,
|
28
|
+
'url' => URI.join(page_url, link.attr('href')).to_s,
|
29
|
+
'products_count' => columns[1].text.to_i
|
30
30
|
}
|
31
31
|
|
32
32
|
riskiness = columns.last.attr('class')
|
33
|
-
if riskiness
|
34
|
-
attributes["riskiness"] = riskiness[/level_(\d+)/, 1].to_i
|
35
|
-
end
|
33
|
+
attributes['riskiness'] = riskiness[/level_(\d+)/, 1].to_i if riskiness
|
36
34
|
|
37
35
|
new(attributes)
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
41
|
-
|
42
39
|
end
|
43
40
|
|
44
41
|
# Get products with additive
|
@@ -46,6 +43,5 @@ module Openfoodfacts
|
|
46
43
|
def products(page: -1)
|
47
44
|
Product.from_website_page(url, page: page, products_count: products_count) if url
|
48
45
|
end
|
49
|
-
|
50
46
|
end
|
51
47
|
end
|
@@ -1,26 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hashie'
|
2
4
|
|
3
5
|
module Openfoodfacts
|
4
6
|
class Allergen < Hashie::Mash
|
5
|
-
|
6
7
|
# TODO: Add more locales
|
7
8
|
LOCALE_PATHS = {
|
8
9
|
'fr' => 'allergenes',
|
9
10
|
'uk' => 'allergens',
|
10
11
|
'us' => 'allergens',
|
11
12
|
'world' => 'allergens'
|
12
|
-
}
|
13
|
+
}.freeze
|
13
14
|
|
14
15
|
class << self
|
15
|
-
|
16
16
|
# Get allergens
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
|
-
if path = LOCALE_PATHS[locale]
|
19
|
+
if (path = LOCALE_PATHS[locale])
|
20
20
|
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
25
24
|
|
26
25
|
# Get products with allergen
|
@@ -28,6 +27,5 @@ module Openfoodfacts
|
|
28
27
|
def products(page: -1)
|
29
28
|
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
33
31
|
end
|
data/lib/openfoodfacts/brand.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hashie'
|
2
4
|
|
3
5
|
module Openfoodfacts
|
4
6
|
class Brand < Hashie::Mash
|
5
|
-
|
6
7
|
# TODO: Add more locales
|
7
8
|
LOCALE_PATHS = {
|
8
9
|
'fr' => 'marques',
|
9
10
|
'uk' => 'brands',
|
10
11
|
'us' => 'brands',
|
11
12
|
'world' => 'brands'
|
12
|
-
}
|
13
|
+
}.freeze
|
13
14
|
|
14
15
|
class << self
|
15
|
-
|
16
16
|
# Get product brands
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
|
-
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
19
|
+
if (path = LOCALE_PATHS[locale])
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/facets/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
25
24
|
|
26
25
|
# Get products with brand
|
@@ -28,6 +27,5 @@ module Openfoodfacts
|
|
28
27
|
def products(page: -1)
|
29
28
|
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
33
31
|
end
|
@@ -1,26 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hashie'
|
2
4
|
|
3
5
|
module Openfoodfacts
|
4
6
|
class Category < Hashie::Mash
|
5
|
-
|
6
7
|
# TODO: Add more locales
|
7
8
|
LOCALE_PATHS = {
|
8
9
|
'fr' => 'categories',
|
9
10
|
'uk' => 'categories',
|
10
11
|
'us' => 'categories',
|
11
12
|
'world' => 'categories'
|
12
|
-
}
|
13
|
+
}.freeze
|
13
14
|
|
14
15
|
class << self
|
15
|
-
|
16
16
|
# Get categories
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
|
-
if path = LOCALE_PATHS[locale]
|
19
|
+
if (path = LOCALE_PATHS[locale])
|
20
20
|
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
25
24
|
|
26
25
|
# Get products with category
|
@@ -28,6 +27,5 @@ module Openfoodfacts
|
|
28
27
|
def products(page: -1)
|
29
28
|
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
33
31
|
end
|
data/lib/openfoodfacts/city.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hashie'
|
2
4
|
|
3
5
|
module Openfoodfacts
|
4
6
|
class City < Hashie::Mash
|
5
|
-
|
6
7
|
# TODO: Add more locales
|
7
8
|
LOCALE_PATHS = {
|
8
9
|
'fr' => 'communes',
|
9
10
|
'uk' => 'cities',
|
10
11
|
'us' => 'cities',
|
11
12
|
'world' => 'cities'
|
12
|
-
}
|
13
|
+
}.freeze
|
13
14
|
|
14
15
|
class << self
|
15
|
-
|
16
16
|
# Get cities
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
|
-
if path = LOCALE_PATHS[locale]
|
19
|
+
if (path = LOCALE_PATHS[locale])
|
20
20
|
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
25
24
|
|
26
25
|
# Get products with city
|
@@ -28,6 +27,5 @@ module Openfoodfacts
|
|
28
27
|
def products(page: -1)
|
29
28
|
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
33
31
|
end
|
@@ -1,26 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hashie'
|
2
4
|
|
3
5
|
module Openfoodfacts
|
4
6
|
class Contributor < Hashie::Mash
|
5
|
-
|
6
7
|
# TODO: Add more locales
|
7
8
|
LOCALE_PATHS = {
|
8
9
|
'fr' => 'contributeurs',
|
9
10
|
'uk' => 'contributors',
|
10
11
|
'us' => 'contributors',
|
11
12
|
'world' => 'contributors'
|
12
|
-
}
|
13
|
+
}.freeze
|
13
14
|
|
14
15
|
class << self
|
15
|
-
|
16
16
|
# Get contributors
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
|
-
if path = LOCALE_PATHS[locale]
|
19
|
+
if (path = LOCALE_PATHS[locale])
|
20
20
|
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
25
24
|
|
26
25
|
# Get products for contributor
|
@@ -28,6 +27,5 @@ module Openfoodfacts
|
|
28
27
|
def products(page: -1)
|
29
28
|
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
33
31
|
end
|
@@ -1,26 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hashie'
|
2
4
|
|
3
5
|
module Openfoodfacts
|
4
6
|
class Country < Hashie::Mash
|
5
|
-
|
6
7
|
# TODO: Add more locales
|
7
8
|
LOCALE_PATHS = {
|
8
9
|
'fr' => 'pays',
|
9
10
|
'uk' => 'countries',
|
10
11
|
'us' => 'countries',
|
11
12
|
'world' => 'countries'
|
12
|
-
}
|
13
|
+
}.freeze
|
13
14
|
|
14
15
|
class << self
|
15
|
-
|
16
16
|
# Get countries
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
|
-
if path = LOCALE_PATHS[locale]
|
19
|
+
if (path = LOCALE_PATHS[locale])
|
20
20
|
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
25
24
|
|
26
25
|
# Get products with country
|
@@ -28,6 +27,5 @@ module Openfoodfacts
|
|
28
27
|
def products(page: -1)
|
29
28
|
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
33
31
|
end
|
@@ -1,26 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hashie'
|
2
4
|
|
3
5
|
module Openfoodfacts
|
4
6
|
class EntryDate < Hashie::Mash
|
5
|
-
|
6
7
|
# TODO: Add more locales
|
7
8
|
LOCALE_PATHS = {
|
8
9
|
'fr' => 'dates-d-ajout',
|
9
10
|
'uk' => 'entry-dates',
|
10
11
|
'us' => 'entry-dates',
|
11
12
|
'world' => 'entry-dates'
|
12
|
-
}
|
13
|
+
}.freeze
|
13
14
|
|
14
15
|
class << self
|
15
|
-
|
16
16
|
# Get entry dates
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
|
-
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
19
|
+
if (path = LOCALE_PATHS[locale])
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/facets/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
25
24
|
|
26
25
|
# Get products with entry date
|
@@ -28,6 +27,5 @@ module Openfoodfacts
|
|
28
27
|
def products(page: -1)
|
29
28
|
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
33
31
|
end
|
data/lib/openfoodfacts/faq.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hashie'
|
2
4
|
require 'nokogiri'
|
3
|
-
require 'open-uri'
|
4
5
|
|
5
6
|
module Openfoodfacts
|
6
7
|
class Faq < Hashie::Mash
|
7
|
-
|
8
8
|
# TODO: Add more locales
|
9
9
|
LOCALE_PATHS = {
|
10
10
|
'fr' => 'questions-frequentes',
|
11
11
|
'uk' => 'faq',
|
12
12
|
'us' => 'faq',
|
13
13
|
'world' => 'faq'
|
14
|
-
}
|
14
|
+
}.freeze
|
15
15
|
|
16
16
|
class << self
|
17
17
|
def items(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
18
|
-
if path = LOCALE_PATHS[locale]
|
19
|
-
html =
|
18
|
+
if (path = LOCALE_PATHS[locale])
|
19
|
+
html = Openfoodfacts.http_get("https://#{locale}.#{domain}/#{path}").read
|
20
20
|
dom = Nokogiri::HTML.fragment(html)
|
21
21
|
|
22
22
|
titles = dom.css('#main_column h2')
|
@@ -25,26 +25,21 @@ module Openfoodfacts
|
|
25
25
|
|
26
26
|
element = item.next_sibling
|
27
27
|
while !element.nil? && element.node_name != 'h2'
|
28
|
-
if element.node_name == 'p'
|
29
|
-
paragraphs.push(element)
|
30
|
-
end
|
28
|
+
paragraphs.push(element) if element.node_name == 'p'
|
31
29
|
|
32
30
|
element = element.next_sibling
|
33
31
|
end
|
34
32
|
|
35
|
-
if index == titles.length - 1
|
36
|
-
paragraphs = paragraphs[0..-3]
|
37
|
-
end
|
33
|
+
paragraphs = paragraphs[0..-3] if index == titles.length - 1
|
38
34
|
|
39
35
|
new({
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
'question' => item.text.strip,
|
37
|
+
'answer' => paragraphs.map { |paragraph| paragraph.text.strip.gsub(/\r?\n/, ' ') }.join("\n\n"),
|
38
|
+
'answer_html' => paragraphs.map(&:to_html).join
|
39
|
+
})
|
44
40
|
end
|
45
41
|
end
|
46
42
|
end
|
47
43
|
end
|
48
|
-
|
49
44
|
end
|
50
45
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hashie'
|
4
|
+
|
5
|
+
module Openfoodfacts
|
6
|
+
class Ingredient < Hashie::Mash
|
7
|
+
# TODO: Add more locales
|
8
|
+
LOCALE_PATHS = {
|
9
|
+
'fr' => 'ingredients',
|
10
|
+
'uk' => 'ingredients',
|
11
|
+
'us' => 'ingredients',
|
12
|
+
'world' => 'ingredients'
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
class << self
|
16
|
+
# Get labels
|
17
|
+
#
|
18
|
+
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
|
+
if (path = LOCALE_PATHS[locale])
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Get products with label
|
26
|
+
#
|
27
|
+
def products(page: -1)
|
28
|
+
Product.from_website_page(url, page: page, products_count: products_count) if url
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,26 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hashie'
|
2
4
|
|
3
5
|
module Openfoodfacts
|
4
6
|
class IngredientThatMayBeFromPalmOil < Hashie::Mash
|
5
|
-
|
6
7
|
# TODO: Add more locales
|
7
8
|
LOCALE_PATHS = {
|
8
9
|
'fr' => 'ingredients-pouvant-etre-issus-de-l-huile-de-palme',
|
9
10
|
'uk' => 'ingredients-that-may-be-from-palm-oil',
|
10
11
|
'us' => 'ingredients-that-may-be-from-palm-oil',
|
11
12
|
'world' => 'ingredients-that-may-be-from-palm-oil'
|
12
|
-
}
|
13
|
+
}.freeze
|
13
14
|
|
14
15
|
class << self
|
15
|
-
|
16
16
|
# Get ingredients that may be from palm oil
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
|
-
if path = LOCALE_PATHS[locale]
|
19
|
+
if (path = LOCALE_PATHS[locale])
|
20
20
|
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
25
24
|
|
26
25
|
# Get products with ingredient that may be from palm oil
|
@@ -28,6 +27,5 @@ module Openfoodfacts
|
|
28
27
|
def products(page: -1)
|
29
28
|
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
33
31
|
end
|
data/lib/openfoodfacts/label.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hashie'
|
2
4
|
|
3
5
|
module Openfoodfacts
|
4
6
|
class Label < Hashie::Mash
|
5
|
-
|
6
7
|
# TODO: Add more locales
|
7
8
|
LOCALE_PATHS = {
|
8
9
|
'fr' => 'labels',
|
9
10
|
'uk' => 'labels',
|
10
11
|
'us' => 'labels',
|
11
12
|
'world' => 'labels'
|
12
|
-
}
|
13
|
+
}.freeze
|
13
14
|
|
14
15
|
class << self
|
15
|
-
|
16
16
|
# Get labels
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
|
-
if path = LOCALE_PATHS[locale]
|
19
|
+
if (path = LOCALE_PATHS[locale])
|
20
20
|
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
25
24
|
|
26
25
|
# Get products with label
|
@@ -28,6 +27,5 @@ module Openfoodfacts
|
|
28
27
|
def products(page: -1)
|
29
28
|
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
33
31
|
end
|
@@ -1,26 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hashie'
|
2
4
|
|
3
5
|
module Openfoodfacts
|
4
6
|
class Language < Hashie::Mash
|
5
|
-
|
6
7
|
# TODO: Add more locales
|
7
8
|
LOCALE_PATHS = {
|
8
9
|
'fr' => 'langues',
|
9
10
|
'uk' => 'languages',
|
10
11
|
'us' => 'languages',
|
11
12
|
'world' => 'languages'
|
12
|
-
}
|
13
|
+
}.freeze
|
13
14
|
|
14
15
|
class << self
|
15
|
-
|
16
16
|
# Get languages
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
|
-
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
19
|
+
if (path = LOCALE_PATHS[locale])
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/facets/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
25
24
|
|
26
25
|
# Get products with language
|
@@ -28,6 +27,5 @@ module Openfoodfacts
|
|
28
27
|
def products(page: -1)
|
29
28
|
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
33
31
|
end
|
@@ -1,26 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hashie'
|
2
4
|
|
3
5
|
module Openfoodfacts
|
4
6
|
class LastEditDate < Hashie::Mash
|
5
|
-
|
6
7
|
# TODO: Add more locales
|
7
8
|
LOCALE_PATHS = {
|
8
9
|
'fr' => 'dates-de-derniere-modification',
|
9
10
|
'uk' => 'last-edit-dates',
|
10
11
|
'us' => 'last-edit-dates',
|
11
12
|
'world' => 'last-edit-dates'
|
12
|
-
}
|
13
|
+
}.freeze
|
13
14
|
|
14
15
|
class << self
|
15
|
-
|
16
16
|
# Get last edit dates
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
|
-
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
19
|
+
if (path = LOCALE_PATHS[locale])
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/facets/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
25
24
|
|
26
25
|
# Get products with last edit date
|
@@ -28,6 +27,5 @@ module Openfoodfacts
|
|
28
27
|
def products(page: -1)
|
29
28
|
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
33
31
|
end
|