class Datakick
Constants
- API_HOST
API_HOST
= “0.0.0.0:5000”- API_VERSION
- VERSION
Public Class Methods
new()
click to toggle source
# File lib/datakick.rb, line 12 def initialize end
Public Instance Methods
add_image(gtin, image, image_type)
click to toggle source
# File lib/datakick.rb, line 29 def add_image(gtin, image, image_type) params = { gtin: gtin, image: image, perspective: image_type } response = http_client.post("/api/items/#{gtin}/images?version=#{API_VERSION}", params) if response.success? JSON.parse(response.body) end end
item(gtin)
click to toggle source
# File lib/datakick.rb, line 15 def item(gtin) response = http_client.get("/api/items/#{gtin}?version=#{API_VERSION}") if response.success? Item.new(JSON.parse(response.body)) end end
items(params = {})
click to toggle source
# File lib/datakick.rb, line 41 def items(params = {}) response = http_client.get("/api/items?version=#{API_VERSION}", params) if response.success? JSON.parse(response.body).map do |item| Item.new(item) end end end
paginated_items(params) { |item| ... }
click to toggle source
# File lib/datakick.rb, line 50 def paginated_items(params, &block) response = http_client.get("/api/items?version=#{API_VERSION}", params) begin links = {} if response.success? JSON.parse(response.body).map do |item| yield Item.new(item) end # https://gist.github.com/davidcelis/5896686 response.headers['Link'].to_s.split(',').each do |link| link.strip! parts = link.match(/<(.+)>; *rel="(.+)"/) links[parts[2]] = parts[1] end end # p links end while links["next"] and (response = http_client.get(links["next"])) end
update_item(gtin, attributes)
click to toggle source
# File lib/datakick.rb, line 22 def update_item(gtin, attributes) response = http_client.put("/api/items/#{gtin}?version=#{API_VERSION}", attributes) if response.success? Item.new(JSON.parse(response.body)) end end
Protected Instance Methods
http_client()
click to toggle source
# File lib/datakick.rb, line 72 def http_client Faraday.new(url: API_HOST) do |conn| conn.request :multipart conn.request :url_encoded conn.adapter :net_http end end