class Giftwrap

Constants

VERSION

Public Class Methods

new(endpoint, *args, &block) click to toggle source
# File lib/giftwrap.rb, line 4
def initialize(endpoint, *args, &block)
  @endpoint = endpoint
end

Public Instance Methods

get(path, params = {}) click to toggle source
# File lib/giftwrap.rb, line 8
def get(path, params = {})
  path = "/api/#{path}.json?#{URI.encode_www_form(params)}"
  response = request(path)
  process(JSON.parse(response.body)) if response.code == "200"
rescue Exception => exception
end

Private Instance Methods

http() click to toggle source
# File lib/giftwrap.rb, line 21
def http
  @http ||= begin
    http = Net::HTTP.new(@endpoint, 443)
    http.use_ssl = true
    http
  end
end
process(json) click to toggle source
# File lib/giftwrap.rb, line 29
def process(json)
  if json.is_a? Array
    json.map { |element| process(element) }
  elsif json.is_a? Hash
    OpenStruct.new(Hash[json.map { |key, value| [key, process(value)] }])
  else
    json
  end
end
request(path) click to toggle source
# File lib/giftwrap.rb, line 17
def request(path)
  http.request(Net::HTTP::Get.new(path))
end