class Fourteeninch::Client

Public Class Methods

auth(email, password) click to toggle source
# File lib/fourteeninch/client.rb, line 5
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
delete(path, params = nil) click to toggle source
# File lib/fourteeninch/client.rb, line 26
def self.delete(path, params = nil)
  self.execute(:delete, path, params)
end
execute(method, path, params = nil) click to toggle source
# File lib/fourteeninch/client.rb, line 30
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
get(path, params = nil) click to toggle source
# File lib/fourteeninch/client.rb, line 14
def self.get(path, params = nil)
  self.execute(:get, path, params)
end
post(path, params) click to toggle source
# File lib/fourteeninch/client.rb, line 18
def self.post(path, params)
  self.execute(:post, path, params)
end
put(path, params) click to toggle source
# File lib/fourteeninch/client.rb, line 22
def self.put(path, params)
 self.execute(:put, path, params)
end