openbeautyfacts 0.6.3 → 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 +19 -1
- data/Rakefile +5 -3
- data/lib/openbeautyfacts/additive.rb +9 -39
- data/lib/openbeautyfacts/allergen.rb +14 -22
- data/lib/openbeautyfacts/brand.rb +14 -22
- data/lib/openbeautyfacts/category.rb +14 -22
- data/lib/openbeautyfacts/city.rb +14 -22
- data/lib/openbeautyfacts/contributor.rb +14 -22
- data/lib/openbeautyfacts/country.rb +14 -22
- data/lib/openbeautyfacts/entry_date.rb +15 -23
- data/lib/openbeautyfacts/faq.rb +16 -41
- data/lib/openbeautyfacts/ingredient.rb +14 -22
- data/lib/openbeautyfacts/ingredient_that_may_be_from_palm_oil.rb +14 -22
- data/lib/openbeautyfacts/label.rb +14 -22
- data/lib/openbeautyfacts/last_edit_date.rb +15 -23
- data/lib/openbeautyfacts/locale.rb +8 -31
- data/lib/openbeautyfacts/manufacturing_place.rb +14 -22
- data/lib/openbeautyfacts/mission.rb +16 -63
- data/lib/openbeautyfacts/number_of_ingredients.rb +15 -23
- data/lib/openbeautyfacts/origin.rb +14 -22
- data/lib/openbeautyfacts/packager_code.rb +14 -22
- data/lib/openbeautyfacts/packaging.rb +14 -22
- data/lib/openbeautyfacts/period_after_opening.rb +14 -22
- data/lib/openbeautyfacts/press.rb +16 -47
- data/lib/openbeautyfacts/product.rb +18 -175
- data/lib/openbeautyfacts/product_state.rb +14 -22
- data/lib/openbeautyfacts/purchase_place.rb +14 -22
- data/lib/openbeautyfacts/store.rb +14 -22
- data/lib/openbeautyfacts/trace.rb +14 -22
- data/lib/openbeautyfacts/user.rb +15 -30
- data/lib/openbeautyfacts/version.rb +3 -1
- data/lib/openbeautyfacts.rb +6 -9
- data/test/fixtures/additives.yml +48 -0
- data/test/fixtures/brands.yml +48 -0
- data/test/fixtures/entry_dates.yml +48 -0
- data/test/fixtures/entry_dates_locale.yml +48 -0
- data/test/fixtures/faq.yml +48 -0
- data/test/fixtures/fetch_product_3600550362626.yml +54 -0
- data/test/fixtures/index.yml +48 -0
- data/test/fixtures/ingredients.yml +99 -0
- data/test/fixtures/ingredients_locale.yml +99 -0
- data/test/fixtures/last_edit_dates.yml +48 -0
- data/test/fixtures/last_edit_dates_locale.yml +48 -0
- data/test/fixtures/login_user.yml +363 -0
- data/test/fixtures/mission.yml +48 -0
- data/test/fixtures/missions.yml +48 -0
- data/test/fixtures/number_of_ingredients_locale.yml +48 -0
- data/test/fixtures/numbers_of_ingredients.yml +48 -0
- data/test/fixtures/press.yml +48 -0
- data/test/fixtures/product_3600550362626.yml +54 -0
- data/test/fixtures/product_states.yml +48 -0
- data/test/fixtures/product_states_locale.yml +48 -0
- data/test/fixtures/products_for_brand.yml +99 -0
- data/test/fixtures/products_for_entry_date.yml +99 -0
- data/test/fixtures/products_for_ingredient.yml +99 -0
- data/test/fixtures/products_for_last_edit_date.yml +99 -0
- data/test/fixtures/products_for_number_of_ingredients.yml +99 -0
- data/test/fixtures/products_for_period_after_opening.yml +99 -0
- data/test/fixtures/products_for_state.yml +99 -0
- data/test/fixtures/products_with_additive.yml +99 -0
- data/test/fixtures/search_doux.yml +105 -0
- data/test/fixtures/search_doux_1_000_000.yml +54 -0
- data/test/minitest_helper.rb +5 -3
- data/test/test_openbeautyfacts.rb +129 -97
- metadata +59 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ee3e3eb895b24332b15083b9e7ab0d0fe14d711792b2bf3e83c4de35e0ccada7
|
|
4
|
+
data.tar.gz: 976b0855a3e6653b90412d53cb132a69cd34e2d56e099da89b30b9724f19e75f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0dfbf80e11a3721d1f34e5a742bd258f3064a52cd258f663c66646320448e9366bd9c2743ead584d942e9b7c2798c13f24de90442b84b4d478f34f7083573be8
|
|
7
|
+
data.tar.gz: 5f57a30b0d77f9e9dd219cc17383f330b7f0db32a3265414e0ad169cd62705fb617f78cb845913a9fbdfdd447131ae7dd50953eb15bb47c193e020a89ad26476
|
data/README.md
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
# Open Beauty Facts
|
|
1
|
+
# Open Beauty Facts Ruby SDK
|
|
2
|
+
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://static.openbeautyfacts.org/images/logos/obf-logo-horizontal-dark.png?refresh_github_cache=1">
|
|
5
|
+
<source media="(prefers-color-scheme: light)" srcset="https://static.openbeautyfacts.org/images/logos/obf-logo-horizontal-light.png?refresh_github_cache=1">
|
|
6
|
+
<img height="48" src="https://static.openbeautyfacts.org/images/logos/obf-logo-horizontal-light.svg"/>
|
|
7
|
+
</picture>
|
|
2
8
|
|
|
3
9
|
[](https://badge.fury.io/rb/openbeautyfacts)
|
|
4
10
|
[](https://github.com/openfoodfacts/openbeautyfacts-ruby/actions/workflows/ruby.yml)
|
|
@@ -6,6 +12,9 @@
|
|
|
6
12
|
[](https://inch-ci.org/github/openfoodfacts/openbeautyfacts-ruby)
|
|
7
13
|
|
|
8
14
|
API Wrapper for [Open Beauty Facts](https://openbeautyfacts.org/), the open database about beauty products.
|
|
15
|
+
- We have a similar package for food: https://github.com/openfoodfacts/openfoodfacts-ruby
|
|
16
|
+
- Note: This package needs updates for the newest APIs.
|
|
17
|
+
- Please see on https://wiki.openfoodfacts.org/API/Ruby how to join the community to help
|
|
9
18
|
|
|
10
19
|
## Installation
|
|
11
20
|
|
|
@@ -112,3 +121,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
112
121
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
113
122
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
114
123
|
5. Create a new Pull Request
|
|
124
|
+
|
|
125
|
+
## Using this SDK and Third party applications
|
|
126
|
+
|
|
127
|
+
- If you use this SDK, feel free to open a PR to add your application in the list in [REUSERS.md](https://github.com/openfoodfacts/openbeautyfacts-ruby/blob/develop/REUSERS.md)
|
|
128
|
+
- 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.
|
|
129
|
+
- Please get in touch at reuse@openfoodfacts.org
|
|
130
|
+
- 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
|
|
131
|
+
|
|
132
|
+
## Authors
|
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
|
|
@@ -1,51 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class Additive <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'additifs',
|
|
9
|
-
'uk' => 'additives',
|
|
10
|
-
'us' => 'additives',
|
|
11
|
-
'world' => 'additives'
|
|
12
|
-
}
|
|
4
|
+
class Additive < Openfoodfacts::Additive
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
# Get additives
|
|
17
|
-
#
|
|
10
|
+
# Override all method to use openbeautyfacts domain
|
|
18
11
|
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
|
|
19
|
-
|
|
20
|
-
page_url = "https://#{locale}.#{domain}/#{path}"
|
|
21
|
-
|
|
22
|
-
Product.tags_from_page(self, page_url) do |tag|
|
|
23
|
-
columns = tag.css('td')
|
|
24
|
-
|
|
25
|
-
link = tag.css('a').first
|
|
26
|
-
attributes = {
|
|
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
|
-
}
|
|
31
|
-
|
|
32
|
-
riskiness = columns[3].attr('class')
|
|
33
|
-
if riskiness
|
|
34
|
-
attributes["riskiness"] = riskiness[/level_(\d+)/, 1].to_i
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
new(attributes)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
12
|
+
super(locale: locale, domain: domain)
|
|
40
13
|
end
|
|
41
|
-
|
|
42
14
|
end
|
|
43
15
|
|
|
44
|
-
#
|
|
45
|
-
#
|
|
16
|
+
# Override products method to use openbeautyfacts domain
|
|
46
17
|
def products(page: -1)
|
|
47
|
-
|
|
18
|
+
super(page: page)
|
|
48
19
|
end
|
|
49
|
-
|
|
50
20
|
end
|
|
51
21
|
end
|
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class Allergen <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'allergenes',
|
|
9
|
-
'uk' => 'allergens',
|
|
10
|
-
'us' => 'allergens',
|
|
11
|
-
'world' => 'allergens'
|
|
12
|
-
}
|
|
4
|
+
class Allergen < Openfoodfacts::Allergen
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
|
21
|
-
end
|
|
10
|
+
# Override all method to use openbeautyfacts domain if it exists
|
|
11
|
+
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
|
|
12
|
+
super(locale: locale, domain: domain, **options)
|
|
13
|
+
rescue NoMethodError
|
|
14
|
+
# Method doesn't exist in parent class, skip
|
|
22
15
|
end
|
|
23
|
-
|
|
24
16
|
end
|
|
25
17
|
|
|
26
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
20
|
+
super(page: page)
|
|
21
|
+
rescue NoMethodError
|
|
22
|
+
# Method doesn't exist in parent class, skip
|
|
30
23
|
end
|
|
31
|
-
|
|
32
24
|
end
|
|
33
25
|
end
|
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class Brand <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'marques',
|
|
9
|
-
'uk' => 'brands',
|
|
10
|
-
'us' => 'brands',
|
|
11
|
-
'world' => 'brands'
|
|
12
|
-
}
|
|
4
|
+
class Brand < Openfoodfacts::Brand
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
|
21
|
-
end
|
|
10
|
+
# Override all method to use openbeautyfacts domain if it exists
|
|
11
|
+
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
|
|
12
|
+
super(locale: locale, domain: domain, **options)
|
|
13
|
+
rescue NoMethodError
|
|
14
|
+
# Method doesn't exist in parent class, skip
|
|
22
15
|
end
|
|
23
|
-
|
|
24
16
|
end
|
|
25
17
|
|
|
26
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
20
|
+
super(page: page)
|
|
21
|
+
rescue NoMethodError
|
|
22
|
+
# Method doesn't exist in parent class, skip
|
|
30
23
|
end
|
|
31
|
-
|
|
32
24
|
end
|
|
33
25
|
end
|
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class Category <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'categories',
|
|
9
|
-
'uk' => 'categories',
|
|
10
|
-
'us' => 'categories',
|
|
11
|
-
'world' => 'categories'
|
|
12
|
-
}
|
|
4
|
+
class Category < Openfoodfacts::Category
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
|
21
|
-
end
|
|
10
|
+
# Override all method to use openbeautyfacts domain if it exists
|
|
11
|
+
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
|
|
12
|
+
super(locale: locale, domain: domain, **options)
|
|
13
|
+
rescue NoMethodError
|
|
14
|
+
# Method doesn't exist in parent class, skip
|
|
22
15
|
end
|
|
23
|
-
|
|
24
16
|
end
|
|
25
17
|
|
|
26
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
20
|
+
super(page: page)
|
|
21
|
+
rescue NoMethodError
|
|
22
|
+
# Method doesn't exist in parent class, skip
|
|
30
23
|
end
|
|
31
|
-
|
|
32
24
|
end
|
|
33
25
|
end
|
data/lib/openbeautyfacts/city.rb
CHANGED
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class City <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'communes',
|
|
9
|
-
'uk' => 'cities',
|
|
10
|
-
'us' => 'cities',
|
|
11
|
-
'world' => 'cities'
|
|
12
|
-
}
|
|
4
|
+
class City < Openfoodfacts::City
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
|
21
|
-
end
|
|
10
|
+
# Override all method to use openbeautyfacts domain if it exists
|
|
11
|
+
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
|
|
12
|
+
super(locale: locale, domain: domain, **options)
|
|
13
|
+
rescue NoMethodError
|
|
14
|
+
# Method doesn't exist in parent class, skip
|
|
22
15
|
end
|
|
23
|
-
|
|
24
16
|
end
|
|
25
17
|
|
|
26
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
20
|
+
super(page: page)
|
|
21
|
+
rescue NoMethodError
|
|
22
|
+
# Method doesn't exist in parent class, skip
|
|
30
23
|
end
|
|
31
|
-
|
|
32
24
|
end
|
|
33
25
|
end
|
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class Contributor <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'contributeurs',
|
|
9
|
-
'uk' => 'contributors',
|
|
10
|
-
'us' => 'contributors',
|
|
11
|
-
'world' => 'contributors'
|
|
12
|
-
}
|
|
4
|
+
class Contributor < Openfoodfacts::Contributor
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
|
21
|
-
end
|
|
10
|
+
# Override all method to use openbeautyfacts domain if it exists
|
|
11
|
+
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
|
|
12
|
+
super(locale: locale, domain: domain, **options)
|
|
13
|
+
rescue NoMethodError
|
|
14
|
+
# Method doesn't exist in parent class, skip
|
|
22
15
|
end
|
|
23
|
-
|
|
24
16
|
end
|
|
25
17
|
|
|
26
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
20
|
+
super(page: page)
|
|
21
|
+
rescue NoMethodError
|
|
22
|
+
# Method doesn't exist in parent class, skip
|
|
30
23
|
end
|
|
31
|
-
|
|
32
24
|
end
|
|
33
25
|
end
|
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class Country <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'pays',
|
|
9
|
-
'uk' => 'countries',
|
|
10
|
-
'us' => 'countries',
|
|
11
|
-
'world' => 'countries'
|
|
12
|
-
}
|
|
4
|
+
class Country < Openfoodfacts::Country
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
|
21
|
-
end
|
|
10
|
+
# Override all method to use openbeautyfacts domain if it exists
|
|
11
|
+
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
|
|
12
|
+
super(locale: locale, domain: domain, **options)
|
|
13
|
+
rescue NoMethodError
|
|
14
|
+
# Method doesn't exist in parent class, skip
|
|
22
15
|
end
|
|
23
|
-
|
|
24
16
|
end
|
|
25
17
|
|
|
26
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
20
|
+
super(page: page)
|
|
21
|
+
rescue NoMethodError
|
|
22
|
+
# Method doesn't exist in parent class, skip
|
|
30
23
|
end
|
|
31
|
-
|
|
32
24
|
end
|
|
33
25
|
end
|
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class EntryDate <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'dates-d-ajout',
|
|
9
|
-
'uk' => 'entry-dates',
|
|
10
|
-
'us' => 'entry-dates',
|
|
11
|
-
'world' => 'entry-dates'
|
|
12
|
-
}
|
|
4
|
+
class EntryDate < Openfoodfacts::EntryDate
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
|
21
|
-
end
|
|
10
|
+
# Override all method to use openbeautyfacts domain if it exists
|
|
11
|
+
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
|
|
12
|
+
super(locale: locale, domain: domain, **options)
|
|
13
|
+
rescue NoMethodError
|
|
14
|
+
# Method doesn't exist in parent class, skip
|
|
22
15
|
end
|
|
23
|
-
|
|
24
16
|
end
|
|
25
17
|
|
|
26
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
20
|
+
super(page: page)
|
|
21
|
+
rescue NoMethodError
|
|
22
|
+
# Method doesn't exist in parent class, skip
|
|
30
23
|
end
|
|
31
|
-
|
|
32
24
|
end
|
|
33
|
-
end
|
|
25
|
+
end
|
data/lib/openbeautyfacts/faq.rb
CHANGED
|
@@ -1,50 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
require 'nokogiri'
|
|
3
|
-
require 'open-uri'
|
|
1
|
+
# frozen_string_literal: true
|
|
4
2
|
|
|
5
3
|
module Openbeautyfacts
|
|
6
|
-
class Faq <
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
'fr' => 'questions-frequentes',
|
|
11
|
-
'uk' => 'faq',
|
|
12
|
-
'us' => 'faq',
|
|
13
|
-
'world' => 'faq'
|
|
14
|
-
}
|
|
4
|
+
class Faq < Openfoodfacts::Faq
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
15
8
|
|
|
16
9
|
class << self
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
titles = dom.css('#main_column h2')
|
|
23
|
-
titles.each_with_index.map do |item, index|
|
|
24
|
-
paragraphs = []
|
|
25
|
-
|
|
26
|
-
element = item.next_sibling
|
|
27
|
-
while !element.nil? && element.node_name != 'h2'
|
|
28
|
-
if element.node_name == 'p'
|
|
29
|
-
paragraphs.push(element)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
element = element.next_sibling
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
if index == titles.length - 1
|
|
36
|
-
paragraphs = paragraphs[0..-3]
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
new({
|
|
40
|
-
"question" => item.text.strip,
|
|
41
|
-
"answer" => paragraphs.map { |paragraph| paragraph.text.strip.gsub(/\r?\n/, ' ') }.join("\n\n"),
|
|
42
|
-
"answer_html" => paragraphs.map(&:to_html).join
|
|
43
|
-
})
|
|
44
|
-
end
|
|
45
|
-
end
|
|
10
|
+
# Override all method to use openbeautyfacts domain if it exists
|
|
11
|
+
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
|
|
12
|
+
super(locale: locale, domain: domain, **options)
|
|
13
|
+
rescue NoMethodError
|
|
14
|
+
# Method doesn't exist in parent class, skip
|
|
46
15
|
end
|
|
47
16
|
end
|
|
48
17
|
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
19
|
+
def products(page: -1)
|
|
20
|
+
super(page: page)
|
|
21
|
+
rescue NoMethodError
|
|
22
|
+
# Method doesn't exist in parent class, skip
|
|
23
|
+
end
|
|
49
24
|
end
|
|
50
25
|
end
|
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class Ingredient <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'ingredients',
|
|
9
|
-
'uk' => 'ingredients',
|
|
10
|
-
'us' => 'ingredients',
|
|
11
|
-
'world' => 'ingredients'
|
|
12
|
-
}
|
|
4
|
+
class Ingredient < Openfoodfacts::Ingredient
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
|
21
|
-
end
|
|
10
|
+
# Override all method to use openbeautyfacts domain if it exists
|
|
11
|
+
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
|
|
12
|
+
super(locale: locale, domain: domain, **options)
|
|
13
|
+
rescue NoMethodError
|
|
14
|
+
# Method doesn't exist in parent class, skip
|
|
22
15
|
end
|
|
23
|
-
|
|
24
16
|
end
|
|
25
17
|
|
|
26
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
20
|
+
super(page: page)
|
|
21
|
+
rescue NoMethodError
|
|
22
|
+
# Method doesn't exist in parent class, skip
|
|
30
23
|
end
|
|
31
|
-
|
|
32
24
|
end
|
|
33
25
|
end
|
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class IngredientThatMayBeFromPalmOil <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'ingredients-pouvant-etre-issus-de-l-huile-de-palme',
|
|
9
|
-
'uk' => 'ingredients-that-may-be-from-palm-oil',
|
|
10
|
-
'us' => 'ingredients-that-may-be-from-palm-oil',
|
|
11
|
-
'world' => 'ingredients-that-may-be-from-palm-oil'
|
|
12
|
-
}
|
|
4
|
+
class IngredientThatMayBeFromPalmOil < Openfoodfacts::IngredientThatMayBeFromPalmOil
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
|
|
21
|
-
end
|
|
10
|
+
# Override all method to use openbeautyfacts domain if it exists
|
|
11
|
+
def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
|
|
12
|
+
super(locale: locale, domain: domain, **options)
|
|
13
|
+
rescue NoMethodError
|
|
14
|
+
# Method doesn't exist in parent class, skip
|
|
22
15
|
end
|
|
23
|
-
|
|
24
16
|
end
|
|
25
17
|
|
|
26
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
20
|
+
super(page: page)
|
|
21
|
+
rescue NoMethodError
|
|
22
|
+
# Method doesn't exist in parent class, skip
|
|
30
23
|
end
|
|
31
|
-
|
|
32
24
|
end
|
|
33
25
|
end
|