openfoodfacts 0.3.1 → 0.4.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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/lib/openfoodfacts.rb +2 -1
  4. data/lib/openfoodfacts/additive.rb +4 -4
  5. data/lib/openfoodfacts/allergen.rb +3 -3
  6. data/lib/openfoodfacts/brand.rb +2 -2
  7. data/lib/openfoodfacts/category.rb +3 -3
  8. data/lib/openfoodfacts/city.rb +3 -3
  9. data/lib/openfoodfacts/contributor.rb +3 -3
  10. data/lib/openfoodfacts/country.rb +3 -3
  11. data/lib/openfoodfacts/faq.rb +5 -5
  12. data/lib/openfoodfacts/ingredient_that_may_be_from_palm_oil.rb +3 -3
  13. data/lib/openfoodfacts/label.rb +5 -10
  14. data/lib/openfoodfacts/locale.rb +2 -2
  15. data/lib/openfoodfacts/manufacturing_place.rb +3 -3
  16. data/lib/openfoodfacts/origin.rb +3 -3
  17. data/lib/openfoodfacts/packager_code.rb +3 -3
  18. data/lib/openfoodfacts/packaging.rb +3 -3
  19. data/lib/openfoodfacts/press.rb +7 -7
  20. data/lib/openfoodfacts/product.rb +17 -22
  21. data/lib/openfoodfacts/product_state.rb +3 -3
  22. data/lib/openfoodfacts/purchase_place.rb +3 -3
  23. data/lib/openfoodfacts/store.rb +3 -3
  24. data/lib/openfoodfacts/trace.rb +3 -3
  25. data/lib/openfoodfacts/user.rb +5 -4
  26. data/lib/openfoodfacts/version.rb +1 -1
  27. data/test/fixtures/fetch_product_3029330003533.yml +1 -1
  28. data/test/fixtures/index.yml +1 -1
  29. data/test/fixtures/login_user.yml +1 -1
  30. data/test/fixtures/product_3029330003533.yml +1 -1
  31. data/test/fixtures/product_states.yml +1 -1
  32. data/test/fixtures/products_for_state.yml +2 -2
  33. data/test/fixtures/search_Chocolat.yml +2 -2
  34. data/test/fixtures/search_Chocolat_1_000_000.yml +1 -1
  35. data/test/test_openfoodfacts.rb +8 -18
  36. metadata +4 -28
  37. data/test/fixtures/additives.yml +0 -1963
  38. data/test/fixtures/additives_locale.yml +0 -1963
  39. data/test/fixtures/brands.yml +0 -31542
  40. data/test/fixtures/brands_locale.yml +0 -17498
  41. data/test/fixtures/faq.yml +0 -1078
  42. data/test/fixtures/labels.yml +0 -9091
  43. data/test/fixtures/press.yml +0 -1284
  44. data/test/fixtures/product_states_locale.yml +0 -1002
  45. data/test/fixtures/products_for_brand.yml +0 -5481
  46. data/test/fixtures/products_with_additive.yml +0 -3130
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e50cecb07962505751ce697e3b99797015126ba3
4
- data.tar.gz: 96ec0cee88a120ef8de7fe0327e051f99468a535
3
+ metadata.gz: 1ab380f0014effa3920df74d1ba593e4f26d50e9
4
+ data.tar.gz: 384401825b4f8fdc2e3ea18555f79f9714567f59
5
5
  SHA512:
6
- metadata.gz: 2dc910d560c309261f07f6b04f811219e553d5a7664107fe81223425c34d4635e25ae6d134135ef77fbba411a4740e405a2d07128dccde5a20758964cdca7e35
7
- data.tar.gz: 42babde6c10c97618d0478734cfd2fe7a6679fc7cb93f65527bed7bee67a7ae3e6eddde113378fb741116a230d2c91391645288d0cd8fbbd3db4dfab18ca5c24
6
+ metadata.gz: 131ae9169cf6279ca8dac267d145e2c18513a2503e225c45f6de7e0ba8e16804ac7e9579a92295eea0078cbe5aa3113e59ee2a253b8ce5ca9cef2e28a775e9f2
7
+ data.tar.gz: c97be50ed729e1a64b40b28c520929df384a6fc02f6f48b364aaf1833e3609879b3c1ccdc3bc3ac61d9e1956f7c5cfb8961d390705ec4684db30cbfaccbaea84
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
- # OpenFoodFacts
1
+ # Open Food Facts
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/openfoodfacts.svg)](http://badge.fury.io/rb/openfoodfacts)
4
4
  [![Build Status](https://travis-ci.org/openfoodfacts/openfoodfacts-ruby.svg?branch=master)](https://travis-ci.org/openfoodfacts/openfoodfacts-ruby)
5
5
  [![Dependency Status](https://gemnasium.com/openfoodfacts/openfoodfacts-ruby.svg)](https://gemnasium.com/openfoodfacts/openfoodfacts-ruby)
6
6
  [![Code Climate](https://codeclimate.com/github/openfoodfacts/openfoodfacts-ruby/badges/gpa.svg)](https://codeclimate.com/github/openfoodfacts/openfoodfacts-ruby)
7
- [![Coverage Status](https://coveralls.io/repos/nicolasleger/openfoodfacts-ruby/badge.svg)](https://coveralls.io/r/nicolasleger/openfoodfacts-ruby)
7
+ [![Coverage Status](https://coveralls.io/repos/github/openfoodfacts/openfoodfacts-ruby/badge.svg?branch=master)](https://coveralls.io/github/openfoodfacts/openfoodfacts-ruby?branch=master)
8
8
  [![Documentation](http://inch-ci.org/github/openfoodfacts/openfoodfacts-ruby.svg?branch=master)](http://inch-ci.org/github/openfoodfacts/openfoodfacts-ruby)
9
9
 
10
- API Wrapper for [OpenFoodFacts](https://openfoodfacts.org/), the open database about food.
10
+ API Wrapper for [Open Food Facts](https://openfoodfacts.org/), the open database about food.
11
11
 
12
12
  ## Installation
13
13
 
@@ -79,7 +79,7 @@ end
79
79
  # Search products
80
80
 
81
81
  products = Openfoodfacts::Product.search("Chocolate", locale: 'world', page_size: 3)
82
- # => [#<Openfoodfacts::Product _id="3045140105502" code="3045140105502" id="3045140105502" image_small_url="http://en.openfoodfacts.org/images/products/304/514/010/5502/front.7.100.jpg" lc="en" product_name="Milka au lait du Pays Alpin">, #<Openfoodfacts::Product _id="3046920028363" code="3046920028363" id="3046920028363" image_small_url="http://en.openfoodfacts.org/images/products/304/692/002/8363/front.5.100.jpg" lc="en" product_name="Tableta de chocolate negro \"Lindt Excellence\" 85% cacao">, #<Openfoodfacts::Product _id="3046920029759" code="3046920029759" id="3046920029759" image_small_url="http://en.openfoodfacts.org/images/products/304/692/002/9759/front.9.100.jpg" lc="en" product_name="Tableta de chocolate negro \"Lindt Excellence\" 90% cacao">]
82
+ # => [#<Openfoodfacts::Product _id="3045140105502" code="3045140105502" id="3045140105502" image_small_url="https://en.openfoodfacts.org/images/products/304/514/010/5502/front.7.100.jpg" lc="en" product_name="Milka au lait du Pays Alpin">, #<Openfoodfacts::Product _id="3046920028363" code="3046920028363" id="3046920028363" image_small_url="https://en.openfoodfacts.org/images/products/304/692/002/8363/front.5.100.jpg" lc="en" product_name="Tableta de chocolate negro \"Lindt Excellence\" 85% cacao">, #<Openfoodfacts::Product _id="3046920029759" code="3046920029759" id="3046920029759" image_small_url="https://en.openfoodfacts.org/images/products/304/692/002/9759/front.9.100.jpg" lc="en" product_name="Tableta de chocolate negro \"Lindt Excellence\" 90% cacao">]
83
83
 
84
84
  # You might need to fetch full product data from results
85
85
 
@@ -28,6 +28,7 @@ require 'open-uri'
28
28
  module Openfoodfacts
29
29
 
30
30
  DEFAULT_LOCALE = Locale::GLOBAL
31
+ DEFAULT_DOMAIN = 'openfoodfacts.org'
31
32
 
32
33
  class << self
33
34
 
@@ -56,4 +57,4 @@ module Openfoodfacts
56
57
  end
57
58
 
58
59
  end
59
- end
60
+ end
@@ -15,9 +15,9 @@ module Openfoodfacts
15
15
 
16
16
  # Get additives
17
17
  #
18
- def all(locale: Openfoodfacts::DEFAULT_LOCALE)
18
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
19
  if path = LOCALE_PATHS[locale]
20
- page_url = "http://#{locale}.openfoodfacts.org/#{path}"
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')
@@ -28,7 +28,7 @@ module Openfoodfacts
28
28
  "url" => URI.join(page_url, link.attr('href')).to_s,
29
29
  "products_count" => columns[1].text.to_i,
30
30
  }
31
-
31
+
32
32
  riskiness = columns[2].attr('class')
33
33
  if riskiness
34
34
  attributes["riskiness"] = riskiness[/level_(\d+)/, 1].to_i
@@ -48,4 +48,4 @@ module Openfoodfacts
48
48
  end
49
49
 
50
50
  end
51
- end
51
+ end
@@ -15,9 +15,9 @@ module Openfoodfacts
15
15
 
16
16
  # Get allergens
17
17
  #
18
- def all(locale: Openfoodfacts::DEFAULT_LOCALE)
18
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
19
  if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "http://#{locale}.openfoodfacts.org/#{path}")
20
+ Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
21
  end
22
22
  end
23
23
 
@@ -30,4 +30,4 @@ module Openfoodfacts
30
30
  end
31
31
 
32
32
  end
33
- end
33
+ end
@@ -15,9 +15,9 @@ module Openfoodfacts
15
15
 
16
16
  # Get product brands
17
17
  #
18
- def all(locale: Openfoodfacts::DEFAULT_LOCALE)
18
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
19
  if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "http://#{locale}.openfoodfacts.org/#{path}")
20
+ Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
21
  end
22
22
  end
23
23
 
@@ -15,9 +15,9 @@ module Openfoodfacts
15
15
 
16
16
  # Get categories
17
17
  #
18
- def all(locale: Openfoodfacts::DEFAULT_LOCALE)
18
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
19
  if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "http://#{locale}.openfoodfacts.org/#{path}")
20
+ Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
21
  end
22
22
  end
23
23
 
@@ -30,4 +30,4 @@ module Openfoodfacts
30
30
  end
31
31
 
32
32
  end
33
- end
33
+ end
@@ -15,9 +15,9 @@ module Openfoodfacts
15
15
 
16
16
  # Get cities
17
17
  #
18
- def all(locale: Openfoodfacts::DEFAULT_LOCALE)
18
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
19
  if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "http://#{locale}.openfoodfacts.org/#{path}")
20
+ Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
21
  end
22
22
  end
23
23
 
@@ -30,4 +30,4 @@ module Openfoodfacts
30
30
  end
31
31
 
32
32
  end
33
- end
33
+ end
@@ -15,9 +15,9 @@ module Openfoodfacts
15
15
 
16
16
  # Get contributors
17
17
  #
18
- def all(locale: Openfoodfacts::DEFAULT_LOCALE)
18
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
19
  if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "http://#{locale}.openfoodfacts.org/#{path}")
20
+ Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
21
  end
22
22
  end
23
23
 
@@ -30,4 +30,4 @@ module Openfoodfacts
30
30
  end
31
31
 
32
32
  end
33
- end
33
+ end
@@ -15,9 +15,9 @@ module Openfoodfacts
15
15
 
16
16
  # Get countries
17
17
  #
18
- def all(locale: Openfoodfacts::DEFAULT_LOCALE)
18
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
19
  if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "http://#{locale}.openfoodfacts.org/#{path}")
20
+ Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
21
  end
22
22
  end
23
23
 
@@ -30,4 +30,4 @@ module Openfoodfacts
30
30
  end
31
31
 
32
32
  end
33
- end
33
+ end
@@ -14,15 +14,15 @@ module Openfoodfacts
14
14
  }
15
15
 
16
16
  class << self
17
- def items(locale: Openfoodfacts::DEFAULT_LOCALE)
17
+ def items(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
18
18
  if path = LOCALE_PATHS[locale]
19
- html = open("http://#{locale}.openfoodfacts.org/#{path}").read
19
+ html = open("https://#{locale}.#{domain}/#{path}").read
20
20
  dom = Nokogiri::HTML.fragment(html)
21
-
21
+
22
22
  titles = dom.css('#main_column h2')
23
23
  titles.each_with_index.map do |item, index|
24
24
  paragraphs = []
25
-
25
+
26
26
  element = item.next_sibling
27
27
  while !element.nil? && element.node_name != 'h2'
28
28
  if element.node_name == 'p'
@@ -47,4 +47,4 @@ module Openfoodfacts
47
47
  end
48
48
 
49
49
  end
50
- end
50
+ end
@@ -15,9 +15,9 @@ module Openfoodfacts
15
15
 
16
16
  # Get ingredients that may be from palm oil
17
17
  #
18
- def all(locale: Openfoodfacts::DEFAULT_LOCALE)
18
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
19
  if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "http://#{locale}.openfoodfacts.org/#{path}")
20
+ Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
21
  end
22
22
  end
23
23
 
@@ -30,4 +30,4 @@ module Openfoodfacts
30
30
  end
31
31
 
32
32
  end
33
- end
33
+ end
@@ -1,10 +1,8 @@
1
1
  require 'hashie'
2
- require 'json'
3
- require 'open-uri'
4
2
 
5
3
  module Openfoodfacts
6
4
  class Label < Hashie::Mash
7
-
5
+
8
6
  # TODO: Add more locales
9
7
  LOCALE_PATHS = {
10
8
  'fr' => 'labels',
@@ -17,12 +15,9 @@ module Openfoodfacts
17
15
 
18
16
  # Get labels
19
17
  #
20
- def all(locale: Openfoodfacts::DEFAULT_LOCALE)
18
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
21
19
  if path = LOCALE_PATHS[locale]
22
- body = open("http://#{locale}.openfoodfacts.org/#{path}.json").read
23
- json = JSON.parse(body)
24
- json_labels = json['tags']
25
- json_labels.map(&method(:new))
20
+ Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
26
21
  end
27
22
  end
28
23
 
@@ -31,8 +26,8 @@ module Openfoodfacts
31
26
  # Get products with label
32
27
  #
33
28
  def products(page: -1)
34
- Product.from_api("#{url}.json", page: page) if url
29
+ Product.from_website_page(url, page: page, products_count: products_count) if url
35
30
  end
36
31
 
37
32
  end
38
- end
33
+ end
@@ -7,8 +7,8 @@ module Openfoodfacts
7
7
 
8
8
  # Get locales
9
9
  #
10
- def all
11
- url = "http://openfoodfacts.org/"
10
+ def all(domain: DEFAULT_DOMAIN)
11
+ url = "https://#{domain}/"
12
12
  body = open(url).read
13
13
  dom = Nokogiri.parse(body)
14
14
 
@@ -15,9 +15,9 @@ module Openfoodfacts
15
15
 
16
16
  # Get manufacturing places
17
17
  #
18
- def all(locale: Openfoodfacts::DEFAULT_LOCALE)
18
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
19
  if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "http://#{locale}.openfoodfacts.org/#{path}")
20
+ Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
21
  end
22
22
  end
23
23
 
@@ -30,4 +30,4 @@ module Openfoodfacts
30
30
  end
31
31
 
32
32
  end
33
- end
33
+ end
@@ -15,9 +15,9 @@ module Openfoodfacts
15
15
 
16
16
  # Get origins
17
17
  #
18
- def all(locale: Openfoodfacts::DEFAULT_LOCALE)
18
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
19
  if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "http://#{locale}.openfoodfacts.org/#{path}")
20
+ Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
21
  end
22
22
  end
23
23
 
@@ -30,4 +30,4 @@ module Openfoodfacts
30
30
  end
31
31
 
32
32
  end
33
- end
33
+ end
@@ -15,9 +15,9 @@ module Openfoodfacts
15
15
 
16
16
  # Get packager codes
17
17
  #
18
- def all(locale: Openfoodfacts::DEFAULT_LOCALE)
18
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
19
  if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "http://#{locale}.openfoodfacts.org/#{path}")
20
+ Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
21
  end
22
22
  end
23
23
 
@@ -30,4 +30,4 @@ module Openfoodfacts
30
30
  end
31
31
 
32
32
  end
33
- end
33
+ end
@@ -15,9 +15,9 @@ module Openfoodfacts
15
15
 
16
16
  # Get packagings
17
17
  #
18
- def all(locale: Openfoodfacts::DEFAULT_LOCALE)
18
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
19
  if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "http://#{locale}.openfoodfacts.org/#{path}")
20
+ Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
21
  end
22
22
  end
23
23
 
@@ -30,4 +30,4 @@ module Openfoodfacts
30
30
  end
31
31
 
32
32
  end
33
- end
33
+ end
@@ -16,17 +16,17 @@ module Openfoodfacts
16
16
 
17
17
  LOCALE_DATE_FORMATS = {
18
18
  'fr' => '%d/%m/%Y',
19
- 'uk' => '%m/%d/%Y',
20
- 'us' => '%m/%d/%Y',
21
- 'world' => '%m/%d/%Y'
19
+ 'uk' => '%d/%m/%Y',
20
+ 'us' => '%d/%m/%Y',
21
+ 'world' => '%d/%m/%Y'
22
22
  }
23
23
 
24
24
  class << self
25
- def items(locale: Openfoodfacts::DEFAULT_LOCALE)
25
+ def items(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
26
26
  if path = LOCALE_PATHS[locale]
27
- html = open("http://#{locale}.openfoodfacts.org/#{path}").read
27
+ html = open("https://#{locale}.#{domain}/#{path}").read
28
28
  dom = Nokogiri::HTML.fragment(html)
29
-
29
+
30
30
  titles = dom.css('#main_column li')
31
31
  titles.each_with_index.map do |item, index|
32
32
  data = item.inner_html.split(' - ')
@@ -53,4 +53,4 @@ module Openfoodfacts
53
53
  end
54
54
 
55
55
  end
56
- end
56
+ end
@@ -16,20 +16,9 @@ module Openfoodfacts
16
16
 
17
17
  class << self
18
18
 
19
- # Products from API
20
- #
21
- def from_api(api_url, page: -1)
22
- if url
23
- body = open(api_url).read
24
- json = JSON.parse(body)
25
- json_products = json['products']
26
- json_products.map(&method(:new))
27
- end
28
- end
29
-
30
19
  # Get product
31
20
  #
32
- def get(code, locale: Openfoodfacts::DEFAULT_LOCALE)
21
+ def get(code, locale: DEFAULT_LOCALE)
33
22
  if code
34
23
  product_url = url(code, locale: locale)
35
24
  json = open(product_url).read
@@ -42,15 +31,19 @@ module Openfoodfacts
42
31
 
43
32
  # Return product API URL
44
33
  #
45
- def url(code, locale: Openfoodfacts::DEFAULT_LOCALE)
46
- "http://#{locale}.openfoodfacts.org/api/v0/produit/#{code}.json" if code
34
+ def url(code, locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
35
+ if code
36
+ path = "api/v0/produit/#{code}.json"
37
+ "https://#{locale}.#{domain}/#{path}"
38
+ end
47
39
  end
48
40
 
49
41
  # Search products
50
42
  #
51
- def search(terms, locale: Openfoodfacts::DEFAULT_LOCALE, page: 1, page_size: 20, sort_by: 'unique_scans_n')
43
+ def search(terms, locale: DEFAULT_LOCALE, page: 1, page_size: 20, sort_by: 'unique_scans_n', domain: DEFAULT_DOMAIN)
52
44
  terms = URI::encode(terms)
53
- url = "http://#{locale}.openfoodfacts.org/cgi/search.pl?search_terms=#{terms}&jqm=1&page=#{page}&page_size=#{page_size}&sort_by=#{sort_by}"
45
+ path = "cgi/search.pl?search_terms=#{terms}&jqm=1&page=#{page}&page_size=#{page_size}&sort_by=#{sort_by}"
46
+ url = "https://#{locale}.#{domain}/#{path}"
54
47
  json = open(url).read
55
48
  hash = JSON.parse(json)
56
49
  html = hash["jqm"]
@@ -154,10 +147,11 @@ module Openfoodfacts
154
147
  # User can be nil
155
148
  # Tested not updatable fields: countries, ingredients_text, purchase_places, purchase_places_tag, purchase_places_tags
156
149
  #
157
- def update(user: nil)
150
+ def update(user: nil, domain: DEFAULT_DOMAIN)
158
151
  if self.code && self.lc
159
152
  subdomain = self.lc == 'world' ? 'world' : "world-#{self.lc}"
160
- uri = URI("http://#{subdomain}.openfoodfacts.org/cgi/product_jqm.pl")
153
+ path = 'cgi/product_jqm.pl'
154
+ uri = URI("https://#{subdomain}.#{domain}/#{path}")
161
155
  params = self.to_hash
162
156
  params.merge!("user_id" => user.user_id, "password" => user.password) if user
163
157
  response = Net::HTTP.post_form(uri, params)
@@ -172,17 +166,18 @@ module Openfoodfacts
172
166
 
173
167
  # Return Product API URL
174
168
  #
175
- def url(locale: Openfoodfacts::DEFAULT_LOCALE)
169
+ def url(locale: DEFAULT_LOCALE)
176
170
  self.class.url(self.code, locale: locale)
177
171
  end
178
172
 
179
173
  # Return Product web URL according to locale
180
174
  #
181
- def weburl(locale: nil)
182
- locale ||= self.lc || Openfoodfacts::DEFAULT_LOCALE
175
+ def weburl(locale: nil, domain: DEFAULT_DOMAIN)
176
+ locale ||= self.lc || DEFAULT_LOCALE
183
177
 
184
178
  if self.code && prefix = LOCALE_WEBURL_PREFIXES[locale]
185
- "http://#{locale}.openfoodfacts.org/#{prefix}/#{self.code}"
179
+ path = "#{prefix}/#{self.code}"
180
+ "https://#{locale}.#{domain}/#{path}"
186
181
  end
187
182
  end
188
183