billomat-rb 0.0.1 → 0.0.2

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/CHANGES.textile ADDED
@@ -0,0 +1,14 @@
1
+ h1. Changes
2
+
3
+ h2. Version 0.0.2
4
+
5
+ * Added models for clients and units (almost working actually)
6
+ * punched some holes through my wall because of an activesupport bug
7
+
8
+ h2. Version 0.0.1
9
+
10
+ * Added models for users, the logged in user (aka "myself") and settings
11
+
12
+ h2. Version 0.0.0
13
+
14
+ The first commit. Ever. Particularly unique
data/TODO.textile CHANGED
@@ -2,10 +2,6 @@ h1. STD (Still To Do)
2
2
 
3
3
  h2. General
4
4
  * General framework
5
- * Formats
6
- ** XML
7
- ** JSON
8
- * Authentification
9
5
  * Distinguish read-only and read-write resources
10
6
  * Error handling
11
7
  * SSL and not SSL (or even exclusively?)
@@ -24,5 +20,5 @@ h2. Resources
24
20
  ** Offer-Comments
25
21
  ** Offer-History
26
22
  * Templates
27
- * Settinfs
23
+ * Settings
28
24
  * User
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
- ---
2
- :build:
3
- :patch: 1
4
- :major: 0
5
- :minor: 0
1
+ ---
2
+ :build:
3
+ :patch: 2
4
+ :major: 0
5
+ :minor: 0
data/billomat-rb.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{billomat-rb}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ronald Becher"]
12
- s.date = %q{2010-03-30}
12
+ s.date = %q{2010-04-01}
13
13
  s.description = %q{A neat ruby library for interacting with the RESTfull API of billomat}
14
14
  s.email = %q{rb@ronald-becher.com}
15
15
  s.extra_rdoc_files = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".gitignore",
21
+ "CHANGES.textile",
21
22
  "LICENSE",
22
23
  "README.textile",
23
24
  "Rakefile",
@@ -25,9 +26,10 @@ Gem::Specification.new do |s|
25
26
  "VERSION.yml",
26
27
  "billomat-rb.gemspec",
27
28
  "lib/billomat-rb.rb",
28
- "lib/billomat/account.rb",
29
+ "lib/billomat/clients.rb",
29
30
  "lib/billomat/myself.rb",
30
31
  "lib/billomat/settings.rb",
32
+ "lib/billomat/unit.rb",
31
33
  "lib/billomat/users.rb"
32
34
  ]
33
35
  s.homepage = %q{http://github.com/rbecher/billomat-rb}
data/lib/billomat-rb.rb CHANGED
@@ -83,10 +83,19 @@ module Billomat
83
83
  end
84
84
  end
85
85
 
86
+ module ResourceWithoutId
87
+ def save
88
+ connection.put(element_path(prefix_options), encode, self.class.headers).tap do |response|
89
+ load_attributes_from_response(response)
90
+ end
91
+ end
92
+ end
93
+
86
94
  # possibly ResourceWithActiveArchived
87
95
 
88
96
  class Base < ActiveResource::Base
89
97
  class << self
98
+ ActiveSupport.dasherize_xml = false
90
99
  def inherited(base)
91
100
  unless base == Billomat::SingletonBase
92
101
  Billomat.resources << base
@@ -99,11 +108,21 @@ module Billomat
99
108
  super
100
109
  end
101
110
 
102
- def element_path(id,prefix_options = {}, query_options = nil)
111
+ def element_path(id, prefix_options = {}, query_options = nil)
103
112
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
104
- "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
113
+ "#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
114
+ end
115
+
116
+ def el_p(id,prefix_options = {}, query_options = nil)
117
+ element_path(id,prefix_options, query_options)
118
+ end
119
+
120
+ def coll_p(prefix_options = {}, query_options = nil)
121
+ collection_path(prefix_options, query_options)
105
122
  end
106
123
 
124
+
125
+
107
126
  def collection_path(prefix_options = {}, query_options = nil)
108
127
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
109
128
  "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
@@ -132,15 +151,28 @@ module Billomat
132
151
  end
133
152
 
134
153
  class SingletonBase < Base
135
- include ResourceWithoutWriteAccess
154
+
155
+ include ResourceWithoutId
136
156
 
137
157
  class << self
138
158
  def collection_name
139
159
  element_name
140
160
  end
161
+
162
+ def element_path(id,prefix_options = {}, query_options = nil)
163
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
164
+ "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
165
+ end
166
+
167
+ def collection_path(prefix_options = {}, query_options = nil)
168
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
169
+ "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
170
+ end
141
171
  end
142
172
 
143
173
  def find
174
+ # TODO: Fetch whether ids where given or not
175
+ # and get the wanted one in those cases
144
176
  super(1)
145
177
  end
146
178
 
@@ -160,12 +192,45 @@ module Billomat
160
192
  raise MethodNotAvailable, "Method not supported on #{self.class.name}"
161
193
  end
162
194
  end
195
+
196
+ class ReadOnlySingletonBase < SingletonBase
197
+ include ResourceWithoutWriteAccess
198
+ end
199
+ end
200
+
201
+ module ActiveSupport #:nodoc:
202
+ module CoreExtensions #:nodoc:
203
+ module Hash #:nodoc:
204
+ module Conversions
205
+ def self.included(klass)
206
+ klass.extend(ClassMethods)
207
+ end
208
+
209
+ module ClassMethods
210
+
211
+ private
212
+
213
+ # Dirty monkey patching indeed
214
+ def typecast_xml_value_with_array_fix(value)
215
+ value.delete('total')
216
+ value.delete('type')
217
+ value.delete('per_page')
218
+ value.delete('page')
219
+ typecast_xml_value_without_array_fix(value)
220
+ end
221
+
222
+ alias_method_chain :typecast_xml_value, :array_fix
223
+ end
224
+ end
225
+ end
226
+ end
163
227
  end
164
228
 
165
229
  #$:.unshift(File.dirname(__FILE__))
166
230
  #Dir[File.join(File.dirname(__FILE__), "billomat/*.rb")].each { |f| require f }
167
231
 
168
- require File.dirname(__FILE__) + '/billomat/account'
169
232
  require File.dirname(__FILE__) + '/billomat/settings'
170
233
  require File.dirname(__FILE__) + '/billomat/users'
171
- require File.dirname(__FILE__) + '/billomat/myself'
234
+ require File.dirname(__FILE__) + '/billomat/myself'
235
+ require File.dirname(__FILE__) + '/billomat/clients'
236
+ require File.dirname(__FILE__) + '/billomat/unit'
@@ -0,0 +1,5 @@
1
+ class Billomat::Clients < Billomat::SingletonBase
2
+ end
3
+
4
+ class Billomat::Client < Billomat::Base
5
+ end
@@ -1,4 +1,4 @@
1
- class Billomat::Myself < Billomat::SingletonBase
1
+ class Billomat::Myself < Billomat::ReadOnlySingletonBase
2
2
 
3
3
  # non standard path
4
4
  def self.element_name
@@ -0,0 +1,5 @@
1
+ class Billomat::Units < Billomat::SingletonBase
2
+ end
3
+
4
+ class Billomat::Unit < Billomat::Base
5
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ronald Becher
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-30 00:00:00 +02:00
17
+ date: 2010-04-01 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -56,6 +56,7 @@ extra_rdoc_files:
56
56
  - README.textile
57
57
  files:
58
58
  - .gitignore
59
+ - CHANGES.textile
59
60
  - LICENSE
60
61
  - README.textile
61
62
  - Rakefile
@@ -63,9 +64,10 @@ files:
63
64
  - VERSION.yml
64
65
  - billomat-rb.gemspec
65
66
  - lib/billomat-rb.rb
66
- - lib/billomat/account.rb
67
+ - lib/billomat/clients.rb
67
68
  - lib/billomat/myself.rb
68
69
  - lib/billomat/settings.rb
70
+ - lib/billomat/unit.rb
69
71
  - lib/billomat/users.rb
70
72
  has_rdoc: true
71
73
  homepage: http://github.com/rbecher/billomat-rb
@@ -1,2 +0,0 @@
1
- class Billomat::Account < Billomat::SingletonBase
2
- end