fastbill-automatic 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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +1 -0
- data/Gemfile +8 -0
- data/LICENSE +23 -0
- data/README.md +203 -0
- data/Rakefile +8 -0
- data/doc/API-Doku_FBA_V1-8.pdf +0 -0
- data/fastbill-automatic.gemspec +20 -0
- data/lib/data/fastbill.crt +17 -0
- data/lib/fastbill-automatic/article.rb +14 -0
- data/lib/fastbill-automatic/base.rb +35 -0
- data/lib/fastbill-automatic/coupon.rb +12 -0
- data/lib/fastbill-automatic/customer.rb +16 -0
- data/lib/fastbill-automatic/invoice.rb +25 -0
- data/lib/fastbill-automatic/item.rb +10 -0
- data/lib/fastbill-automatic/request/base.rb +36 -0
- data/lib/fastbill-automatic/request/connection.rb +37 -0
- data/lib/fastbill-automatic/request/info.rb +32 -0
- data/lib/fastbill-automatic/request/validator.rb +33 -0
- data/lib/fastbill-automatic/services/cancel.rb +22 -0
- data/lib/fastbill-automatic/services/changearticle.rb +19 -0
- data/lib/fastbill-automatic/services/complete.rb +22 -0
- data/lib/fastbill-automatic/services/create.rb +19 -0
- data/lib/fastbill-automatic/services/delete.rb +22 -0
- data/lib/fastbill-automatic/services/delete_item.rb +21 -0
- data/lib/fastbill-automatic/services/get.rb +28 -0
- data/lib/fastbill-automatic/services/sendbyemail.rb +19 -0
- data/lib/fastbill-automatic/services/sendbypost.rb +22 -0
- data/lib/fastbill-automatic/services/setaddon.rb +19 -0
- data/lib/fastbill-automatic/services/setpaid.rb +19 -0
- data/lib/fastbill-automatic/services/setusagedata.rb +21 -0
- data/lib/fastbill-automatic/services/sign.rb +22 -0
- data/lib/fastbill-automatic/services/update.rb +28 -0
- data/lib/fastbill-automatic/subscription.rb +16 -0
- data/lib/fastbill-automatic/template.rb +12 -0
- data/lib/fastbill-automatic/usage_data.rb +171 -0
- data/lib/fastbill-automatic/version.rb +5 -0
- data/lib/fastbill-automatic.rb +93 -0
- data/spec/fastbill-automatic/base_spec.rb +35 -0
- data/spec/fastbill-automatic/customer_spec.rb +100 -0
- data/spec/fastbill-automatic/subscription_spec.rb +61 -0
- data/spec/fastbill-automatic/usage_data_spec.rb +340 -0
- data/spec/fastbill-automatic_spec.rb +37 -0
- data/spec/spec_helper.rb +10 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7b1fd723a730eb7892d3ded62364d414f43ba603
|
4
|
+
data.tar.gz: 5baecfd6d6cd8d66edc9b2e46b2ddac57200579f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf0bac650fc90c0c61c480616dee3bd943503b45d3de6d9bed84d0a160864f7f73e12e1f019cc49ad4c027a372133e4b69b254831e9f1f680eec9d28e917ffa8
|
7
|
+
data.tar.gz: e4d0036c4d2d464dd686625cb357308a1f101a1eab3ab9c93df47fb16f2d0a21ff0880607124519f0ce4b06f292db00f59f2f0fc19574dfdbb9672c1dcf96282
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Sascha Korth
|
4
|
+
Copyright (c) 2013 Reputami GmbH
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
20
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
21
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
22
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
23
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
Fastbill Automatic
|
2
|
+
==================
|
3
|
+
|
4
|
+
This is a Ruby wrapper for FastBill's Automatic API based on API-Documentation v1.8 (PA. 04.09.2013)
|
5
|
+
|
6
|
+
Usage
|
7
|
+
======
|
8
|
+
|
9
|
+
First, you've to install the gem
|
10
|
+
|
11
|
+
gem 'fastbill-automatic', git: 'git://github.com/reputami/fastbill-automatic.git', tag: 'v0.0.3'
|
12
|
+
|
13
|
+
and require it
|
14
|
+
|
15
|
+
require "fastbill-automatic"
|
16
|
+
|
17
|
+
Then you have to set your Email Adress & API key:
|
18
|
+
|
19
|
+
Fastbill::Automatic.api_key = "your-api-key"
|
20
|
+
Fastbill::Automatic.email = "your-email-adress"
|
21
|
+
|
22
|
+
Article
|
23
|
+
-------
|
24
|
+
|
25
|
+
Find existing articles (see API limits):
|
26
|
+
|
27
|
+
Fastbill::Automatic::Article.get()
|
28
|
+
|
29
|
+
Due to the API implementation the result is an array.
|
30
|
+
|
31
|
+
Coupon
|
32
|
+
------
|
33
|
+
|
34
|
+
Find existing coupons (see API limits):
|
35
|
+
|
36
|
+
Fastbill::Automatic::Coupon.get()
|
37
|
+
|
38
|
+
Due to the API implementation the result is an array.
|
39
|
+
|
40
|
+
Customer
|
41
|
+
--------
|
42
|
+
|
43
|
+
Creating a new customer:
|
44
|
+
|
45
|
+
Fastbill::Automatic::Customer.create(customer_type: 'business', organization: 'Company name', country_code: 'DE', payment_type: 1)
|
46
|
+
|
47
|
+
Find existing customers (see API limits):
|
48
|
+
|
49
|
+
Fastbill::Automatic::Customer.get(customer_id: "123456") # With filters
|
50
|
+
Fastbill::Automatic::Customer.get() # Without filters
|
51
|
+
|
52
|
+
Due to the API implementation the result in both cases is an array.
|
53
|
+
|
54
|
+
Updating an existing customer only works on an instance:
|
55
|
+
|
56
|
+
customer = Fastbill::Automatic::Customer.get(customer_id: "123456").first
|
57
|
+
customer.update_attributes(first_name: 'Max', last_name: 'Mustermann')
|
58
|
+
|
59
|
+
Deleting a customer:
|
60
|
+
|
61
|
+
Fastbill::Automatic::Customer.delete("123456")
|
62
|
+
|
63
|
+
|
64
|
+
Subscription
|
65
|
+
------------
|
66
|
+
|
67
|
+
Creating a new subscription:
|
68
|
+
|
69
|
+
Fastbill::Automatic::Subscription.create(article_number: '123', customer_id: '123456')
|
70
|
+
|
71
|
+
Find existing subscriptions (see API limits):
|
72
|
+
|
73
|
+
Fastbill::Automatic::Subscription.get(customer_id: '123456') # With filter
|
74
|
+
Fastbill::Automatic::Subscription.get(subscription_id: '1234') # # With filter
|
75
|
+
Fastbill::Automatic::Subscription.get() # Without filters
|
76
|
+
|
77
|
+
Due to the API implementation the result in both cases is an array.
|
78
|
+
|
79
|
+
Updating an existing subscription only works on an instance:
|
80
|
+
|
81
|
+
subscription = Fastbill::Automatic::Subscription.get(subscription_id: "123456").first
|
82
|
+
subscription.update_attributes(next_event: '2013-07-10')
|
83
|
+
|
84
|
+
Changing an article for a given subscription:
|
85
|
+
|
86
|
+
Fastbill::Automatic::Subscription.changearticle(subscription_id: '1234', article_number: '123')
|
87
|
+
|
88
|
+
Create new addon for a given subscription:
|
89
|
+
|
90
|
+
Fastbill::Automatic::Subscription.setaddon(subscription_id: '1234', article_number: '123', quantity: '10')
|
91
|
+
|
92
|
+
API Bug! => (Subscription Error: Missing / invalid field: ARTICLE_NUMBER)
|
93
|
+
|
94
|
+
Set usage data for given subscription:
|
95
|
+
|
96
|
+
Fastbill::Automatic::Subscription.setusagedata(subscription_id: '1234', article_number: '123', quantity: '10')
|
97
|
+
|
98
|
+
Cancel a subscription:
|
99
|
+
|
100
|
+
Fastbill::Subscription.cancel('1234')
|
101
|
+
|
102
|
+
Invoice
|
103
|
+
-------
|
104
|
+
|
105
|
+
Creating a new invoice:
|
106
|
+
|
107
|
+
item = {description: 'Some info text', unit_price: '60.00', vat_percent: '19.00'}
|
108
|
+
items = (Array.new << item)
|
109
|
+
|
110
|
+
Fastbill::Automatic::Invoice.create(customer_id: '123456', items: items)
|
111
|
+
|
112
|
+
Find existing invoices (see API limits):
|
113
|
+
|
114
|
+
Fastbill::Automatic::Invoive.get(invoice_id: '123456') # With filter
|
115
|
+
Fastbill::Automatic::Invoive.get(customer_id: '123456') # # With filter
|
116
|
+
Fastbill::Automatic::Invoive.get() # Without filters
|
117
|
+
|
118
|
+
Due to the API implementation the result in both cases is an array.
|
119
|
+
|
120
|
+
Updating an existing invoice only works on an instance:
|
121
|
+
|
122
|
+
invoice = Fastbill::Automatic::Invoice.get(invoice_id: '123456').first
|
123
|
+
invoice.update_attributes(currency_code: 'USD', introtext: 'Some intro text')
|
124
|
+
|
125
|
+
Deleting an invoice (type needs to be 'draft'):
|
126
|
+
|
127
|
+
Fastbill::Automatic::Invoice.delete('123456')
|
128
|
+
|
129
|
+
Complete an invoice (type needs to be 'draft'):
|
130
|
+
|
131
|
+
Fastbill::Automatic::Invoice.complete('123456')
|
132
|
+
|
133
|
+
Cancel an invoice (type needs to be 'draft'):
|
134
|
+
|
135
|
+
Fastbill::Automatic::Invoice.cancel('123456')
|
136
|
+
|
137
|
+
Sign and invoice:
|
138
|
+
|
139
|
+
Fastbill::Automatic::Invoice.sign('123456')
|
140
|
+
|
141
|
+
Send invoice via email:
|
142
|
+
|
143
|
+
Fastbill::Automatic::Invoice.sendbyemail(invoice_id: '123456', recipient: { to: 'info@example.com', cc: 'support@example.com' }, subject: 'Some subject text', message: 'Some message text')
|
144
|
+
|
145
|
+
Send invoice by post:
|
146
|
+
|
147
|
+
Fastbill::Automatic::Invoice.sendbypost('123456')
|
148
|
+
|
149
|
+
Set invoice as paid:
|
150
|
+
|
151
|
+
Fastbill::Automatic::Invoice.setpaid(invoice_id: '123456', paid_date: '2013-03-05')
|
152
|
+
|
153
|
+
Item
|
154
|
+
----
|
155
|
+
|
156
|
+
Find existing items (see API limits):
|
157
|
+
|
158
|
+
Fastbill::Automatic::Item.get(invoice_id: '123456') # With filter
|
159
|
+
Fastbill::Automatic::Item.get() # Without filters
|
160
|
+
|
161
|
+
Due to the API implementation the result in both cases is an array.
|
162
|
+
|
163
|
+
Deleting an item:
|
164
|
+
|
165
|
+
Fastbill::Automatic::Item.delete('123456')
|
166
|
+
|
167
|
+
Template
|
168
|
+
--------
|
169
|
+
|
170
|
+
Find existing templates (see API limits):
|
171
|
+
|
172
|
+
Fastbill::Automatic::Template.get()
|
173
|
+
|
174
|
+
Due to the API implementation the result is an array.
|
175
|
+
|
176
|
+
|
177
|
+
Testing
|
178
|
+
=======
|
179
|
+
|
180
|
+
To make testing easier in your app use change the default request mode from `:https` to:
|
181
|
+
|
182
|
+
Fastbill::Automatic.request_method = :test
|
183
|
+
|
184
|
+
Instead of actual requests you find an array with the request infos that you can inspect:
|
185
|
+
|
186
|
+
Fastbill::Automatic::Base.request_infos
|
187
|
+
|
188
|
+
To clear the request infos before or after your test runs do:
|
189
|
+
|
190
|
+
Fastbill::Automatic::Base.clear_request_infos
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
|
data/Rakefile
ADDED
Binary file
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "fastbill-automatic/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "fastbill-automatic"
|
7
|
+
s.version = Fastbill::Automatic::VERSION
|
8
|
+
s.authors = ["Sascha Korth"]
|
9
|
+
s.email = ["sascha.korth@zweitag.de"]
|
10
|
+
s.homepage = "https://github.com/skorth/fastbill-automatic"
|
11
|
+
s.summary = %q{API wrapper for Fastbill.}
|
12
|
+
s.description = %q{API wrapper for Fastbill.}
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_dependency "json"
|
19
|
+
s.add_development_dependency "rspec"
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDJzCCApCgAwIBAgIBATANBgkqhkiG9w0BAQQFADCBzjELMAkGA1UEBhMCWkExFTATBgNVBAgT
|
3
|
+
DFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZSBUb3duMR0wGwYDVQQKExRUaGF3dGUgQ29uc3Vs
|
4
|
+
dGluZyBjYzEoMCYGA1UECxMfQ2VydGlmaWNhdGlvbiBTZXJ2aWNlcyBEaXZpc2lvbjEhMB8GA1UE
|
5
|
+
AxMYVGhhd3RlIFByZW1pdW0gU2VydmVyIENBMSgwJgYJKoZIhvcNAQkBFhlwcmVtaXVtLXNlcnZl
|
6
|
+
ckB0aGF3dGUuY29tMB4XDTk2MDgwMTAwMDAwMFoXDTIwMTIzMTIzNTk1OVowgc4xCzAJBgNVBAYT
|
7
|
+
AlpBMRUwEwYDVQQIEwxXZXN0ZXJuIENhcGUxEjAQBgNVBAcTCUNhcGUgVG93bjEdMBsGA1UEChMU
|
8
|
+
VGhhd3RlIENvbnN1bHRpbmcgY2MxKDAmBgNVBAsTH0NlcnRpZmljYXRpb24gU2VydmljZXMgRGl2
|
9
|
+
aXNpb24xITAfBgNVBAMTGFRoYXd0ZSBQcmVtaXVtIFNlcnZlciBDQTEoMCYGCSqGSIb3DQEJARYZ
|
10
|
+
cHJlbWl1bS1zZXJ2ZXJAdGhhd3RlLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0jY2
|
11
|
+
aovXwlue2oFBYo847kkEVdbQ7xwblRZH7xhINTpS9CtqBo87L+pW46+GjZ4X9560ZXUCTe/LCaIh
|
12
|
+
Udib0GfQug2SBhRz1JPLlyoAnFxODLz6FVL88kRu2hFKbgifLy3j+ao6hnO2RlNYyIkFvYMRuHM/
|
13
|
+
qgeN9EJN50CdHDcCAwEAAaMTMBEwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQQFAAOBgQAm
|
14
|
+
SCwWwlj66BZ0DKqqX1Q/8tfJeGBeXm43YyJ3Nn6yF8Q0ufUIhfzJATj/Tb7yFkJD57taRvvBxhEf
|
15
|
+
8UqwKEbJw8RCfbz6q1lu1bdRiBHjpIUZa4JMpAwSremkrj/xw0llmozFyD4lt5SZu5IycQfwhl7t
|
16
|
+
UCemDaYj+bvLpgcUQg==
|
17
|
+
-----END CERTIFICATE-----
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
class Article < Base
|
4
|
+
|
5
|
+
attr_reader :article_number, :title, :description, :unit_price, :allow_multiple, :is_addon, :currency_code,
|
6
|
+
:vat_percent, :setup_fee, :subscription_interval, :subscription_number_events, :subscription_trail,
|
7
|
+
:subscription_duration, :subscription_cancellation, :return_url_success, :return_url_cancel, :checkout_url
|
8
|
+
|
9
|
+
def self.create(attributes)
|
10
|
+
raise FastbillError.new('Create method not implemented.')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
class Base
|
4
|
+
include Fastbill::Automatic::Services::Get
|
5
|
+
include Fastbill::Automatic::Services::Create
|
6
|
+
|
7
|
+
attr_accessor :attributes
|
8
|
+
|
9
|
+
@@request_infos = []
|
10
|
+
|
11
|
+
def self.request_infos
|
12
|
+
@@request_infos
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.request_infos=(info_array)
|
16
|
+
@@request_infos = info_array
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.clear_request_infos
|
20
|
+
@@request_infos = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(attributes = {})
|
24
|
+
self.attributes = attributes
|
25
|
+
set_attributes(attributes)
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_attributes(attributes)
|
29
|
+
attributes.each_pair do |key, value|
|
30
|
+
instance_variable_set("@#{key.downcase}", value)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
class Coupon < Base
|
4
|
+
|
5
|
+
attr_reader :code, :title, :discount, :discount_period, :valid_from, :valid_to, :assigned_articles
|
6
|
+
|
7
|
+
def self.create(attributes)
|
8
|
+
raise FastbillError.new('Create method not implemented.')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
class Customer < Base
|
4
|
+
include Fastbill::Automatic::Services::Update
|
5
|
+
include Fastbill::Automatic::Services::Delete
|
6
|
+
|
7
|
+
attr_accessor :customer_number, :country_code, :city, :term, :comment, :changedata_url, :paymill_token,
|
8
|
+
:customer_ext_uid, :customer_type, :organization, :position, :salutation, :first_name, :last_name,
|
9
|
+
:address, :address_2, :zipcode, :phone, :phone_2, :fax, :mobile, :email, :account_receivable, :currency_code,
|
10
|
+
:vat_id, :days_for_payment, :payment_type, :show_payment_notice, :bank_name, :bank_code, :bank_account_number,
|
11
|
+
:bank_account_owner, :newsletter_optin, :language_code
|
12
|
+
|
13
|
+
attr_reader :customer_id, :dashboard_url, :changedata_url, :status
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
class Invoice < Base
|
4
|
+
include Fastbill::Automatic::Services::Update
|
5
|
+
include Fastbill::Automatic::Services::Delete
|
6
|
+
include Fastbill::Automatic::Services::Complete
|
7
|
+
include Fastbill::Automatic::Services::Cancel
|
8
|
+
include Fastbill::Automatic::Services::Sign
|
9
|
+
include Fastbill::Automatic::Services::Sendbyemail
|
10
|
+
include Fastbill::Automatic::Services::Sendbypost
|
11
|
+
include Fastbill::Automatic::Services::Setpaid
|
12
|
+
|
13
|
+
attr_accessor :invoice_id, :type, :customer_id, :customer_number, :customer_costcenter_id,
|
14
|
+
:organization, :salutation, :first_name, :last_name, :address, :address_2,
|
15
|
+
:zipcode, :city, :comment, :payment_type, :days_for_payment, :bank_name,
|
16
|
+
:bank_account_number, :bank_code, :bank_account_owner, :bank_iban, :bank_bic,
|
17
|
+
:affiliate, :country_code, :vat_id, :currency_code, :template_id, :subscription_id,
|
18
|
+
:subscription_invoice_counter, :invoice_number, :invoice_title, :introtext, :paid_date,
|
19
|
+
:is_canceled, :invoice_date, :due_date, :delivery_date, :cash_discount_percent, :cash_discount_days,
|
20
|
+
:sub_total, :vat_total, :vat_items, :items, :total, :payment_info, :document_url, :paypal_url
|
21
|
+
|
22
|
+
attr_reader :remaining_credits
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Request
|
4
|
+
class Base
|
5
|
+
attr_reader :info
|
6
|
+
attr_accessor :response
|
7
|
+
|
8
|
+
def initialize(info)
|
9
|
+
@info = info
|
10
|
+
end
|
11
|
+
|
12
|
+
def perform
|
13
|
+
raise AuthenticationError if Fastbill::Automatic.api_key.nil? || Fastbill::Automatic.email.nil?
|
14
|
+
connection.setup_https
|
15
|
+
send_request
|
16
|
+
|
17
|
+
validator.validated_data_for(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def send_request
|
23
|
+
self.response = connection.request
|
24
|
+
end
|
25
|
+
|
26
|
+
def connection
|
27
|
+
@connection ||= Connection.new(info)
|
28
|
+
end
|
29
|
+
|
30
|
+
def validator
|
31
|
+
@validator ||= Validator.new(info)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Request
|
4
|
+
class Connection
|
5
|
+
attr_reader :https
|
6
|
+
|
7
|
+
def initialize(request_info)
|
8
|
+
@info = request_info
|
9
|
+
end
|
10
|
+
|
11
|
+
def setup_https
|
12
|
+
@https = Net::HTTP.new(API_BASE, Net::HTTP.https_default_port)
|
13
|
+
@https.use_ssl = true
|
14
|
+
@https.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
15
|
+
@https.ca_file = File.join(ROOT_PATH, "data/fastbill.crt")
|
16
|
+
end
|
17
|
+
|
18
|
+
def request
|
19
|
+
https.start do |connection|
|
20
|
+
https.request(https_request)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def https_request
|
27
|
+
https_request = Net::HTTP::Post.new(@info.url)
|
28
|
+
https_request.basic_auth(Fastbill::Automatic.email, Fastbill::Automatic.api_key)
|
29
|
+
body = {service: @info.service}
|
30
|
+
body[(@info.service.include?('.get') ? :filter : :data)] = @info.data
|
31
|
+
https_request.body = body.to_json
|
32
|
+
https_request
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Request
|
4
|
+
class Info
|
5
|
+
attr_accessor :service, :data
|
6
|
+
|
7
|
+
def ==(other)
|
8
|
+
@service == other.service && @data == other.data
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(service, data)
|
12
|
+
@service = service
|
13
|
+
@data = data
|
14
|
+
end
|
15
|
+
|
16
|
+
def url
|
17
|
+
url = "/api/#{API_VERSION}/api.php"
|
18
|
+
url
|
19
|
+
end
|
20
|
+
|
21
|
+
def path_with_params(path, params)
|
22
|
+
unless params.empty?
|
23
|
+
encoded_params = URI.encode_www_form(params)
|
24
|
+
[path, encoded_params].join("?")
|
25
|
+
else
|
26
|
+
path
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Request
|
4
|
+
class Validator
|
5
|
+
attr_reader :info
|
6
|
+
attr_accessor :response
|
7
|
+
|
8
|
+
def initialize(info)
|
9
|
+
@info = info
|
10
|
+
end
|
11
|
+
|
12
|
+
def validated_data_for(incoming_response)
|
13
|
+
self.response = incoming_response
|
14
|
+
verify_response_code
|
15
|
+
info.data = JSON.parse(response.body)
|
16
|
+
validate_response_data
|
17
|
+
info.data
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def verify_response_code
|
23
|
+
raise AuthenticationError if response.code.to_i == 401
|
24
|
+
raise APIError if response.code.to_i >= 500
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate_response_data
|
28
|
+
raise APIError.new(info.data["RESPONSE"]["ERRORS"]) if info.data["RESPONSE"]["ERRORS"]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Services
|
4
|
+
module Cancel
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def cancel(id)
|
8
|
+
id_attribute = "#{self.name.split("::").last.downcase}_id".to_sym
|
9
|
+
attributes = {}
|
10
|
+
attributes[id_attribute] = id
|
11
|
+
response = Fastbill::Automatic.request("#{self.name.split("::").last.downcase}.cancel", attributes)
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
base.extend(ClassMethods)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Services
|
4
|
+
module Changearticle
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def changearticle(attributes)
|
8
|
+
response = Fastbill::Automatic.request("#{self.name.split("::").last.downcase}.changearticle", attributes)
|
9
|
+
true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.included(base)
|
14
|
+
base.extend(ClassMethods)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Services
|
4
|
+
module Complete
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def complete(id)
|
8
|
+
id_attribute = "#{self.name.split("::").last.downcase}_id".to_sym
|
9
|
+
attributes = {}
|
10
|
+
attributes[id_attribute] = id
|
11
|
+
response = Fastbill::Automatic.request("#{self.name.split("::").last.downcase}.complete", attributes)
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
base.extend(ClassMethods)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Services
|
4
|
+
module Create
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def create(attributes)
|
8
|
+
response = Fastbill::Automatic.request("#{self.name.split("::").last.downcase}.create", attributes)
|
9
|
+
self.new(response["RESPONSE"])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.included(base)
|
14
|
+
base.extend(ClassMethods)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Services
|
4
|
+
module Delete
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def delete(id)
|
8
|
+
id_attribute = "#{self.name.split("::").last.downcase}_id".to_sym
|
9
|
+
attributes = {}
|
10
|
+
attributes[id_attribute] = id
|
11
|
+
response = Fastbill::Automatic.request("#{self.name.split("::").last.downcase}.delete", attributes)
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
base.extend(ClassMethods)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|