forked from digitalepidemiologylab/foodrepo_api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenfood_api.rb
More file actions
29 lines (21 loc) · 818 Bytes
/
openfood_api.rb
File metadata and controls
29 lines (21 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Sample Ruby code for a call against the OpenFood API products listing, with paging
# Replace [API_KEY] with your API Key
# curl -i -g -H "Accept: application/vnd.api+json" -H 'Content-Type:application/vnd.api+json' -X GET "https://www.openfood.ch/api/v2/products?page[number]=2&page[size]=3" -H 'Authorization: Token token="[API_KEY]"'
# USAGE:
# $ ruby openfood_api.rb
require 'httparty'
require 'json'
BASE_URL='https://www.openfood.ch/api/v2'
API_KEY='secret'
url = "#{BASE_URL}/products"
query = {
"page[number]" => "2",
"size[size]" => "5"
}
headers = {
"Authorization" => "Token token=#{API_KEY}",
"Accept" => "application/vnd.api+json",
"Content-Type" => "application/vnd.api+json"
}
response = HTTParty.get(url, query: query, headers: headers, :debug_output => $stdout)
puts response.body