ruby-freshbooks 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.4.0
2
+ * added support for (invoice|recurring).line methods
3
+
1
4
  == 0.3.1
2
5
  * *actually* add LoggingClient example
3
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
data/lib/freshbooks.rb CHANGED
@@ -101,10 +101,10 @@ module FreshBooks
101
101
  xml.target!
102
102
  end
103
103
 
104
- # infer API methods based on 2-deep method chains sent to
105
- # clients. this allows us to provide a simple interface
106
- # without actually knowing anything about the supported API
107
- # methods (and hence trusting users to read the official
104
+ # infer API methods based on 2-(and sometimes 3) deep method
105
+ # chains sent to clients. this allows us to provide a simple
106
+ # interface without actually knowing anything about the supported
107
+ # API methods (and hence trusting users to read the official
108
108
  # FreshBooks API documentation)
109
109
  def method_missing(sym, *args) # :nodoc:
110
110
  NamespaceProxy.new self, sym
@@ -113,7 +113,13 @@ module FreshBooks
113
113
  # nothing to see here...
114
114
  class NamespaceProxy < Struct.new(:client, :namespace) # :nodoc:
115
115
  def method_missing(sym, *args)
116
- client.post "#{namespace}.#{sym}", *args
116
+ # check for subordinate resources
117
+ if [:invoice, :recurring].include?(namespace) and
118
+ sym == :lines
119
+ NamespaceProxy.new client, "#{namespace}.#{sym}"
120
+ else
121
+ client.post "#{namespace}.#{sym}", *args
122
+ end
117
123
  end
118
124
  end
119
125
 
@@ -55,9 +55,37 @@ describe "XML generation:" do
55
55
  end
56
56
  end
57
57
 
58
- describe "FreshBooks Client instantiation" do
59
- it "should create a TokenClient instance when Connection.new is called" do
60
- c = FreshBooks::Connection.new('foo.freshbooks.com', 'abcdefghijklm')
61
- c.should be_a(FreshBooks::TokenClient)
58
+ describe "FreshBooks Client" do
59
+ describe "instantiation" do
60
+ it "should create a TokenClient instance when Connection.new is called" do
61
+ c = FreshBooks::Connection.new('foo.freshbooks.com', 'abcdefghijklm')
62
+ c.should be_a(FreshBooks::TokenClient)
63
+ end
64
+ end
65
+
66
+ describe "proxies" do
67
+ before(:each) do
68
+ @c = FreshBooks::Connection.new('foo.freshbooks.com', 'abcdefghijklm')
69
+ end
70
+
71
+ it "should not hit API for single method send" do
72
+ @c.should_not_receive(:post)
73
+ @c.invoice
74
+ end
75
+
76
+ it "should hit API for normal double method send" do
77
+ @c.should_receive(:post, "invoice.list").once
78
+ @c.invoice.list
79
+ end
80
+
81
+ it "should not hit API for subordinate resource double method send" do
82
+ @c.should_not_receive(:post)
83
+ @c.invoice.lines
84
+ end
85
+
86
+ it "should hit API for subordinate resource triple method send" do
87
+ @c.should_receive(:post, "invoice.items.add").once
88
+ @c.invoice.lines.add
89
+ end
62
90
  end
63
91
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-freshbooks
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 15
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 3
8
- - 1
9
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Justin Giancola
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-27 00:00:00 -04:00
18
+ date: 2010-11-16 00:00:00 -05:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: httparty
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 11
27
30
  segments:
28
31
  - 0
29
32
  - 5
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: builder
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 15
41
46
  segments:
42
47
  - 2
43
48
  - 1
@@ -49,9 +54,11 @@ dependencies:
49
54
  name: rspec
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
61
+ hash: 27
55
62
  segments:
56
63
  - 1
57
64
  - 3
@@ -87,16 +94,20 @@ rdoc_options: []
87
94
  require_paths:
88
95
  - lib
89
96
  required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
90
98
  requirements:
91
99
  - - ">="
92
100
  - !ruby/object:Gem::Version
101
+ hash: 3
93
102
  segments:
94
103
  - 0
95
104
  version: "0"
96
105
  required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
97
107
  requirements:
98
108
  - - ">="
99
109
  - !ruby/object:Gem::Version
110
+ hash: 11
100
111
  segments:
101
112
  - 1
102
113
  - 2
@@ -104,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
115
  requirements: []
105
116
 
106
117
  rubyforge_project:
107
- rubygems_version: 1.3.6
118
+ rubygems_version: 1.3.7
108
119
  signing_key:
109
120
  specification_version: 3
110
121
  summary: simple FreshBooks API wrapper. supports both OAuth and API token authentication