Class: Dotloop::Client

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

Constant Summary collapse

DOTLOOP_FILE_UPLOAD_BOUNDARY =
"AaB03x"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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



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

def initialize(access_token:, application: 'dotloop')
  @access_token = access_token
  @application  = application
  raise 'Please enter an Access Token' unless @access_token
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



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

def access_token
  @access_token
end

#applicationObject

Returns the value of attribute application.



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

def application
  @application
end

Class Method Details

.snakify(hash) ⇒ Object



117
118
119
120
121
122
123
# File 'lib/dotloop/client.rb', line 117

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

Instance Method Details

#accountObject



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

def 
  get('/account', {})
end

#ContactObject



113
114
115
# File 'lib/dotloop/client.rb', line 113

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

#delete(page) ⇒ Object



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

def delete(page)
  response = self.class.delete(page, headers: headers, timeout: 60)
  handle_dotloop_error(response) if response.code != 204
  self.class.snakify(response.parsed_response)
end

#DocumentObject



81
82
83
# File 'lib/dotloop/client.rb', line 81

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

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



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

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

#FolderObject



85
86
87
# File 'lib/dotloop/client.rb', line 85

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

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



26
27
28
29
30
# File 'lib/dotloop/client.rb', line 26

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

#handle_dotloop_error(response) ⇒ Object

Raises:

  • (error)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/dotloop/client.rb', line 56

def handle_dotloop_error(response)
  response_code = response.code
  error = case response_code
          when 400
            Dotloop::BadRequest
          when 401
            Dotloop::Unauthorized
          when 403
            Dotloop::Forbidden
          when 404
            Dotloop::NotFound
          when 422
            Dotloop::UnprocessableEntity
          when 429
            Dotloop::TooManyRequest
          else
            StandardError
          end
  raise error, "Error communicating: Response code #{response_code}"
end

#LoopObject



93
94
95
# File 'lib/dotloop/client.rb', line 93

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

#ParticipantObject



97
98
99
# File 'lib/dotloop/client.rb', line 97

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

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



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

def patch(page, params = {})
  response = self.class.patch(page, body: params.to_json, headers: post_headers, timeout: 60)
  handle_dotloop_error(response) if response.code != 200
  self.class.snakify(response.parsed_response)
end

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



32
33
34
35
36
# File 'lib/dotloop/client.rb', line 32

def post(page, params = {})
  response = self.class.post(page, body: params.to_json, headers: post_headers, timeout: 60)
  handle_dotloop_error(response) if response.code != 201
  self.class.snakify(response.parsed_response)
end

#ProfileObject



89
90
91
# File 'lib/dotloop/client.rb', line 89

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

#TaskObject



105
106
107
# File 'lib/dotloop/client.rb', line 105

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

#TasklistObject



101
102
103
# File 'lib/dotloop/client.rb', line 101

def Tasklist
  @tasklist ||= Dotloop::Tasklist.new(client: self)
end

#TemplateObject



109
110
111
# File 'lib/dotloop/client.rb', line 109

def Template
  @template ||= Dotloop::Template.new(client: self)
end

#upload(page, body) ⇒ Object



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

def upload(page, body)
  response = self.class.post(page, body: body, headers: upload_headers, timeout: 600)
  handle_dotloop_error(response) if response.code != 201
  self.class.snakify(response.parsed_response)
end