get_invoice 0.2.0 → 0.2.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/Gemfile CHANGED
@@ -4,11 +4,13 @@ source "http://rubygems.org"
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
  gem "invoice_harvester"
6
6
  gem "blinksale"
7
+ gem "ruby-freshbooks", "~> 0.4.0"
7
8
 
8
9
  # Add dependencies to develop your gem here.
9
10
  # Include everything needed to run rake, tests, features, etc.
10
11
  group :development do
11
12
  gem "rspec", "~> 2.3.0"
13
+ gem "mocha", "~> 0.9.12"
12
14
  gem "bundler", "~> 1.0.0"
13
15
  gem "jeweler", "~> 1.6.2"
14
16
  gem "rcov", ">= 0"
@@ -4,8 +4,12 @@ GEM
4
4
  blinksale (0.1.0)
5
5
  nokogiri
6
6
  rest-client
7
+ builder (3.0.0)
8
+ crack (0.1.8)
7
9
  diff-lcs (1.1.2)
8
10
  git (1.2.5)
11
+ httparty (0.7.8)
12
+ crack (= 0.1.8)
9
13
  invoice_harvester (0.1.0)
10
14
  nokogiri
11
15
  rest-client
@@ -14,6 +18,7 @@ GEM
14
18
  git (>= 1.2.5)
15
19
  rake
16
20
  mime-types (1.16)
21
+ mocha (0.9.12)
17
22
  nokogiri (1.4.6)
18
23
  rake (0.9.2)
19
24
  rcov (0.9.9)
@@ -27,6 +32,9 @@ GEM
27
32
  rspec-expectations (2.3.0)
28
33
  diff-lcs (~> 1.1.2)
29
34
  rspec-mocks (2.3.0)
35
+ ruby-freshbooks (0.4.0)
36
+ builder (>= 2.1.2)
37
+ httparty (>= 0.5.0)
30
38
 
31
39
  PLATFORMS
32
40
  ruby
@@ -36,5 +44,7 @@ DEPENDENCIES
36
44
  bundler (~> 1.0.0)
37
45
  invoice_harvester
38
46
  jeweler (~> 1.6.2)
47
+ mocha (~> 0.9.12)
39
48
  rcov
40
49
  rspec (~> 2.3.0)
50
+ ruby-freshbooks (~> 0.4.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{get_invoice}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tomasz Werbicki"]
12
- s.date = %q{2011-06-27}
12
+ s.date = %q{2011-06-28}
13
13
  s.description = %q{Common API for managing invoices from different online accounting services.}
14
14
  s.email = %q{tomasz@werbicki.net}
15
15
  s.extra_rdoc_files = [
@@ -31,10 +31,14 @@ Gem::Specification.new do |s|
31
31
  "lib/services/blinksale.rb",
32
32
  "lib/services/blinksale/invoice.rb",
33
33
  "lib/services/blinksale/invoice_manager.rb",
34
+ "lib/services/freshbooks.rb",
35
+ "lib/services/freshbooks/invoice.rb",
36
+ "lib/services/freshbooks/invoice_manager.rb",
34
37
  "lib/services/harvest.rb",
35
38
  "lib/services/harvest/invoice.rb",
36
39
  "lib/services/harvest/invoice_manager.rb",
37
40
  "spec/services/blinksale_spec.rb",
41
+ "spec/services/freshbooks_spec.rb",
38
42
  "spec/services/harvest_spec.rb",
39
43
  "spec/spec_helper.rb"
40
44
  ]
@@ -51,14 +55,18 @@ Gem::Specification.new do |s|
51
55
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
56
  s.add_runtime_dependency(%q<invoice_harvester>, [">= 0"])
53
57
  s.add_runtime_dependency(%q<blinksale>, [">= 0"])
58
+ s.add_runtime_dependency(%q<ruby-freshbooks>, ["~> 0.4.0"])
54
59
  s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
60
+ s.add_development_dependency(%q<mocha>, ["~> 0.9.12"])
55
61
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
56
62
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
57
63
  s.add_development_dependency(%q<rcov>, [">= 0"])
58
64
  else
59
65
  s.add_dependency(%q<invoice_harvester>, [">= 0"])
60
66
  s.add_dependency(%q<blinksale>, [">= 0"])
67
+ s.add_dependency(%q<ruby-freshbooks>, ["~> 0.4.0"])
61
68
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
69
+ s.add_dependency(%q<mocha>, ["~> 0.9.12"])
62
70
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
71
  s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
64
72
  s.add_dependency(%q<rcov>, [">= 0"])
@@ -66,7 +74,9 @@ Gem::Specification.new do |s|
66
74
  else
67
75
  s.add_dependency(%q<invoice_harvester>, [">= 0"])
68
76
  s.add_dependency(%q<blinksale>, [">= 0"])
77
+ s.add_dependency(%q<ruby-freshbooks>, ["~> 0.4.0"])
69
78
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
79
+ s.add_dependency(%q<mocha>, ["~> 0.9.12"])
70
80
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
71
81
  s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
72
82
  s.add_dependency(%q<rcov>, [">= 0"])
@@ -1,3 +1,4 @@
1
1
  require "invoice"
2
2
  require "services/blinksale"
3
3
  require "services/harvest"
4
+ require "services/freshbooks"
@@ -0,0 +1,14 @@
1
+ require "freshbooks"
2
+ require "services/freshbooks/invoice_manager"
3
+
4
+ module Invoicer
5
+ class Freshbooks
6
+ attr_reader :freshbooks
7
+ attr_reader :invoices
8
+
9
+ def initialize(subdomain, api_key)
10
+ @freshbooks = ::FreshBooks::Client.new("#{ subdomain }.freshbooks.com", api_key)
11
+ @invoices = Invoicer::FreshbooksInvoiceManager.new(self)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module Invoicer
2
+ class FreshbooksInvoice
3
+ def self.from_freshbooks(freshbooks_invoice)
4
+ total = freshbooks_invoice["total_amount"].to_f
5
+ date = Date.strptime(freshbooks_invoice["date"], "%Y-%m-%d 00:00:00")
6
+ Invoice.new(
7
+ :id => freshbooks_invoice["invoice_id"],
8
+ :number => freshbooks_invoice["number"],
9
+ :total_amount => total,
10
+ :due_amount => total - freshbooks_invoice["paid"].to_f,
11
+ :issued_on => Date.strptime(freshbooks_invoice["date"], "%Y-%m-%d 00:00:00"),
12
+ :currency => freshbooks_invoice["currency_code"],
13
+ :service => :freshbooks
14
+ )
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ require "services/freshbooks/invoice"
2
+
3
+ module Invoicer
4
+ class FreshbooksInvoiceManager
5
+ attr_reader :service
6
+
7
+ def initialize(service)
8
+ @service = service
9
+ end
10
+
11
+ def all
12
+ service.freshbooks.invoice.list["invoices"]["invoice"].map do |i|
13
+ Invoicer::FreshbooksInvoice.from_freshbooks(i)
14
+ end
15
+ end
16
+
17
+ def get(id)
18
+ hash = service.freshbooks.invoice.get(:invoice_id => id)["invoice"]
19
+ Invoicer::FreshbooksInvoice.from_freshbooks(hash)
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
+
3
4
  describe Invoicer::Blinksale do
4
5
  let(:service) { Invoicer::Blinksale.new('test', 'test', 'test') }
5
6
 
@@ -13,44 +14,46 @@ end
13
14
  describe Invoicer::BlinksaleInvoiceManager do
14
15
  let(:manager) { Invoicer::Blinksale.new('test', 'test', 'test').invoices }
15
16
 
17
+ let(:invoices) do
18
+ [
19
+ stub(
20
+ :id => 1,
21
+ :number => "00001",
22
+ :total_amount => 20,
23
+ :due_amount => 10,
24
+ :issued_on => Date.today,
25
+ :due_on => Date.today + 30,
26
+ :currency => "USD"
27
+ ),
28
+ stub(
29
+ :id => 2,
30
+ :number => "00002",
31
+ :total_amount => 20,
32
+ :due_amount => 10,
33
+ :issued_on => Date.today,
34
+ :due_on => Date.today + 30,
35
+ :currency => "USD"
36
+ ),
37
+ stub(
38
+ :id => 3,
39
+ :number => "00003",
40
+ :total_amount => 20,
41
+ :due_amount => 10,
42
+ :issued_on => Date.today,
43
+ :due_on => Date.today + 30,
44
+ :currency => "USD"
45
+ )
46
+ ]
47
+ end
48
+
16
49
  describe "#all" do
17
50
  before(:each) do
18
- invoices = [
19
- mock('invoice',
20
- :id => 1,
21
- :number => "00001",
22
- :total_amount => 20,
23
- :due_amount => 10,
24
- :issued_on => Date.today,
25
- :due_on => Date.today + 30,
26
- :currency => "USD"
27
- ),
28
- mock('invoice',
29
- :id => 2,
30
- :number => "00002",
31
- :total_amount => 20,
32
- :due_amount => 10,
33
- :issued_on => Date.today,
34
- :due_on => Date.today + 30,
35
- :currency => "USD"
36
- ),
37
- mock('invoice',
38
- :id => 3,
39
- :number => "00003",
40
- :total_amount => 20,
41
- :due_amount => 10,
42
- :issued_on => Date.today,
43
- :due_on => Date.today + 30,
44
- :currency => "USD"
45
- )
46
- ]
47
-
48
- manager.service.blinksale.stub!(:all).and_return(invoices)
51
+ manager.service.blinksale.stubs(:all).returns(invoices)
49
52
  end
50
53
 
51
54
  it "passes params to Blinksale client" do
52
55
  params = { :status => "draft" }
53
- manager.service.blinksale.should_receive(:all).with(params).once
56
+ manager.service.blinksale.expects(:all).with(params).returns(invoices).once
54
57
  manager.all(params)
55
58
  end
56
59
 
@@ -85,7 +88,7 @@ describe Invoicer::BlinksaleInvoiceManager do
85
88
  :currency => "USD"
86
89
  )
87
90
 
88
- manager.service.blinksale.stub!(:get).and_return(invoice)
91
+ manager.service.blinksale.stubs(:get).returns(invoice)
89
92
  end
90
93
 
91
94
  let(:invoice) { manager.get(1) }
@@ -0,0 +1,128 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Invoicer::Freshbooks do
4
+ let(:service) { Invoicer::Freshbooks.new('test-subdomain', 'test-apikey') }
5
+
6
+ describe "#invoices" do
7
+ it "returns invoice manager instance" do
8
+ service.invoices.should be_an_instance_of(Invoicer::FreshbooksInvoiceManager)
9
+ end
10
+ end
11
+ end
12
+
13
+ describe Invoicer::FreshbooksInvoiceManager do
14
+ let(:manager) { Invoicer::Freshbooks.new('test', 'test').invoices }
15
+
16
+ describe "#all" do
17
+ before(:each) do
18
+ invoices = { "invoices"=>
19
+ { "invoice"=>
20
+ [
21
+ {
22
+ "invoice_id"=>"0000000001",
23
+ "number"=>"0000001",
24
+ "amount"=>"24.00",
25
+ "paid"=>"0.00",
26
+ "date"=>"2011-06-27 00:00:00",
27
+ "terms"=>"15 days",
28
+ "currency_code"=>"USD",
29
+ },
30
+ {
31
+ "invoice_id"=>"0000000002",
32
+ "number"=>"0000002",
33
+ "amount"=>"24.00",
34
+ "paid"=>"0.00",
35
+ "date"=>"2011-06-27 00:00:00",
36
+ "terms"=>"15 days",
37
+ "currency_code"=>"USD"
38
+ }
39
+ ]
40
+ }
41
+ }
42
+
43
+ FreshBooks::Client::NamespaceProxy.any_instance.stubs(:list).returns(invoices)
44
+ end
45
+
46
+ it "returns collection of invoices" do
47
+ manager.all.should_not be_empty
48
+ end
49
+
50
+ describe "invoice" do
51
+ let(:invoice) { manager.all.first }
52
+
53
+ it "is an Invoicer::Invoice instance" do
54
+ invoice.should be_an_instance_of(Invoicer::Invoice)
55
+ end
56
+
57
+ it "has proper attributes set" do
58
+ invoice.number.should eql("0000001")
59
+ invoice.currency.should eql("USD")
60
+ invoice.service.should eql(:freshbooks)
61
+ end
62
+ end
63
+ end
64
+
65
+ describe "#get" do
66
+ before(:each) do
67
+ invoice = {"invoice"=>
68
+ {"invoice_id"=>"00000000001",
69
+ "number"=>"0000001",
70
+ "client_id"=>"3",
71
+ "recurring_id"=>nil,
72
+ "organization"=>"Test Client",
73
+ "first_name"=>nil,
74
+ "last_name"=>nil,
75
+ "p_street1"=>nil,
76
+ "p_street2"=>nil,
77
+ "p_city"=>nil,
78
+ "p_state"=>nil,
79
+ "p_country"=>nil,
80
+ "p_code"=>nil,
81
+ "po_number"=>nil,
82
+ "status"=>"draft",
83
+ "amount"=>"24.00",
84
+ "amount_outstanding"=>"24",
85
+ "paid"=>"0.00",
86
+ "date"=>"2011-06-27 00:00:00",
87
+ "notes"=>nil,
88
+ "terms"=>"15 days",
89
+ "discount"=>"0",
90
+ "url"=>"https://xteamtest.freshbooks.com/view/3M3n7nNhEC44NTKD",
91
+ "auth_url"=>"https://xteamtest.freshbooks.com/invoices/7095",
92
+ "links"=>
93
+ {"client_view"=>"https://xteamtest.freshbooks.com/view/3M3n7nNhEC44NTKD",
94
+ "view"=>"https://xteamtest.freshbooks.com/invoices/7095",
95
+ "edit"=>"https://xteamtest.freshbooks.com/invoices/7095/edit"},
96
+ "return_uri"=>nil,
97
+ "updated"=>"2011-06-27 10:27:02",
98
+ "currency_code"=>"USD",
99
+ "language"=>"en",
100
+ "vat_name"=>nil,
101
+ "vat_number"=>nil,
102
+ "folder"=>"active",
103
+ "staff_id"=>"1",
104
+ "lines"=>
105
+ {"line"=> []}}}
106
+
107
+ FreshBooks::Client::NamespaceProxy.any_instance.stubs(:get).returns(invoice)
108
+ end
109
+
110
+ let(:invoice) { manager.get(1) }
111
+
112
+ it "returns invoice instance" do
113
+ invoice.should be_an_instance_of(Invoicer::Invoice)
114
+ end
115
+
116
+ describe "invoice" do
117
+ it "is an Invoicer::Invoice instance" do
118
+ invoice.should be_an_instance_of(Invoicer::Invoice)
119
+ end
120
+
121
+ it "has proper attributes set" do
122
+ invoice.number.should eql("0000001")
123
+ invoice.currency.should eql("USD")
124
+ invoice.service.should eql(:freshbooks)
125
+ end
126
+ end
127
+ end
128
+ end
@@ -13,44 +13,46 @@ end
13
13
  describe Invoicer::HarvestInvoiceManager do
14
14
  let(:manager) { Invoicer::Harvest.new('test', 'test', 'test').invoices }
15
15
 
16
+ let(:invoices) do
17
+ [
18
+ mock('invoice',
19
+ :id => 1,
20
+ :number => "00001",
21
+ :total_amount => 20,
22
+ :due_amount => 10,
23
+ :issued_on => Date.today,
24
+ :due_on => Date.today + 30,
25
+ :currency => "USD"
26
+ ),
27
+ mock('invoice',
28
+ :id => 2,
29
+ :number => "00002",
30
+ :total_amount => 20,
31
+ :due_amount => 10,
32
+ :issued_on => Date.today,
33
+ :due_on => Date.today + 30,
34
+ :currency => "USD"
35
+ ),
36
+ mock('invoice',
37
+ :id => 3,
38
+ :number => "00003",
39
+ :total_amount => 20,
40
+ :due_amount => 10,
41
+ :issued_on => Date.today,
42
+ :due_on => Date.today + 30,
43
+ :currency => "USD"
44
+ )
45
+ ]
46
+ end
47
+
16
48
  describe "#all" do
17
49
  before(:each) do
18
- invoices = [
19
- mock('invoice',
20
- :id => 1,
21
- :number => "00001",
22
- :total_amount => 20,
23
- :due_amount => 10,
24
- :issued_on => Date.today,
25
- :due_on => Date.today + 30,
26
- :currency => "USD"
27
- ),
28
- mock('invoice',
29
- :id => 2,
30
- :number => "00002",
31
- :total_amount => 20,
32
- :due_amount => 10,
33
- :issued_on => Date.today,
34
- :due_on => Date.today + 30,
35
- :currency => "USD"
36
- ),
37
- mock('invoice',
38
- :id => 3,
39
- :number => "00003",
40
- :total_amount => 20,
41
- :due_amount => 10,
42
- :issued_on => Date.today,
43
- :due_on => Date.today + 30,
44
- :currency => "USD"
45
- )
46
- ]
47
-
48
- manager.service.harvester.stub!(:all).and_return(invoices)
50
+ manager.service.harvester.stubs(:all).returns(invoices)
49
51
  end
50
52
 
51
53
  it "passes params to Harvesb client" do
52
54
  params = { :status => "draft" }
53
- manager.service.harvester.should_receive(:all).with(params).once
55
+ manager.service.harvester.expects(:all).with(params).returns(invoices).once
54
56
  manager.all(params)
55
57
  end
56
58
 
@@ -85,7 +87,7 @@ describe Invoicer::HarvestInvoiceManager do
85
87
  :currency => "USD"
86
88
  )
87
89
 
88
- manager.service.harvester.stub!(:get).and_return(invoice)
90
+ manager.service.harvester.stubs(:get).returns(invoice)
89
91
  end
90
92
 
91
93
  let(:invoice) { manager.get(1) }
@@ -8,5 +8,5 @@ require 'invoicer'
8
8
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
9
 
10
10
  RSpec.configure do |config|
11
-
11
+ config.mock_with :mocha
12
12
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tomasz Werbicki
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-06-27 00:00:00 +02:00
17
+ date: 2011-06-28 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -44,8 +44,23 @@ dependencies:
44
44
  prerelease: false
45
45
  version_requirements: *id002
46
46
  - !ruby/object:Gem::Dependency
47
- name: rspec
47
+ name: ruby-freshbooks
48
48
  requirement: &id003 !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ - 4
56
+ - 0
57
+ version: 0.4.0
58
+ type: :runtime
59
+ prerelease: false
60
+ version_requirements: *id003
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: &id004 !ruby/object:Gem::Requirement
49
64
  none: false
50
65
  requirements:
51
66
  - - ~>
@@ -57,10 +72,25 @@ dependencies:
57
72
  version: 2.3.0
58
73
  type: :development
59
74
  prerelease: false
60
- version_requirements: *id003
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: mocha
78
+ requirement: &id005 !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ - 9
86
+ - 12
87
+ version: 0.9.12
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *id005
61
91
  - !ruby/object:Gem::Dependency
62
92
  name: bundler
63
- requirement: &id004 !ruby/object:Gem::Requirement
93
+ requirement: &id006 !ruby/object:Gem::Requirement
64
94
  none: false
65
95
  requirements:
66
96
  - - ~>
@@ -72,10 +102,10 @@ dependencies:
72
102
  version: 1.0.0
73
103
  type: :development
74
104
  prerelease: false
75
- version_requirements: *id004
105
+ version_requirements: *id006
76
106
  - !ruby/object:Gem::Dependency
77
107
  name: jeweler
78
- requirement: &id005 !ruby/object:Gem::Requirement
108
+ requirement: &id007 !ruby/object:Gem::Requirement
79
109
  none: false
80
110
  requirements:
81
111
  - - ~>
@@ -87,10 +117,10 @@ dependencies:
87
117
  version: 1.6.2
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *id005
120
+ version_requirements: *id007
91
121
  - !ruby/object:Gem::Dependency
92
122
  name: rcov
93
- requirement: &id006 !ruby/object:Gem::Requirement
123
+ requirement: &id008 !ruby/object:Gem::Requirement
94
124
  none: false
95
125
  requirements:
96
126
  - - ">="
@@ -100,7 +130,7 @@ dependencies:
100
130
  version: "0"
101
131
  type: :development
102
132
  prerelease: false
103
- version_requirements: *id006
133
+ version_requirements: *id008
104
134
  description: Common API for managing invoices from different online accounting services.
105
135
  email: tomasz@werbicki.net
106
136
  executables: []
@@ -125,10 +155,14 @@ files:
125
155
  - lib/services/blinksale.rb
126
156
  - lib/services/blinksale/invoice.rb
127
157
  - lib/services/blinksale/invoice_manager.rb
158
+ - lib/services/freshbooks.rb
159
+ - lib/services/freshbooks/invoice.rb
160
+ - lib/services/freshbooks/invoice_manager.rb
128
161
  - lib/services/harvest.rb
129
162
  - lib/services/harvest/invoice.rb
130
163
  - lib/services/harvest/invoice_manager.rb
131
164
  - spec/services/blinksale_spec.rb
165
+ - spec/services/freshbooks_spec.rb
132
166
  - spec/services/harvest_spec.rb
133
167
  - spec/spec_helper.rb
134
168
  has_rdoc: true
@@ -145,7 +179,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
179
  requirements:
146
180
  - - ">="
147
181
  - !ruby/object:Gem::Version
148
- hash: -4578703806334281031
182
+ hash: 1870407123010217142
149
183
  segments:
150
184
  - 0
151
185
  version: "0"