Skip to content

Instantly share code, notes, and snippets.

@sahidursuman
Forked from derwiki/pixelpeeper_basic.rb
Created May 31, 2018 08:59
Show Gist options
  • Save sahidursuman/9f1e88bb0f359e3fe25363418f1fdbdf to your computer and use it in GitHub Desktop.
Save sahidursuman/9f1e88bb0f359e3fe25363418f1fdbdf to your computer and use it in GitHub Desktop.
Example thin JSON API client in Ruby
require 'httparty'
class PixelPeeper
include HTTParty
base_uri 'www.pixel-peeper.com'
def api_key
ENV['PIXELPEEPER_API_KEY']
end
def base_path
"/rest/?method=list_photos&api_key=#{ api_key }"
end
def examples_for_camera(camera_id, options = {})
url = "#{ base_path }&camera=#{ camera_id }"
self.class.get(url, options)['data']['results']
end
def examples_for_lens(lens_id, options = {})
url = "#{ base_path }&lens=#{ lens_id }"
self.class.get(url, options)['data']['results']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment