gocoin 0.1.2

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.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +2 -0
  3. data/LICENSE +191 -0
  4. data/README.md +242 -0
  5. data/Rakefile +7 -0
  6. data/VERSION +1 -0
  7. data/history.md +21 -0
  8. data/lib/gocoin.rb +27 -0
  9. data/lib/gocoin/api.rb +35 -0
  10. data/lib/gocoin/api/accounts.rb +16 -0
  11. data/lib/gocoin/api/invoices.rb +33 -0
  12. data/lib/gocoin/api/merchant.rb +38 -0
  13. data/lib/gocoin/api/merchants/currencies.rb +35 -0
  14. data/lib/gocoin/api/merchants/currency_conversions.rb +35 -0
  15. data/lib/gocoin/api/merchants/payouts.rb +35 -0
  16. data/lib/gocoin/api/user.rb +43 -0
  17. data/lib/gocoin/auth.rb +51 -0
  18. data/lib/gocoin/client.rb +201 -0
  19. data/lib/gocoin/errors/api_connection_error.rb +4 -0
  20. data/lib/gocoin/errors/api_error.rb +4 -0
  21. data/lib/gocoin/errors/authentication_error.rb +4 -0
  22. data/lib/gocoin/errors/gocoin_error.rb +20 -0
  23. data/lib/gocoin/errors/invalid_request_error.rb +10 -0
  24. data/lib/gocoin/util.rb +29 -0
  25. data/lib/gocoin/version.rb +3 -0
  26. data/lib/gocoin/xrate.rb +28 -0
  27. data/spec/gocoin/api/accounts_spec.rb +32 -0
  28. data/spec/gocoin/api/invoices_spec.rb +67 -0
  29. data/spec/gocoin/api/merchant_spec.rb +66 -0
  30. data/spec/gocoin/api/merchants/currencies_spec.rb +64 -0
  31. data/spec/gocoin/api/merchants/currency_conversions_spec.rb +63 -0
  32. data/spec/gocoin/api/merchants/payouts_spec.rb +63 -0
  33. data/spec/gocoin/api/user_spec.rb +88 -0
  34. data/spec/gocoin/api_spec.rb +19 -0
  35. data/spec/gocoin/auth_spec.rb +40 -0
  36. data/spec/gocoin/client_spec.rb +139 -0
  37. data/spec/gocoin/xrate_spec.rb +37 -0
  38. data/spec/spec_helper.rb +6 -0
  39. metadata +136 -0
@@ -0,0 +1,4 @@
1
+ module Gocoin
2
+ class APIConnectionError < GocoinError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Gocoin
2
+ class APIError < GocoinError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Gocoin
2
+ class AuthenticationError < GocoinError
3
+ end
4
+ end
@@ -0,0 +1,20 @@
1
+ module Gocoin
2
+ class GocoinError < StandardError
3
+ attr_reader :message
4
+ attr_reader :http_status
5
+ attr_reader :http_body
6
+ attr_reader :json_body
7
+
8
+ def initialize(message=nil, http_status=nil, http_body=nil, json_body=nil)
9
+ @message = message
10
+ @http_status = http_status
11
+ @http_body = http_body
12
+ @json_body = json_body
13
+ end
14
+
15
+ def to_s
16
+ status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
17
+ "#{status_string}#{@message}"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ module Gocoin
2
+ class InvalidRequestError < GocoinError
3
+ attr_accessor :param
4
+
5
+ def initialize(message, http_status=nil, http_body=nil, json_body=nil)
6
+ super(message, http_status, http_body, json_body)
7
+ @param = param
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,29 @@
1
+ module Gocoin
2
+ module Util
3
+
4
+ class << self
5
+
6
+ def symbolize_names(object)
7
+ case object
8
+ when Hash
9
+ new = {}
10
+ object.each do |key, value|
11
+ key = (key.to_sym rescue key) || key
12
+ new[key] = symbolize_names(value)
13
+ end
14
+ new
15
+ when Array
16
+ object.map { |value| symbolize_names(value) }
17
+ else
18
+ object
19
+ end
20
+ end
21
+
22
+ def hash_to_url_params(hash)
23
+ hash.map{|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"}.join("&")
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Gocoin
2
+ VERSION = '0.1.2'
3
+ end
@@ -0,0 +1,28 @@
1
+ module Gocoin
2
+ class Xrate
3
+
4
+ attr_reader :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def get(options = {})
11
+ @client.logger.debug 'Gocoin::Xrate#get method called.'
12
+
13
+ headers = @client.headers.merge(options[:headers] || {})
14
+ options = @client.options.merge options
15
+ route = '/prices'
16
+
17
+ config = {
18
+ url: "https://#{@client.options[:xrate_host]}#{route}",
19
+ method: 'GET',
20
+ headers: {},
21
+ options: {}
22
+ }
23
+
24
+ @client.raw_request config
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gocoin::Accounts do
4
+
5
+ before :each do
6
+
7
+
8
+ # Values for GET /accounts/:id/transactions?option1=OPTION1 API behavior (#transactions)
9
+ @account_id = 'account_id'
10
+ @transactions_params = {
11
+ start_time: '2013-08-18 00:00',
12
+ page: 2
13
+ }
14
+ @transactions_route = "/accounts/#{@account_id}/transactions?#{Gocoin::Util.hash_to_url_params(@transactions_params)}"
15
+ @transactions_api_return_hash = 'mock_transactions_api_return_hash'
16
+
17
+ @accounts = Gocoin::Accounts.new(@api = double(Gocoin::API))
18
+ @api.stub(:client).and_return(Gocoin::Client.new)
19
+
20
+ @api.stub(:request).and_return('Incorrect parameters provided to API#request')
21
+ @api.stub(:request).with(@transactions_route, {}).and_return(@transactions_api_return_hash)
22
+ end
23
+
24
+ describe "'transactions' method" do
25
+
26
+ it 'should return the correct result' do
27
+ @accounts.transactions(@account_id, @transactions_params).should == @transactions_api_return_hash
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gocoin::Invoices do
4
+
5
+ before :each do
6
+
7
+ # Values for GET /invoices/:id API behavior (#get)
8
+ @get_invoice_id = 'getinvoiceid'
9
+ @get_route = "/invoices/#{@get_invoice_id}"
10
+ @get_options = {}
11
+ @get_api_return_hash = 'mock_get_api_return_hash'
12
+
13
+ # Values for POST /merchants/:id/invoices API behavior (#create)
14
+ @merchant_id = 'somemerchantid'
15
+ @create_params = {
16
+ price_currency: "BTC"
17
+ # more unnecessary for testing
18
+ }
19
+ @create_route = "/merchants/#{@merchant_id}/invoices"
20
+ @create_options = {
21
+ method: 'POST',
22
+ payload: @create_params
23
+ }
24
+ @create_api_return_hash = 'mock_create_api_return_hash'
25
+
26
+ # Values for GET /invoices/search?option1=OPTION1 API behavior (#search)
27
+ @search_options = {
28
+ status: 'new',
29
+ page: 2
30
+ }
31
+ @search_route = "/invoices/search?#{Gocoin::Util.hash_to_url_params(@search_options)}"
32
+ @search_api_return_hash = 'mock_search_api_return_hash'
33
+
34
+ @invoices = Gocoin::Invoices.new(@api = double(Gocoin::API))
35
+ @api.stub(:client).and_return(Gocoin::Client.new)
36
+
37
+ @api.stub(:request).and_return('Incorrect parameters provided to API#request')
38
+ @api.stub(:request).with(@get_route, @get_options).and_return(@get_api_return_hash)
39
+ @api.stub(:request).with(@create_route, @create_options).and_return(@create_api_return_hash)
40
+ @api.stub(:request).with(@search_route, {}).and_return(@search_api_return_hash)
41
+ end
42
+
43
+ describe "'get' method" do
44
+
45
+ it 'should return the correct result' do
46
+ @invoices.get(@get_invoice_id).should == @get_api_return_hash
47
+ end
48
+
49
+ end
50
+
51
+ describe "'create' method" do
52
+
53
+ it 'should return the correct result' do
54
+ @invoices.create(@merchant_id, @create_params).should == @create_api_return_hash
55
+ end
56
+
57
+ end
58
+
59
+ describe "'search' method" do
60
+
61
+ it 'should return the correct result' do
62
+ @invoices.search(@search_options).should == @search_api_return_hash
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gocoin::Merchant do
4
+
5
+ before :each do
6
+ # Values for GET /merchants/:id API behavior (#get)
7
+ @get_merchant_id = 'getmerchantid'
8
+ @get_route = "/merchants/#{@get_merchant_id}"
9
+ @get_options = {}
10
+ @get_api_return_hash = 'mock_get_api_return_hash'
11
+
12
+ # Values for PATCH /merchants/:id API behavior (#update)
13
+ @update_merchant_id = 'updatemerchantid'
14
+ @update_params = {
15
+ name: "Blingin' Merchant",
16
+ address_1: "123 Main St."
17
+ # more is unnecessary
18
+ }
19
+ @update_route = "/merchants/#{@update_merchant_id}"
20
+ @update_options = {
21
+ method: 'PATCH',
22
+ payload: @update_params
23
+ }
24
+ @update_api_return_hash = 'mock_update_api_return_hash'
25
+
26
+ # Values for GET /merchants/:id/accounts API behavior (#accounts)
27
+ @accounts_merchant_id = 'accountsmerchantid'
28
+ @accounts_route = "/merchants/#{@accounts_merchant_id}/accounts"
29
+ @accounts_options = {}
30
+ @accounts_api_return_hash = 'mock_accounts_api_return_hash'
31
+
32
+
33
+ @merchant = Gocoin::Merchant.new(@api = double(Gocoin::API))
34
+ @api.stub(:client).and_return(Gocoin::Client.new)
35
+
36
+ @api.stub(:request).and_return('Incorrect parameters provided to API#request')
37
+ @api.stub(:request).with(@get_route, @get_options).and_return(@get_api_return_hash)
38
+ @api.stub(:request).with(@update_route, @update_options).and_return(@update_api_return_hash)
39
+ @api.stub(:request).with(@accounts_route, @accounts_options).and_return(@accounts_api_return_hash)
40
+ end
41
+
42
+ describe "'get' method" do
43
+
44
+ it 'should return the correct result' do
45
+ @merchant.get(@get_merchant_id).should == @get_api_return_hash
46
+ end
47
+
48
+ end
49
+
50
+ describe "'update' method" do
51
+
52
+ it 'should return the correct result' do
53
+ @merchant.update(@update_merchant_id, @update_params).should == @update_api_return_hash
54
+ end
55
+
56
+ end
57
+
58
+ describe "'accounts' method" do
59
+
60
+ it 'should return the correct result' do
61
+ @merchant.accounts(@accounts_merchant_id).should == @accounts_api_return_hash
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gocoin::Merchants::Currencies do
4
+
5
+ before :each do
6
+
7
+ @merchant_id = 'merchant_id'
8
+
9
+ # Values for GET /merchants/:merchant_id/currencies/:id API behavior (#get)
10
+ @get_currency_id = 'get_currency_id'
11
+ @get_route = "/merchants/#{@merchant_id}/currencies/#{@get_currency_id}"
12
+ @get_options = {}
13
+ @get_api_return_hash = 'mock_get_api_return_hash'
14
+
15
+ # Values for PATCH /merchants/:merchant_id/ API behavior (#update)
16
+ @update_currency_id = 'updatecurrencyid'
17
+ @update_params = {
18
+ payment_crypto_split: 60
19
+ }
20
+ @update_route = "/merchants/#{@merchant_id}/currencies/#{@update_currency_id}"
21
+ @update_options = {
22
+ method: 'PATCH',
23
+ payload: @update_params
24
+ }
25
+ @update_api_return_hash = 'mock_update_api_return_hash'
26
+
27
+ # Values for GET /merchants/:merchant_id/currencies (#list)
28
+ @list_route = "/merchants/#{@merchant_id}/currencies"
29
+ @list_api_return_hash = 'mock_list_api_return_hash'
30
+
31
+ @currencies = Gocoin::Merchants::Currencies.new(@api = double(Gocoin::API))
32
+ @api.stub(:client).and_return(Gocoin::Client.new)
33
+
34
+ @api.stub(:request).and_return('Incorrect parameters provided to API#request')
35
+ @api.stub(:request).with(@get_route, @get_options).and_return(@get_api_return_hash)
36
+ @api.stub(:request).with(@update_route, @update_options).and_return(@update_api_return_hash)
37
+ @api.stub(:request).with(@list_route, {}).and_return(@list_api_return_hash)
38
+ end
39
+
40
+ describe "'get' method" do
41
+
42
+ it 'should return the correct result' do
43
+ @currencies.get(@merchant_id, @get_currency_id).should == @get_api_return_hash
44
+ end
45
+
46
+ end
47
+
48
+ describe "'update' method" do
49
+
50
+ it 'should return the correct result' do
51
+ @currencies.update(@merchant_id, @update_currency_id, @update_params).should == @update_api_return_hash
52
+ end
53
+
54
+ end
55
+
56
+ describe "'list' method" do
57
+
58
+ it 'should return the correct result' do
59
+ @currencies.list(@merchant_id).should == @list_api_return_hash
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gocoin::Merchants::CurrencyConversions do
4
+
5
+ before :each do
6
+
7
+ @merchant_id = 'merchant_id'
8
+
9
+ # Values for GET /merchants/:merchant_id/currency_conversions/:id API behavior (#get)
10
+ @get_currency_conversion_id = 'get_currency_conversion_id'
11
+ @get_route = "/merchants/#{@merchant_id}/currency_conversions/#{@get_currency_conversion_id}"
12
+ @get_options = {}
13
+ @get_api_return_hash = 'mock_get_api_return_hash'
14
+
15
+ # Values for POST /merchants/:id/currency_conversions API behavior (#request)
16
+ @request_params = {
17
+ base_currency: "BTC"
18
+ }
19
+ @request_route = "/merchants/#{@merchant_id}/currency_conversions"
20
+ @request_options = {
21
+ method: 'POST',
22
+ payload: @request_params
23
+ }
24
+ @request_api_return_hash = 'mock_request_api_return_hash'
25
+
26
+ # Values for GET /merchants/:merchant_id/currency_conversions (#list)
27
+ @list_route = "/merchants/#{@merchant_id}/currency_conversions"
28
+ @list_api_return_hash = 'mock_list_api_return_hash'
29
+
30
+ @currency_conversions = Gocoin::Merchants::CurrencyConversions.new(@api = double(Gocoin::API))
31
+ @api.stub(:client).and_return(Gocoin::Client.new)
32
+
33
+ @api.stub(:request).and_return('Incorrect parameters provided to API#request')
34
+ @api.stub(:request).with(@get_route, @get_options).and_return(@get_api_return_hash)
35
+ @api.stub(:request).with(@request_route, @request_options).and_return(@request_api_return_hash)
36
+ @api.stub(:request).with(@list_route, {}).and_return(@list_api_return_hash)
37
+ end
38
+
39
+ describe "'get' method" do
40
+
41
+ it 'should return the correct result' do
42
+ @currency_conversions.get(@merchant_id, @get_currency_conversion_id).should == @get_api_return_hash
43
+ end
44
+
45
+ end
46
+
47
+ describe "'request' method" do
48
+
49
+ it 'should return the correct result' do
50
+ @currency_conversions.request(@merchant_id, @request_params).should == @request_api_return_hash
51
+ end
52
+
53
+ end
54
+
55
+ describe "'list' method" do
56
+
57
+ it 'should return the correct result' do
58
+ @currency_conversions.list(@merchant_id).should == @list_api_return_hash
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gocoin::Merchants::Payouts do
4
+
5
+ before :each do
6
+
7
+ @merchant_id = 'merchant_id'
8
+
9
+ # Values for GET /merchants/:merchant_id/payouts/:id API behavior (#get)
10
+ @get_payout_id = 'get_payout_id'
11
+ @get_route = "/merchants/#{@merchant_id}/payouts/#{@get_payout_id}"
12
+ @get_options = {}
13
+ @get_api_return_hash = 'mock_get_api_return_hash'
14
+
15
+ # Values for POST /merchants/:id/payouts API behavior (#request)
16
+ @request_params = {
17
+ currency_code: "BTC"
18
+ }
19
+ @request_route = "/merchants/#{@merchant_id}/payouts"
20
+ @request_options = {
21
+ method: 'POST',
22
+ payload: @request_params
23
+ }
24
+ @request_api_return_hash = 'mock_request_api_return_hash'
25
+
26
+ # Values for GET /merchants/:merchant_id/payouts (#list)
27
+ @list_route = "/merchants/#{@merchant_id}/payouts"
28
+ @list_api_return_hash = 'mock_list_api_return_hash'
29
+
30
+ @payouts = Gocoin::Merchants::Payouts.new(@api = double(Gocoin::API))
31
+ @api.stub(:client).and_return(Gocoin::Client.new)
32
+
33
+ @api.stub(:request).and_return('Incorrect parameters provided to API#request')
34
+ @api.stub(:request).with(@get_route, @get_options).and_return(@get_api_return_hash)
35
+ @api.stub(:request).with(@request_route, @request_options).and_return(@request_api_return_hash)
36
+ @api.stub(:request).with(@list_route, {}).and_return(@list_api_return_hash)
37
+ end
38
+
39
+ describe "'get' method" do
40
+
41
+ it 'should return the correct result' do
42
+ @payouts.get(@merchant_id, @get_payout_id).should == @get_api_return_hash
43
+ end
44
+
45
+ end
46
+
47
+ describe "'request' method" do
48
+
49
+ it 'should return the correct result' do
50
+ @payouts.request(@merchant_id, @request_params).should == @request_api_return_hash
51
+ end
52
+
53
+ end
54
+
55
+ describe "'list' method" do
56
+
57
+ it 'should return the correct result' do
58
+ @payouts.list(@merchant_id).should == @list_api_return_hash
59
+ end
60
+
61
+ end
62
+
63
+ end