Class: Dotloop::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/dotloop/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, application: 'dotloop') ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
# File 'lib/dotloop/client.rb', line 11

def initialize(api_key:, application: 'dotloop')
  @api_key = api_key
  @application = application
  raise 'Please enter an API key' unless @api_key
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



8
9
10
# File 'lib/dotloop/client.rb', line 8

def api_key
  @api_key
end

#applicationObject

Returns the value of attribute application.



9
10
11
# File 'lib/dotloop/client.rb', line 9

def application
  @application
end

Class Method Details

.snakify(hash) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/dotloop/client.rb', line 80

def self.snakify(hash)
  if hash.is_a? Array
    hash.map { |item| item.to_snake_keys.symbolize_keys }
  else
    hash.to_snake_keys.symbolize_keys
  end
end

Instance Method Details

#DocumentObject



48
49
50
# File 'lib/dotloop/client.rb', line 48

def Document
  @document ||= Dotloop::Document.new(client: self)
end

#DocumentActivityObject



72
73
74
# File 'lib/dotloop/client.rb', line 72

def DocumentActivity
  @document_activity ||= Dotloop::DocumentActivity.new(client: self)
end

#EmployeeObject



68
69
70
# File 'lib/dotloop/client.rb', line 68

def Employee
  @employee ||= Dotloop::Employee.new(client: self)
end

#FolderObject



64
65
66
# File 'lib/dotloop/client.rb', line 64

def Folder
  @folder ||= Dotloop::Folder.new(client: self)
end

#get(page, params = {}) ⇒ Object



17
18
19
20
# File 'lib/dotloop/client.rb', line 17

def get(page, params = {})
  response = raw(page, params)
  self.class.snakify(response)
end

#handle_dotloop_error(response_code) ⇒ Object

Raises:

  • (error)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dotloop/client.rb', line 28

def handle_dotloop_error(response_code)
  error = case response_code
          when 401
            Dotloop::Unauthorized
          when 403
            Dotloop::Forbidden
          else
            StandardError
          end
  raise error, "Error communicating: Response code #{response_code}"
end

#LoopObject



44
45
46
# File 'lib/dotloop/client.rb', line 44

def Loop
  @loop ||= Dotloop::Loop.new(client: self)
end

#LoopActivityObject



56
57
58
# File 'lib/dotloop/client.rb', line 56

def LoopActivity
  @loop_activity ||= Dotloop::LoopActivity.new(client: self)
end

#ParticipantObject



52
53
54
# File 'lib/dotloop/client.rb', line 52

def Participant
  @participant ||= Dotloop::Participant.new(client: self)
end

#PersonObject



76
77
78
# File 'lib/dotloop/client.rb', line 76

def Person
  @person ||= Dotloop::Person.new(client: self)
end

#ProfileObject



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

def Profile
  @profile ||= Dotloop::Profile.new(client: self)
end

#raw(page, params = {}) ⇒ Object



22
23
24
25
26
# File 'lib/dotloop/client.rb', line 22

def raw(page, params = {})
  response = self.class.get(page, query: params, headers: headers, timeout: 60)
  handle_dotloop_error(response.code) if response.code != 200
  response.parsed_response
end

#TaskObject



60
61
62
# File 'lib/dotloop/client.rb', line 60

def Task
  @task ||= Dotloop::Task.new(client: self)
end