get_invoice 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "blinksale"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "rspec", "~> 2.3.0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.6.2"
13
+ gem "rcov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ blinksale (0.1.0)
5
+ nokogiri
6
+ rest-client
7
+ diff-lcs (1.1.2)
8
+ git (1.2.5)
9
+ jeweler (1.6.2)
10
+ bundler (~> 1.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ mime-types (1.16)
14
+ nokogiri (1.4.6)
15
+ rake (0.9.2)
16
+ rcov (0.9.9)
17
+ rest-client (1.6.3)
18
+ mime-types (>= 1.16)
19
+ rspec (2.3.0)
20
+ rspec-core (~> 2.3.0)
21
+ rspec-expectations (~> 2.3.0)
22
+ rspec-mocks (~> 2.3.0)
23
+ rspec-core (2.3.1)
24
+ rspec-expectations (2.3.0)
25
+ diff-lcs (~> 1.1.2)
26
+ rspec-mocks (2.3.0)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ blinksale
33
+ bundler (~> 1.0.0)
34
+ jeweler (~> 1.6.2)
35
+ rcov
36
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Tomasz Werbicki
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = invoicer
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to invoicer
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Tomasz Werbicki. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "get_invoice"
18
+ gem.homepage = "http://github.com/neaf/invoicer"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Common API for managing invoices from different online accounting services.}
21
+ gem.description = %Q{Common API for managing invoices from different online accounting services.}
22
+ gem.email = "tomasz@werbicki.net"
23
+ gem.authors = ["Tomasz Werbicki"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "invoicer #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/invoicer.gemspec ADDED
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{invoicer}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Tomasz Werbicki"]
12
+ s.date = %q{2011-06-27}
13
+ s.description = %q{Common API for managing invoices from different online accounting services.}
14
+ s.email = %q{tomasz@werbicki.net}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "invoicer.gemspec",
29
+ "lib/invoice.rb",
30
+ "lib/invoicer.rb",
31
+ "lib/services/blinksale.rb",
32
+ "lib/services/blinksale/invoice.rb",
33
+ "lib/services/blinksale/invoice_manager.rb",
34
+ "spec/services/blinksale_spec.rb",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/neaf/invoicer}
38
+ s.licenses = ["MIT"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.7}
41
+ s.summary = %q{Common API for managing invoices from different online accounting services.}
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<blinksale>, [">= 0"])
49
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
50
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
51
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
52
+ s.add_development_dependency(%q<rcov>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<blinksale>, [">= 0"])
55
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
58
+ s.add_dependency(%q<rcov>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<blinksale>, [">= 0"])
62
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
65
+ s.add_dependency(%q<rcov>, [">= 0"])
66
+ end
67
+ end
68
+
data/lib/invoice.rb ADDED
@@ -0,0 +1,15 @@
1
+ module Invoicer
2
+ class Invoice
3
+ attr_accessor :attributes
4
+
5
+ def initialize(attributes = {})
6
+ @attributes = attributes
7
+ end
8
+
9
+ [:id, :number, :total_amount, :due_amount, :issued_on, :due_on, :currency, :service].each do |attr|
10
+ define_method(attr) do
11
+ attributes[attr]
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/invoicer.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "invoice"
2
+ require "services/blinksale"
@@ -0,0 +1,13 @@
1
+ require "services/blinksale/invoice_manager"
2
+
3
+ module Invoicer
4
+ class Blinksale
5
+ attr_reader :blinksale
6
+ attr_reader :invoices
7
+
8
+ def initialize(*args)
9
+ @blinksale = ::Blinksale::Client.new(*args)
10
+ @invoices = Invoicer::BlinksaleInvoiceManager.new(self)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module Invoicer
2
+ class BlinksaleInvoice
3
+ def self.from_blinksale(blinksale_invoice)
4
+ Invoice.new(
5
+ :id => blinksale_invoice.id,
6
+ :number => blinksale_invoice.number,
7
+ :total_amount => blinksale_invoice.total_amount,
8
+ :due_amount => blinksale_invoice.due_amount,
9
+ :issued_on => blinksale_invoice.issued_on,
10
+ :due_on => blinksale_invoice.due_on,
11
+ :currency => blinksale_invoice.currency,
12
+ :service => :blinksale
13
+ )
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ require "blinksale"
2
+ require "services/blinksale/invoice"
3
+
4
+ module Invoicer
5
+ class BlinksaleInvoiceManager
6
+ attr_reader :service
7
+
8
+ def initialize(service)
9
+ @service = service
10
+ end
11
+
12
+ def all(params = {})
13
+ service.blinksale.all(params).map do |i|
14
+ Invoicer::BlinksaleInvoice.from_blinksale(i)
15
+ end
16
+ end
17
+
18
+ def get(id)
19
+ Invoicer::BlinksaleInvoice.from_blinksale(service.blinksale.get(id))
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,109 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Invoicer::Blinksale do
4
+ let(:service) { Invoicer::Blinksale.new('test', 'test', 'test') }
5
+
6
+ describe "#invoices" do
7
+ it "returns invoice manager instance" do
8
+ service.invoices.should be_an_instance_of(Invoicer::BlinksaleInvoiceManager)
9
+ end
10
+ end
11
+ end
12
+
13
+ describe Invoicer::BlinksaleInvoiceManager do
14
+ let(:manager) { Invoicer::Blinksale.new('test', 'test', 'test').invoices }
15
+
16
+ describe "#all" do
17
+ 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)
49
+ end
50
+
51
+ it "passes params to Blinksale client" do
52
+ params = { :status => "draft" }
53
+ manager.service.blinksale.should_receive(:all).with(params).once
54
+ manager.all(params)
55
+ end
56
+
57
+ it "returns collection of invoices" do
58
+ manager.all.should_not be_empty
59
+ end
60
+
61
+ describe "invoice" do
62
+ let(:invoice) { manager.all.first }
63
+
64
+ it "is an Invoicer::Invoice instance" do
65
+ invoice.should be_an_instance_of(Invoicer::Invoice)
66
+ end
67
+
68
+ it "has proper attributes set" do
69
+ invoice.number.should eql("00001")
70
+ invoice.currency.should eql("USD")
71
+ invoice.service.should eql(:blinksale)
72
+ end
73
+ end
74
+ end
75
+
76
+ describe "#get" do
77
+ before(:each) do
78
+ invoice = mock('invoice',
79
+ :id => 1,
80
+ :number => "00001",
81
+ :total_amount => 20,
82
+ :due_amount => 10,
83
+ :issued_on => Date.today,
84
+ :due_on => Date.today + 30,
85
+ :currency => "USD"
86
+ )
87
+
88
+ manager.service.blinksale.stub!(:get).and_return(invoice)
89
+ end
90
+
91
+ let(:invoice) { manager.get(1) }
92
+
93
+ it "returns invoice instance" do
94
+ invoice.should be_an_instance_of(Invoicer::Invoice)
95
+ end
96
+
97
+ describe "invoice" do
98
+ it "is an Invoicer::Invoice instance" do
99
+ invoice.should be_an_instance_of(Invoicer::Invoice)
100
+ end
101
+
102
+ it "has proper attributes set" do
103
+ invoice.number.should eql("00001")
104
+ invoice.currency.should eql("USD")
105
+ invoice.service.should eql(:blinksale)
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'invoicer'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: get_invoice
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Tomasz Werbicki
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-06-27 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: blinksale
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ prerelease: false
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 2
42
+ - 3
43
+ - 0
44
+ version: 2.3.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 0
58
+ - 0
59
+ version: 1.0.0
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: jeweler
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 1
72
+ - 6
73
+ - 2
74
+ version: 1.6.2
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: rcov
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *id005
91
+ description: Common API for managing invoices from different online accounting services.
92
+ email: tomasz@werbicki.net
93
+ executables: []
94
+
95
+ extensions: []
96
+
97
+ extra_rdoc_files:
98
+ - LICENSE.txt
99
+ - README.rdoc
100
+ files:
101
+ - .document
102
+ - .rspec
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - LICENSE.txt
106
+ - README.rdoc
107
+ - Rakefile
108
+ - VERSION
109
+ - invoicer.gemspec
110
+ - lib/invoice.rb
111
+ - lib/invoicer.rb
112
+ - lib/services/blinksale.rb
113
+ - lib/services/blinksale/invoice.rb
114
+ - lib/services/blinksale/invoice_manager.rb
115
+ - spec/services/blinksale_spec.rb
116
+ - spec/spec_helper.rb
117
+ has_rdoc: true
118
+ homepage: http://github.com/neaf/invoicer
119
+ licenses:
120
+ - MIT
121
+ post_install_message:
122
+ rdoc_options: []
123
+
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ hash: -2770695777343712863
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ segments:
141
+ - 0
142
+ version: "0"
143
+ requirements: []
144
+
145
+ rubyforge_project:
146
+ rubygems_version: 1.3.7
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: Common API for managing invoices from different online accounting services.
150
+ test_files: []
151
+