Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha Korth committed Aug 23, 2013
1 parent 570ff20 commit dc84cef
Show file tree
Hide file tree
Showing 35 changed files with 872 additions and 17 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.gem
.bundle
Gemfile.lock
pkg/*
*.html
/.rvmrc
.project
.ruby-version
.ruby-gemset

5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "http://rubygems.org"

gemspec

gem 'pry'
33 changes: 18 additions & 15 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
The MIT License (MIT)
(The MIT License)

Copyright (c) 2013 Sascha Korth
Copyright (c) 2013 Reputami GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
173 changes: 171 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,173 @@
fastbill-automatic
Fastbill Automatic
==================

Ruby wrapper for the Fastbill Automatic API
This is a Ruby wrapper for FastBill's Automatic API based on API-Documentation v1.6 (21.08.2013)

Usage
======

First, you've to install the gem

gem 'fastbill-automatic', git: 'git://github.com/skorth/fastbill-automatic.git'

and require it

require "fastbill-automatic"

Then you have to set your Email Adress & API key:

Fastbill::Automatic.api_key = "your-api-key"
Fastbill::Automatic.email = "your-email-adress"

Article
-------

Find existing articles (see API limits):

Fastbill::Automatic::Article.get()

Due to the API implementation the result is an array.

Coupon
------

Find existing coupons (see API limits):

Fastbill::Automatic::Coupon.get()

Due to the API implementation the result is an array.

Customer
--------

Creating a new customer:

Fastbill::Automatic::Customer.create(customer_type: 'business', organization: 'Company name', country_code: 'DE', payment_type: 1)

Find existing customers (see API limits):

Fastbill::Automatic::Customer.get(customer_id: "123456") # With filters
Fastbill::Automatic::Customer.get() # Without filters

Due to the API implementation the result in both cases is an array.

Updating an existing customer only works on an instance:

customer = Fastbill::Automatic::Customer.get(customer_id: "123456").first
customer.update_attributes(first_name: 'Max', last_name: 'Mustermann')

Deleting a customer:

Fastbill::Automatic::Customer.delete("123456")

Subscription
------------

Creating a new subscription:

Fastbill::Automatic::Subscription.create(article_number: '123', customer_id: '123456')

Find existing subscriptions (see API limits):

Fastbill::Automatic::Subscription.get(customer_id: '123456') # With filter
Fastbill::Automatic::Subscription.get(subscription_id: '1234') # # With filter
Fastbill::Automatic::Subscription.get() # Without filters

Due to the API implementation the result in both cases is an array.

Updating an existing subscription only works on an instance:

subscription = Fastbill::Automatic::Subscription.get(subscription_id: "123456").first
subscription.update_attributes(next_event: '2013-07-10')

Changing an article for a given subscription:

Fastbill::Automatic::Subscription.changearticle(subscription_id: '1234', article_number: '123')

Create new addon for a given subscription:

Fastbill::Automatic::Subscription.setaddon(subscription_id: '1234', article_number: '123', quantity: '10')

API Bug! => (Subscription Error: Missing / invalid field: ARTICLE_NUMBER)

Set usage data for given subscription:

Fastbill::Automatic::Subscription.setusagedata(subscription_id: '1234', article_number: '123', quantity: '10')

Cancel a subscription:

Fastbill::Subscription.cancel('1234')

Invoice
-------

Creating a new invoice:

item = {description: 'Some info text', unit_price: '60.00', vat_percent: '19.00'}
items = (Array.new << item)

Fastbill::Automatic::Invoice.create(customer_id: '123456', items: items)

Find existing invoices (see API limits):

Fastbill::Automatic::Invoive.get(invoice_id: '123456') # With filter
Fastbill::Automatic::Invoive.get(customer_id: '123456') # # With filter
Fastbill::Automatic::Invoive.get() # Without filters

Due to the API implementation the result in both cases is an array.

Updating an existing invoice only works on an instance:

invoice = Fastbill::Automatic::Invoice.get(invoice_id: '123456').first
invoice.update_attributes(currency_code: 'USD', introtext: 'Some intro text')

Deleting an invoice (type needs to be 'draft'):

Fastbill::Automatic::Invoice.delete('123456')

Complete an invoice (type needs to be 'draft'):

Fastbill::Automatic::Invoice.complete('123456')

Cancel an invoice (type needs to be 'draft'):

Fastbill::Automatic::Invoice.cancel('123456')

Sign and invoice:

Fastbill::Automatic::Invoice.sign('123456')

Send invoice via email:

Fastbill::Automatic::Invoice.sendbyemail(invoice_id: '123456', recipient: { to: 'info@example.com', cc: 'support@example.com' }, subject: 'Some subject text', message: 'Some message text')

Send invoice by post:

Fastbill::Automatic::Invoice.sendbypost('123456')

Set invoice as paid:

Fastbill::Automatic::Invoice.setpaid(invoice_id: '123456', paid_date: '2013-03-05')

Item
----

Find existing items (see API limits):

Fastbill::Automatic::Item.get(invoice_id: '123456') # With filter
Fastbill::Automatic::Item.get() # Without filters

Due to the API implementation the result in both cases is an array.

Deleting an item:

Fastbill::Automatic::Item.delete('123456')

Template
--------

Find existing templates (see API limits):

Fastbill::Automatic::Template.get()

Due to the API implementation the result is an array.
Binary file added doc/API-Doku_FBA_V1-6.pdf
Binary file not shown.
19 changes: 19 additions & 0 deletions fastbill-automatic.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# coding: utf-8
$:.push File.expand_path("../lib", __FILE__)
require "fastbill-automatic/version"

Gem::Specification.new do |s|
s.name = "fastbill-automatic"
s.version = Fastbill::Automatic::VERSION
s.authors = ["Sascha Korth"]
s.email = ["sascha.korth@zweitag.de"]
s.homepage = "https://github.com/skorth/fastbill-automatic"
s.summary = %q{API wrapper for Fastbill.}
s.description = %q{API wrapper for Fastbill.}
s.license = "MIT"

s.files = `git ls-files`.split("\n")
s.require_paths = ["lib"]

s.add_dependency "json"
end
17 changes: 17 additions & 0 deletions lib/data/fastbill.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE-----
MIIDJzCCApCgAwIBAgIBATANBgkqhkiG9w0BAQQFADCBzjELMAkGA1UEBhMCWkExFTATBgNVBAgT
DFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZSBUb3duMR0wGwYDVQQKExRUaGF3dGUgQ29uc3Vs
dGluZyBjYzEoMCYGA1UECxMfQ2VydGlmaWNhdGlvbiBTZXJ2aWNlcyBEaXZpc2lvbjEhMB8GA1UE
AxMYVGhhd3RlIFByZW1pdW0gU2VydmVyIENBMSgwJgYJKoZIhvcNAQkBFhlwcmVtaXVtLXNlcnZl
ckB0aGF3dGUuY29tMB4XDTk2MDgwMTAwMDAwMFoXDTIwMTIzMTIzNTk1OVowgc4xCzAJBgNVBAYT
AlpBMRUwEwYDVQQIEwxXZXN0ZXJuIENhcGUxEjAQBgNVBAcTCUNhcGUgVG93bjEdMBsGA1UEChMU
VGhhd3RlIENvbnN1bHRpbmcgY2MxKDAmBgNVBAsTH0NlcnRpZmljYXRpb24gU2VydmljZXMgRGl2
aXNpb24xITAfBgNVBAMTGFRoYXd0ZSBQcmVtaXVtIFNlcnZlciBDQTEoMCYGCSqGSIb3DQEJARYZ
cHJlbWl1bS1zZXJ2ZXJAdGhhd3RlLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0jY2
aovXwlue2oFBYo847kkEVdbQ7xwblRZH7xhINTpS9CtqBo87L+pW46+GjZ4X9560ZXUCTe/LCaIh
Udib0GfQug2SBhRz1JPLlyoAnFxODLz6FVL88kRu2hFKbgifLy3j+ao6hnO2RlNYyIkFvYMRuHM/
qgeN9EJN50CdHDcCAwEAAaMTMBEwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQQFAAOBgQAm
SCwWwlj66BZ0DKqqX1Q/8tfJeGBeXm43YyJ3Nn6yF8Q0ufUIhfzJATj/Tb7yFkJD57taRvvBxhEf
8UqwKEbJw8RCfbz6q1lu1bdRiBHjpIUZa4JMpAwSremkrj/xw0llmozFyD4lt5SZu5IycQfwhl7t
UCemDaYj+bvLpgcUQg==
-----END CERTIFICATE-----
73 changes: 73 additions & 0 deletions lib/fastbill-automatic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
require "net/http"
require "net/https"
require "json"
require "fastbill-automatic/version"

module Fastbill
module Automatic
API_BASE = "automatic.fastbill.com"
API_VERSION = "1.0"
ROOT_PATH = File.dirname(__FILE__)

@@api_key = nil
@@email = nil

autoload :Base, "fastbill-automatic/base"
autoload :Customer, "fastbill-automatic/customer"
autoload :Invoice, "fastbill-automatic/Invoice"
autoload :Item, "fastbill-automatic/Item"
autoload :Subscription, "fastbill-automatic/subscription"
autoload :Template, "fastbill-automatic/Template"
autoload :Article, "fastbill-automatic/Article"
autoload :Coupon, "fastbill-automatic/Coupon"

module Services
autoload :Get, "fastbill-automatic/services/get"
autoload :Create, "fastbill-automatic/services/create"
autoload :Update, "fastbill-automatic/services/update"
autoload :Delete, "fastbill-automatic/services/delete"
autoload :DeleteItem, "fastbill-automatic/services/delete_item"
autoload :Cancel, "fastbill-automatic/services/cancel"
autoload :Changearticle, "fastbill-automatic/services/changearticle"
autoload :Complete, "fastbill-automatic/services/complete"
autoload :Sign, "fastbill-automatic/services/sign"
autoload :Sendbyemail, "fastbill-automatic/services/sendbyemail"
autoload :Sendbypost, "fastbill-automatic/services/sendbypost"
autoload :Setaddon, "fastbill-automatic/services/setaddon"
autoload :Setpaid, "fastbill-automatic/services/setpaid"
autoload :Setusagedata, "fastbill-automatic/services/setusagedata"
end

module Request
autoload :Base, "fastbill-automatic/request/base"
autoload :Connection, "fastbill-automatic/request/connection"
autoload :Info, "fastbill-automatic/request/info"
autoload :Validator, "fastbill-automatic/request/validator"
end

class FastbillError < StandardError; end
class AuthenticationError < FastbillError; end
class APIError < FastbillError; end

def self.api_key
@@api_key
end

def self.api_key=(api_key)
@@api_key = api_key
end

def self.email
@@email
end

def self.email=(email)
@@email = email
end

def self.request(service, data)
info = Request::Info.new(service, data)
Request::Base.new(info).perform
end
end
end
14 changes: 14 additions & 0 deletions lib/fastbill-automatic/article.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Fastbill
module Automatic
class Article < Base

attr_reader :article_number, :title, :description, :unit_price, :allow_multiple, :is_addon, :currency_code,
:vat_percent, :setup_fee, :subscription_interval, :subscription_number_events, :subscription_trail,
:subscription_duration, :subscription_cancellation, :return_url_success, :return_url_cancel, :checkout_url

def self.create(attributes)
raise FastbillError.new('Create method not implemented.')
end
end
end
end
18 changes: 18 additions & 0 deletions lib/fastbill-automatic/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Fastbill
module Automatic
class Base
include Fastbill::Automatic::Services::Get
include Fastbill::Automatic::Services::Create

def initialize(attributes = {})
set_attributes(attributes)
end

def set_attributes(attributes)
attributes.each_pair do |key, value|
instance_variable_set("@#{key.downcase}", value)
end
end
end
end
end
12 changes: 12 additions & 0 deletions lib/fastbill-automatic/coupon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Fastbill
module Automatic
class Coupon < Base

attr_reader :code, :title, :discount, :discount_period, :valid_from, :valid_to, :assigned_articles

def self.create(attributes)
raise FastbillError.new('Create method not implemented.')
end
end
end
end
Loading

0 comments on commit dc84cef

Please sign in to comment.