class Shopli::OpenFoodFacts
Constants
- API_ENDPOINT
- API_URL
- API_VERSION
Public Instance Methods
fetch_product(barcode)
click to toggle source
# File lib/shopli/open_food_facts.rb, line 10 def fetch_product(barcode) url = [API_URL, API_VERSION, API_ENDPOINT, barcode + '.json'].join '/' resource = RestClient::Resource.new url resource.get end
product(barcode)
click to toggle source
# File lib/shopli/open_food_facts.rb, line 16 def product(barcode) json = fetch_product(barcode) p = JSON.parse(json) if p['status'] == 1 product = Product.new p['product']['_id'] product.name = p['product']['generic_name'] product else nil end end