bitpay-client 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 063c4a9c971e736ff4e9665c18fa44383af868ef
4
- data.tar.gz: b8fdf9f0a4aa70555091c3419fb5f57fd774f2e8
3
+ metadata.gz: 58908ccf542a4fde0d28f13ccd59c9aae77b4916
4
+ data.tar.gz: b50be1b001ab2a3a8cbf9e72619051e385855531
5
5
  SHA512:
6
- metadata.gz: ae8073ac737a7a76d9e328ed0f4f03747b60acd230496e7d7188ae33dadf17da8dbfd2ee0d1fc20374be6da165405e9af78285ea1d823dbe7b6714aa4ac16b18
7
- data.tar.gz: 0f35a0992fff715c0173fe74cb432d830fb422bfc7964db2777a7d3dca748731b0e46524213ee310e3433b522d81f2634eb315bf9cb3d1fbf4afd9ed660ec44a
6
+ metadata.gz: 07d7b3a8ff9dd4d6fe2a1d78dbf2f96a32268b22801498e6d08908cd0d6d09c575bae3619312663b7add7bff569c1dcf747debc7572b93d5f3389efcee14dcd5
7
+ data.tar.gz: f6a7251e498a226f9e7d4f686ebb067b55a043c51a871c70db2aa4be15e81a43d56982a14c2de667c491f41ffb0bb3cb03dd4c1d5b80d4d979fe4369d3a7b2a8
data/README.md CHANGED
@@ -42,6 +42,14 @@ To get updated information on this invoice, make a get call with the id returned
42
42
 
43
43
  invoice = client.get 'invoice/DGrAEmbsXe9bavBPMJ8kuk'
44
44
 
45
+ ## Testnet Usage
46
+
47
+ During development and testing, take advantage of the [Bitcoin TestNet](https://en.bitcoin.it/wiki/Testnet) by passing a custom `api_uri` option on initialization:
48
+
49
+ BitPay::Client.new("myAPIKey", {api_uri: "https://test.bitpay.com/api"})
50
+
51
+ Note that you will need a separate API key for `test.bitpay.com` which can be obtained by registering for a test account at https://test.bitpay.com/start
52
+
45
53
  ## API Documentation
46
54
 
47
55
  API Documentation is available on the [BitPay site](https://bitpay.com/bitcoin-payment-gateway-api).
data/lib/bitpay/client.rb CHANGED
@@ -37,11 +37,7 @@ module BitPay
37
37
  # # Get an invoice:
38
38
  # existing_invoice = client.get 'invoice/YOUR_INVOICE_ID'
39
39
  def get(path)
40
- request = Net::HTTP::Get.new @uri.path+'/'+path
41
- request.basic_auth @api_key, ''
42
- request['User-Agent'] = USER_AGENT
43
- response = @https.request request
44
- JSON.parse response.body
40
+ request(Net::HTTP::Get, path)
45
41
  end
46
42
 
47
43
  # Makes a POST call to the BitPay API.
@@ -50,15 +46,27 @@ module BitPay
50
46
  # # Create an invoice:
51
47
  # created_invoice = client.post 'invoice', {:price => 1.45, :currency => 'BTC'}
52
48
  def post(path, params={})
49
+ request(Net::HTTP::Post, path, params)
50
+ end
51
+
52
+ private
53
+
54
+ def request(request_klass, path, params=nil)
55
+ request = make_request(request_klass, path, params)
56
+ response = @https.request(request)
57
+ return JSON.parse(response.body)
58
+ rescue => e
59
+ fail BitPayError, "Bitpay Request Error: #{e}"
60
+ end
53
61
 
54
- request = Net::HTTP::Post.new @uri.path+'/'+path
55
- request.basic_auth @api_key, ''
56
- request['User-Agent'] = USER_AGENT
57
- request['Content-Type'] = 'application/json'
58
- request['X-BitPay-Plugin-Info'] = 'Rubylib' + VERSION
59
- request.body = params.to_json
60
- response = @https.request request
61
- JSON.parse response.body
62
+ def make_request(request_klass, path, params)
63
+ request_klass.new(@uri.path + '/' + path).tap do |r|
64
+ r.basic_auth @api_key, ''
65
+ r['User-Agent'] = USER_AGENT
66
+ r['Content-Type'] = 'application/json'
67
+ r['X-BitPay-Plugin-Info'] = 'Rubylib' + VERSION
68
+ r.body = params.to_json if params
69
+ end
62
70
  end
63
71
  end
64
72
  end
@@ -1,3 +1,3 @@
1
1
  module BitPay
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitpay-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bitpay, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-13 00:00:00.000000000 Z
11
+ date: 2014-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: 1.3.4
134
134
  requirements: []
135
135
  rubyforge_project: bitpay-client
136
- rubygems_version: 2.3.0
136
+ rubygems_version: 2.2.2
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: Official ruby client library for the BitPay API