require 'httmultiparty' module Fourteeninch class Client def self.auth(email, password) begin request = HTTParty.post(Fourteeninch.api_url('auth'), {query: {email: email, password: password}}) return request.parsed_response # parse JSON rescue => e return 'error' => e.message # error end end def self.get(path, params = nil) self.execute(:get, path, params) end def self.post(path, params) self.execute(:post, path, params) end def self.put(path, params) self.execute(:put, path, params) end def self.delete(path, params = nil) self.execute(:delete, path, params) end def self.execute(method, path, params = nil) Fourteeninch.load_settings if !Fourteeninch.api_key begin request = HTTMultiParty.send(method, Fourteeninch.api_url(path), { :query => params, :basic_auth => {:username => Fourteeninch.api_key, :password => Fourteeninch.api_secret}, :timeout => 300 }) if request.respond_to?('parsed_response') return request.parsed_response # parse JSON else return request # raw end rescue => e return 'error' => e.message # error end end end end