openbeautyfacts 0.1.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +15 -9
- data/lib/openbeautyfacts.rb +6 -0
- data/lib/openbeautyfacts/additive.rb +1 -1
- data/lib/openbeautyfacts/allergen.rb +1 -1
- data/lib/openbeautyfacts/brand.rb +1 -1
- data/lib/openbeautyfacts/category.rb +1 -1
- data/lib/openbeautyfacts/city.rb +1 -1
- data/lib/openbeautyfacts/contributor.rb +1 -1
- data/lib/openbeautyfacts/country.rb +1 -1
- data/lib/openbeautyfacts/entry_date.rb +33 -0
- data/lib/openbeautyfacts/faq.rb +1 -1
- data/lib/openbeautyfacts/ingredient.rb +33 -0
- data/lib/openbeautyfacts/ingredient_that_may_be_from_palm_oil.rb +1 -1
- data/lib/openbeautyfacts/label.rb +1 -1
- data/lib/openbeautyfacts/last_edit_date.rb +33 -0
- data/lib/openbeautyfacts/locale.rb +20 -6
- data/lib/openbeautyfacts/manufacturing_place.rb +1 -1
- data/lib/openbeautyfacts/mission.rb +72 -0
- data/lib/openbeautyfacts/number_of_ingredients.rb +33 -0
- data/lib/openbeautyfacts/origin.rb +1 -1
- data/lib/openbeautyfacts/packager_code.rb +1 -1
- data/lib/openbeautyfacts/packaging.rb +1 -1
- data/lib/openbeautyfacts/period_after_opening.rb +33 -0
- data/lib/openbeautyfacts/press.rb +1 -1
- data/lib/openbeautyfacts/product.rb +12 -11
- data/lib/openbeautyfacts/product_state.rb +1 -1
- data/lib/openbeautyfacts/purchase_place.rb +1 -1
- data/lib/openbeautyfacts/store.rb +1 -1
- data/lib/openbeautyfacts/trace.rb +1 -1
- data/lib/openbeautyfacts/user.rb +1 -2
- data/lib/openbeautyfacts/version.rb +1 -1
- data/test/minitest_helper.rb +6 -0
- data/test/test_openbeautyfacts.rb +155 -17
- metadata +35 -41
- data/test/fixtures/additives.yml +0 -1422
- data/test/fixtures/additives_locale.yml +0 -1422
- data/test/fixtures/brands.yml +0 -2144
- data/test/fixtures/brands_locale.yml +0 -2024
- data/test/fixtures/faq.yml +0 -1031
- data/test/fixtures/fetch_product_3600550362626.yml +0 -104
- data/test/fixtures/index.yml +0 -169
- data/test/fixtures/login_user.yml +0 -40
- data/test/fixtures/press.yml +0 -986
- data/test/fixtures/product_3600550362626.yml +0 -104
- data/test/fixtures/product_states.yml +0 -936
- data/test/fixtures/product_states_locale.yml +0 -976
- data/test/fixtures/products_for_brand.yml +0 -1707
- data/test/fixtures/products_for_state.yml +0 -2260
- data/test/fixtures/products_with_additive.yml +0 -1723
- data/test/fixtures/search_doux.yml +0 -538
- data/test/fixtures/search_doux_1_000_000.yml +0 -257
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cc506aa648b094eb8218c5cc4408c2cefde133e60677e1fd97a1c8f8e92a33c8
|
4
|
+
data.tar.gz: 61c3e27a3a945ce47c6e71a0c727ddfda9eb818206118f8f1529725d2064cec8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c8f56653b09b9d5fd46eef55c420e2fc8817afba5fce876ae72db5058b2d18efd24600f8f75189c2f2e06662335ac70fb91ca3edc1b96a9df3a83a92df9067c
|
7
|
+
data.tar.gz: 49796fc369ac2a22dfeb61e54174aa763563f80591ed2ce24857c84f3bf157ffb248bdd45b191e5705b39c7b5c87325446611437663d7ba324f2f10fafcf75c8
|
data/README.md
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
# Open Beauty Facts
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/openbeautyfacts.svg)](
|
4
|
-
[![Build Status](https://travis-ci.org/
|
5
|
-
[![
|
6
|
-
[![
|
7
|
-
[![
|
8
|
-
[![
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/openbeautyfacts.svg)](https://badge.fury.io/rb/openbeautyfacts)
|
4
|
+
[![Build Status](https://travis-ci.org/openfoodfacts/openbeautyfacts-ruby.svg?branch=master)](https://travis-ci.org/openfoodfacts/openbeautyfacts-ruby)
|
5
|
+
[![Build status](https://ci.appveyor.com/api/projects/status/n3t47kwl6hanw87c/branch/master?svg=true)](https://ci.appveyor.com/project/nicolasleger/openbeautyfacts-ruby-3n54g/branch/master)
|
6
|
+
[![Dependency Status](https://gemnasium.com/openfoodfacts/openbeautyfacts-ruby.svg)](https://gemnasium.com/openfoodfacts/openbeautyfacts-ruby)
|
7
|
+
[![Code Climate](https://codeclimate.com/github/openfoodfacts/openbeautyfacts-ruby/badges/gpa.svg)](https://codeclimate.com/github/openfoodfacts/openbeautyfacts-ruby)
|
8
|
+
[![Coverage Status](https://coveralls.io/repos/github/openfoodfacts/openbeautyfacts-ruby/badge.svg?branch=master)](https://coveralls.io/github/openfoodfacts/openbeautyfacts-ruby?branch=master)
|
9
|
+
[![Documentation](https://inch-ci.org/github/openfoodfacts/openbeautyfacts-ruby.svg?branch=master)](https://inch-ci.org/github/openfoodfacts/openbeautyfacts-ruby)
|
9
10
|
|
10
|
-
API Wrapper for [Open Beauty Facts](
|
11
|
+
API Wrapper for [Open Beauty Facts](https://openbeautyfacts.org/), the open database about beauty products.
|
11
12
|
|
12
13
|
## Installation
|
13
14
|
|
@@ -35,14 +36,19 @@ All data is available for World, French, UK and US version for now. You should u
|
|
35
36
|
- City
|
36
37
|
- Contributor
|
37
38
|
- Country
|
39
|
+
- EntryDate
|
38
40
|
- Faq
|
39
41
|
- IngredientThatMayBeFromPalmOil
|
40
42
|
- Label
|
43
|
+
- LastEditDate
|
41
44
|
- Locale
|
42
45
|
- ManufacturingPlace
|
46
|
+
- Mission
|
47
|
+
- NumberOfIngredients
|
43
48
|
- Origin
|
44
49
|
- PackagerCode
|
45
50
|
- Packaging
|
51
|
+
- PeriodAfterOpening
|
46
52
|
- Press
|
47
53
|
- Product
|
48
54
|
- ProductState
|
@@ -79,7 +85,7 @@ end
|
|
79
85
|
# Search products
|
80
86
|
|
81
87
|
products = Openbeautyfacts::Product.search("Chocolate", locale: 'world', page_size: 3)
|
82
|
-
# => [#<Openbeautyfacts::Product _id="3045140105502" code="3045140105502" id="3045140105502" image_small_url="
|
88
|
+
# => [#<Openbeautyfacts::Product _id="3045140105502" code="3045140105502" id="3045140105502" image_small_url="https://en.openbeautyfacts.org/images/products/304/514/010/5502/front.7.100.jpg" lc="en" product_name="Milka au lait du Pays Alpin">, #<Openbeautyfacts::Product _id="3046920028363" code="3046920028363" id="3046920028363" image_small_url="https://en.openbeautyfacts.org/images/products/304/692/002/8363/front.5.100.jpg" lc="en" product_name="Tableta de chocolate negro \"Lindt Excellence\" 85% cacao">, #<Openbeautyfacts::Product _id="3046920029759" code="3046920029759" id="3046920029759" image_small_url="https://en.openbeautyfacts.org/images/products/304/692/002/9759/front.9.100.jpg" lc="en" product_name="Tableta de chocolate negro \"Lindt Excellence\" 90% cacao">]
|
83
89
|
|
84
90
|
# You might need to fetch full product data from results
|
85
91
|
|
@@ -104,7 +110,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
104
110
|
|
105
111
|
## Contributing
|
106
112
|
|
107
|
-
1. Fork it ( https://github.com/
|
113
|
+
1. Fork it ( https://github.com/openfoodfacts/openbeautyfacts-ruby/fork )
|
108
114
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
109
115
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
110
116
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/openbeautyfacts.rb
CHANGED
@@ -4,14 +4,20 @@ require_relative 'openbeautyfacts/category'
|
|
4
4
|
require_relative 'openbeautyfacts/city'
|
5
5
|
require_relative 'openbeautyfacts/contributor'
|
6
6
|
require_relative 'openbeautyfacts/country'
|
7
|
+
require_relative 'openbeautyfacts/entry_date'
|
7
8
|
require_relative 'openbeautyfacts/faq'
|
9
|
+
require_relative 'openbeautyfacts/ingredient'
|
8
10
|
require_relative 'openbeautyfacts/ingredient_that_may_be_from_palm_oil'
|
9
11
|
require_relative 'openbeautyfacts/label'
|
12
|
+
require_relative 'openbeautyfacts/last_edit_date'
|
10
13
|
require_relative 'openbeautyfacts/locale'
|
11
14
|
require_relative 'openbeautyfacts/manufacturing_place'
|
15
|
+
require_relative 'openbeautyfacts/mission'
|
16
|
+
require_relative 'openbeautyfacts/number_of_ingredients'
|
12
17
|
require_relative 'openbeautyfacts/origin'
|
13
18
|
require_relative 'openbeautyfacts/packager_code'
|
14
19
|
require_relative 'openbeautyfacts/packaging'
|
20
|
+
require_relative 'openbeautyfacts/period_after_opening'
|
15
21
|
require_relative 'openbeautyfacts/press'
|
16
22
|
require_relative 'openbeautyfacts/product'
|
17
23
|
require_relative 'openbeautyfacts/product_state'
|
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
page_url = "
|
20
|
+
page_url = "https://#{locale}.#{domain}/#{path}"
|
21
21
|
|
22
22
|
Product.tags_from_page(self, page_url) do |tag|
|
23
23
|
columns = tag.css('td')
|
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
data/lib/openbeautyfacts/city.rb
CHANGED
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module Openbeautyfacts
|
4
|
+
class EntryDate < Hashie::Mash
|
5
|
+
|
6
|
+
# TODO: Add more locales
|
7
|
+
LOCALE_PATHS = {
|
8
|
+
'fr' => 'dates-d-ajout',
|
9
|
+
'uk' => 'entry-dates',
|
10
|
+
'us' => 'entry-dates',
|
11
|
+
'world' => 'entry-dates'
|
12
|
+
}
|
13
|
+
|
14
|
+
class << self
|
15
|
+
|
16
|
+
# Get entry dates
|
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
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get products with entry date
|
27
|
+
#
|
28
|
+
def products(page: -1)
|
29
|
+
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/lib/openbeautyfacts/faq.rb
CHANGED
@@ -16,7 +16,7 @@ module Openbeautyfacts
|
|
16
16
|
class << self
|
17
17
|
def items(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
18
18
|
if path = LOCALE_PATHS[locale]
|
19
|
-
html = open("
|
19
|
+
html = URI.open("https://#{locale}.#{domain}/#{path}").read
|
20
20
|
dom = Nokogiri::HTML.fragment(html)
|
21
21
|
|
22
22
|
titles = dom.css('#main_column h2')
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module Openbeautyfacts
|
4
|
+
class Ingredient < Hashie::Mash
|
5
|
+
|
6
|
+
# TODO: Add more locales
|
7
|
+
LOCALE_PATHS = {
|
8
|
+
'fr' => 'ingredients',
|
9
|
+
'uk' => 'ingredients',
|
10
|
+
'us' => 'ingredients',
|
11
|
+
'world' => 'ingredients'
|
12
|
+
}
|
13
|
+
|
14
|
+
class << self
|
15
|
+
|
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
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get products with label
|
27
|
+
#
|
28
|
+
def products(page: -1)
|
29
|
+
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module Openbeautyfacts
|
4
|
+
class LastEditDate < Hashie::Mash
|
5
|
+
|
6
|
+
# TODO: Add more locales
|
7
|
+
LOCALE_PATHS = {
|
8
|
+
'fr' => 'dates-de-derniere-modification',
|
9
|
+
'uk' => 'last-edit-dates',
|
10
|
+
'us' => 'last-edit-dates',
|
11
|
+
'world' => 'last-edit-dates'
|
12
|
+
}
|
13
|
+
|
14
|
+
class << self
|
15
|
+
|
16
|
+
# Get last edit dates
|
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
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get products with last edit date
|
27
|
+
#
|
28
|
+
def products(page: -1)
|
29
|
+
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
1
3
|
module Openbeautyfacts
|
2
4
|
class Locale < String
|
3
5
|
|
@@ -8,13 +10,14 @@ module Openbeautyfacts
|
|
8
10
|
# Get locales
|
9
11
|
#
|
10
12
|
def all(domain: DEFAULT_DOMAIN)
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
path = 'cgi/i18n/countries.pl?_type=query'
|
14
|
+
url = "https://#{GLOBAL}.#{domain}/#{path}"
|
15
|
+
json = URI.open(url).read
|
16
|
+
hash = JSON.parse(json)
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
}.
|
18
|
+
hash.map { |pair|
|
19
|
+
locale_from_pair(pair, domain: domain)
|
20
|
+
}.compact
|
18
21
|
end
|
19
22
|
|
20
23
|
# Return locale from link
|
@@ -24,6 +27,17 @@ module Openbeautyfacts
|
|
24
27
|
locale unless locale.nil? || locale == 'static'
|
25
28
|
end
|
26
29
|
|
30
|
+
# Return locale from pair
|
31
|
+
#
|
32
|
+
def locale_from_pair(pair, domain: DEFAULT_DOMAIN)
|
33
|
+
code = pair.first
|
34
|
+
{
|
35
|
+
"name" => pair.last.strip,
|
36
|
+
"code" => code,
|
37
|
+
"url" => "https://#{code}.#{domain}"
|
38
|
+
} if code
|
39
|
+
end
|
40
|
+
|
27
41
|
end
|
28
42
|
|
29
43
|
end
|
@@ -17,7 +17,7 @@ module Openbeautyfacts
|
|
17
17
|
#
|
18
18
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
19
19
|
if path = LOCALE_PATHS[locale]
|
20
|
-
Product.tags_from_page(self, "
|
20
|
+
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
module Openbeautyfacts
|
5
|
+
class Mission < Hashie::Mash
|
6
|
+
|
7
|
+
# TODO: Add more locales
|
8
|
+
LOCALE_PATHS = {
|
9
|
+
'fr' => 'missions',
|
10
|
+
'uk' => 'missions',
|
11
|
+
'us' => 'missions',
|
12
|
+
'world' => 'missions'
|
13
|
+
}
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
17
|
+
if path = LOCALE_PATHS[locale]
|
18
|
+
url = "https://#{locale}.#{domain}/#{path}"
|
19
|
+
html = URI.open(url).read
|
20
|
+
dom = Nokogiri::HTML.fragment(html)
|
21
|
+
|
22
|
+
dom.css('#missions li').map do |mission_dom|
|
23
|
+
links = mission_dom.css('a')
|
24
|
+
|
25
|
+
attributes = {
|
26
|
+
"title" => links.first.text.strip,
|
27
|
+
"url" => URI.join(url, links.first.attr('href')).to_s,
|
28
|
+
"description" => mission_dom.css('div').first.children[2].text.gsub('→', '').strip,
|
29
|
+
"users_count" => links.last.text[/(\d+)/, 1].to_i
|
30
|
+
}
|
31
|
+
|
32
|
+
new(attributes)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Fetch mission
|
39
|
+
#
|
40
|
+
def fetch
|
41
|
+
if (self.url)
|
42
|
+
html = URI.open(self.url).read
|
43
|
+
dom = Nokogiri::HTML.fragment(html)
|
44
|
+
|
45
|
+
description = dom.css('#description').first
|
46
|
+
|
47
|
+
# Remove "All missions" link
|
48
|
+
users = dom.css('#main_column a')[0..-2].map do |user_link|
|
49
|
+
User.new(
|
50
|
+
"user_id" => user_link.text.strip,
|
51
|
+
"url" => URI.join(self.url, user_link.attr('href')).to_s,
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
mission = {
|
56
|
+
"title" => dom.css('h1').first.text.strip,
|
57
|
+
"description" => description.text.strip,
|
58
|
+
"description_long" => description.next.text.strip,
|
59
|
+
|
60
|
+
"users" => users,
|
61
|
+
"users_count" => users.count
|
62
|
+
}
|
63
|
+
|
64
|
+
self.merge!(mission)
|
65
|
+
end
|
66
|
+
|
67
|
+
self
|
68
|
+
end
|
69
|
+
alias_method :reload, :fetch
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module Openbeautyfacts
|
4
|
+
class NumberOfIngredients < Hashie::Mash
|
5
|
+
|
6
|
+
# TODO: Add more locales
|
7
|
+
LOCALE_PATHS = {
|
8
|
+
'fr' => 'nombres-d-ingredients',
|
9
|
+
'uk' => 'numbers-of-ingredients',
|
10
|
+
'us' => 'numbers-of-ingredients',
|
11
|
+
'world' => 'numbers-of-ingredients'
|
12
|
+
}
|
13
|
+
|
14
|
+
class << self
|
15
|
+
|
16
|
+
# Get last edit dates
|
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
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get products with last edit date
|
27
|
+
#
|
28
|
+
def products(page: -1)
|
29
|
+
Product.from_website_page(url, page: page, products_count: products_count) if url
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|