billomat-rb 0.0.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/.gitignore +11 -0
- data/LICENSE +20 -0
- data/README.textile +21 -0
- data/Rakefile +45 -0
- data/TODO.textile +28 -0
- data/VERSION.yml +5 -0
- data/billomat-rb.gemspec +56 -0
- data/lib/billomat-rb.rb +171 -0
- data/lib/billomat/account.rb +2 -0
- data/lib/billomat/myself.rb +15 -0
- data/lib/billomat/settings.rb +2 -0
- data/lib/billomat/users.rb +3 -0
- metadata +101 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2009 Ronald Becher
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
h1. billomat-rb
|
|
2
|
+
|
|
3
|
+
A neat ruby library for interacting with the "RESTful API":http://www.billomat.com/api/ of "billomat":http://www.billomat.com/.
|
|
4
|
+
|
|
5
|
+
h2. Requirements
|
|
6
|
+
|
|
7
|
+
billomat-rb requires active_resource and active_support in version 2.3.2 or above.
|
|
8
|
+
|
|
9
|
+
h2. Note on Patches/Pull Requests
|
|
10
|
+
* Fork the project.
|
|
11
|
+
* Make your feature addition or bug fix.
|
|
12
|
+
* Add tests for it. This is important so I don't break it in a
|
|
13
|
+
future version unintentionally.
|
|
14
|
+
* Commit, do not mess with rakefile, version, or history.
|
|
15
|
+
(if you want to have your own version, that is fine but
|
|
16
|
+
bump version in a commit by itself I can ignore when I pull)
|
|
17
|
+
* Send me a pull request. Bonus points for topic branches.
|
|
18
|
+
|
|
19
|
+
h2. Copyright
|
|
20
|
+
|
|
21
|
+
Copyright (c) 2010 Ronald Becher. See LICENSE for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
task :default => [:build]
|
|
5
|
+
|
|
6
|
+
$gem_name = "billomat-rb"
|
|
7
|
+
|
|
8
|
+
#desc "Run specs"
|
|
9
|
+
#task :spec do
|
|
10
|
+
# sh "spec spec/* --format specdoc --color"
|
|
11
|
+
#end
|
|
12
|
+
|
|
13
|
+
begin
|
|
14
|
+
require 'jeweler'
|
|
15
|
+
Jeweler::Tasks.new do |gem|
|
|
16
|
+
gem.name = "billomat-rb"
|
|
17
|
+
gem.summary = "Ruby library for interacting with the RESTfull billomat api."
|
|
18
|
+
gem.description = "A neat ruby library for interacting with the RESTfull API of billomat"
|
|
19
|
+
gem.email = "rb@ronald-becher.com"
|
|
20
|
+
gem.homepage = "http://github.com/rbecher/billomat-rb"
|
|
21
|
+
gem.authors = ["Ronald Becher"]
|
|
22
|
+
gem.rubyforge_project = "billomat-rb"
|
|
23
|
+
gem.add_dependency(%q<activesupport>, [">= 2.3.2"])
|
|
24
|
+
gem.add_dependency(%q<activeresource>, [">= 2.3.2"])
|
|
25
|
+
end
|
|
26
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
|
27
|
+
rubyforge.doc_task = "rdoc"
|
|
28
|
+
end
|
|
29
|
+
rescue LoadError
|
|
30
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
require 'rake/rdoctask'
|
|
34
|
+
Rake::RDocTask.new do |rdoc|
|
|
35
|
+
if File.exist?('VERSION')
|
|
36
|
+
version = File.read('VERSION')
|
|
37
|
+
else
|
|
38
|
+
version = ""
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
42
|
+
rdoc.title = "billomat-rb #{version}"
|
|
43
|
+
rdoc.rdoc_files.include('README*')
|
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
45
|
+
end
|
data/TODO.textile
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
h1. STD (Still To Do)
|
|
2
|
+
|
|
3
|
+
h2. General
|
|
4
|
+
* General framework
|
|
5
|
+
* Formats
|
|
6
|
+
** XML
|
|
7
|
+
** JSON
|
|
8
|
+
* Authentification
|
|
9
|
+
* Distinguish read-only and read-write resources
|
|
10
|
+
* Error handling
|
|
11
|
+
* SSL and not SSL (or even exclusively?)
|
|
12
|
+
|
|
13
|
+
h2. Resources
|
|
14
|
+
* Customer
|
|
15
|
+
* Articles
|
|
16
|
+
* Units
|
|
17
|
+
* Bills
|
|
18
|
+
** Bill-Items
|
|
19
|
+
** Bill-Comments
|
|
20
|
+
** BIll-History
|
|
21
|
+
** Payments
|
|
22
|
+
* Offers
|
|
23
|
+
** Offer-Items
|
|
24
|
+
** Offer-Comments
|
|
25
|
+
** Offer-History
|
|
26
|
+
* Templates
|
|
27
|
+
* Settinfs
|
|
28
|
+
* User
|
data/VERSION.yml
ADDED
data/billomat-rb.gemspec
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = %q{billomat-rb}
|
|
8
|
+
s.version = "0.0.1"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["Ronald Becher"]
|
|
12
|
+
s.date = %q{2010-03-30}
|
|
13
|
+
s.description = %q{A neat ruby library for interacting with the RESTfull API of billomat}
|
|
14
|
+
s.email = %q{rb@ronald-becher.com}
|
|
15
|
+
s.extra_rdoc_files = [
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"README.textile"
|
|
18
|
+
]
|
|
19
|
+
s.files = [
|
|
20
|
+
".gitignore",
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"README.textile",
|
|
23
|
+
"Rakefile",
|
|
24
|
+
"TODO.textile",
|
|
25
|
+
"VERSION.yml",
|
|
26
|
+
"billomat-rb.gemspec",
|
|
27
|
+
"lib/billomat-rb.rb",
|
|
28
|
+
"lib/billomat/account.rb",
|
|
29
|
+
"lib/billomat/myself.rb",
|
|
30
|
+
"lib/billomat/settings.rb",
|
|
31
|
+
"lib/billomat/users.rb"
|
|
32
|
+
]
|
|
33
|
+
s.homepage = %q{http://github.com/rbecher/billomat-rb}
|
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
35
|
+
s.require_paths = ["lib"]
|
|
36
|
+
s.rubyforge_project = %q{billomat-rb}
|
|
37
|
+
s.rubygems_version = %q{1.3.6}
|
|
38
|
+
s.summary = %q{Ruby library for interacting with the RESTfull billomat api.}
|
|
39
|
+
|
|
40
|
+
if s.respond_to? :specification_version then
|
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
42
|
+
s.specification_version = 3
|
|
43
|
+
|
|
44
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
45
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.2"])
|
|
46
|
+
s.add_runtime_dependency(%q<activeresource>, [">= 2.3.2"])
|
|
47
|
+
else
|
|
48
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.2"])
|
|
49
|
+
s.add_dependency(%q<activeresource>, [">= 2.3.2"])
|
|
50
|
+
end
|
|
51
|
+
else
|
|
52
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.2"])
|
|
53
|
+
s.add_dependency(%q<activeresource>, [">= 2.3.2"])
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
data/lib/billomat-rb.rb
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
gem 'activeresource', '=2.3.5'
|
|
3
|
+
gem 'activesupport', '=2.3.5'
|
|
4
|
+
require 'active_support'
|
|
5
|
+
require 'active_resource'
|
|
6
|
+
|
|
7
|
+
# A neat ruby library for interacting with the RESTfull API of billomat
|
|
8
|
+
|
|
9
|
+
module Billomat
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
attr_accessor :email, :password, :host_format, :domain_format, :protocol, :port, :api_path
|
|
13
|
+
attr_reader :account, :key
|
|
14
|
+
|
|
15
|
+
# Sets the account name and updates all resources with the new domain
|
|
16
|
+
def account=(name)
|
|
17
|
+
resources.each do |klass|
|
|
18
|
+
klass.site = klass.site_format % (host_format % [protocol, domain_format % name, ":#{port}", api_path])
|
|
19
|
+
end
|
|
20
|
+
@account = name
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Sets up basic authentication credentials for all resources.
|
|
24
|
+
# Removes all earlier authentication info
|
|
25
|
+
def authenticate (email,password)
|
|
26
|
+
resources.each do |klass|
|
|
27
|
+
klass.email = email
|
|
28
|
+
klass.password = password
|
|
29
|
+
klass.headers.delete 'X-BillomatApiKey'
|
|
30
|
+
end
|
|
31
|
+
@email = email
|
|
32
|
+
@password = password
|
|
33
|
+
@key = nil
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Sets the api key for all resource
|
|
37
|
+
# Removes all earlier authentication info
|
|
38
|
+
def key=(value)
|
|
39
|
+
resources.each do |klass|
|
|
40
|
+
klass.headers['X-BillomatApiKey'] = value
|
|
41
|
+
end
|
|
42
|
+
@key = value
|
|
43
|
+
@email = nil
|
|
44
|
+
@password = nil
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Validates connection
|
|
48
|
+
# returns true when valid false when not
|
|
49
|
+
def validate
|
|
50
|
+
validate! rescue false
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Same as validate
|
|
54
|
+
# but raises http-error when connection is invalid
|
|
55
|
+
def validate!
|
|
56
|
+
!!Billomat::Myself.find
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def resources
|
|
60
|
+
@resources ||= []
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
self.host_format = '%s://%s%s%s' # protocol :// domain_format port path
|
|
65
|
+
self.domain_format = '%s.billomat.net'
|
|
66
|
+
self.api_path = '/api'
|
|
67
|
+
self.protocol = 'http'
|
|
68
|
+
self.port = '80'
|
|
69
|
+
|
|
70
|
+
class MethodNotAvailable < StandardError; end
|
|
71
|
+
|
|
72
|
+
module ResourceWithoutWriteAccess
|
|
73
|
+
def save
|
|
74
|
+
raise MethodNotAvailable, "Cannot save #{self.class.name} over billomat api"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def create
|
|
78
|
+
raise MethodNotAvailable, "Cannot save #{self.class.name} over billomat api"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def destroy
|
|
82
|
+
raise MethodNotAvailable, "Cannot save #{self.class.name} over billomat api"
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# possibly ResourceWithActiveArchived
|
|
87
|
+
|
|
88
|
+
class Base < ActiveResource::Base
|
|
89
|
+
class << self
|
|
90
|
+
def inherited(base)
|
|
91
|
+
unless base == Billomat::SingletonBase
|
|
92
|
+
Billomat.resources << base
|
|
93
|
+
class << base
|
|
94
|
+
attr_accessor :site_format
|
|
95
|
+
end
|
|
96
|
+
base.site_format = '%s'
|
|
97
|
+
base.timeout = 20
|
|
98
|
+
end
|
|
99
|
+
super
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def element_path(id,prefix_options = {}, query_options = nil)
|
|
103
|
+
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
|
|
104
|
+
"#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def collection_path(prefix_options = {}, query_options = nil)
|
|
108
|
+
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
|
|
109
|
+
"#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Some common shortcuts from ActiveRecord
|
|
113
|
+
|
|
114
|
+
def all(options={})
|
|
115
|
+
find(:all,options)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def first(options={})
|
|
119
|
+
find_every(options).first
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def last(options={})
|
|
123
|
+
find_every(options).last
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
private
|
|
128
|
+
|
|
129
|
+
def query_string?(options)
|
|
130
|
+
options.is_a?(String) ? "#{options}" : super
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
class SingletonBase < Base
|
|
135
|
+
include ResourceWithoutWriteAccess
|
|
136
|
+
|
|
137
|
+
class << self
|
|
138
|
+
def collection_name
|
|
139
|
+
element_name
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def find
|
|
144
|
+
super(1)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def self.first
|
|
148
|
+
self.find
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def self.last
|
|
152
|
+
self.find
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
alias_method :first, :find
|
|
156
|
+
alias_method :last, :find
|
|
157
|
+
|
|
158
|
+
# Prevent collection methods
|
|
159
|
+
def self.all
|
|
160
|
+
raise MethodNotAvailable, "Method not supported on #{self.class.name}"
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
#$:.unshift(File.dirname(__FILE__))
|
|
166
|
+
#Dir[File.join(File.dirname(__FILE__), "billomat/*.rb")].each { |f| require f }
|
|
167
|
+
|
|
168
|
+
require File.dirname(__FILE__) + '/billomat/account'
|
|
169
|
+
require File.dirname(__FILE__) + '/billomat/settings'
|
|
170
|
+
require File.dirname(__FILE__) + '/billomat/users'
|
|
171
|
+
require File.dirname(__FILE__) + '/billomat/myself'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class Billomat::Myself < Billomat::SingletonBase
|
|
2
|
+
|
|
3
|
+
# non standard path
|
|
4
|
+
def self.element_name
|
|
5
|
+
"users/myself"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# get the billomat user for the logged in person
|
|
9
|
+
def user
|
|
10
|
+
Billomat::Users.all.each do |user|
|
|
11
|
+
return user if user.id==self.id
|
|
12
|
+
end
|
|
13
|
+
raise StandardError
|
|
14
|
+
end
|
|
15
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: billomat-rb
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 0
|
|
8
|
+
- 1
|
|
9
|
+
version: 0.0.1
|
|
10
|
+
platform: ruby
|
|
11
|
+
authors:
|
|
12
|
+
- Ronald Becher
|
|
13
|
+
autorequire:
|
|
14
|
+
bindir: bin
|
|
15
|
+
cert_chain: []
|
|
16
|
+
|
|
17
|
+
date: 2010-03-30 00:00:00 +02:00
|
|
18
|
+
default_executable:
|
|
19
|
+
dependencies:
|
|
20
|
+
- !ruby/object:Gem::Dependency
|
|
21
|
+
name: activesupport
|
|
22
|
+
prerelease: false
|
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
segments:
|
|
28
|
+
- 2
|
|
29
|
+
- 3
|
|
30
|
+
- 2
|
|
31
|
+
version: 2.3.2
|
|
32
|
+
type: :runtime
|
|
33
|
+
version_requirements: *id001
|
|
34
|
+
- !ruby/object:Gem::Dependency
|
|
35
|
+
name: activeresource
|
|
36
|
+
prerelease: false
|
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
segments:
|
|
42
|
+
- 2
|
|
43
|
+
- 3
|
|
44
|
+
- 2
|
|
45
|
+
version: 2.3.2
|
|
46
|
+
type: :runtime
|
|
47
|
+
version_requirements: *id002
|
|
48
|
+
description: A neat ruby library for interacting with the RESTfull API of billomat
|
|
49
|
+
email: rb@ronald-becher.com
|
|
50
|
+
executables: []
|
|
51
|
+
|
|
52
|
+
extensions: []
|
|
53
|
+
|
|
54
|
+
extra_rdoc_files:
|
|
55
|
+
- LICENSE
|
|
56
|
+
- README.textile
|
|
57
|
+
files:
|
|
58
|
+
- .gitignore
|
|
59
|
+
- LICENSE
|
|
60
|
+
- README.textile
|
|
61
|
+
- Rakefile
|
|
62
|
+
- TODO.textile
|
|
63
|
+
- VERSION.yml
|
|
64
|
+
- billomat-rb.gemspec
|
|
65
|
+
- lib/billomat-rb.rb
|
|
66
|
+
- lib/billomat/account.rb
|
|
67
|
+
- lib/billomat/myself.rb
|
|
68
|
+
- lib/billomat/settings.rb
|
|
69
|
+
- lib/billomat/users.rb
|
|
70
|
+
has_rdoc: true
|
|
71
|
+
homepage: http://github.com/rbecher/billomat-rb
|
|
72
|
+
licenses: []
|
|
73
|
+
|
|
74
|
+
post_install_message:
|
|
75
|
+
rdoc_options:
|
|
76
|
+
- --charset=UTF-8
|
|
77
|
+
require_paths:
|
|
78
|
+
- lib
|
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
segments:
|
|
84
|
+
- 0
|
|
85
|
+
version: "0"
|
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - ">="
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
segments:
|
|
91
|
+
- 0
|
|
92
|
+
version: "0"
|
|
93
|
+
requirements: []
|
|
94
|
+
|
|
95
|
+
rubyforge_project: billomat-rb
|
|
96
|
+
rubygems_version: 1.3.6
|
|
97
|
+
signing_key:
|
|
98
|
+
specification_version: 3
|
|
99
|
+
summary: Ruby library for interacting with the RESTfull billomat api.
|
|
100
|
+
test_files: []
|
|
101
|
+
|