class Dotloop::Client

Constants

DOTLOOP_FILE_UPLOAD_BOUNDARY

Attributes

access_token[RW]
application[RW]

Public Class Methods

new(access_token:, application: 'dotloop') click to toggle source
# 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
snakify(hash) click to toggle source
# File lib/dotloop/client.rb, line 117
def self.snakify(hash)
  if hash.is_a? Array
    hash.map{ |item| symbolize(item.to_snake_keys) }
  else
    symbolize(hash.to_snake_keys)
  end
end

Private Class Methods

symbolize(obj) click to toggle source
# File lib/dotloop/client.rb, line 127
def self.symbolize(obj)
  return obj.reduce({}) do |memo, (k, v)|
    memo.tap { |m| m[k.to_sym] = symbolize(v) }
  end if obj.is_a? Hash
  return obj.reduce([]) do |memo, v|
    memo << symbolize(v); memo
  end if obj.is_a? Array
  obj
end

Public Instance Methods

Contact() click to toggle source
# File lib/dotloop/client.rb, line 113
def Contact
  @person ||= Dotloop::Contact.new(client: self)
end
Document() click to toggle source
# File lib/dotloop/client.rb, line 81
def Document
  @document ||= Dotloop::Document.new(client: self)
end
Folder() click to toggle source
# File lib/dotloop/client.rb, line 85
def Folder
  @folder ||= Dotloop::Folder.new(client: self)
end
Loop() click to toggle source
# File lib/dotloop/client.rb, line 93
def Loop
  @loop ||= Dotloop::Loop.new(client: self)
end
Participant() click to toggle source
# File lib/dotloop/client.rb, line 97
def Participant
  @participant ||= Dotloop::Participant.new(client: self)
end
Profile() click to toggle source
# File lib/dotloop/client.rb, line 89
def Profile
  @profile ||= Dotloop::Profile.new(client: self)
end
Task() click to toggle source
# File lib/dotloop/client.rb, line 105
def Task
  @task ||= Dotloop::Task.new(client: self)
end
Tasklist() click to toggle source
# File lib/dotloop/client.rb, line 101
def Tasklist
  @tasklist ||= Dotloop::Tasklist.new(client: self)
end
Template() click to toggle source
# File lib/dotloop/client.rb, line 109
def Template
  @template ||= Dotloop::Template.new(client: self)
end
account() click to toggle source
# File lib/dotloop/client.rb, line 77
def account
  get('/account', {})
end
delete(page) click to toggle source
# 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
download(page, params = {}) click to toggle source
# 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
get(page, params = {}) click to toggle source
# 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) click to toggle source
# 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
patch(page, params = {}) click to toggle source
# 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 = {}) click to toggle source
# 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
upload(page, body) click to toggle source
# 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

Private Instance Methods

download_headers() click to toggle source
# File lib/dotloop/client.rb, line 137
def download_headers
  {
    'Authorization' => "Bearer #{@access_token}",
    'User-Agent' => @application,
    'Accept' => 'application/pdf'
  }
end
headers() click to toggle source
# File lib/dotloop/client.rb, line 153
def headers
  {
    'Authorization' => "Bearer #{@access_token}",
    'User-Agent' => @application,
    'Accept' => '*/*'
  }
end
post_headers() click to toggle source
# File lib/dotloop/client.rb, line 161
def post_headers
  {
    'Authorization' => "Bearer #{@access_token}",
    'User-Agent' => @application,
    'Accept' => '*/*',
    'Content-Type' => 'application/json'
  }
end
upload_headers() click to toggle source
# File lib/dotloop/client.rb, line 145
def upload_headers
  {
    'Authorization' => "Bearer #{@access_token}",
    'User-Agent' => @application,
    'Content-Type' => "multipart/form-data\; boundary=#{DOTLOOP_FILE_UPLOAD_BOUNDARY}"
  }
end