Sha256: b670391c041b7ca58f95e9ae528f75b8ce7844bb2de1917e2731efea3af6da72
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
require 'rest-client' require 'json' module Siteleaf class Client def self.auth(email, password) request = RestClient::Request.new(:url => Siteleaf.api_url('auth'), :method => :post, :user => email, :password => password) begin response = request.execute return JSON.parse(response) # parse JSON rescue => e return e.inspect # error end end def self.get(path, params = nil) self.execute(:get, path, nil, 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) self.execute(:delete, path) end def self.execute(method, path, payload = nil, params = nil) Siteleaf.load_settings if !Siteleaf.api_key request = RestClient::Request.new(:url => Siteleaf.api_url(path), :method => method, :payload => payload, :headers => { :params => params }, :user => Siteleaf.api_key, :password => Siteleaf.api_secret) #begin response = request.execute if response.headers[:content_type].to_s.include?('json') return JSON.parse(response) # parse JSON else return response # 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.8.3 | lib/siteleaf/client.rb |