invoice_maker 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +96 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/invoice_in.json +20 -0
- data/examples/usage.rb +23 -0
- data/fixtures/invoice.pdf +0 -0
- data/fixtures/invoice_appended.json +20 -0
- data/fixtures/invoice_in.json +15 -0
- data/invoice_maker.gemspec +35 -0
- data/lib/invoice_maker/invoice.rb +50 -0
- data/lib/invoice_maker/version.rb +3 -0
- data/lib/invoice_maker.rb +5 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2f67e03c7be70612a9652351ede322783d6942ed
|
4
|
+
data.tar.gz: 3913f1c725d444678a007bdd1ae87db9825805fd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7b76f3928b9955d3f070e9478640b5ad1fdc1b42c75b3833a5e75fc26cab4d1462ed3c9025315312c8a23a5296029421e464213a35cb2dc52f121cbe2f82a053
|
7
|
+
data.tar.gz: 315f86de186ef3995cdb7f5a80bb13ec0ed05bab790c69e2653fc859f57b7c0cdf14865e8901e89325760a082f4de026d4e6f0a15c1d317e2da8e542881c0566
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Chris Horton
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
[![CircleCI](https://circleci.com/gh/hortoncd/invoice_maker.svg?style=svg)](https://circleci.com/gh/hortoncd/invoice_maker)
|
2
|
+
|
3
|
+
# InvoiceMaker
|
4
|
+
|
5
|
+
A gem to do the basic work of creating a PDF invoice using https://invoice-generator.com. Inspired by
|
6
|
+
the article here:
|
7
|
+
https://gelato.io/blog/minimum-viable-ruby-api-client-with-invoiced-and-httparty.
|
8
|
+
|
9
|
+
API documentation lives at https://github.com/Invoiced/invoice-generator-api.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'invoice_maker'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install invoice_maker
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Require the gem, and optionally include the module for simplicity
|
30
|
+
```ruby
|
31
|
+
require 'invoice_maker'
|
32
|
+
|
33
|
+
include InvoiceMaker
|
34
|
+
```
|
35
|
+
|
36
|
+
The gem relies on general options for the invoice being set with the 'set' method. This can include all the line items, or they can be added individually after initial options are set.
|
37
|
+
|
38
|
+
The basic data can include any of the options documented in the API documentation referenced above. A
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
data = {
|
42
|
+
"from": "My Great Company, Inc. ®\nMy Street Address\nMy City, State 00000",
|
43
|
+
"to": "My Great Customer\nATTN: The Dude\nCust Address\nCust Street Address\nCust City, State 11111",
|
44
|
+
"logo": "http://placekitten.com/320/140",
|
45
|
+
"number": 1,
|
46
|
+
"date": "2016-10-24",
|
47
|
+
"items": [
|
48
|
+
{
|
49
|
+
"name": "Some awesome task",
|
50
|
+
"quantity": 1,
|
51
|
+
"unit_cost": 270.0
|
52
|
+
}
|
53
|
+
],
|
54
|
+
"notes": "Thank you so much for your business!"
|
55
|
+
}
|
56
|
+
```
|
57
|
+
|
58
|
+
Instantiate an object and add the data, followed by adding any line items as necessary.
|
59
|
+
```ruby
|
60
|
+
i = Invoice
|
61
|
+
i.set(data)
|
62
|
+
|
63
|
+
item = {
|
64
|
+
"name": "Some additional awesome task",
|
65
|
+
"quantity": 2,
|
66
|
+
"unit_cost": 270.0
|
67
|
+
}
|
68
|
+
|
69
|
+
i.append_item(item)
|
70
|
+
```
|
71
|
+
Optionally set a destination directory for the generated PDF invoice. Default is "/tmp".
|
72
|
+
```ruby
|
73
|
+
i.dest_dir = "/somedir"
|
74
|
+
```
|
75
|
+
|
76
|
+
Once all data is set, generate the PDF invoice. The filename will be returned from the call to generate.
|
77
|
+
```ruby
|
78
|
+
fname = i.generate
|
79
|
+
puts fname
|
80
|
+
```
|
81
|
+
|
82
|
+
`examples/usage.rb` is a sample script that loads data from a json file and generates a sample invoice.
|
83
|
+
|
84
|
+
## Development
|
85
|
+
|
86
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake true` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
87
|
+
|
88
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hortoncd/invoice_maker.
|
93
|
+
|
94
|
+
## License
|
95
|
+
|
96
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "invoice_maker"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"from": "My Great Company, Inc. ®\nMy Street Address\nMy City, State 00000",
|
3
|
+
"to": "My Great Customer\nATTN: The Dude\nCust Address\nCust Street Address\nCust City, State 11111",
|
4
|
+
"logo": "http://placekitten.com/320/140",
|
5
|
+
"number": 1,
|
6
|
+
"date": "2016-10-24",
|
7
|
+
"items": [
|
8
|
+
{
|
9
|
+
"name": "Some awesome task",
|
10
|
+
"quantity": 1,
|
11
|
+
"unit_cost": 270.0
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"name": "Some other task",
|
15
|
+
"quantity": 2,
|
16
|
+
"unit_cost": 270.0
|
17
|
+
}
|
18
|
+
],
|
19
|
+
"notes": "Thank you so much for your business!"
|
20
|
+
}
|
data/examples/usage.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'invoice_maker'
|
4
|
+
include InvoiceMaker
|
5
|
+
|
6
|
+
i = Invoice.new
|
7
|
+
puts "i is an instance of an #{i.class} class."
|
8
|
+
puts
|
9
|
+
|
10
|
+
data = JSON.parse(File.open(File.join(File.dirname(__FILE__), 'invoice_in.json'), 'r').read)
|
11
|
+
puts "data is the JSON that will be sent to the api to generate the invoice:"
|
12
|
+
puts data
|
13
|
+
puts
|
14
|
+
|
15
|
+
i.set(data)
|
16
|
+
fname = i.generate
|
17
|
+
|
18
|
+
puts "After generation, we have a pdf file name, or 'nil' to indicate and error:"
|
19
|
+
if fname
|
20
|
+
puts fname
|
21
|
+
else
|
22
|
+
puts "Failed to generate invoice."
|
23
|
+
end
|
Binary file
|
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"from": "My Great Company, Inc. ®\nMy Street Address\nMy City, State 00000",
|
3
|
+
"to": "My Great Customer\nATTN: The Dude\nCust Address\nCust Street Address\nCust City, State 11111",
|
4
|
+
"logo": "http://placekitten.com/320/140",
|
5
|
+
"number": 1,
|
6
|
+
"date": "2016-10-24",
|
7
|
+
"items": [
|
8
|
+
{
|
9
|
+
"name": "Some awesome task",
|
10
|
+
"quantity": 1,
|
11
|
+
"unit_cost": 270.0
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"name": "Some other task",
|
15
|
+
"quantity": 2,
|
16
|
+
"unit_cost": 270.0
|
17
|
+
}
|
18
|
+
],
|
19
|
+
"notes": "Thank you so much for your business!"
|
20
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"from": "My Great Company, Inc. ®\nMy Street Address\nMy City, State 00000",
|
3
|
+
"to": "My Great Customer\nATTN: The Dude\nCust Address\nCust Street Address\nCust City, State 11111",
|
4
|
+
"logo": "http://placekitten.com/320/140",
|
5
|
+
"number": 1,
|
6
|
+
"date": "2016-10-24",
|
7
|
+
"items": [
|
8
|
+
{
|
9
|
+
"name": "Some awesome task",
|
10
|
+
"quantity": 1,
|
11
|
+
"unit_cost": 270.0
|
12
|
+
}
|
13
|
+
],
|
14
|
+
"notes": "Thank you so much for your business!"
|
15
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'invoice_maker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "invoice_maker"
|
8
|
+
spec.version = InvoiceMaker::VERSION
|
9
|
+
spec.authors = ["Chris Horton"]
|
10
|
+
spec.email = ["hortoncd@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Generate simple invoices using https://invoice-generator.com}
|
13
|
+
spec.description = %q{Generate simple invoices using https://invoice-generator.com.}
|
14
|
+
spec.homepage = "https://github.com/hortoncd/invoice_maker"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
#if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
#else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
#end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
33
|
+
spec.add_development_dependency "webmock", "~> 2.1.0"
|
34
|
+
spec.add_dependency "httparty", "~> 0.14.0"
|
35
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module InvoiceMaker
|
2
|
+
class Invoice
|
3
|
+
PDF_CONTENT_TYPE = 'application/pdf'
|
4
|
+
JSON_CONTENT_TYPE = 'application/json'
|
5
|
+
|
6
|
+
attr_accessor :dest_dir
|
7
|
+
attr_reader :data
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@dest_dir = '/tmp'
|
11
|
+
@data = Hash.new
|
12
|
+
@base_uri = 'https://invoice-generator.com'
|
13
|
+
end
|
14
|
+
|
15
|
+
# set invoice data
|
16
|
+
def set(options = {})
|
17
|
+
@data = options
|
18
|
+
end
|
19
|
+
|
20
|
+
def data
|
21
|
+
@data
|
22
|
+
end
|
23
|
+
|
24
|
+
def append_item(item)
|
25
|
+
raise "Unable to add items to an empty invoice data. Did you 'set' first?" if @data.empty?
|
26
|
+
@data['items'] = [] unless @data.has_key?('items')
|
27
|
+
@data['items'].push item unless @data.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
# Let's generate a pdf
|
31
|
+
def generate
|
32
|
+
response = HTTParty.post(@base_uri, body: @data.to_json, headers: { "Content-Type" => JSON_CONTENT_TYPE })
|
33
|
+
if response.success? && response.content_type == PDF_CONTENT_TYPE
|
34
|
+
filename = File.join(@dest_dir, SecureRandom.urlsafe_base64(16)) + '.pdf'
|
35
|
+
save_pdf(filename, response.parsed_response)
|
36
|
+
else
|
37
|
+
return nil
|
38
|
+
end
|
39
|
+
return filename
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def save_pdf(filename, data)
|
45
|
+
File.open(filename, "wb+") do |f|
|
46
|
+
f << data
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: invoice_maker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Horton
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.14.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.14.0
|
83
|
+
description: Generate simple invoices using https://invoice-generator.com.
|
84
|
+
email:
|
85
|
+
- hortoncd@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- examples/invoice_in.json
|
98
|
+
- examples/usage.rb
|
99
|
+
- fixtures/invoice.pdf
|
100
|
+
- fixtures/invoice_appended.json
|
101
|
+
- fixtures/invoice_in.json
|
102
|
+
- invoice_maker.gemspec
|
103
|
+
- lib/invoice_maker.rb
|
104
|
+
- lib/invoice_maker/invoice.rb
|
105
|
+
- lib/invoice_maker/version.rb
|
106
|
+
homepage: https://github.com/hortoncd/invoice_maker
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.6.6
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Generate simple invoices using https://invoice-generator.com
|
130
|
+
test_files: []
|