bitpay-client 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fa770bdf4bff602b5a1d08ae90adaad37cbae6b7
4
+ data.tar.gz: 9028c2eef4e4f36c0921f1ba7cfbd0931dd3431d
5
+ SHA512:
6
+ metadata.gz: ccb93210155e6b26b69dfdc025587253c46ddfb163eb5fcbd7b1cc998ccd3e05a16eb29cd36e1ec355ced828cda64ea7f2f73e1a8ddfc8420c00043e81137f0a
7
+ data.tar.gz: c6d5d4c7f90bc10c095c04f12e2d8172acc800104d8d3319151c98fc9a11fa7eb1a00ade1bc9128553d95e13ff8d2a5a783621f59cc3a587f5a875be508b7643
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ test.rb
3
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - jruby-18mode
5
+ - jruby-19mode
6
+ - rbx-18mode
7
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ platform :jruby do
5
+ gem 'jruby-openssl'
6
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (C) 2013 BitPay
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # BitPay Library for Ruby [![](https://secure.travis-ci.org/bitpay/ruby-client.png)](http://travis-ci.org/bitpay/ruby-client)
2
+ Powerful, flexible, lightweight interface to the BitPay Bitcoin Payment Gateway API.
3
+
4
+ ## Installation
5
+
6
+ gem install bitpay-client
7
+
8
+ In your Gemfile:
9
+
10
+ gem 'bitpay-client', :require => 'bitpay'
11
+
12
+ Or directly:
13
+
14
+ require 'bitpay'
15
+
16
+ ## Basic Usage
17
+
18
+ To create an invoice:
19
+
20
+ invoice = client.post 'invoice', {:price => 10.00, :currency => 'USD'}
21
+
22
+ With invoice creation, `price` and `currency` are the only required fields. If you are sending a customer from your website to make a purchase, setting `redirectURL` is
23
+
24
+ Response will be a hash with information on your newly created invoice. Send your customer to the `url` to complete payment:
25
+
26
+ {
27
+ "id" => "DGrAEmbsXe9bavBPMJ8kuk",
28
+ "url" => "https://bitpay.com/invoice?id=DGrAEmbsXe9bavBPMJ8kuk",
29
+ "status" => "new",
30
+ "btcPrice" => "0.0495",
31
+ "price" => 10,
32
+ "currency" => "USD",
33
+ "invoiceTime" => 1383265343674,
34
+ "expirationTime" => 1383266243674,
35
+ "currentTime" => 1383265957613
36
+ }
37
+
38
+ There are many options available when creating invoices, which are listed in the [BitPay API documentation](https://bitpay.com/bitcoin-payment-gateway-api).
39
+
40
+ To get updated information on this invoice, make a get call with the id returned:
41
+
42
+ invoice = client.get 'invoice/DGrAEmbsXe9bavBPMJ8kuk'
43
+
44
+ ## API Documentation
45
+
46
+ API Documentation is available on the [BitPay site](https://bitpay.com/bitcoin-payment-gateway-api).
47
+
48
+ ## RDoc/YARD Documentation
49
+ The code has been fully code documented, and the latest version is always available at the [Rubydoc Site](http://rubydoc.info/gems/bitpay-client).
50
+
51
+ ## Running the Tests
52
+
53
+ $ bundle install
54
+ $ bundle exec rake
55
+
56
+ In addition to a full test suite, there is Travis integration for MRI 1.9, JRuby and Rubinius.
57
+
58
+ ## Found a bug?
59
+ Let us know! Send a pull request or a patch. Questions? Ask! We're here to help. We will respond to all filed issues.
60
+
61
+ ## Authors
62
+ * Kyle Drake
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "rake/testtask"
2
+
3
+ desc "Run all tests"
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "spec"
6
+ t.test_files = FileList['test/*_test.rb','test/bitpay/*_test.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,23 @@
1
+ require './lib/bitpay/version.rb'
2
+ Gem::Specification.new do |s|
3
+ s.name = 'bitpay-client'
4
+ s.version = BitPay::VERSION
5
+ s.authors = ['Kyle Drake']
6
+ s.email = ['kyle@bitpay.com']
7
+ s.homepage = 'https://github.com/bitpay/ruby-client'
8
+ s.summary = 'Official ruby client library for the BitPay API'
9
+ s.description = 'Powerful, flexible, lightweight, thread-safe interface to the BitPay developers API'
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+ s.require_paths = %w[lib]
13
+ s.rubyforge_project = s.name
14
+ s.required_rubygems_version = '>= 1.3.4'
15
+
16
+ s.add_dependency 'json'
17
+ s.add_dependency 'rack', '>= 0'
18
+
19
+ s.add_development_dependency 'rake'
20
+ s.add_development_dependency 'minitest'
21
+ s.add_development_dependency 'webmock'
22
+ s.add_development_dependency 'yard'
23
+ end
data/lib/bitpay.rb ADDED
@@ -0,0 +1,24 @@
1
+ libdir = File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
3
+ require 'json'
4
+ require 'uri'
5
+ require 'net/https'
6
+ require 'bitpay/client'
7
+ require 'bitpay/version'
8
+
9
+ module BitPay
10
+ # Location of the directory of SSL certificates.
11
+ DATA_DIR = File.join File.dirname(__FILE__), 'bitpay', 'data'
12
+
13
+ # SSL Certificate
14
+ CERT = File.join DATA_DIR, 'cert.pem'
15
+
16
+ # SSL Key
17
+ KEY = File.join DATA_DIR, 'key.pem'
18
+
19
+ # Location of API
20
+ API_URI = 'https://bitpay.com/api'
21
+
22
+ # User agent reported to API
23
+ USER_AGENT = 'ruby-bitpay-client '+VERSION
24
+ end
@@ -0,0 +1,53 @@
1
+ module BitPay
2
+ # This class is used to instantiate a BitPay Client object. It is expected to be thread safe.
3
+ #
4
+ # @example
5
+ # # Create a client with your BitPay API key (obtained from the BitPay API access page at BitPay.com):
6
+ # client = BitPay::Client.new 'YOUR_API_KEY'
7
+ class Client
8
+ class BitPayError < StandardError; end
9
+
10
+ # Creates a BitPay Client object. The second parameter is a hash for overriding defaults.
11
+ #
12
+ # @return [Client]
13
+ # @example
14
+ # # Create a client with your BitPay API key (obtained from the BitPay API access page at BitPay.com):
15
+ # client = BitPay::Client.new 'YOUR_API_KEY'
16
+ def initialize(api_key, opts={})
17
+ @api_key = api_key
18
+ @uri = URI.parse opts[:api_uri] || API_URI
19
+ @https = Net::HTTP.new @uri.host, @uri.port
20
+ @https.use_ssl = true
21
+ @https.cert = OpenSSL::X509::Certificate.new File.read(opts[:cert] || CERT)
22
+ @https.verify_mode = OpenSSL::SSL::VERIFY_PEER
23
+ end
24
+
25
+ # Makes a GET call to the BitPay API.
26
+ # @return [Hash]
27
+ # @see get_invoice
28
+ # @example
29
+ # # Get an invoice:
30
+ # existing_invoice = client.get 'invoice/YOUR_INVOICE_ID'
31
+ def get(path)
32
+ request = Net::HTTP::Get.new @uri.path+'/'+path
33
+ request.basic_auth @api_key, ''
34
+ request['User-Agent'] = USER_AGENT
35
+ response = @https.request request
36
+ JSON.parse response.body
37
+ end
38
+
39
+ # Makes a POST call to the BitPay API.
40
+ # @return [Hash]
41
+ # @see create_invoice
42
+ # # Create an invoice:
43
+ # created_invoice = client.post 'invoice', {:price => 1.45, :currency => 'BTC'}
44
+ def post(path, params={})
45
+ request = Net::HTTP::Post.new @uri.path+'/'+path
46
+ request.basic_auth @api_key, ''
47
+ request['User-Agent'] = USER_AGENT
48
+ request.body = params
49
+ response = @https.request request
50
+ JSON.parse response.body
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,15 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIICWDCCAcGgAwIBAgIJAP4dy3lMOd97MA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV
3
+ BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
4
+ aWRnaXRzIFB0eSBMdGQwHhcNMTEwODE1MTUxMDU2WhcNMjEwODEyMTUxMDU2WjBF
5
+ MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50
6
+ ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB
7
+ gQDZ92nLT7OmfKJPIWzpNDc4gbUmUhBzHKG5aLaXpDZtvyqaMH2lUzGjIxY8taKS
8
+ Q8gvzLnIDuZJ6+99e7OlX9w5In5x1B2tVrwCXZo9ZUIy7a34ULQYxRhI5ZzCKtsC
9
+ O84fakQfNgKfkjlqUBr6ksK7IusftPwc7UHEPWSJfaakCQIDAQABo1AwTjAdBgNV
10
+ HQ4EFgQUfubRYcwiDLT98VoHiVXcGlXXAMAwHwYDVR0jBBgwFoAUfubRYcwiDLT9
11
+ 8VoHiVXcGlXXAMAwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQCruca0
12
+ pys5xJ3l4qts/gBxpAuW3Yx6Jkrr35ertgj108SIN+O5uBCu+/AZfTJArVSdh+Zn
13
+ ML6zF2T5E5ho7T/UHUXUW6hf5uCJVbRusx73pw4Hh1yE0x/+1Rwnf9uDD2gIeL2W
14
+ 3u6e+8/ladZJtplIYvCK031MxAwO4s2LMznpTQ==
15
+ -----END CERTIFICATE-----
@@ -0,0 +1,3 @@
1
+ module BitPay
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,47 @@
1
+ require File.join File.dirname(__FILE__), '..', 'env.rb'
2
+
3
+ USER_AGENT = 'ruby-bitpay-client '+BitPay::VERSION
4
+
5
+ def invoice_body
6
+ {
7
+ "id" => "DGrAEmbsXe9bavBPMJ8kuk",
8
+ "url" => "https://bitpay.com/invoice?id=DGrAEmbsXe9bavBPMJ8kuk",
9
+ "status" => "new",
10
+ "btcPrice" => "0.0495",
11
+ "price" => 10,
12
+ "currency" => "USD",
13
+ "invoiceTime" => 1383265343674,
14
+ "expirationTime" => 1383266243674,
15
+ "currentTime" => 1383265957613
16
+ }
17
+ end
18
+
19
+ stub_request(:post, "https://KEY:@bitpay.com/api/invoice/create").
20
+ with(:headers => {'User-Agent'=>USER_AGENT}).
21
+ to_return(:body => invoice_body.to_json)
22
+
23
+ stub_request(:get, "https://KEY:@bitpay.com/api/invoice/DGrAEmbsXe9bavBPMJ8kuk").
24
+ with(:headers => {'User-Agent'=>USER_AGENT}).
25
+ to_return(:body => invoice_body.to_json)
26
+
27
+ describe BitPay::Client do
28
+ before do
29
+ @client = BitPay::Client.new 'KEY'
30
+ end
31
+
32
+ describe 'post' do
33
+ it 'creates invoice' do
34
+ response = @client.post 'invoice/create', {}
35
+ response.class.must_equal Hash
36
+ response['id'].must_equal 'DGrAEmbsXe9bavBPMJ8kuk'
37
+ end
38
+ end
39
+
40
+ describe 'get' do
41
+ it 'retreives invoice' do
42
+ response = @client.get 'invoice/DGrAEmbsXe9bavBPMJ8kuk'
43
+ response.class.must_equal Hash
44
+ response['id'].must_equal 'DGrAEmbsXe9bavBPMJ8kuk'
45
+ end
46
+ end
47
+ end
data/test/env.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'addressable/uri'
2
+ require 'json'
3
+ require 'minitest/autorun'
4
+ require 'webmock'
5
+ require './lib/bitpay.rb'
6
+
7
+ include WebMock::API
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitpay-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Drake
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Powerful, flexible, lightweight, thread-safe interface to the BitPay
98
+ developers API
99
+ email:
100
+ - kyle@bitpay.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - .travis.yml
107
+ - Gemfile
108
+ - LICENSE.md
109
+ - README.md
110
+ - Rakefile
111
+ - bitpay-client.gemspec
112
+ - lib/bitpay.rb
113
+ - lib/bitpay/client.rb
114
+ - lib/bitpay/data/cert.pem
115
+ - lib/bitpay/version.rb
116
+ - test/bitpay/client_test.rb
117
+ - test/env.rb
118
+ homepage: https://github.com/bitpay/ruby-client
119
+ licenses: []
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: 1.3.4
135
+ requirements: []
136
+ rubyforge_project: bitpay-client
137
+ rubygems_version: 2.0.3
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Official ruby client library for the BitPay API
141
+ test_files: []
142
+ has_rdoc: