freshbooks 1.0.0 → 2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/freshbooks.rb +29 -12
- metadata +2 -2
data/lib/freshbooks.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#------------------------------------------------------------------------------
|
|
2
|
-
#
|
|
2
|
+
# FreshBooks.rb - Ruby interface to the FreshBooks API
|
|
3
3
|
#
|
|
4
|
-
# Copyright (c) 2007 Ben Vinegar (http://www.benlog.org)
|
|
4
|
+
# Copyright (c) 2007-2008 Ben Vinegar (http://www.benlog.org)
|
|
5
5
|
#
|
|
6
6
|
# This work is distributed under an MIT License:
|
|
7
7
|
# http://www.opensource.org/licenses/mit-license.php
|
|
@@ -28,12 +28,13 @@
|
|
|
28
28
|
|
|
29
29
|
require 'net/https'
|
|
30
30
|
require 'rexml/document'
|
|
31
|
+
|
|
31
32
|
include REXML
|
|
32
33
|
|
|
33
34
|
module FreshBooks
|
|
34
|
-
VERSION = '1.
|
|
35
|
+
VERSION = '2.1' # Only works with 2.1
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
SERVICE_URL = "/api/#{VERSION}/xml-in"
|
|
37
38
|
|
|
38
39
|
class InternalError < Exception; end;
|
|
39
40
|
class AuthenticationError < Exception; end;
|
|
@@ -92,7 +93,7 @@ module FreshBooks
|
|
|
92
93
|
connection.use_ssl = true
|
|
93
94
|
connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
94
95
|
|
|
95
|
-
request = Net::HTTP::Post.new(FreshBooks::
|
|
96
|
+
request = Net::HTTP::Post.new(FreshBooks::SERVICE_URL)
|
|
96
97
|
request.basic_auth @@auth_token, 'X'
|
|
97
98
|
request.body = body
|
|
98
99
|
request.content_type = 'application/xml'
|
|
@@ -208,7 +209,7 @@ module FreshBooks
|
|
|
208
209
|
def create
|
|
209
210
|
resp = FreshBooks::call_api('client.create', 'client' => self)
|
|
210
211
|
if resp.success?
|
|
211
|
-
self.client_id = resp.elements[1].to_i
|
|
212
|
+
self.client_id = resp.elements[1].text.to_i
|
|
212
213
|
end
|
|
213
214
|
|
|
214
215
|
resp.success? ? self.client_id : nil
|
|
@@ -232,8 +233,11 @@ module FreshBooks
|
|
|
232
233
|
|
|
233
234
|
def self.list(options = {})
|
|
234
235
|
resp = FreshBooks::call_api('client.list', options)
|
|
236
|
+
|
|
237
|
+
return nil unless resp.success?
|
|
235
238
|
|
|
236
|
-
|
|
239
|
+
client_elems = resp.elements[1].elements
|
|
240
|
+
client_elems.map { |elem| self.new_from_xml(elem) }
|
|
237
241
|
end
|
|
238
242
|
|
|
239
243
|
def self.delete(client_id)
|
|
@@ -300,8 +304,11 @@ module FreshBooks
|
|
|
300
304
|
|
|
301
305
|
def self.list(options = {})
|
|
302
306
|
resp = FreshBooks::call_api('invoice.list', options)
|
|
307
|
+
|
|
308
|
+
return nil unless resp.success?
|
|
303
309
|
|
|
304
|
-
|
|
310
|
+
invoice_nodes = resp.elements[1].elements
|
|
311
|
+
invoice_nodes.map { |elem| self.new_from_xml(elem) }
|
|
305
312
|
end
|
|
306
313
|
|
|
307
314
|
def self.send_by_email(invoice_id)
|
|
@@ -369,8 +376,11 @@ module FreshBooks
|
|
|
369
376
|
|
|
370
377
|
def self.list(options = {})
|
|
371
378
|
resp = FreshBooks::call_api('item.list', options)
|
|
379
|
+
|
|
380
|
+
return nil unless resp.success?
|
|
372
381
|
|
|
373
|
-
|
|
382
|
+
item_elems = resp.elements[1].elements
|
|
383
|
+
item_elems.map { |elem| self.new_from_xml(elem) }
|
|
374
384
|
end
|
|
375
385
|
end
|
|
376
386
|
|
|
@@ -406,8 +416,11 @@ module FreshBooks
|
|
|
406
416
|
def self.list(options = {})
|
|
407
417
|
resp = FreshBooks::call_api('payment.list', options)
|
|
408
418
|
|
|
409
|
-
resp.success?
|
|
410
|
-
|
|
419
|
+
return nil unless resp.success?
|
|
420
|
+
|
|
421
|
+
payment_elems = resp.elements[1].elements
|
|
422
|
+
payment_elems.map { |elem| self.new_from_xml(elem) }
|
|
423
|
+
end
|
|
411
424
|
end
|
|
412
425
|
|
|
413
426
|
#--------------------------------------------------------------------------
|
|
@@ -464,7 +477,11 @@ module FreshBooks
|
|
|
464
477
|
def self.list(options = {})
|
|
465
478
|
resp = FreshBooks::call_api('recurring.list', options)
|
|
466
479
|
|
|
467
|
-
resp.success?
|
|
480
|
+
return nil unless resp.success?
|
|
481
|
+
|
|
482
|
+
recurring_elems = resp.elements[1].elements
|
|
483
|
+
|
|
484
|
+
recurring_elems.map { |elem| self.new_from_xml(elem) }
|
|
468
485
|
end
|
|
469
486
|
|
|
470
487
|
end
|
metadata
CHANGED
|
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
|
3
3
|
specification_version: 1
|
|
4
4
|
name: freshbooks
|
|
5
5
|
version: !ruby/object:Gem::Version
|
|
6
|
-
version: 1
|
|
7
|
-
date:
|
|
6
|
+
version: "2.1"
|
|
7
|
+
date: 2008-02-24 00:00:00 -05:00
|
|
8
8
|
summary: The author was too lazy to write a summary
|
|
9
9
|
require_paths:
|
|
10
10
|
- lib
|