fastbill 0.0.2 → 0.0.3

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/fastbill.rb CHANGED
@@ -2,6 +2,9 @@ require 'httparty'
2
2
  require 'crack/xml'
3
3
  require "fastbill/version"
4
4
  require "fastbill/customer"
5
+ require "fastbill/invoice"
6
+ require "fastbill/invoice_item"
7
+ require "fastbill/invoice_vat_item"
5
8
 
6
9
  module Fastbill
7
10
  attr_reader :auth
@@ -18,5 +21,8 @@ module Fastbill
18
21
  def customer_get(id)
19
22
  Customer.new(@auth).get(id)
20
23
  end
24
+ def invoice
25
+ Invoice.new(@auth)
26
+ end
21
27
  end
22
28
  end
@@ -0,0 +1,97 @@
1
+ class Invoice
2
+ include HTTParty
3
+ base_uri 'https://portal.fastbill.com'
4
+
5
+ attr_accessor :id, :invoice_type, :customer_id, :customer_costcenter_id, :currency_code, :template_id, :intro_text, :invoice_number, :payed_date, :is_canceled, :invoice_date, :due_date, :delivery_date, :sub_total, :vat_total, :total, :vat_items, :items, :is_new
6
+
7
+ def initialize(auth = nil)
8
+ @auth = auth
9
+ @is_new = true
10
+ end
11
+
12
+ def get(id = nil, customer_id = nil, month = nil, year = nil)
13
+ if id
14
+ #fetch invoice
15
+ options = {
16
+ :basic_auth => @auth,
17
+ :headers => {
18
+ "Content-Type" => "application/xml"
19
+ },
20
+ :body => '<?xml version="1.0" encoding="utf-8"?><FBAPI><SERVICE>invoice.get</SERVICE><FILTER><INVOICE_ID>' + id.to_s + '</INVOICE_ID></FILTER></FBAPI>'
21
+ }
22
+ r = self.class.post('/api/0.1/api.php', options)
23
+ body = Crack::XML.parse r.body
24
+ if !body['FBAPI']["RESPONSE"]["INVOICES"].nil?
25
+ hydrate(body['FBAPI']["RESPONSE"]["INVOICES"]["INVOICE"])
26
+ self
27
+ else
28
+ false
29
+ end
30
+ else
31
+ #search invoices
32
+ end
33
+ end
34
+ def save
35
+
36
+ end
37
+ def delete!
38
+
39
+ end
40
+ def hydrate(body)
41
+ @is_new = false
42
+ @id = body["INVOICE_ID"]
43
+ @invoice_type = body["INVOICE_TYPE"]
44
+ @customer_id = body["CUSTOMER_ID"]
45
+ @customer_costcenter_id = body["CUSTOMER_COSTCENTER_ID"]
46
+ @currency_code = body["CURRENCY_CODE"]
47
+ @template_id = body["TEMPLATE_ID"]
48
+ @invoice_number = body["INVOICE_NUMBER"]
49
+ @introtext = body["INTROTEXT"]
50
+ @payed_date = parse_date body["PAYED_DATE"]
51
+ @is_canceled = body["IS_CANCELED"] == "1" ? true : false
52
+ @invoice_date = parse_date body["INVOICE_DATE"]
53
+ @due_date = parse_date body["INVOICE_DATE"]
54
+ @delivery_date = parse_date body["DELIVERY_DATE"]
55
+ @sub_total = body["SUB_TOTAL"]
56
+ @vat_total = body["VAT_TOTAL"]
57
+ @vat_items = []
58
+ for vat_item in body["VAT_ITEMS"].each
59
+ @vat_items.push InvoiceVatItem.new vat_item.last
60
+ end
61
+ @items = []
62
+ for item in body["ITEMS"].each
63
+ i = InvoiceItem.new(@auth)
64
+ i.hydrate(item.last)
65
+ @items.push i
66
+ end
67
+ @total = body["TOTAl"]
68
+ end
69
+ def parse_date(date)
70
+ if date != nil && date != "0000-00-00 00:00:00"
71
+ Time.parse date
72
+ else
73
+ false
74
+ end
75
+ end
76
+ def to_xml
77
+
78
+ end
79
+ def complete
80
+
81
+ end
82
+ def sign!
83
+
84
+ end
85
+ def send_by_email
86
+
87
+ end
88
+ def send_by_ground_mail
89
+
90
+ end
91
+ def set_paid
92
+
93
+ end
94
+ def items
95
+
96
+ end
97
+ end
@@ -0,0 +1,31 @@
1
+ class InvoiceItem
2
+ include HTTParty
3
+ base_uri 'https://portal.fastbill.com'
4
+
5
+ attr_accessor :id, :description, :quantity, :unit_price, :vat_percent, :vat_value, :complete_net, :complete_gross, :currency_code, :sort_order
6
+
7
+ def initialize(auth = nil)
8
+ @auth = auth
9
+ end
10
+ def get(invoice_id)
11
+
12
+ end
13
+ def delete!
14
+
15
+ end
16
+ def hydrate(body)
17
+ @id = body["INVOICE_ITEM_ID"]
18
+ @article_number = body["ARTICLE_NUMBER"]
19
+ @description = body["DESCRIPTION"]
20
+ @quantity = body["QUANTITY"]
21
+ @unit_price = body["UNIT_PRICE"]
22
+ @vat_percent = body["VAT_PERCENT"]
23
+ @vat_value = body["VAT_VALUE"]
24
+ @complete_net = body["COMPLETE_NET"]
25
+ @complete_gross = body["COMPLETE_GROSS"]
26
+ @sort_order = body["SORT_ORDER"]
27
+ end
28
+ def to_xml
29
+
30
+ end
31
+ end
@@ -0,0 +1,12 @@
1
+ class InvoiceVatItem
2
+ attr_accessor :vat_percent, :vat_value
3
+
4
+ def initialize(body)
5
+ @vat_percent = body["VAT_PERCENT"]
6
+ @vat_value = body["VAT_VALUE"]
7
+ self
8
+ end
9
+ def to_xml
10
+
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Fastbill
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastbill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-04 00:00:00.000000000Z
12
+ date: 2011-10-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70149179260980 !ruby/object:Gem::Requirement
16
+ requirement: &70234096898640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70149179260980
24
+ version_requirements: *70234096898640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &70149179260440 !ruby/object:Gem::Requirement
27
+ requirement: &70234096965960 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70149179260440
35
+ version_requirements: *70234096965960
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: crack
38
- requirement: &70149179259940 !ruby/object:Gem::Requirement
38
+ requirement: &70234097064800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70149179259940
46
+ version_requirements: *70234097064800
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: httparty
49
- requirement: &70149179259220 !ruby/object:Gem::Requirement
49
+ requirement: &70234097149960 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70149179259220
57
+ version_requirements: *70234097149960
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: crack
60
- requirement: &70149179248880 !ruby/object:Gem::Requirement
60
+ requirement: &70234097324120 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70149179248880
68
+ version_requirements: *70234097324120
69
69
  description: a basic ruby wrapper for the methods provided by the fastbill API
70
70
  email:
71
71
  - kai@4ware.net
@@ -82,6 +82,9 @@ files:
82
82
  - fastbill.gemspec
83
83
  - lib/fastbill.rb
84
84
  - lib/fastbill/customer.rb
85
+ - lib/fastbill/invoice.rb
86
+ - lib/fastbill/invoice_item.rb
87
+ - lib/fastbill/invoice_vat_item.rb
85
88
  - lib/fastbill/version.rb
86
89
  homepage: ''
87
90
  licenses: []