Sha256: b18353d8b3c69c5ac7d63659e86f84094b59f2097c1d8c52dcbc86d4620d4e79

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require 'httparty'

module Siteleaf
  class Client  
    def self.auth(email, password)
      begin
        request = HTTParty.post(Siteleaf.api_url('auth'), {:basic_auth => {:username => email, :password => password}})
        return request.parsed_response # parse JSON
      rescue => e
        return e.inspect # 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)
      Siteleaf.load_settings if !Siteleaf.api_key
      begin
        request = HTTParty.send(method, Siteleaf.api_url(path), {:body => params, :basic_auth => {:username => Siteleaf.api_key, :password => Siteleaf.api_secret}})
        if request.respond_to?('parsed_response')
          return request.parsed_response # parse JSON
        else
          return request # raw
        end
      rescue => e
        return e.inspect # error
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
siteleaf-0.9.0 lib/siteleaf/client.rb