Class: Dotloop::Client
- Inherits:
-
Object
- Object
- Dotloop::Client
- Includes:
- HTTParty
- Defined in:
- lib/dotloop/client.rb
Constant Summary collapse
- DOTLOOP_FILE_UPLOAD_BOUNDARY =
"AaB03x"
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#application ⇒ Object
Returns the value of attribute application.
Class Method Summary collapse
Instance Method Summary collapse
- #account ⇒ Object
- #Contact ⇒ Object
- #delete(page) ⇒ Object
- #Document ⇒ Object
- #download(page, params = {}) ⇒ Object
- #Folder ⇒ Object
- #get(page, params = {}) ⇒ Object
- #handle_dotloop_error(response) ⇒ Object
-
#initialize(access_token:, application: 'dotloop') ⇒ Client
constructor
A new instance of Client.
- #Loop ⇒ Object
- #Participant ⇒ Object
- #patch(page, params = {}) ⇒ Object
- #post(page, params = {}) ⇒ Object
- #Profile ⇒ Object
- #Task ⇒ Object
- #Tasklist ⇒ Object
- #Template ⇒ Object
- #upload(page, body) ⇒ Object
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_token ⇒ Object
Returns the value of attribute access_token.
11 12 13 |
# File 'lib/dotloop/client.rb', line 11 def access_token @access_token end |
#application ⇒ Object
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
#account ⇒ Object
77 78 79 |
# File 'lib/dotloop/client.rb', line 77 def account get('/account', {}) end |
#Contact ⇒ Object
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 |
#Document ⇒ Object
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 |
#Folder ⇒ Object
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
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 |
#Loop ⇒ Object
93 94 95 |
# File 'lib/dotloop/client.rb', line 93 def Loop @loop ||= Dotloop::Loop.new(client: self) end |
#Participant ⇒ Object
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 |
#Profile ⇒ Object
89 90 91 |
# File 'lib/dotloop/client.rb', line 89 def Profile @profile ||= Dotloop::Profile.new(client: self) end |
#Task ⇒ Object
105 106 107 |
# File 'lib/dotloop/client.rb', line 105 def Task @task ||= Dotloop::Task.new(client: self) end |
#Tasklist ⇒ Object
101 102 103 |
# File 'lib/dotloop/client.rb', line 101 def Tasklist @tasklist ||= Dotloop::Tasklist.new(client: self) end |
#Template ⇒ Object
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 |