Class: FreshBooks::Client

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

Constant Summary collapse

TYPE_MAPPINGS =
{ 'client_id' => Fixnum }

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.delete(client_id) ⇒ Object



244
245
246
247
248
# File 'lib/freshbooks.rb', line 244

def self.delete(client_id)
  resp = FreshBooks::call_api('client.delete', 'client_id' => client_id)

  resp.success?
end

.get(client_id) ⇒ Object



229
230
231
232
233
# File 'lib/freshbooks.rb', line 229

def self.get(client_id)
  resp = FreshBooks::call_api('client.get', 'client_id' => client_id)

  resp.success? ? self.new_from_xml(resp.elements[1]) : nil
end

.list(options = {}) ⇒ Object



235
236
237
238
239
240
241
242
# File 'lib/freshbooks.rb', line 235

def self.list(options = {})
  resp = FreshBooks::call_api('client.list', options)
  
  return nil unless resp.success?

  client_elems = resp.elements[1].elements
  client_elems.map { |elem| self.new_from_xml(elem) }
end

Instance Method Details

#createObject



210
211
212
213
214
215
216
217
# File 'lib/freshbooks.rb', line 210

def create
  resp = FreshBooks::call_api('client.create', 'client' => self)
  if resp.success?
    self.client_id = resp.elements[1].text.to_i
  end

  resp.success? ? self.client_id : nil
end

#deleteObject



225
226
227
# File 'lib/freshbooks.rb', line 225

def delete
  Client::delete(self.client_id)
end

#invoices(options = {}) ⇒ Object



250
251
252
253
254
# File 'lib/freshbooks.rb', line 250

def invoices(options = {})
  options.merge( 'client_id' => self.client_id )

  Invoice::list(options)
end

#updateObject



219
220
221
222
223
# File 'lib/freshbooks.rb', line 219

def update
  resp = FreshBooks::call_api('client.update', 'client' => self)

  resp.success?
end