class Rottendesk::Client
Public Class Methods
new(url)
click to toggle source
# File lib/rottendesk/client.rb, line 4 def initialize(url) @rest_client = RestClient::Resource.new(url) end
Public Instance Methods
delete(url, options = {})
click to toggle source
# File lib/rottendesk/client.rb, line 20 def delete(url, options = {}) request(url, options.merge(method: :delete)) end
get(url, options = {})
click to toggle source
# File lib/rottendesk/client.rb, line 8 def get(url, options = {}) request(url, options.merge(method: :get)) end
patch(url, body, options = {})
click to toggle source
# File lib/rottendesk/client.rb, line 16 def patch(url, body, options = {}) request(url, options.merge(method: :patch, body: body)) end
post(url, body, options = {})
click to toggle source
# File lib/rottendesk/client.rb, line 12 def post(url, body, options = {}) request(url, options.merge(method: :post, body: body)) end
request(url, options = {})
click to toggle source
# File lib/rottendesk/client.rb, line 24 def request(url, options = {}) defaults = { method: :get, content_type: :json, accept: :json } options = defaults.merge(options) Rottendesk.logger.info "Rottendesk: #{options[:method].upcase} /#{url}.json with #{options.except(:method)}" args = [options[:method], options[:body], options.except(:method, :body)].compact response = @rest_client[url + '.json'].send(*args) Rottendesk.logger.info "Rottendesk: #{response.code}" response rescue RestClient::Exception => e Rottendesk.logger.warn "Rottendesk: #{e.response.code}" raise e end