openbeautyfacts 0.5.1 → 0.6.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
- SHA1:
3
- metadata.gz: 51847b4724a92c3136027fd5e1901527f2ede8e5
4
- data.tar.gz: 75a13bffe213105afd84ff8c23fc65e9a8159d88
2
+ SHA256:
3
+ metadata.gz: cc506aa648b094eb8218c5cc4408c2cefde133e60677e1fd97a1c8f8e92a33c8
4
+ data.tar.gz: 61c3e27a3a945ce47c6e71a0c727ddfda9eb818206118f8f1529725d2064cec8
5
5
  SHA512:
6
- metadata.gz: aedb7561dacc935930bd36b88d949e624de58958e260e64b70acc7a20630096694dbea5df7a0941ae331beb732202676ad7a93ac0f0ee2dab018a06ae0514d54
7
- data.tar.gz: 3f833e3890e6626e779ebb8156f622a40806ebcca2f8ce30751d2d7f1c239c6d9807689cf3ae4dbf55d019ee2e6e2e6120c50bc86718d58735a8a1785dadb7ef
6
+ metadata.gz: 7c8f56653b09b9d5fd46eef55c420e2fc8817afba5fce876ae72db5058b2d18efd24600f8f75189c2f2e06662335ac70fb91ca3edc1b96a9df3a83a92df9067c
7
+ data.tar.gz: 49796fc369ac2a22dfeb61e54174aa763563f80591ed2ce24857c84f3bf157ffb248bdd45b191e5705b39c7b5c87325446611437663d7ba324f2f10fafcf75c8
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
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
+ [![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)
5
6
  [![Dependency Status](https://gemnasium.com/openfoodfacts/openbeautyfacts-ruby.svg)](https://gemnasium.com/openfoodfacts/openbeautyfacts-ruby)
6
7
  [![Code Climate](https://codeclimate.com/github/openfoodfacts/openbeautyfacts-ruby/badges/gpa.svg)](https://codeclimate.com/github/openfoodfacts/openbeautyfacts-ruby)
7
8
  [![Coverage Status](https://coveralls.io/repos/github/openfoodfacts/openbeautyfacts-ruby/badge.svg?branch=master)](https://coveralls.io/github/openfoodfacts/openbeautyfacts-ruby?branch=master)
@@ -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("https://#{locale}.#{domain}/#{path}").read
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')
@@ -1,3 +1,5 @@
1
+ require 'open-uri'
2
+
1
3
  module Openbeautyfacts
2
4
  class Locale < String
3
5
 
@@ -8,12 +10,13 @@ module Openbeautyfacts
8
10
  # Get locales
9
11
  #
10
12
  def all(domain: DEFAULT_DOMAIN)
11
- url = "https://#{domain}/"
12
- body = open(url).read
13
- dom = Nokogiri.parse(body)
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
- dom.css('#select_country option').map { |option|
16
- locale_from_option(option, domain: domain)
18
+ hash.map { |pair|
19
+ locale_from_pair(pair, domain: domain)
17
20
  }.compact
18
21
  end
19
22
 
@@ -24,18 +27,18 @@ module Openbeautyfacts
24
27
  locale unless locale.nil? || locale == 'static'
25
28
  end
26
29
 
27
- # Return locale from option
30
+ # Return locale from pair
28
31
  #
29
- def locale_from_option(option, domain: DEFAULT_DOMAIN)
30
- value = option.attr('value')
32
+ def locale_from_pair(pair, domain: DEFAULT_DOMAIN)
33
+ code = pair.first
31
34
  {
32
- "name" => option.text.strip,
33
- "code" => value,
34
- "url" => "https://#{value}.#{domain}"
35
- } if value
35
+ "name" => pair.last.strip,
36
+ "code" => code,
37
+ "url" => "https://#{code}.#{domain}"
38
+ } if code
36
39
  end
37
40
 
38
41
  end
39
42
 
40
43
  end
41
- end
44
+ end
@@ -1,4 +1,5 @@
1
1
  require 'hashie'
2
+ require 'open-uri'
2
3
 
3
4
  module Openbeautyfacts
4
5
  class Mission < Hashie::Mash
@@ -15,7 +16,7 @@ module Openbeautyfacts
15
16
  def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
16
17
  if path = LOCALE_PATHS[locale]
17
18
  url = "https://#{locale}.#{domain}/#{path}"
18
- html = open(url).read
19
+ html = URI.open(url).read
19
20
  dom = Nokogiri::HTML.fragment(html)
20
21
 
21
22
  dom.css('#missions li').map do |mission_dom|
@@ -38,7 +39,7 @@ module Openbeautyfacts
38
39
  #
39
40
  def fetch
40
41
  if (self.url)
41
- html = open(self.url).read
42
+ html = URI.open(self.url).read
42
43
  dom = Nokogiri::HTML.fragment(html)
43
44
 
44
45
  description = dom.css('#description').first
@@ -24,7 +24,7 @@ module Openbeautyfacts
24
24
  class << self
25
25
  def items(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
26
26
  if path = LOCALE_PATHS[locale]
27
- html = open("https://#{locale}.#{domain}/#{path}").read
27
+ html = URI.open("https://#{locale}.#{domain}/#{path}").read
28
28
  dom = Nokogiri::HTML.fragment(html)
29
29
 
30
30
  titles = dom.css('#main_column li')
@@ -1,3 +1,4 @@
1
+ require 'cgi'
1
2
  require 'hashie'
2
3
  require 'net/http'
3
4
  require 'nokogiri'
@@ -21,7 +22,7 @@ module Openbeautyfacts
21
22
  def get(code, locale: DEFAULT_LOCALE)
22
23
  if code
23
24
  product_url = url(code, locale: locale)
24
- json = open(product_url).read
25
+ json = URI.open(product_url).read
25
26
  hash = JSON.parse(json)
26
27
 
27
28
  new(hash["product"]) if !hash["status"].nil? && hash["status"] == 1
@@ -44,7 +45,7 @@ module Openbeautyfacts
44
45
  terms = CGI.escape(terms)
45
46
  path = "cgi/search.pl?search_terms=#{terms}&jqm=1&page=#{page}&page_size=#{page_size}&sort_by=#{sort_by}"
46
47
  url = "https://#{locale}.#{domain}/#{path}"
47
- json = open(url).read
48
+ json = URI.open(url).read
48
49
  hash = JSON.parse(json)
49
50
  html = hash["jqm"]
50
51
 
@@ -78,7 +79,7 @@ module Openbeautyfacts
78
79
  end
79
80
 
80
81
  def from_jquery_mobile_list(jqm_html)
81
- from_html_list(jqm_html, 'ul li:not(#loadmore)', /code=(\d+)\Z/i)
82
+ from_html_list(jqm_html, 'ul#search_results_list li:not(#loadmore)', /code=(\d+)\Z/i)
82
83
  end
83
84
 
84
85
  def from_website_list(html, locale: 'world')
@@ -104,13 +105,13 @@ module Openbeautyfacts
104
105
  products
105
106
  end
106
107
  else
107
- html = open("#{page_url}/#{page}").read
108
+ html = URI.open("#{page_url}/#{page}").read
108
109
  from_website_list(html, locale: Locale.locale_from_link(page_url))
109
110
  end
110
111
  end
111
112
 
112
113
  def tags_from_page(_klass, page_url, &custom_tag_parsing)
113
- html = open(page_url).read
114
+ html = URI.open(page_url).read
114
115
  dom = Nokogiri::HTML.fragment(html)
115
116
 
116
117
  dom.css('table#tagstable tbody tr').map do |tag|
@@ -1,3 +1,3 @@
1
1
  module Openbeautyfacts
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -6,6 +6,12 @@ require 'minitest/autorun'
6
6
  require 'webmock/minitest'
7
7
  require 'vcr'
8
8
 
9
+ # Avoid OpenSSL certificate verify failed error
10
+ if ENV.has_key?('APPVEYOR') && Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.4')
11
+ require 'openssl'
12
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
13
+ end
14
+
9
15
  VCR.configure do |c|
10
16
  c.cassette_library_dir = "test/fixtures"
11
17
  c.hook_into :webmock
@@ -103,16 +103,17 @@ class TestOpenbeautyfacts < Minitest::Test
103
103
 
104
104
  def test_it_fetches_additives
105
105
  VCR.use_cassette("additives") do
106
- additives = ::Openbeautyfacts::Additive.all(locale: 'fr') # FR to have riskiness
107
- assert_equal "https://fr.openbeautyfacts.org/additif/e470-sels-de-sodium-potassium-calcium-d-acides-gras", additives.first.url
106
+ additives = ::Openbeautyfacts::Additive.all # World to have riskiness
107
+ assert_includes additives.map { |additive| additive['url'] }, "https://world.openbeautyfacts.org/additive/e508-potassium-chloride"
108
108
  refute_nil additives.detect { |additive| !additive['riskiness'].nil? }
109
109
  end
110
110
  end
111
111
 
112
112
  def test_it_fetches_additives_for_locale
113
113
  VCR.use_cassette("additives_locale") do
114
+ skip("Website have a bug with Additives page on https://fr.openbeautyfacts.org/additifs")
114
115
  additives = ::Openbeautyfacts::Additive.all(locale: 'fr')
115
- assert_equal "https://fr.openbeautyfacts.org/additif/e470-sels-de-sodium-potassium-calcium-d-acides-gras", additives.first.url
116
+ assert_includes additives.map { |additive| additive['url'] }, "https://fr.openbeautyfacts.org/additif/e470-sels-de-sodium-potassium-calcium-d-acides-gras"
116
117
  end
117
118
  end
118
119
 
@@ -135,6 +136,7 @@ class TestOpenbeautyfacts < Minitest::Test
135
136
 
136
137
  def test_it_fetches_brands_for_locale
137
138
  VCR.use_cassette("brands_locale") do
139
+ skip("Website have a bug with Brands page on https://fr.openbeautyfacts.org/marques")
138
140
  brands = ::Openbeautyfacts::Brand.all(locale: 'fr')
139
141
  assert_includes brands.map { |brand| brand['name'] }, "Sedapoux"
140
142
  end
@@ -153,14 +155,14 @@ class TestOpenbeautyfacts < Minitest::Test
153
155
  def test_it_fetches_product_states
154
156
  VCR.use_cassette("product_states") do
155
157
  product_states = ::Openbeautyfacts::ProductState.all
156
- assert_equal "https://world.openbeautyfacts.org/state/empty", product_states.last.url
158
+ assert_includes product_states.map { |product_state| product_state['url'] }, "https://world.openbeautyfacts.org/state/empty"
157
159
  end
158
160
  end
159
161
 
160
162
  def test_it_fetches_product_states_for_locale
161
163
  VCR.use_cassette("product_states_locale") do
162
164
  product_states = ::Openbeautyfacts::ProductState.all(locale: 'fr')
163
- assert_equal "https://fr.openbeautyfacts.org/etat/vide", product_states.last.url
165
+ assert_includes product_states.map { |product_state| product_state['url'] }, "https://fr.openbeautyfacts.org/etat/vide"
164
166
  end
165
167
  end
166
168
 
@@ -287,6 +289,7 @@ class TestOpenbeautyfacts < Minitest::Test
287
289
  # Period after openings
288
290
 
289
291
  def test_it_fetches_period_after_openings
292
+ skip "Source page is gone"
290
293
  VCR.use_cassette("period_after_openings") do
291
294
  period_after_openings = ::Openbeautyfacts::PeriodAfterOpening.all
292
295
  assert_includes period_after_openings.map { |period_after_opening| period_after_opening['name'] }, "12 months"
@@ -294,6 +297,7 @@ class TestOpenbeautyfacts < Minitest::Test
294
297
  end
295
298
 
296
299
  def test_it_fetches_period_after_openings_for_locale
300
+ skip "Source page is gone"
297
301
  VCR.use_cassette("period_after_openings_locale") do
298
302
  period_after_openings = ::Openbeautyfacts::PeriodAfterOpening.all(locale: 'fr')
299
303
  assert_includes period_after_openings.map { |period_after_opening| period_after_opening['name'] }, "12 mois"
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openbeautyfacts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Leger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-30 00:00:00.000000000 Z
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.4'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3.4'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: nokogiri
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +50,14 @@ dependencies:
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '1.8'
53
+ version: '2.1'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '1.8'
60
+ version: '2.1'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: rake
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -86,31 +92,31 @@ dependencies:
86
92
  requirements:
87
93
  - - "~>"
88
94
  - !ruby/object:Gem::Version
89
- version: '3.0'
95
+ version: '5.1'
90
96
  type: :development
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
100
  - - "~>"
95
101
  - !ruby/object:Gem::Version
96
- version: '3.0'
102
+ version: '5.1'
97
103
  - !ruby/object:Gem::Dependency
98
104
  name: webmock
99
105
  requirement: !ruby/object:Gem::Requirement
100
106
  requirements:
101
107
  - - "~>"
102
108
  - !ruby/object:Gem::Version
103
- version: '2.3'
109
+ version: '3.10'
104
110
  type: :development
105
111
  prerelease: false
106
112
  version_requirements: !ruby/object:Gem::Requirement
107
113
  requirements:
108
114
  - - "~>"
109
115
  - !ruby/object:Gem::Version
110
- version: '2.3'
116
+ version: '3.10'
111
117
  description: Open Beauty Facts API Wrapper, the open database about beauty products.
112
118
  email:
113
- - nicolas.leger@nleger.com
119
+ - opensource@nleger.com
114
120
  executables: []
115
121
  extensions: []
116
122
  extra_rdoc_files: []
@@ -150,11 +156,11 @@ files:
150
156
  - lib/openbeautyfacts/version.rb
151
157
  - test/minitest_helper.rb
152
158
  - test/test_openbeautyfacts.rb
153
- homepage: https://github.com/openbeautyfacts/openbeautyfacts-ruby
159
+ homepage: https://github.com/openfoodfacts/openbeautyfacts-ruby
154
160
  licenses:
155
161
  - MIT
156
162
  metadata: {}
157
- post_install_message:
163
+ post_install_message:
158
164
  rdoc_options: []
159
165
  require_paths:
160
166
  - lib
@@ -162,16 +168,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
168
  requirements:
163
169
  - - ">="
164
170
  - !ruby/object:Gem::Version
165
- version: '2.0'
171
+ version: '2.5'
166
172
  required_rubygems_version: !ruby/object:Gem::Requirement
167
173
  requirements:
168
174
  - - ">="
169
175
  - !ruby/object:Gem::Version
170
176
  version: '0'
171
177
  requirements: []
172
- rubyforge_project:
173
- rubygems_version: 2.6.13
174
- signing_key:
178
+ rubygems_version: 3.2.3
179
+ signing_key:
175
180
  specification_version: 4
176
181
  summary: Open Beauty Facts API Wrapper
177
182
  test_files: []