Sha256: 7856177ddb8c6ce1de87ab5d6d661cb4b1c3b40f68614212f2cb0736ca2624d0

Contents?: true

Size: 1.19 KB

Versions: 13

Compression:

Stored size: 1.19 KB

Contents

require 'httmultiparty'

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 = HTTMultiParty.send(method, Siteleaf.api_url(path), {:query => 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

13 entries across 13 versions & 1 rubygems

Version Path
siteleaf-0.9.14 lib/siteleaf/client.rb
siteleaf-0.9.13 lib/siteleaf/client.rb
siteleaf-0.9.12 lib/siteleaf/client.rb
siteleaf-0.9.11 lib/siteleaf/client.rb
siteleaf-0.9.10 lib/siteleaf/client.rb
siteleaf-0.9.9 lib/siteleaf/client.rb
siteleaf-0.9.8 lib/siteleaf/client.rb
siteleaf-0.9.7 lib/siteleaf/client.rb
siteleaf-0.9.6 lib/siteleaf/client.rb
siteleaf-0.9.5 lib/siteleaf/client.rb
siteleaf-0.9.3 lib/siteleaf/client.rb
siteleaf-0.9.2 lib/siteleaf/client.rb
siteleaf-0.9.1 lib/siteleaf/client.rb