Class: HarvestToInfakt::Infakt::Client

Inherits:
Resource
  • Object
show all
Defined in:
lib/harvest_to_infakt/infakt/client.rb

Class Method Summary collapse

Methods inherited from Resource

#id, #initialize, #method_missing

Constructor Details

This class inherits a constructor from HarvestToInfakt::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HarvestToInfakt::Resource

Class Method Details

.allObject



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

def all
  @all ||= fetch_all
end

.basic_auth_optionsObject



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

def basic_auth_options
  { :username => HarvestToInfakt.configuration.infakt[:username], :password => HarvestToInfakt.configuration.infakt[:password] + HarvestToInfakt.configuration.infakt[:api_key]}
end

.fetch_allObject



23
24
25
26
27
28
29
30
# File 'lib/harvest_to_infakt/infakt/client.rb', line 23

def fetch_all
  response = get('/api/clients.xml', :basic_auth => basic_auth_options)

  response.parsed_response['clients'].inject([]) do |invoices, data|
    invoices << new(data)
    invoices
  end
end

.find(id) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/harvest_to_infakt/infakt/client.rb', line 15

def find(id)
  @find ||= all.inject({}) do |hash, client|
    hash[client.id.to_s] = client
    hash
  end
  @find[id.to_s]
end