Class: FreeAgent::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/free_agent/client.rb

Constant Summary collapse

BASE_URL =
"https://api.freeagent.com/v2"
SANDBOX_BASE_URL =
"https://api.sandbox.freeagent.com/v2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token:, sandbox: false, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
# File 'lib/free_agent/client.rb', line 8

def initialize(access_token:, sandbox: false, adapter: Faraday.default_adapter, stubs: nil)
  @access_token = access_token
  @sandbox = sandbox
  @adapter = adapter

  # Test stubs for requests
  @stubs = stubs
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



6
7
8
# File 'lib/free_agent/client.rb', line 6

def access_token
  @access_token
end

#adapterObject (readonly)

Returns the value of attribute adapter.



6
7
8
# File 'lib/free_agent/client.rb', line 6

def adapter
  @adapter
end

#sandboxObject (readonly)

Returns the value of attribute sandbox.



6
7
8
# File 'lib/free_agent/client.rb', line 6

def sandbox
  @sandbox
end

Instance Method Details

#attachmentsObject



53
54
55
# File 'lib/free_agent/client.rb', line 53

def attachments
  AttachmentsResource.new(self)
end

#bank_accountsObject



25
26
27
# File 'lib/free_agent/client.rb', line 25

def bank_accounts
  BankAccountsResource.new(self)
end

#bank_transaction_explanationsObject



33
34
35
# File 'lib/free_agent/client.rb', line 33

def bank_transaction_explanations
  BankTransactionExplanationsResource.new(self)
end

#bank_transactionsObject



29
30
31
# File 'lib/free_agent/client.rb', line 29

def bank_transactions
  BankTransactionsResource.new(self)
end

#billsObject



73
74
75
# File 'lib/free_agent/client.rb', line 73

def bills
  BillsResource.new(self)
end

#companyObject



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

def company
  CompanyResource.new(self)
end

#connectionObject



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/free_agent/client.rb', line 77

def connection
  url = (sandbox == true ? SANDBOX_BASE_URL : BASE_URL)
  @connection ||= Faraday.new(url) do |conn|
    conn.request :authorization, :Bearer, access_token
    conn.request :json

    conn.response :dates
    conn.response :json, content_type: "application/json"

    conn.adapter adapter, @stubs
  end
end

#connection_uploadObject

Uses Faraday Multipart (lostisland/faraday-multipart)



91
92
93
94
95
96
97
# File 'lib/free_agent/client.rb', line 91

def connection_upload
  url = (sandbox == true ? SANDBOX_BASE_URL : BASE_URL)
  @connection ||= Faraday.new(url) do |conn|
    conn.request :authorization, :Bearer, access_token
    conn.request :multipart
  end
end

#contactsObject



21
22
23
# File 'lib/free_agent/client.rb', line 21

def contacts
  ContactsResource.new(self)
end

#credit_notesObject



69
70
71
# File 'lib/free_agent/client.rb', line 69

def credit_notes
  CreditNotesResource.new(self)
end

#estimate_itemsObject



65
66
67
# File 'lib/free_agent/client.rb', line 65

def estimate_items
  EstimateItemsResource.new(self)
end

#estimatesObject



61
62
63
# File 'lib/free_agent/client.rb', line 61

def estimates
  EstimatesResource.new(self)
end

#invoicesObject



57
58
59
# File 'lib/free_agent/client.rb', line 57

def invoices
  InvoicesResource.new(self)
end

#projectsObject



37
38
39
# File 'lib/free_agent/client.rb', line 37

def projects
  ProjectsResource.new(self)
end

#tasksObject



41
42
43
# File 'lib/free_agent/client.rb', line 41

def tasks
  TasksResource.new(self)
end

#timeslipsObject



45
46
47
# File 'lib/free_agent/client.rb', line 45

def timeslips
  TimeslipsResource.new(self)
end

#usersObject



49
50
51
# File 'lib/free_agent/client.rb', line 49

def users
  UsersResource.new(self)
end