Class: OctadeskApi::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/octadesk_api/client.rb,
lib/octadesk_api/client/person_api.rb,
lib/octadesk_api/client/ticket_api.rb,
lib/octadesk_api/client/organization_api.rb

Defined Under Namespace

Classes: OrganizationApi, PersonApi, TicketApi

Instance Method Summary collapse

Constructor Details

#initialize(access_token = nil) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/octadesk_api/client.rb', line 9

def initialize access_token = nil
  @access_token = access_token || OctadeskApi.access_key || ENV['OCTADESK_ACCESS_TOKEN']
  raise OctadeskApi::MissingTokenError unless @access_token
  self.class.default_options.merge!(headers: { 'Authorization' => "Bearer #{@access_token}", 'Content-Type' => 'application/json'}, verify: OctadeskApi.production? )
end

Instance Method Details

#get(path, options = {}) ⇒ Object



32
33
34
# File 'lib/octadesk_api/client.rb', line 32

def get(path, options  = {})
  self.class.get(path, options)
end

#organizationsObject



24
25
26
# File 'lib/octadesk_api/client.rb', line 24

def organizations
  @organizations_client ||= OrganizationApi.new(self)
end

#perform_request(path) ⇒ Object



15
16
17
18
# File 'lib/octadesk_api/client.rb', line 15

def perform_request(path)
  response = self.class.get(path)
  response
end

#personsObject



20
21
22
# File 'lib/octadesk_api/client.rb', line 20

def persons
  @person_client ||= PersonApi.new(self)
end

#post(path, options = {}) ⇒ Object



36
37
38
# File 'lib/octadesk_api/client.rb', line 36

def post(path, options = {})
  self.class.post(path, body: options.to_json, headers: default_headers)
end

#put(path, options = {}) ⇒ Object



40
41
42
# File 'lib/octadesk_api/client.rb', line 40

def put(path, options = {})
  self.class.put(path, body: options.to_json, headers: default_headers)
end

#ticketsObject



28
29
30
# File 'lib/octadesk_api/client.rb', line 28

def tickets
  @tickets_client ||= TicketApi.new(self)
end