openbeautyfacts 0.1.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a05e2fba051f2eb1fc70cd7a13a740b6a7909783
4
- data.tar.gz: 18de8b97c52c45c636c396dcc121655b47a1754a
3
+ metadata.gz: 14999a9b6ccae0d6b356ffa2ece4539012d11896
4
+ data.tar.gz: 2eee40350db2fb6f5b1b94a83da55a47d9fbef3c
5
5
  SHA512:
6
- metadata.gz: c8ff286d06da3a12dcce36cec633ad7990c0aa4a1e3404dc253b40d0f86773b42312ebe6c870c99e43282f8e8655b21a4484eeb30b375fa2c7bded8e055d7f9d
7
- data.tar.gz: b241d88d2fba5da98dcf1226cce738bcdf22d00b594b8d29641ae369e4061748e36cd75d0892efd74d1f9169d41215d140aab97959674ab93ee125f562108c7a
6
+ metadata.gz: 8192cbe32bb23b4d6d8b241c24022edef7dcb7400380edaba3fcc2b600cf92d4201205564397b9fcb6611adecee8fdcbb37787f2584dfe48558fc5202556cd13
7
+ data.tar.gz: 57aeb89751737202685bca0c627a2cb56d13693cd7581d4f17bae520a9ebc2d9e390ed4ed9a6c46b1c37630834dd39d2a9609c4e45a6870ee63a0ba54ee7edaf
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Open Beauty Facts
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/openbeautyfacts.svg)](http://badge.fury.io/rb/openbeautyfacts)
3
+ [![Gem Version](https://badge.fury.io/rb/openbeautyfacts.svg)](https://badge.fury.io/rb/openbeautyfacts)
4
4
  [![Build Status](https://travis-ci.org/openfoodfacts/openbeautyfacts-ruby.svg?branch=master)](https://travis-ci.org/openfoodfacts/openbeautyfacts-ruby)
5
5
  [![Dependency Status](https://gemnasium.com/openfoodfacts/openbeautyfacts-ruby.svg)](https://gemnasium.com/openfoodfacts/openbeautyfacts-ruby)
6
6
  [![Code Climate](https://codeclimate.com/github/openfoodfacts/openbeautyfacts-ruby/badges/gpa.svg)](https://codeclimate.com/github/openfoodfacts/openbeautyfacts-ruby)
7
7
  [![Coverage Status](https://coveralls.io/repos/github/openfoodfacts/openbeautyfacts-ruby/badge.svg?branch=master)](https://coveralls.io/github/openfoodfacts/openbeautyfacts-ruby?branch=master)
8
- [![Documentation](http://inch-ci.org/github/openfoodfacts/openbeautyfacts-ruby.svg?branch=master)](http://inch-ci.org/github/openfoodfacts/openbeautyfacts-ruby)
8
+ [![Documentation](https://inch-ci.org/github/openfoodfacts/openbeautyfacts-ruby.svg?branch=master)](https://inch-ci.org/github/openfoodfacts/openbeautyfacts-ruby)
9
9
 
10
10
  API Wrapper for [Open Beauty Facts](https://openbeautyfacts.org/), the open database about beauty products.
11
11
 
@@ -35,14 +35,19 @@ All data is available for World, French, UK and US version for now. You should u
35
35
  - City
36
36
  - Contributor
37
37
  - Country
38
+ - EntryDate
38
39
  - Faq
39
40
  - IngredientThatMayBeFromPalmOil
40
41
  - Label
42
+ - LastEditDate
41
43
  - Locale
42
44
  - ManufacturingPlace
45
+ - Mission
46
+ - NumberOfIngredients
43
47
  - Origin
44
48
  - PackagerCode
45
49
  - Packaging
50
+ - PeriodAfterOpening
46
51
  - Press
47
52
  - Product
48
53
  - ProductState
@@ -4,12 +4,16 @@ 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'
8
9
  require_relative 'openbeautyfacts/ingredient'
9
10
  require_relative 'openbeautyfacts/ingredient_that_may_be_from_palm_oil'
10
11
  require_relative 'openbeautyfacts/label'
12
+ require_relative 'openbeautyfacts/last_edit_date'
11
13
  require_relative 'openbeautyfacts/locale'
12
14
  require_relative 'openbeautyfacts/manufacturing_place'
15
+ require_relative 'openbeautyfacts/mission'
16
+ require_relative 'openbeautyfacts/number_of_ingredients'
13
17
  require_relative 'openbeautyfacts/origin'
14
18
  require_relative 'openbeautyfacts/packager_code'
15
19
  require_relative 'openbeautyfacts/packaging'
@@ -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
@@ -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
@@ -0,0 +1,71 @@
1
+ require 'hashie'
2
+
3
+ module Openbeautyfacts
4
+ class Mission < Hashie::Mash
5
+
6
+ # TODO: Add more locales
7
+ LOCALE_PATHS = {
8
+ 'fr' => 'missions',
9
+ 'uk' => 'missions',
10
+ 'us' => 'missions',
11
+ 'world' => 'missions'
12
+ }
13
+
14
+ class << self
15
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
16
+ if path = LOCALE_PATHS[locale]
17
+ url = "https://#{locale}.#{domain}/#{path}"
18
+ html = open(url).read
19
+ dom = Nokogiri::HTML.fragment(html)
20
+
21
+ dom.css('#missions li').map do |mission_dom|
22
+ links = mission_dom.css('a')
23
+
24
+ attributes = {
25
+ "title" => links.first.text.strip,
26
+ "url" => URI.join(url, links.first.attr('href')).to_s,
27
+ "description" => mission_dom.css('div').first.children[2].text.gsub('→', '').strip,
28
+ "users_count" => links.last.text[/(\d+)/, 1].to_i
29
+ }
30
+
31
+ new(attributes)
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ # Fetch mission
38
+ #
39
+ def fetch
40
+ if (self.url)
41
+ html = open(self.url).read
42
+ dom = Nokogiri::HTML.fragment(html)
43
+
44
+ description = dom.css('#description').first
45
+
46
+ # Remove "All missions" link
47
+ users = dom.css('#main_column a')[0..-2].map do |user_link|
48
+ User.new(
49
+ "user_id" => user_link.text.strip,
50
+ "url" => URI.join(self.url, user_link.attr('href')).to_s,
51
+ )
52
+ end
53
+
54
+ mission = {
55
+ "title" => dom.css('h1').first.text.strip,
56
+ "description" => description.text.strip,
57
+ "description_long" => description.next.text.strip,
58
+
59
+ "users" => users,
60
+ "users_count" => users.count
61
+ }
62
+
63
+ self.merge!(mission)
64
+ end
65
+
66
+ self
67
+ end
68
+ alias_method :reload, :fetch
69
+
70
+ end
71
+ 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
@@ -6,7 +6,6 @@ module Openbeautyfacts
6
6
  class << self
7
7
 
8
8
  # Login
9
- # WARNING SECURITY: It is not made throught HTTPS Secure so password can be read on the way.
10
9
  #
11
10
  def login(user_id, password, locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
12
11
  path = 'cgi/session.pl'
@@ -1,3 +1,3 @@
1
1
  module Openbeautyfacts
2
- VERSION = "0.1.2"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -198,6 +198,94 @@ class TestOpenbeautyfacts < Minitest::Test
198
198
  end
199
199
  end
200
200
 
201
+ # Entry date
202
+
203
+ def test_it_fetches_entry_dates
204
+ VCR.use_cassette("entry_dates") do
205
+ entry_dates = ::Openbeautyfacts::EntryDate.all
206
+ assert_includes entry_dates.map { |entry_date| entry_date['name'] }, "2017-03-09"
207
+ end
208
+ end
209
+
210
+ def test_it_fetches_entry_dates_for_locale
211
+ VCR.use_cassette("entry_dates_locale") do
212
+ entry_dates = ::Openbeautyfacts::EntryDate.all(locale: 'fr')
213
+ assert_includes entry_dates.map { |entry_date| entry_date['name'] }, "2017-03-09"
214
+ end
215
+ end
216
+
217
+ def test_it_fetches_products_for_entry_date
218
+ entry_date = ::Openbeautyfacts::EntryDate.new("url" => "https://world.openbeautyfacts.org/entry-date/2016-02-12")
219
+ VCR.use_cassette("products_for_entry_date") do
220
+ products_for_entry_date = entry_date.products(page: -1)
221
+ refute_empty products_for_entry_date
222
+ end
223
+ end
224
+
225
+ # Last edit date
226
+
227
+ def test_it_fetches_last_edit_dates
228
+ VCR.use_cassette("last_edit_dates") do
229
+ last_edit_dates = ::Openbeautyfacts::LastEditDate.all
230
+ assert_includes last_edit_dates.map { |last_edit_date| last_edit_date['name'] }, "2017-03-23"
231
+ end
232
+ end
233
+
234
+ def test_it_fetches_last_edit_dates_for_locale
235
+ VCR.use_cassette("last_edit_dates_locale") do
236
+ last_edit_dates = ::Openbeautyfacts::LastEditDate.all(locale: 'fr')
237
+ assert_includes last_edit_dates.map { |last_edit_date| last_edit_date['name'] }, "2017-03-23"
238
+ end
239
+ end
240
+
241
+ def test_it_fetches_products_for_last_edit_date
242
+ last_edit_date = ::Openbeautyfacts::LastEditDate.new("url" => "https://world.openbeautyfacts.org/last-edit-date/2016-02-12")
243
+ VCR.use_cassette("products_for_last_edit_date") do
244
+ products_for_last_edit_date = last_edit_date.products(page: -1)
245
+ refute_empty products_for_last_edit_date
246
+ end
247
+ end
248
+
249
+ # Mission
250
+
251
+ def test_it_fetches_missions
252
+ VCR.use_cassette("missions") do
253
+ refute_empty ::Openbeautyfacts::Mission.all(locale: 'fr')
254
+ end
255
+ end
256
+
257
+ def test_it_fetches_mission
258
+ VCR.use_cassette("mission", record: :once, match_requests_on: [:host, :path]) do
259
+ mission = ::Openbeautyfacts::Mission.new(url: "https://fr.openbeautyfacts.org/mission/25-produits")
260
+ mission.fetch
261
+ refute_empty mission.users
262
+ end
263
+ end
264
+
265
+ # Number of Ingredients
266
+
267
+ def test_it_fetches_numbers_of_ingredients
268
+ VCR.use_cassette("numbers_of_ingredients") do
269
+ numbers_of_ingredients = ::Openbeautyfacts::NumberOfIngredients.all
270
+ assert_includes numbers_of_ingredients.map { |number_of_ingredients| number_of_ingredients['name'] }, "38"
271
+ end
272
+ end
273
+
274
+ def test_it_fetches_numbers_of_ingredients_for_locale
275
+ VCR.use_cassette("number_of_ingredients_locale") do
276
+ numbers_of_ingredients = ::Openbeautyfacts::NumberOfIngredients.all(locale: 'fr')
277
+ assert_includes numbers_of_ingredients.map { |number_of_ingredients| number_of_ingredients['name'] }, "38"
278
+ end
279
+ end
280
+
281
+ def test_it_fetches_products_for_number_of_ingredients
282
+ number_of_ingredients = ::Openbeautyfacts::NumberOfIngredients.new("url" => "https://world.openbeautyfacts.org/number-of-ingredients/38")
283
+ VCR.use_cassette("products_for_number_of_ingredients") do
284
+ products_for_number_of_ingredients = number_of_ingredients.products(page: -1)
285
+ refute_empty products_for_number_of_ingredients
286
+ end
287
+ end
288
+
201
289
  # Period after openings
202
290
 
203
291
  def test_it_fetches_period_after_openings
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openbeautyfacts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Leger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-24 00:00:00.000000000 Z
11
+ date: 2017-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -126,12 +126,16 @@ files:
126
126
  - lib/openbeautyfacts/city.rb
127
127
  - lib/openbeautyfacts/contributor.rb
128
128
  - lib/openbeautyfacts/country.rb
129
+ - lib/openbeautyfacts/entry_date.rb
129
130
  - lib/openbeautyfacts/faq.rb
130
131
  - lib/openbeautyfacts/ingredient.rb
131
132
  - lib/openbeautyfacts/ingredient_that_may_be_from_palm_oil.rb
132
133
  - lib/openbeautyfacts/label.rb
134
+ - lib/openbeautyfacts/last_edit_date.rb
133
135
  - lib/openbeautyfacts/locale.rb
134
136
  - lib/openbeautyfacts/manufacturing_place.rb
137
+ - lib/openbeautyfacts/mission.rb
138
+ - lib/openbeautyfacts/number_of_ingredients.rb
135
139
  - lib/openbeautyfacts/origin.rb
136
140
  - lib/openbeautyfacts/packager_code.rb
137
141
  - lib/openbeautyfacts/packaging.rb
@@ -189,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
193
  version: '0'
190
194
  requirements: []
191
195
  rubyforge_project:
192
- rubygems_version: 2.6.8
196
+ rubygems_version: 2.6.13
193
197
  signing_key:
194
198
  specification_version: 4
195
199
  summary: Open Beauty Facts API Wrapper