turingstudio-freshbooks-rb 3.0.2 → 3.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.
- data/History.txt +9 -3
- data/lib/freshbooks.rb +3 -1
- data/lib/freshbooks/base.rb +32 -22
- data/lib/freshbooks/staff.rb +1 -1
- data/lib/freshbooks/version.rb +1 -1
- data/spec/lib/freshbooks/base_spec.rb +2 -2
- data/spec/lib/freshbooks/staff_spec.rb +1 -1
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
|
1
|
+
* 3.0.3
|
2
|
+
* Merged with http://github.com/bcurren/freshbooks.rb
|
3
|
+
* Create connection class
|
4
|
+
* Convert xml to ruby type: date, date_time, boolean
|
5
|
+
* Added links to objects
|
2
6
|
|
3
|
-
*
|
4
|
-
*
|
7
|
+
* 3.0 major enhancement:
|
8
|
+
* Gemified
|
9
|
+
* Added specs
|
10
|
+
* Added methods to describe FreshBooks objects and actions
|
data/lib/freshbooks.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Usage:
|
3
3
|
#
|
4
|
-
# FreshBooks::Base.
|
4
|
+
# FreshBooks::Base.establish_connection!('sample.freshbooks.com', 'mytoken')
|
5
5
|
#
|
6
6
|
# clients = FreshBooks::Client.list
|
7
7
|
# client = clients[0]
|
@@ -21,6 +21,7 @@ $:.unshift(File.dirname(__FILE__))
|
|
21
21
|
|
22
22
|
require 'net/https'
|
23
23
|
require 'rexml/document'
|
24
|
+
require 'logger'
|
24
25
|
require 'activesupport'
|
25
26
|
|
26
27
|
require 'freshbooks/version'
|
@@ -43,3 +44,4 @@ require 'freshbooks/staff'
|
|
43
44
|
require 'freshbooks/task'
|
44
45
|
require 'freshbooks/time_entry'
|
45
46
|
require 'freshbooks/xml_serializer'
|
47
|
+
require 'freshbooks/xml_serializer/serializers'
|
data/lib/freshbooks/base.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module FreshBooks
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
class InternalError < Exception; end;
|
3
|
+
class AuthenticationError < Exception; end;
|
4
|
+
class UnknownSystemError < Exception; end;
|
5
|
+
class InvalidParameterError < Exception; end;
|
6
|
+
class InvalidAccountUrlError < Exception; end;
|
7
|
+
|
8
|
+
class Base
|
9
9
|
def initialize(data = {})
|
10
10
|
@changed_fields = []
|
11
11
|
self.class.attributes.each do |name, options|
|
@@ -14,9 +14,8 @@ module FreshBooks
|
|
14
14
|
data.each do |name, value|
|
15
15
|
send("#{name}=", value) if self.class.attributes[name]
|
16
16
|
end
|
17
|
-
#@changed_fields = [] # reset changed fields
|
18
17
|
end
|
19
|
-
|
18
|
+
|
20
19
|
def to_xml(elem_name = nil)
|
21
20
|
root = REXML::Element.new(node_name)
|
22
21
|
self.class.attributes.each do |name, options|
|
@@ -32,7 +31,7 @@ module FreshBooks
|
|
32
31
|
end
|
33
32
|
root
|
34
33
|
end
|
35
|
-
|
34
|
+
|
36
35
|
class << self
|
37
36
|
attr_reader :connection
|
38
37
|
|
@@ -51,7 +50,7 @@ module FreshBooks
|
|
51
50
|
end
|
52
51
|
object
|
53
52
|
end
|
54
|
-
|
53
|
+
|
55
54
|
def node_name
|
56
55
|
self.to_s.split('::').last.underscore
|
57
56
|
end
|
@@ -129,13 +128,13 @@ module FreshBooks
|
|
129
128
|
#
|
130
129
|
def define_class_method(name, &block)
|
131
130
|
self.class.send(:define_method, name, &block)
|
132
|
-
end
|
133
|
-
|
131
|
+
end
|
132
|
+
|
134
133
|
def actions(*args)
|
135
134
|
args.each do |action|
|
136
135
|
method = action.to_s
|
137
136
|
api_method = method.camelize(:lower)
|
138
|
-
|
137
|
+
|
139
138
|
case method
|
140
139
|
when 'list'
|
141
140
|
define_class_method(method) do |*args|
|
@@ -171,27 +170,38 @@ module FreshBooks
|
|
171
170
|
end
|
172
171
|
|
173
172
|
def api_list_action(method, options = {})
|
174
|
-
|
175
|
-
|
176
|
-
|
173
|
+
list_page_proc = proc do |page|
|
174
|
+
options["page"] = page
|
175
|
+
response = FreshBooks::Base.connection.call_api("#{node_name}.#{method}", options)
|
176
|
+
raise FreshBooks::InternalError.new("Response was not successful. This should never happen.") unless response.success?
|
177
|
+
|
178
|
+
root = response.elements[1]
|
179
|
+
array = root.elements.map { |item| self.new_from_xml(item) }
|
180
|
+
current_page = Page.new(root.attributes['page'], root.attributes['per_page'], root.attributes['total'])
|
177
181
|
|
182
|
+
[array, current_page]
|
183
|
+
end
|
184
|
+
|
185
|
+
ListProxy.new(list_page_proc)
|
186
|
+
end
|
187
|
+
|
178
188
|
def api_get_action(method, id)
|
179
189
|
resp = Base.connection.call_api("#{node_name}.#{method}", "#{node_name}_id" => id)
|
180
190
|
resp.success? ? self.new_from_xml(resp.elements[1]) : nil
|
181
191
|
end
|
182
|
-
|
192
|
+
|
183
193
|
def api_delete_action(method, id)
|
184
194
|
resp = Base.connection.call_api("#{node_name}.#{method}", "#{node_name}_id" => id)
|
185
195
|
resp.success?
|
186
196
|
end
|
187
|
-
|
197
|
+
|
188
198
|
def api_action(method, id)
|
189
199
|
resp = Base.connection.call_api("#{node_name}.#{method}", "#{node_name}_id" => id)
|
190
200
|
resp.success?
|
191
201
|
end
|
192
202
|
end
|
193
203
|
end
|
194
|
-
|
204
|
+
|
195
205
|
protected
|
196
206
|
|
197
207
|
def node_name
|
@@ -203,10 +213,10 @@ module FreshBooks
|
|
203
213
|
self.send("#{node_name}_id=", resp.elements[1].text.to_i) if resp.success?
|
204
214
|
resp.success?
|
205
215
|
end
|
206
|
-
|
216
|
+
|
207
217
|
def api_update_action(method)
|
208
218
|
resp = Base.connection.call_api("#{node_name}.#{method}", node_name => self)
|
209
219
|
resp.success?
|
210
|
-
end
|
220
|
+
end
|
211
221
|
end
|
212
222
|
end
|
data/lib/freshbooks/staff.rb
CHANGED
data/lib/freshbooks/version.rb
CHANGED
@@ -292,13 +292,13 @@ describe FreshBooks::Base do
|
|
292
292
|
end
|
293
293
|
|
294
294
|
it "should call api method" do
|
295
|
-
@connection.should_receive(:call_api).with('test.list', :name => 'value').and_return(@resp)
|
295
|
+
@connection.should_receive(:call_api).with('test.list', 'page' => 1, :name => 'value').and_return(@resp)
|
296
296
|
Test.list(:name => 'value')
|
297
297
|
end
|
298
298
|
|
299
299
|
it "should return nil if request failed" do
|
300
300
|
@resp.stub!(:success?).and_return(false)
|
301
|
-
Test.list.should
|
301
|
+
lambda { Test.list }.should raise_error
|
302
302
|
end
|
303
303
|
|
304
304
|
it "should create a list proxy if request succeeded" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turingstudio-freshbooks-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Turing Studio, Inc.
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-05 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|