Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ccea3a4ea0 | ||
|
|
9c24e3acee | ||
|
|
44253dd34e |
@ -54,6 +54,7 @@ module BitPay
|
||||
def request(request_klass, path, params=nil)
|
||||
request = make_request(request_klass, path, params)
|
||||
response = @https.request(request)
|
||||
raise BitPayError, "HTTP Status " + response.code + " with body: " + response.body unless response.kind_of?(Net::HTTPSuccess)
|
||||
return JSON.parse(response.body)
|
||||
rescue => e
|
||||
fail BitPayError, "Bitpay Request Error: #{e}"
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
module BitPay
|
||||
VERSION = '0.1.4'
|
||||
VERSION = '0.1.5'
|
||||
end
|
||||
|
||||
@ -20,6 +20,10 @@ def invoice_response_body
|
||||
}
|
||||
end
|
||||
|
||||
def unauthorized_key_body
|
||||
{"error" => {"type" => "unauthorized", "message" => "invalid api key"}}
|
||||
end
|
||||
|
||||
stub_request(:post, "https://KEY:@bitpay.com/api/invoice/create").
|
||||
with(
|
||||
:headers => {'User-Agent'=>USER_AGENT, 'Content-Type' => 'application/json'},
|
||||
@ -31,6 +35,10 @@ stub_request(:get, "https://KEY:@bitpay.com/api/invoice/DGrAEmbsXe9bavBPMJ8kuk")
|
||||
with(:headers => {'User-Agent'=>USER_AGENT}).
|
||||
to_return(:body => invoice_response_body.to_json)
|
||||
|
||||
stub_request(:get, "https://KEY:@bitpay.com/api/invoice/BADAPIKEY").
|
||||
with(:headers => {'User-Agent'=>USER_AGENT}).
|
||||
to_return(:status => 403, :body => unauthorized_key_body.to_json)
|
||||
|
||||
describe BitPay::Client do
|
||||
before do
|
||||
@client = BitPay::Client.new 'KEY'
|
||||
@ -51,4 +59,12 @@ describe BitPay::Client do
|
||||
response['id'].must_equal 'DGrAEmbsXe9bavBPMJ8kuk'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'bad API Key' do
|
||||
it 'returns Error' do
|
||||
assert_raises(BitPay::Client::BitPayError) {
|
||||
response = @client.get 'invoice/BADAPIKEY'
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user