curdbee 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.
Files changed (48) hide show
  1. data/Gemfile +16 -0
  2. data/Gemfile.lock +35 -0
  3. data/LICENSE +22 -0
  4. data/README.markdown +43 -0
  5. data/Rakefile +19 -0
  6. data/VERSION +1 -0
  7. data/curdbee.gemspec +103 -0
  8. data/examples/create_invoice_for_new_client.rb +58 -0
  9. data/lib/curdbee.rb +20 -0
  10. data/lib/curdbee/base.rb +75 -0
  11. data/lib/curdbee/client.rb +6 -0
  12. data/lib/curdbee/config.rb +33 -0
  13. data/lib/curdbee/error.rb +23 -0
  14. data/lib/curdbee/estimate.rb +14 -0
  15. data/lib/curdbee/invoice.rb +10 -0
  16. data/lib/curdbee/invoiceable.rb +35 -0
  17. data/lib/curdbee/item.rb +6 -0
  18. data/lib/curdbee/parser.rb +13 -0
  19. data/lib/curdbee/payment.rb +18 -0
  20. data/lib/curdbee/recurring_profile.rb +6 -0
  21. data/spec/client_spec.rb +144 -0
  22. data/spec/estimate_spec.rb +312 -0
  23. data/spec/fixtures/client.json +20 -0
  24. data/spec/fixtures/clients.json +20 -0
  25. data/spec/fixtures/customers.json +12 -0
  26. data/spec/fixtures/estimate.json +24 -0
  27. data/spec/fixtures/estimates.json +26 -0
  28. data/spec/fixtures/invoice.json +24 -0
  29. data/spec/fixtures/invoices.json +26 -0
  30. data/spec/fixtures/item.json +11 -0
  31. data/spec/fixtures/items.json +11 -0
  32. data/spec/fixtures/new_client.json +20 -0
  33. data/spec/fixtures/new_estimate.json +24 -0
  34. data/spec/fixtures/new_invoice.json +24 -0
  35. data/spec/fixtures/new_item.json +11 -0
  36. data/spec/fixtures/new_payment.json +10 -0
  37. data/spec/fixtures/new_recurring_profile.json +26 -0
  38. data/spec/fixtures/payment.json +10 -0
  39. data/spec/fixtures/payments.json +10 -0
  40. data/spec/fixtures/recurring_profile.json +26 -0
  41. data/spec/fixtures/recurring_profiles.json +28 -0
  42. data/spec/invoice_spec.rb +280 -0
  43. data/spec/item_spec.rb +137 -0
  44. data/spec/payment_spec.rb +143 -0
  45. data/spec/recurring_profile_spec.rb +140 -0
  46. data/spec/spec_helper.rb +24 -0
  47. data/spec/support/fakeweb_stubs.rb +33 -0
  48. metadata +156 -0
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+
3
+ describe CurdBee::Item do
4
+
5
+ describe 'list' do
6
+
7
+ before do
8
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
9
+ CurdBee::Config.subdomain = "test"
10
+ end
11
+
12
+ it "should return a list of items" do
13
+ stub_get "http://test.curdbee.com/items.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=1&per_page=20", "items.json"
14
+ result = CurdBee::Item.list
15
+ result.first.name.should == "My Item"
16
+ end
17
+
18
+ it "should take limit as an option" do
19
+ stub_get "http://test.curdbee.com/items.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=1&per_page=1", "items.json"
20
+ result = CurdBee::Item.list(:limit => 1)
21
+ result.length.should == 1
22
+ end
23
+
24
+ it "should take page as an option" do
25
+ stub_get "http://test.curdbee.com/items.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=2&per_page=1", "items.json"
26
+ result = CurdBee::Item.list(:limit => 1, :page => 2)
27
+ result.length.should == 1
28
+ end
29
+ end
30
+
31
+ describe 'show' do
32
+
33
+ before do
34
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
35
+ CurdBee::Config.subdomain = "test"
36
+ end
37
+
38
+ it "should return the matching item" do
39
+ stub_get "http://test.curdbee.com/items/25.json?api_token=TYMuwW6rM2PQnoWx1ht4", "item.json"
40
+ result = CurdBee::Item.show(25)
41
+ result.name.should == "My Item"
42
+ end
43
+
44
+ it "should raise an error if nothing found" do
45
+ stub_get "http://test.curdbee.com/items/27.json?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
46
+ lambda{
47
+ CurdBee::Item.show(27)
48
+ }.should raise_error(CurdBee::Error::NotFound)
49
+ end
50
+
51
+ end
52
+
53
+ describe 'create' do
54
+
55
+ before do
56
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
57
+ CurdBee::Config.subdomain = "test"
58
+ end
59
+
60
+ it "should return the created item" do
61
+ stub_post "http://test.curdbee.com/items?api_token=TYMuwW6rM2PQnoWx1ht4", "new_item.json"
62
+ @item = CurdBee::Item.new(:name => "My New Item")
63
+ result = @item.create
64
+ @item.id.should == 28
65
+ end
66
+
67
+ it "should raise an error if creation fails" do
68
+ stub_post "http://test.curdbee.com/items?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
69
+ lambda{
70
+ @item = CurdBee::Item.new()
71
+ @item.create
72
+ }.should raise_error(CurdBee::Error::BadRequest)
73
+ end
74
+
75
+
76
+ end
77
+
78
+ describe 'update' do
79
+
80
+ before do
81
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
82
+ CurdBee::Config.subdomain = "test"
83
+ stub_get "http://test.curdbee.com/items/25.json?api_token=TYMuwW6rM2PQnoWx1ht4", "item.json"
84
+ @item = CurdBee::Item.show(25)
85
+ end
86
+
87
+ it "should return the updated item" do
88
+ stub_put "http://test.curdbee.com/items/25?api_token=TYMuwW6rM2PQnoWx1ht4", "new_item.json"
89
+ @item.name = "My New Item"
90
+ result = @item.update
91
+
92
+ result.should be_true
93
+ end
94
+
95
+ it "should raise an error if update fails" do
96
+ stub_put "http://test.curdbee.com/items/25?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
97
+ lambda{
98
+ @item.name = ""
99
+ @item.update
100
+ }.should raise_error(CurdBee::Error::BadRequest)
101
+ end
102
+
103
+
104
+ end
105
+
106
+ describe 'delete' do
107
+
108
+ before do
109
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
110
+ CurdBee::Config.subdomain = "test"
111
+ stub_get "http://test.curdbee.com/items/25.json?api_token=TYMuwW6rM2PQnoWx1ht4", "item.json"
112
+ @item = CurdBee::Item.show(25)
113
+ end
114
+
115
+ it "should return true if item was deleted" do
116
+ stub_delete "http://test.curdbee.com/items/25?api_token=TYMuwW6rM2PQnoWx1ht4", "", 200
117
+ result = @item.delete
118
+ result.should == true
119
+ end
120
+
121
+ it "should raise a bad request error if deletion fails" do
122
+ stub_delete "http://test.curdbee.com/items/25?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
123
+ lambda{
124
+ @item.delete
125
+ }.should raise_error(CurdBee::Error::BadRequest)
126
+ end
127
+
128
+ it "should raise a not found error if item doesnt exist" do
129
+ stub_delete "http://test.curdbee.com/items/25?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
130
+ lambda{
131
+ @item.delete
132
+ }.should raise_error(CurdBee::Error::NotFound)
133
+ end
134
+
135
+ end
136
+
137
+ end
@@ -0,0 +1,143 @@
1
+ require 'spec_helper'
2
+
3
+ describe CurdBee::Payment do
4
+
5
+ describe 'list' do
6
+
7
+ before do
8
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
9
+ CurdBee::Config.subdomain = "test"
10
+ CurdBee::Payment.invoice_id = 23
11
+ end
12
+
13
+ it "should return a list of payments" do
14
+ stub_get "http://test.curdbee.com/invoices/23/payments.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=1&per_page=20", "payments.json"
15
+ result = CurdBee::Payment.list
16
+ result.first.payment_method.should == "cash"
17
+ end
18
+
19
+ it "should raise an error if invoice id is not provided" do
20
+ end
21
+ end
22
+
23
+ describe 'show' do
24
+
25
+ before do
26
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
27
+ CurdBee::Config.subdomain = "test"
28
+ CurdBee::Payment.invoice_id = 23
29
+ end
30
+
31
+ it "should return the matching payment" do
32
+ stub_get "http://test.curdbee.com/invoices/23/payments/25.json?api_token=TYMuwW6rM2PQnoWx1ht4", "payment.json"
33
+ result = CurdBee::Payment.show(25)
34
+ result.payment_method.should == "cash"
35
+ end
36
+
37
+ it "should raise an error if invoice id is not provided" do
38
+ end
39
+
40
+ it "should raise an error if nothing found" do
41
+ stub_get "http://test.curdbee.com/invoices/23/payments/28.json?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
42
+ lambda{
43
+ CurdBee::Payment.show(28)
44
+ }.should raise_error(CurdBee::Error::NotFound)
45
+ end
46
+
47
+ end
48
+
49
+ describe 'create' do
50
+
51
+ before do
52
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
53
+ CurdBee::Config.subdomain = "test"
54
+ CurdBee::Payment.invoice_id = 23
55
+ end
56
+
57
+ it "should return the created payment" do
58
+ stub_post "http://test.curdbee.com/invoices/23/payments?api_token=TYMuwW6rM2PQnoWx1ht4", "new_payment.json"
59
+ payment_info = {
60
+ :amount => 50,
61
+ :date => Date.today,
62
+ :payment_method => "custom payment",
63
+ }
64
+ @payment = CurdBee::Payment.new(payment_info)
65
+ result = @payment.create
66
+ @payment.id.should == 25
67
+ end
68
+
69
+ it "should raise an error if creation fails" do
70
+ stub_post "http://test.curdbee.com/invoices/23/payments?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
71
+ lambda{
72
+ @payment = CurdBee::Payment.new({})
73
+ @payment.create
74
+ }.should raise_error(CurdBee::Error::BadRequest)
75
+ end
76
+
77
+ end
78
+
79
+ describe 'update' do
80
+
81
+ before do
82
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
83
+ CurdBee::Config.subdomain = "test"
84
+ CurdBee::Payment.invoice_id = 23
85
+
86
+ stub_get "http://test.curdbee.com/invoices/23/payments/25.json?api_token=TYMuwW6rM2PQnoWx1ht4", "payment.json"
87
+ @payment = CurdBee::Payment.show(25)
88
+ end
89
+
90
+ it "should return the updated payment" do
91
+ stub_put "http://test.curdbee.com/invoices/23/payments/25?api_token=TYMuwW6rM2PQnoWx1ht4", "new_payment.json"
92
+ @payment.payment_method = "custom payment"
93
+
94
+ result = @payment.update
95
+ result.should be_true
96
+ end
97
+
98
+ it "should raise an error if update fails" do
99
+ stub_put "http://test.curdbee.com/invoices/23/payments/25?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
100
+
101
+ lambda{
102
+ @payment.amount = ""
103
+ @payment.update
104
+ }.should raise_error(CurdBee::Error::BadRequest)
105
+ end
106
+
107
+
108
+ end
109
+
110
+ describe 'delete' do
111
+
112
+ before do
113
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
114
+ CurdBee::Config.subdomain = "test"
115
+ CurdBee::Payment.invoice_id = 23
116
+
117
+ stub_get "http://test.curdbee.com/invoices/23/payments/25.json?api_token=TYMuwW6rM2PQnoWx1ht4", "payment.json"
118
+ @payment = CurdBee::Payment.show(25)
119
+ end
120
+
121
+ it "should return true if payment was deleted" do
122
+ stub_delete "http://test.curdbee.com/invoices/23/payments/25?api_token=TYMuwW6rM2PQnoWx1ht4", "", 200
123
+ result = @payment.delete
124
+ result.should be_true
125
+ end
126
+
127
+ it "should raise a bad request error if deletion fails" do
128
+ stub_delete "http://test.curdbee.com/invoices/23/payments/25?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
129
+ lambda{
130
+ @payment.delete
131
+ }.should raise_error(CurdBee::Error::BadRequest)
132
+ end
133
+
134
+ it "should raise a not found error if payment doesnt exist" do
135
+ stub_delete "http://test.curdbee.com/invoices/23/payments/25?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
136
+ lambda{
137
+ @payment.delete
138
+ }.should raise_error(CurdBee::Error::NotFound)
139
+ end
140
+
141
+ end
142
+
143
+ end
@@ -0,0 +1,140 @@
1
+ require 'spec_helper'
2
+
3
+ describe CurdBee::RecurringProfile do
4
+
5
+ describe 'list' do
6
+
7
+ before do
8
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
9
+ CurdBee::Config.subdomain = "test"
10
+ end
11
+
12
+ it "should return a list of recurring_profiles" do
13
+ stub_get "http://test.curdbee.com/recurring_profiles.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=1&per_page=20", "recurring_profiles.json"
14
+ result = CurdBee::RecurringProfile.list
15
+ result.first.profile_name.should == "RP-Test"
16
+ end
17
+
18
+ it "should take limit as an option" do
19
+ stub_get "http://test.curdbee.com/recurring_profiles.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=1&per_page=1", "recurring_profiles.json"
20
+ result = CurdBee::RecurringProfile.list(:limit => 1)
21
+ result.length.should == 1
22
+ end
23
+
24
+ it "should take page as an option" do
25
+ stub_get "http://test.curdbee.com/recurring_profiles.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=2&per_page=1", "recurring_profiles.json"
26
+ result = CurdBee::RecurringProfile.list(:limit => 1, :page => 2)
27
+ result.length.should == 1
28
+ end
29
+ end
30
+
31
+ describe 'show' do
32
+
33
+ before do
34
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
35
+ CurdBee::Config.subdomain = "test"
36
+ end
37
+
38
+ it "should return the matching recurring_profile" do
39
+ stub_get "http://test.curdbee.com/recurring_profiles/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "recurring_profile.json"
40
+ result = CurdBee::RecurringProfile.show(31)
41
+ result.profile_name.should == "RP-Test"
42
+ end
43
+
44
+ it "should raise an error if nothing found" do
45
+ stub_get "http://test.curdbee.com/recurring_profiles/32.json?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
46
+ lambda{
47
+ CurdBee::RecurringProfile.show(32)
48
+ }.should raise_error(CurdBee::Error::NotFound)
49
+ end
50
+
51
+ end
52
+
53
+ describe 'create' do
54
+
55
+ before do
56
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
57
+ CurdBee::Config.subdomain = "test"
58
+ end
59
+
60
+ it "should return the created recurring_profile" do
61
+ stub_post "http://test.curdbee.com/recurring_profiles?api_token=TYMuwW6rM2PQnoWx1ht4", "new_recurring_profile.json"
62
+ recurring_profile_info = {:start_date => Date.today, :invoice_no => "RP-NEW", :client_id => @client.id,
63
+ :frequency => "1", :occurences => "0", :profile_name => "test profile",
64
+ :line_items_attributes => [{:name_and_description => "Sample Item", :quantity => 1, :price => 25.00, :unit => "hour"}]
65
+ }
66
+ @recurring_profile = CurdBee::RecurringProfile.new(recurring_profile_info)
67
+ result = @recurring_profile.create
68
+ @recurring_profile.id.should == 31
69
+ end
70
+
71
+ it "should raise an error if creation fails" do
72
+ stub_post "http://test.curdbee.com/recurring_profiles?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
73
+ lambda{
74
+ @recurring_profile = CurdBee::RecurringProfile.new({})
75
+ @recurring_profile.create
76
+ }.should raise_error(CurdBee::Error::BadRequest)
77
+ end
78
+
79
+ end
80
+
81
+ describe 'update' do
82
+
83
+ before do
84
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
85
+ CurdBee::Config.subdomain = "test"
86
+ stub_get "http://test.curdbee.com/recurring_profiles/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "recurring_profile.json"
87
+ @recurring_profile = CurdBee::RecurringProfile.show(31)
88
+ end
89
+
90
+ it "should return the updated recurring_profile" do
91
+ stub_put "http://test.curdbee.com/recurring_profiles/31?api_token=TYMuwW6rM2PQnoWx1ht4", "new_recurring_profile.json"
92
+ @recurring_profile.profile_name = "RP-New"
93
+ @recurring_profile.date = Date.today
94
+
95
+ result = @recurring_profile.update
96
+ result.should be_true
97
+ end
98
+
99
+ it "should raise an error if update fails" do
100
+ stub_put "http://test.curdbee.com/recurring_profiles/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
101
+ lambda{
102
+ @recurring_profile.profile_name = ""
103
+ @recurring_profile.update
104
+ }.should raise_error(CurdBee::Error::BadRequest)
105
+ end
106
+
107
+ end
108
+
109
+ describe 'delete' do
110
+
111
+ before do
112
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
113
+ CurdBee::Config.subdomain = "test"
114
+ stub_get "http://test.curdbee.com/recurring_profiles/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "recurring_profile.json"
115
+ @recurring_profile = CurdBee::RecurringProfile.show(31)
116
+ end
117
+
118
+ it "should return true if recurring_profile was deleted" do
119
+ stub_delete "http://test.curdbee.com/recurring_profiles/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 200
120
+ result = @recurring_profile.delete
121
+ result.should be_true
122
+ end
123
+
124
+ it "should raise a bad request error if deletion fails" do
125
+ stub_delete "http://test.curdbee.com/recurring_profiles/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
126
+ lambda{
127
+ @recurring_profile.delete
128
+ }.should raise_error(CurdBee::Error::BadRequest)
129
+ end
130
+
131
+ it "should raise a not found error if recurring_profile doesnt exist" do
132
+ stub_delete "http://test.curdbee.com/recurring_profiles/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
133
+ lambda{
134
+ @recurring_profile.delete
135
+ }.should raise_error(CurdBee::Error::NotFound)
136
+ end
137
+
138
+ end
139
+
140
+ end
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'logger'
4
+ require 'spec'
5
+
6
+ Bundler.require(:default, :runtime, :test)
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+
10
+ require 'curdbee'
11
+
12
+ # Requires supporting files with custom matchers and macros, etc,
13
+ # in ./support/ and its subdirectories.
14
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
15
+
16
+ FakeWeb.allow_net_connect = false
17
+
18
+ Spec::Runner.configure do |config|
19
+
20
+
21
+ end
22
+
23
+
24
+
@@ -0,0 +1,33 @@
1
+ def fixture_file(filename)
2
+ return '' if filename == ''
3
+ file_path = File.join(File.dirname(__FILE__), '..', 'fixtures', filename)
4
+ File.read(file_path)
5
+ end
6
+
7
+ def stub_get(url, filename, status=nil)
8
+ options = {:body => fixture_file(filename)}
9
+ options.merge!({:status => status}) unless status.nil?
10
+
11
+ FakeWeb.register_uri(:get, url, options)
12
+ end
13
+
14
+ def stub_post(url, filename, status=nil)
15
+ options = {:body => fixture_file(filename)}
16
+ options.merge!({:status => status}) unless status.nil?
17
+
18
+ FakeWeb.register_uri(:post, url, options)
19
+ end
20
+
21
+ def stub_put(url, filename, status=nil)
22
+ options = {:body => fixture_file(filename)}
23
+ options.merge!({:status => status}) unless status.nil?
24
+
25
+ FakeWeb.register_uri(:put, url, options)
26
+ end
27
+
28
+ def stub_delete(url, filename, status=nil)
29
+ options = {:body => fixture_file(filename)}
30
+ options.merge!({:status => status}) unless status.nil?
31
+
32
+ FakeWeb.register_uri(:delete, url, options)
33
+ end