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



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

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.



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

def api_key
  @api_key
end

#applicationObject

Returns the value of attribute application.



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

def application
  @application
end

Class Method Details

.snakify(hash) ⇒ Object



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

def self.snakify(hash)
  if hash.is_a? Array
    hash.map(&:to_snake_keys)
  else
    hash.to_snake_keys
  end
end

Instance Method Details

#DocumentObject



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

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

#DocumentActivityObject



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

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

#EmployeeObject



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

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

#FolderObject



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

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

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



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

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

#handle_dotloop_error(response_code) ⇒ Object

Raises:

  • (error)


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

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



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

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

#LoopActivityObject



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

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

#ParticipantObject



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

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

#PersonObject



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

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

#ProfileObject



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

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

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



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

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



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

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