Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit 1dad52d

Browse files
committed
Gemify
1 parent 44c0485 commit 1dad52d

File tree

7 files changed

+129
-33
lines changed

7 files changed

+129
-33
lines changed

Diff for: Gemfile

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
source "http://rubygems.org"
1+
source :rubygems
22

3-
gem "log4r", "~> 1.1.10"
4-
gem "faraday", "~> 0.8.4"
5-
gem "sinatra", "~> 1.3.3", :require => false
6-
gem "webrick", "~> 1.3.1", :require => false
7-
8-
# development
9-
gem "rake", "~> 0.9.2.2"
3+
gemspec

Diff for: Gemfile.lock

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
PATH
2+
remote: .
3+
specs:
4+
bitpay-ruby (0.1.0)
5+
faraday (~> 0.8.4)
6+
log4r (~> 1.1.10)
7+
sinatra (~> 1.3.3)
8+
webrick (~> 1.3.1)
9+
110
GEM
211
remote: http://rubygems.org/
312
specs:
@@ -8,7 +17,7 @@ GEM
817
rack (1.4.1)
918
rack-protection (1.2.0)
1019
rack
11-
rake (0.9.2.2)
20+
rake (10.0.0)
1221
sinatra (1.3.3)
1322
rack (~> 1.3, >= 1.3.6)
1423
rack-protection (~> 1.2)
@@ -20,8 +29,5 @@ PLATFORMS
2029
ruby
2130

2231
DEPENDENCIES
23-
faraday (~> 0.8.4)
24-
log4r (~> 1.1.10)
25-
rake (~> 0.9.2.2)
26-
sinatra (~> 1.3.3)
27-
webrick (~> 1.3.1)
32+
bitpay-ruby!
33+
rake (~> 10.0.0)

Diff for: bin/create_invoice

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env ruby
2+
3+
require "bundler"
4+
Bundler.require :default
5+
6+
require File.dirname(__FILE__) + "/../lib/bitpay-ruby"
7+
8+
require "optparse"
9+
10+
begin
11+
options = {}
12+
optparse = OptionParser.new do |opts|
13+
opts.banner = "Usage: #{$0} [options]"
14+
15+
# specify an API key
16+
opts.on("-a", "--api-key API_KEY", "Specify an API key.") do |api_key|
17+
options[:api_key] = api_key
18+
end
19+
20+
# specfy a price
21+
opts.on("-p", "--price PRICE", "Specify a price.") do |price|
22+
options[:price] = price.to_f
23+
end
24+
25+
# specify a currency
26+
opts.on("-c", "--currency CURRENCY", "Specify a currency.") do |currency|
27+
options[:currency] = currency
28+
end
29+
30+
# version
31+
opts.on("-v", "--version", "Show the version number.") do
32+
$stdout.puts "0.1.0"
33+
exit
34+
end
35+
36+
# help
37+
opts.on("-h", "--help", "Show this help message.") do
38+
$stdout.puts opts
39+
exit
40+
end
41+
end
42+
43+
optparse.parse!
44+
45+
BitPayRuby::config["api_key"] = options[:api_key]
46+
invoice = BitPayRuby::Invoice.new(options[:price], options[:currency])
47+
invoice.create
48+
$stdout.puts invoice.to_s
49+
rescue BitPayRuby::BitPayRubyError => e
50+
$stderr.puts e.message
51+
exit e.status_code
52+
rescue Interrupt => e
53+
exit 1
54+
end

Diff for: bin/bitpay-ruby renamed to bin/fetch_invoice

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,22 @@ require "bundler"
44
Bundler.require :default
55

66
require File.dirname(__FILE__) + "/../lib/bitpay-ruby"
7-
include BitPayRuby
87

98
require "optparse"
109

1110
begin
1211
options = {}
1312
optparse = OptionParser.new do |opts|
1413
opts.banner = "Usage: #{$0} [options]"
15-
# create an invoice
16-
opts.on("-c", "--create PRICE CURRENCY", "Create an invoice.") do |price, currency|
17-
i = Invoice.new(price.to_f, currency)
18-
i.create
19-
$stdout.puts i.to_s
20-
exit
14+
15+
# specify an API key
16+
opts.on("-a", "--api-key API_KEY", "Specify an API key.") do |api_key|
17+
options[:api_key] = api_key
2118
end
2219

23-
# fetch an invoice status
24-
opts.on("-f", "--fetch ID", "Fetch an invoice status.") do |id|
25-
i = Invoice.fetch(id)
26-
$stdout.puts i.to_s
27-
exit
20+
# specify an id
21+
opts.on("-i", "--id ID", "Specify an id.") do |id|
22+
options[:id] = id
2823
end
2924

3025
# version
@@ -39,8 +34,13 @@ begin
3934
exit
4035
end
4136
end
37+
4238
optparse.parse!
43-
rescue BitPayRubyError => e
39+
40+
BitPayRuby::config["api_key"] = options[:api_key]
41+
invoice = BitPayRuby::Invoice.fetch(options[:id])
42+
$stdout.puts invoice.to_s
43+
rescue BitPayRuby::BitPayRubyError => e
4444
$stderr.puts e.message
4545
exit e.status_code
4646
rescue Interrupt => e

Diff for: bitpay-ruby.gemspec

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- encoding: utf-8 -*-
2+
$:.push File.expand_path("../lib", __FILE__)
3+
require "bitpay-ruby/version"
4+
5+
Gem::Specification.new do |s|
6+
s.name = "bitpay-ruby"
7+
s.version = BitPayRuby::VERSION
8+
s.authors = ["Martin Harrigan"]
9+
s.email = ["[email protected]"]
10+
s.homepage = "http://www.martinharrigan.ie"
11+
s.summary = %q{A library for interacting with the BitPay.com Bitcoin Payment Gateway API.}
12+
s.description = %q{A library for interacting with the BitPay.com Bitcoin Payment Gateway API.}
13+
14+
s.rubyforge_project = "bitpay-ruby"
15+
16+
s.files = `git ls-files`.split("\n")
17+
s.files += Dir['ext/java/jar/**/*.jar']
18+
s.test_files = `git ls-files -- spec}/*`.split("\n")
19+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20+
s.require_paths = ["config", "lib"]
21+
22+
s.add_runtime_dependency "log4r", "~> 1.1.10"
23+
s.add_runtime_dependency "faraday", "~> 0.8.4"
24+
s.add_runtime_dependency "sinatra", "~> 1.3.3"
25+
s.add_runtime_dependency "webrick", "~> 1.3.1"
26+
s.add_development_dependency "rake", "~> 10.0.0"
27+
case RUBY_PLATFORM.downcase
28+
when "java"
29+
else
30+
case RUBY_PLATFORM.downcase
31+
when "darwin"
32+
end
33+
end
34+
end

Diff for: lib/bitpay-ruby.rb

+13-6
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,26 @@
44
require "faraday"
55

66
module BitPayRuby
7-
class << self
8-
attr_accessor :config, :connection
7+
class BitPayRubyError < StandardError
98
end
109

11-
class BitPayRubyError < StandardError
10+
class << self
11+
attr_accessor :config
12+
13+
@@connection = nil
14+
15+
def connection
16+
if @@connection.nil?
17+
@@connection = Faraday.new :url => config["api_endpoint"]
18+
@@connection.basic_auth config["api_key"], ""
19+
end
20+
@@connection
21+
end
1222
end
1323
end
1424

1525
BitPayRuby::config = YAML.load_file(File.dirname(__FILE__) + "/../config/bitpay-ruby.yml")
1626

17-
BitPayRuby::connection = Faraday.new :url => BitPayRuby::config["api_endpoint"]
18-
BitPayRuby::connection.basic_auth BitPayRuby::config["api_key"], ""
19-
2027
require File.join File.dirname(__FILE__), "bitpay-ruby", "version"
2128
require File.join File.dirname(__FILE__), "bitpay-ruby", "logging"
2229

Diff for: lib/bitpay-ruby/invoice.rb

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def create
2727
"price" => price,
2828
"currency" => currency
2929
}
30+
3031
update! response.body
3132
self
3233
end

0 commit comments

Comments
 (0)