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,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gocoin::User do
4
+
5
+ before :each do
6
+ # Values for GET /user API behavior (#self)
7
+ @self_route = "/user"
8
+ @self_options = {}
9
+ @self_api_return_hash = 'mock_self_api_return_hash'
10
+
11
+ # Values for GET /users/:id API behavior (#get)
12
+ @get_user_id = 'getuserid'
13
+ @get_route = "/users/#{@get_user_id}"
14
+ @get_options = {}
15
+ @get_api_return_hash = 'mock_get_api_return_hash'
16
+
17
+ # Values for PATCH /users/:id API behavior (#update)
18
+ @update_user_id = 'updateuserid'
19
+ @update_params = {
20
+ email: "some@email.address",
21
+ first_name: "First",
22
+ last_name: "Last"
23
+ }
24
+ @update_route = "/users/#{@update_user_id}"
25
+ @update_options = {
26
+ method: 'PATCH',
27
+ payload: @update_params
28
+ }
29
+ @update_api_return_hash = 'mock_update_api_return_hash'
30
+
31
+ # Values for PATCH /users/:id/password API behavior
32
+ @update_password_user_id = 'updatepasswordsomeuserid'
33
+ @update_password_params = {
34
+ current_password: "currentpassword",
35
+ password: "newpassword",
36
+ password_confirmation: "newpassword"
37
+ }
38
+ @update_password_route = "/users/#{@update_password_user_id}/password"
39
+ @update_password_options = {
40
+ method: 'PATCH',
41
+ payload: @update_password_params
42
+ }
43
+ @update_password_api_return_hash = 'mock_update_password_api_return_hash'
44
+
45
+ @user = Gocoin::User.new(@api = double(Gocoin::API))
46
+ @api.stub(:client).and_return(Gocoin::Client.new)
47
+
48
+ @api.stub(:request).and_return('Incorrect parameters provided to API#request')
49
+ @api.stub(:request).with(@self_route, @self_options).and_return(@self_api_return_hash)
50
+ @api.stub(:request).with(@get_route, @get_options).and_return(@get_api_return_hash)
51
+ @api.stub(:request).with(@update_route, @update_options).and_return(@update_api_return_hash)
52
+ @api.stub(:request).with(@update_password_route, @update_password_options).and_return(@update_password_api_return_hash)
53
+ end
54
+
55
+
56
+ describe "'self' method" do
57
+
58
+ it 'should return the correct result' do
59
+ @user.self.should == @self_api_return_hash
60
+ end
61
+
62
+ end
63
+
64
+ describe "'get' method" do
65
+
66
+ it 'should return the correct result' do
67
+ @user.get(@get_user_id).should == @get_api_return_hash
68
+ end
69
+
70
+ end
71
+
72
+ describe "'update' method" do
73
+
74
+ it 'should return the correct result' do
75
+ @user.update(@update_user_id, @update_params).should == @update_api_return_hash
76
+ end
77
+
78
+ end
79
+
80
+ describe "'update_password' method" do
81
+
82
+ it 'should return the correct result' do
83
+ @user.update_password(@update_password_user_id, @update_password_params).should == @update_password_api_return_hash
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gocoin::API do
4
+
5
+ describe "'request' method" do
6
+
7
+ it "should raise an error if route is not passed as parameter" do
8
+ @gocoin_client = Gocoin::Client.new
9
+ expect{@gocoin_client.api.request}.to raise_error ArgumentError
10
+ end
11
+
12
+ it "should raise an error if token is undefined" do
13
+ @gocoin_client = Gocoin::Client.new
14
+ expect{@gocoin_client.api.request '/somewhere'}.to raise_error 'Gocoin::API#request: API not ready. Token was not defined'
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gocoin::Auth do
4
+
5
+ describe "'auth' method" do
6
+
7
+ it "should raise an error if an improper grant_type is specified" do
8
+ @gocoin_client = Gocoin::Client.new(grant_type: 'invalid_grant_type')
9
+ expect{@gocoin_client.auth.authenticate}.to raise_error 'Gocoin::Auth#authenticate: grant_type was not defined properly or is unsupported'
10
+ end
11
+
12
+ it "should raise an error if missing required properties for authorization_code grant_type" do
13
+ @gocoin_client = Gocoin::Client.new(
14
+ grant_type: 'authorization_code',
15
+ client_id: 'someid',
16
+ client_secret: 'somesecret',
17
+ redirect_uri: 'someuri'
18
+ )
19
+ expect{@gocoin_client.auth.authenticate}.to raise_error "Gocoin::Auth#authenticate requires 'code' option."
20
+ end
21
+
22
+ end
23
+
24
+ describe "'construct_code_url' method" do
25
+
26
+ it "should create and return an authorization_code url" do
27
+ @gocoin_client = Gocoin::Client.new(
28
+ grant_type: 'password',
29
+ client_secret: 'somesecret',
30
+ username: 'admin@gocoin.com',
31
+ password: 'password123',
32
+ scope: 'user_read'
33
+ )
34
+ url = @gocoin_client.auth.construct_code_url param_key: 'param_value'
35
+ url.should == 'https://dashboard.gocoin.com/auth?param_key=param_value'
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,139 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gocoin::Client do
4
+
5
+ describe "::initialize" do
6
+
7
+ describe "with an empty options hash" do
8
+
9
+ before :each do
10
+ @gocoin_client = Gocoin::Client.new
11
+ end
12
+
13
+ it "should have the default options" do
14
+ @gocoin_client.options[:client_id].should be_nil
15
+ @gocoin_client.options[:client_secret].should be_nil
16
+ @gocoin_client.options[:host].should == 'api.gocoin.com'
17
+ @gocoin_client.options[:port].should be_nil
18
+ @gocoin_client.options[:path].should == '/api'
19
+ @gocoin_client.options[:api_version].should == 'v1'
20
+ @gocoin_client.options[:secure].should == true
21
+ @gocoin_client.options[:method].should == 'GET'
22
+ @gocoin_client.options[:grant_type].should == 'authorization_code'
23
+ @gocoin_client.options[:request_id].should be_nil
24
+ @gocoin_client.options[:dashboard_host].should == 'dashboard.gocoin.com'
25
+ @gocoin_client.options[:xrate_host].should == 'x.g0cn.com'
26
+ @gocoin_client.options[:log_file].should be_nil
27
+ end
28
+
29
+ it "should have the default headers" do
30
+ @gocoin_client.headers.should == { 'Content-Type' => 'application/json' }
31
+ end
32
+
33
+ it "should allow access to 'logger'" do
34
+ @gocoin_client.logger.class.to_s.should == 'Logger'
35
+ end
36
+
37
+ it "should allow access to 'auth'" do
38
+ @gocoin_client.auth.class.to_s.should == 'Gocoin::Auth'
39
+ end
40
+
41
+ it "should allow access to 'api'" do
42
+ @gocoin_client.api.class.to_s.should == 'Gocoin::API'
43
+ end
44
+
45
+ it "should allow access to 'auth'" do
46
+ @gocoin_client.auth.class.to_s.should == 'Gocoin::Auth'
47
+ end
48
+
49
+ it "should allow access to 'user'" do
50
+ @gocoin_client.user.class.to_s.should == 'Gocoin::User'
51
+ end
52
+
53
+ it "should allow access to 'merchant'" do
54
+ @gocoin_client.merchant.class.to_s.should == 'Gocoin::Merchant'
55
+ end
56
+
57
+ it "should allow access to 'invoices'" do
58
+ @gocoin_client.invoices.class.to_s.should == 'Gocoin::Invoices'
59
+ end
60
+
61
+ end
62
+
63
+ describe "with a non-empty options hash" do
64
+
65
+ before :each do
66
+ @options = {
67
+ client_id: 'the_client_id_string',
68
+ client_secret: 'the_client_secret_string',
69
+ host: 'a.different.host',
70
+ port: '5',
71
+ path: '/a_different_api',
72
+ api_version: 'v6.28',
73
+ secure: false,
74
+ method: 'PUT',
75
+ headers: {'Content-Length' => '628'},
76
+ grant_type: 'a_different_grant_type',
77
+ request_id: 'a_request_id_string',
78
+ dashboard_host: 'a.different.dash.host',
79
+ }
80
+ @gocoin_client = Gocoin::Client.new(@options)
81
+ end
82
+
83
+ it "should not be nil" do
84
+ @gocoin_client.should_not be_nil
85
+ end
86
+
87
+ it "should set the options with the provided values" do
88
+ @gocoin_client.options[:client_id].should == @options[:client_id]
89
+ @gocoin_client.options[:client_secret].should == @options[:client_secret]
90
+ @gocoin_client.options[:host].should == @options[:host]
91
+ @gocoin_client.options[:port].should == @options[:port]
92
+ @gocoin_client.options[:path].should == @options[:path]
93
+ @gocoin_client.options[:api_version].should == @options[:api_version]
94
+ @gocoin_client.options[:secure].should == @options[:secure]
95
+ @gocoin_client.options[:method].should == @options[:method]
96
+ @gocoin_client.options[:headers].should == @options[:headers].merge('X-Request-Id' => 'a_request_id_string')
97
+ @gocoin_client.options[:grant_type].should == @options[:grant_type]
98
+ @gocoin_client.options[:request_id].should == @options[:request_id]
99
+ @gocoin_client.options[:dashboard_host].should == @options[:dashboard_host]
100
+ end
101
+
102
+ end
103
+
104
+ it "should interpret a 'false' (String type) options as a boolean false" do
105
+ @gocoin_client = Gocoin::Client.new( :secure => 'false')
106
+ @gocoin_client.options[:secure].should == false
107
+ end
108
+
109
+ end
110
+
111
+ describe '#http_prefix' do
112
+
113
+ it "should return https when secure=ture" do
114
+ @gocoin_client = Gocoin::Client.new
115
+ @gocoin_client.http_prefix.should == 'https://'
116
+ end
117
+
118
+ it "should return http when secure=false" do
119
+ @gocoin_client = Gocoin::Client.new
120
+ @gocoin_client.http_prefix(false).should == 'http://'
121
+ end
122
+
123
+ end
124
+
125
+ describe '#port' do
126
+
127
+ it "should return a specified port (precded by a colon)" do
128
+ @gocoin_client = Gocoin::Client.new( :port => 628 )
129
+ @gocoin_client.port.should == ':628'
130
+ end
131
+
132
+ it "should return nil when port unspecified" do
133
+ @gocoin_client = Gocoin::Client.new()
134
+ @gocoin_client.port.should be_nil
135
+ end
136
+
137
+ end
138
+
139
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gocoin::Xrate do
4
+
5
+ before :each do
6
+ @host = 'fake.xrate.host'
7
+ @route = '/prices'
8
+
9
+ # Values for Xrate GET /prices API behavior (#get)
10
+ @get_raw_request_config = {
11
+ url: "https://#{@host}#{@route}",
12
+ method: 'GET',
13
+ headers: {},
14
+ options: {}
15
+ }
16
+ @get_api_return_hash = 'mock_get_api_return_hash'
17
+
18
+ @xrate = Gocoin::Xrate.new(@client = double(Gocoin::Client))
19
+
20
+ @client.stub(:logger).and_return(Logger.new(STDOUT))
21
+ @client.stub(:headers).and_return({ client: 'fake_header_hash_that_wont_be_used' })
22
+ @client.stub(:options).and_return({ xrate_host: @host })
23
+
24
+
25
+ @client.stub(:raw_request).and_return('Incorrect parameters provided to API#raw_request')
26
+ @client.stub(:raw_request).with(@get_raw_request_config).and_return(@get_api_return_hash)
27
+ end
28
+
29
+ describe "'get' method" do
30
+
31
+ it 'should make a raw_request' do
32
+ @xrate.get.should == @get_api_return_hash
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,6 @@
1
+ require 'gocoin'
2
+
3
+ RSpec.configure do |config|
4
+ config.color_enabled = true
5
+ config.formatter = 'documentation'
6
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gocoin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - GoCoin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ description: GoCoin is the best way to accept Bitcoin payments for online businesses. See
56
+ https://gocoin.com for details.
57
+ email:
58
+ - kevin@gocoin.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - VERSION
68
+ - history.md
69
+ - lib/gocoin.rb
70
+ - lib/gocoin/api.rb
71
+ - lib/gocoin/api/accounts.rb
72
+ - lib/gocoin/api/invoices.rb
73
+ - lib/gocoin/api/merchant.rb
74
+ - lib/gocoin/api/merchants/currencies.rb
75
+ - lib/gocoin/api/merchants/currency_conversions.rb
76
+ - lib/gocoin/api/merchants/payouts.rb
77
+ - lib/gocoin/api/user.rb
78
+ - lib/gocoin/auth.rb
79
+ - lib/gocoin/client.rb
80
+ - lib/gocoin/errors/api_connection_error.rb
81
+ - lib/gocoin/errors/api_error.rb
82
+ - lib/gocoin/errors/authentication_error.rb
83
+ - lib/gocoin/errors/gocoin_error.rb
84
+ - lib/gocoin/errors/invalid_request_error.rb
85
+ - lib/gocoin/util.rb
86
+ - lib/gocoin/version.rb
87
+ - lib/gocoin/xrate.rb
88
+ - spec/gocoin/api/accounts_spec.rb
89
+ - spec/gocoin/api/invoices_spec.rb
90
+ - spec/gocoin/api/merchant_spec.rb
91
+ - spec/gocoin/api/merchants/currencies_spec.rb
92
+ - spec/gocoin/api/merchants/currency_conversions_spec.rb
93
+ - spec/gocoin/api/merchants/payouts_spec.rb
94
+ - spec/gocoin/api/user_spec.rb
95
+ - spec/gocoin/api_spec.rb
96
+ - spec/gocoin/auth_spec.rb
97
+ - spec/gocoin/client_spec.rb
98
+ - spec/gocoin/xrate_spec.rb
99
+ - spec/spec_helper.rb
100
+ homepage: http://www.gocoin.com
101
+ licenses:
102
+ - Apache
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.2.1
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: A Ruby gem for the GoCoin API.
124
+ test_files:
125
+ - spec/gocoin/api/accounts_spec.rb
126
+ - spec/gocoin/api/invoices_spec.rb
127
+ - spec/gocoin/api/merchant_spec.rb
128
+ - spec/gocoin/api/merchants/currencies_spec.rb
129
+ - spec/gocoin/api/merchants/currency_conversions_spec.rb
130
+ - spec/gocoin/api/merchants/payouts_spec.rb
131
+ - spec/gocoin/api/user_spec.rb
132
+ - spec/gocoin/api_spec.rb
133
+ - spec/gocoin/auth_spec.rb
134
+ - spec/gocoin/client_spec.rb
135
+ - spec/gocoin/xrate_spec.rb
136
+ - spec/spec_helper.rb