class Freshdesk::Rest::Api

Public Class Methods

new(rest_client:, api_key:, domain:) click to toggle source
# File lib/freshdesk-rest/api.rb, line 4
def initialize(rest_client:, api_key:, domain:)
  @client = rest_client
  @api_key = api_key
  @domain = domain
end

Public Instance Methods

delete(path) click to toggle source
# File lib/freshdesk-rest/api.rb, line 22
def delete(path)
  resource(path).delete.body
  '{}'
end
get(path) click to toggle source
# File lib/freshdesk-rest/api.rb, line 10
def get(path)
  resource(path).get.body
end
post(path, data) click to toggle source
# File lib/freshdesk-rest/api.rb, line 14
def post(path, data)
  resource(path).post(data.to_json, content_type: 'application/json').body
end
put(path, data) click to toggle source
# File lib/freshdesk-rest/api.rb, line 18
def put(path, data)
  resource(path).put(data.to_json, content_type: 'application/json').body
end

Private Instance Methods

base_url() click to toggle source
# File lib/freshdesk-rest/api.rb, line 33
def base_url
  @base_url ||= "https://#{@domain}.freshdesk.com/api/v2".freeze
end
resource(path) click to toggle source
# File lib/freshdesk-rest/api.rb, line 29
def resource(path)
  @client::Resource.new([base_url, path].join, @api_key, 'X')
end