fastbill 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fastbill.gemspec
4
+ gemspec
data/README.markdown ADDED
@@ -0,0 +1 @@
1
+ test
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/TODO.txt ADDED
@@ -0,0 +1,15 @@
1
+ - invoice
2
+ get
3
+ create
4
+ update
5
+ delete
6
+ sign
7
+ sendbyemail
8
+ - item
9
+ get
10
+ delete
11
+ - recurring
12
+ get
13
+ create
14
+ update
15
+ delete
data/fastbill.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "fastbill/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "fastbill"
7
+ s.version = Fastbill::VERSION
8
+ s.authors = ["Kai Wernicke"]
9
+ s.email = ["kai@4ware.net"]
10
+ s.homepage = ""
11
+ s.summary = %q{ruby wrapper for the fastbill API}
12
+ s.description = %q{a basic ruby wrapper for the methods provided by the fastbill API}
13
+
14
+ s.rubyforge_project = "fastbill"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ s.add_development_dependency "httparty"
24
+ s.add_development_dependency "crack"
25
+ s.add_runtime_dependency "httparty"
26
+ s.add_runtime_dependency "crack"
27
+ end
data/lib/fastbill.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'httparty'
2
+ require 'crack/xml'
3
+ require "fastbill/version"
4
+ require "fastbill/customer"
5
+
6
+ module Fastbill
7
+ attr_reader :auth
8
+ class << self
9
+ include HTTParty
10
+ base_uri 'https://portal.fastbill.com'
11
+ def new(email, api_key)
12
+ @auth = {:username => email, :password => api_key}
13
+ self
14
+ end
15
+ def customers
16
+ c = Customer.new(@auth).customers
17
+ end
18
+ def customer_get(id)
19
+ Customer.new(@auth).get(id)
20
+ end
21
+
22
+ def fetch(req)
23
+ options = { :query => req, :basic_auth => @auth }
24
+ self.class.post('/api/0.1/api.php', options)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,241 @@
1
+ class Customer
2
+ include HTTParty
3
+ base_uri 'https://portal.fastbill.com'
4
+
5
+ attr_accessor :id, :number, :days_for_payment, :created_at, :payment_type, :bank_name, :bank_account_number, :bank_code, :bank_account_owner, :show_payment_notice, :account_receiveable, :customer_type, :top, :organization, :position, :saltuation, :first_name, :last_name, :address, :address_2, :zipcode, :city, :country_code, :phone, :phone_2, :fax, :mobile, :email, :vat_id, :currency_code, :comment
6
+
7
+ def initialize(auth = nil)
8
+ @auth = auth
9
+ @is_new = true
10
+ end
11
+
12
+ def customers
13
+ options = {
14
+ :basic_auth => @auth,
15
+ :headers => {
16
+ "Content-Type" => "application/xml"
17
+ },
18
+ :body => '<?xml version="1.0" encoding="utf-8"?><FBAPI><SERVICE>customer.get</SERVICE></FBAPI>'
19
+ }
20
+ r = self.class.post('/api/0.1/api.php', options)
21
+ unless r.body.nil?
22
+ body = Crack::XML.parse r.body
23
+ unless body['FBAPI']["RESPONSE"]["CUSTOMERS"].nil?
24
+ customers = []
25
+ for customer in body['FBAPI']["RESPONSE"]["CUSTOMERS"]["CUSTOMER"].each
26
+ c = Customer.new(@auth)
27
+ c.hydrate(customer)
28
+ customers.push c
29
+ end
30
+ customers
31
+ end
32
+ end
33
+ end
34
+
35
+ def get(id)
36
+ options = {
37
+ :basic_auth => @auth,
38
+ :headers => {
39
+ "Content-Type" => "application/xml"
40
+ },
41
+ :body => '<?xml version="1.0" encoding="utf-8"?><FBAPI><SERVICE>customer.get</SERVICE><FILTER><CUSTOMER_ID>' + id.to_s + '</CUSTOMER_ID></FILTER></FBAPI>'
42
+ }
43
+ r = self.class.post('/api/0.1/api.php', options)
44
+ body = Crack::XML.parse r.body
45
+ if !body['FBAPI']["RESPONSE"]["CUSTOMERS"].nil?
46
+ hydrate(body['FBAPI']["RESPONSE"]["CUSTOMERS"]["CUSTOMER"])
47
+ self
48
+ else
49
+ false
50
+ end
51
+ end
52
+ def save
53
+ if @is_new
54
+ #create
55
+ options = {
56
+ :basic_auth => @auth,
57
+ :headers => {
58
+ "Content-Type" => "application/xml"
59
+ },
60
+ :body => '<?xml version="1.0" encoding="utf-8"?><FBAPI><SERVICE>customer.create</SERVICE><DATA>' + self.to_xml + '</DATA></FBAPI>'
61
+ }
62
+ r = self.class.post('/api/0.1/api.php', options)
63
+ body = Crack::XML.parse r.body
64
+ if !body['FBAPI']["RESPONSE"]["STATUS"].nil? && body['FBAPI']["RESPONSE"]["STATUS"] == "success"
65
+ unless body['FBAPI']["RESPONSE"]["STATUS"]["CUSTOMER_ID"].nil?
66
+ @id = body['FBAPI']["RESPONSE"]["STATUS"]["CUSTOMER_ID"]
67
+ end
68
+ @is_new = false
69
+ self
70
+ else
71
+ false
72
+ end
73
+ else
74
+ #update
75
+ options = {
76
+ :basic_auth => @auth,
77
+ :headers => {
78
+ "Content-Type" => "application/xml"
79
+ },
80
+ :body => '<?xml version="1.0" encoding="utf-8"?><FBAPI><SERVICE>customer.update</SERVICE><DATA>' + self.to_xml + '</DATA></FBAPI>'
81
+ }
82
+ r = self.class.post('/api/0.1/api.php', options)
83
+ body = Crack::XML.parse r.body
84
+ if !body['FBAPI']["RESPONSE"]["STATUS"].nil? && body['FBAPI']["RESPONSE"]["STATUS"] == "success"
85
+ unless body['FBAPI']["RESPONSE"]["STATUS"]["CUSTOMER_ID"].nil?
86
+ @id = body['FBAPI']["RESPONSE"]["STATUS"]["CUSTOMER_ID"]
87
+ end
88
+ self
89
+ else
90
+ false
91
+ end
92
+ end
93
+ end
94
+ def delete!
95
+ options = {
96
+ :basic_auth => @auth,
97
+ :headers => {
98
+ "Content-Type" => "application/xml"
99
+ },
100
+ :body => '<?xml version="1.0" encoding="utf-8"?><FBAPI><SERVICE>customer.delete</SERVICE><DATA><CUSTOMER_ID>' + @id + '</CUSTOMER_ID></DATA></FBAPI>'
101
+ }
102
+ r = self.class.post('/api/0.1/api.php', options)
103
+ body = Crack::XML.parse r.body
104
+ if !body['FBAPI']["RESPONSE"]["STATUS"].nil? && body['FBAPI']["RESPONSE"]["STATUS"] == "success"
105
+ true
106
+ else
107
+ false
108
+ end
109
+
110
+ end
111
+
112
+ def hydrate(body)
113
+ @is_new = false
114
+ @id = body["CUSTOMER_ID"]
115
+ @number = body["CUSTOMER_NUMBER"]
116
+ @days_for_payment = body["DAYS_FOR_PAYMENT"]
117
+ @created_at = Time.parse body["CREATED"]
118
+ @payment_type = body["PAYMENT_TYPE"]
119
+ @bank_name = body["BANK_NAME"]
120
+ @bank_account_number = body["BANK_ACCOUNT_NUMBER"]
121
+ @bank_code = body["BANK_CODE"]
122
+ @bank_account_owner = body["BANK_ACCOUNT_OWNER"]
123
+ @show_payment_notice = body["SHOW_PAYMENT_NOTICE"]
124
+ @account_receiveable = body["ACCOUNT_RECEIVEABLE"]
125
+ @type = body["CUSTOMER_TYPE"]
126
+ @top = body["TOP"] == "1" ? true : false
127
+ @organization = body["ORGANIZATION"]
128
+ @position = body["POSITION"]
129
+ @saltuation = body["SALUATION"]
130
+ @first_name = body["FIRST_NAME"]
131
+ @last_name = body["LAST_NAME"]
132
+ @address = body["ADDRESS"]
133
+ @address_2 = body["ADDRESS_2"]
134
+ @zipcode = body["ZIPCODE"]
135
+ @city = body["CITY"]
136
+ @country_code = body["COUNTRY_CODE"]
137
+ @phone = body["PHONE"]
138
+ @phone_2 = body["PHONE_2"]
139
+ @fax = body["FAX"]
140
+ @mobile = body["MOBILE"]
141
+ @email = body["EMAIL"]
142
+ @vat_id = body["VAT_ID"]
143
+ @currency_code = body["CURRENCY_CODE"]
144
+ @comment = body["COMMENT"]
145
+ end
146
+ def to_xml
147
+ xml = ""
148
+ unless @id.nil?
149
+ xml = xml + "<CUSTOMER_ID>#{@id}</CUSTOMER_ID>"
150
+ end
151
+ unless @number.nil?
152
+ xml = xml + "<CUSTOMER_NUMBER>#{@number}</CUSTOMER_NUMBER>"
153
+ end
154
+ unless @days_for_payment.nil?
155
+ xml = xml + "<DAYS_FOR_PAYMENT>#{@days_for_payment}</DAYS_FOR_PAYMENT>"
156
+ end
157
+ unless @payment_type.nil?
158
+ xml = xml + "<PAYMENT_TYPE>#{@payment_type}</PAYMENT_TYPE>"
159
+ end
160
+ unless @bank_name.nil?
161
+ xml = xml + "<BANK_NAME>#{@bank_name}</BANK_NAME>"
162
+ end
163
+ unless @bank_account_number.nil?
164
+ xml = xml + "<BANK_ACCOUNT_NUMBER>#{@bank_account_number}</BANK_ACCOUNT_NUMBER>"
165
+ end
166
+ unless @bank_code.nil?
167
+ xml = xml + "<BANK_CODE>#{@bank_code}</BANK_CODE>"
168
+ end
169
+ unless @bank_account_owner.nil?
170
+ xml = xml + "<BANK_ACCOUNT_OWNER>#{@bank_account_owner}</BANK_ACCOUNT_OWNER>"
171
+ end
172
+ unless @show_payment_notice.nil?
173
+ xml = xml + "<SHOW_PAYMENT_NOTICE>#{@show_payment_notice}</SHOW_PAYMENT_NOTICE>"
174
+ end
175
+ unless @account_receivable.nil?
176
+ xml = xml + "<ACCOUNT_RECEIVABLE>#{@account_receivable}</ACCOUNT_RECEIVABLE>"
177
+ end
178
+ unless @customer_type.nil?
179
+ xml = xml + "<CUSTOMER_TYPE>#{@customer_type}</CUSTOMER_TYPE>"
180
+ end
181
+ unless @top.nil?
182
+ t = @top ? 1 : 0
183
+ xml = xml + "<TOP>#{t}</TOP>"
184
+ end
185
+ unless @organization.nil?
186
+ xml = xml + "<ORGANIZATION>#{@organization}</ORGANIZATION>"
187
+ end
188
+ unless @position.nil?
189
+ xml = xml + "<POSITION>#{@position}</POSITION>"
190
+ end
191
+ unless @saltuation.nil?
192
+ xml = xml + "<SALUATION>#{@saltuation}</SALUATION>"
193
+ end
194
+ unless @first_name.nil?
195
+ xml = xml + "<FIRST_NAME>#{@first_name}</FIRST_NAME>"
196
+ end
197
+ unless @last_name.nil?
198
+ xml = xml + "<LAST_NAME>#{@last_name}</LAST_NAME>"
199
+ end
200
+ unless @address.nil?
201
+ xml = xml + "<ADDRESS>#{@address}</ADDRESS>"
202
+ end
203
+ unless @address_2.nil?
204
+ xml = xml + "<ADDRESS_2>#{@address_2}</ADDRESS_2>"
205
+ end
206
+ unless @zipcode.nil?
207
+ xml = xml + "<ZIPCODE>#{@zipcode}</ZIPCODE>"
208
+ end
209
+ unless @city.nil?
210
+ xml = xml + "<CITY>#{@city}</CITY>"
211
+ end
212
+ unless @country_code.nil?
213
+ xml = xml + "<COUNTRY_CODE>#{@country_code}</COUNTRY_CODE>"
214
+ end
215
+ unless @phone.nil?
216
+ xml = xml + "<PHONE>#{@phone}</PHONE>"
217
+ end
218
+ unless @phone_2.nil?
219
+ xml = xml + "<PHONE_2>#{@phone_2}</PHONE_2>"
220
+ end
221
+ unless @fax.nil?
222
+ xml = xml + "<FAX>#{@fax}</FAX>"
223
+ end
224
+ unless @mobile.nil?
225
+ xml = xml + "<MOBILE>#{@mobile}</MOBILE>"
226
+ end
227
+ unless @email.nil?
228
+ xml = xml + "<EMAIL>#{@email}</EMAIL>"
229
+ end
230
+ unless @vat_id.nil?
231
+ xml = xml + "<VAT_ID>#{@vat_id}</VAT_ID>"
232
+ end
233
+ unless @currency_code.nil?
234
+ xml = xml + "<CURRENCY_CODE>#{@currency_code}</CURRENCY_CODE>"
235
+ end
236
+ unless @comment.nil?
237
+ xml = xml + "<COMMENT>#{@comment}</COMMENT>"
238
+ end
239
+ xml
240
+ end
241
+ end
@@ -0,0 +1,3 @@
1
+ module Fastbill
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastbill
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kai Wernicke
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-01 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70169263735100 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70169263735100
25
+ - !ruby/object:Gem::Dependency
26
+ name: httparty
27
+ requirement: &70169263734120 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70169263734120
36
+ - !ruby/object:Gem::Dependency
37
+ name: crack
38
+ requirement: &70169263732960 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70169263732960
47
+ - !ruby/object:Gem::Dependency
48
+ name: httparty
49
+ requirement: &70169263731800 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70169263731800
58
+ - !ruby/object:Gem::Dependency
59
+ name: crack
60
+ requirement: &70169263730960 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70169263730960
69
+ description: a basic ruby wrapper for the methods provided by the fastbill API
70
+ email:
71
+ - kai@4ware.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - README.markdown
79
+ - Rakefile
80
+ - TODO.txt
81
+ - fastbill.gemspec
82
+ - lib/fastbill.rb
83
+ - lib/fastbill/customer.rb
84
+ - lib/fastbill/version.rb
85
+ homepage: ''
86
+ licenses: []
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project: fastbill
105
+ rubygems_version: 1.8.10
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: ruby wrapper for the fastbill API
109
+ test_files: []