Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0cf038b
Showing
5 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.rvmrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# heroku-invoice | ||
|
||
publish invoice on your heroku account. | ||
|
||
## Installation | ||
|
||
$ heroku plugins:install https://github.com/hsbt/heroku-invoice.git | ||
|
||
## Usage | ||
|
||
$ heroku invoice --app myapp | ||
$ heroku invoice:pdf --app myapp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require "invoice/heroku/client" | ||
require "invoice/heroku/command/invoice" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Heroku::Client | ||
def get_invoice(y, m) | ||
get("invoices/show/#{y}/#{m}").to_s | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class Heroku::Command::Invoice < Heroku::Command::Base | ||
def index | ||
write_body(filename) | ||
end | ||
|
||
def pdf | ||
require 'tempfile' | ||
|
||
t = Tempfile.new | ||
write_body(t.path) | ||
system "wkhtmltopdf #{t.path} #{filename.sub(/\.html\z/, '.pdf')}" | ||
t.flush | ||
end | ||
|
||
private | ||
|
||
def write_body(name) | ||
Zlib::GzipReader.wrap(StringIO.new(get_body)) do |gz| | ||
File.open(name, 'w'){|f| f.print gz.read} | ||
end | ||
end | ||
|
||
def get_body | ||
heroku.get_invoice(optparse).net_http_res.body | ||
end | ||
|
||
def filename | ||
"%04d%02d.html" % optparse | ||
end | ||
|
||
def optparse | ||
if args[0] | ||
args[0].scan(/(\d{4})(\d{2})/).first.map(&:to_i) | ||
else | ||
t = Time.now | ||
[t.year, t.month] | ||
end | ||
end | ||
end |