mtgox 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1,3 +1 @@
1
1
  --color
2
- --format=nested
3
- --backtrace
@@ -1,7 +1,3 @@
1
1
  rvm:
2
- - 1.8.7
3
- - 1.9.1
4
2
  - 1.9.2
5
- - jruby
6
- - ree
7
- - ruby-head
3
+ - 1.9.3
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- platforms :jruby do
4
- gem 'jruby-openssl', '~> 0.7'
3
+ platforms :mri do
4
+ gem 'simplecov'
5
5
  end
6
6
 
7
7
  gemspec
data/README.md CHANGED
@@ -1,50 +1,37 @@
1
1
  # Ruby wrapper for the Mt. Gox Trade API
2
-
3
2
  Mt. Gox allows you to trade US Dollars (USD) for Bitcoins (BTC) or Bitcoins for
4
3
  US Dollars.
5
4
 
6
- Installation
7
- ------------
5
+ ## <a name="installation"></a>Installation
8
6
  gem install mtgox
9
7
 
10
- Alias
11
- -----
8
+ ## <a name="alias"></a>Alias
12
9
  After installing the gem, you can get the current price for 1 BTC in USD by
13
10
  typing `btc` in your bash shell simply by setting the following alias:
14
11
 
15
- alias btc='ruby -r rubygems -r mtgox -e "puts MtGox.ticker.last"'
12
+ alias btc='ruby -r rubygems -r mtgox -e "puts MtGox.ticker.sell"'
16
13
 
17
- Documentation
18
- -------------
19
- [http://rdoc.info/gems/mtgox](http://rdoc.info/gems/mtgox)
14
+ ## <a name="documentation"></a>Documentation
15
+ [http://rdoc.info/gems/mtgox][documentation]
20
16
 
21
- Donate
22
- ------
23
- If you find this library useful, please consider sending a donation to the
24
- author, which you can do using the following script:
17
+ [documentation]: http://rdoc.info/gems/mtgox
25
18
 
26
- require 'rubygems'
27
- require 'mtgox'
19
+ ## <a name="ci"></a>Continuous Integration
20
+ [![Build Status](https://secure.travis-ci.org/sferik/mtgox.png)][ci]
28
21
 
29
- # Certain methods require authentication
30
- MtGox.configure do |config|
31
- config.name = YOUR_MTGOX_USERNAME
32
- config.pass = YOUR_MTGOX_PASSWORD
33
- end
22
+ [ci]: http://travis-ci.org/sferik/mtgox
34
23
 
35
- MtGox.withdraw 1.0, "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L"
24
+ ## <a name="dependencies"></a>Dependency Status
25
+ [![Dependency Status](https://gemnasium.com/sferik/mtgox.png)][gemnasium]
36
26
 
37
- Continuous Integration
38
- ----------------------
39
- [![Build Status](https://secure.travis-ci.org/sferik/mtgox.png)](http://travis-ci.org/sferik/mtgox)
27
+ [gemnasium]: https://gemnasium.com/sferik/mtgox
40
28
 
41
- Usage Examples
42
- --------------
29
+ ## <a name="examples"></a>Usage Examples
43
30
  require 'rubygems'
44
31
  require 'mtgox'
45
32
 
46
33
  # Fetch the latest price for 1 BTC in USD
47
- puts MtGox.ticker.last
34
+ puts MtGox.ticker.sell
48
35
 
49
36
  # Fetch open asks
50
37
  puts MtGox.asks
@@ -57,8 +44,8 @@ Usage Examples
57
44
 
58
45
  # Certain methods require authentication
59
46
  MtGox.configure do |config|
60
- config.name = YOUR_MTGOX_USERNAME
61
- config.pass = YOUR_MTGOX_PASSWORD
47
+ config.key = YOUR_MTGOX_KEY
48
+ config.secret = YOUR_MTGOX_SECRET
62
49
  end
63
50
 
64
51
  # Fetch your current balance
@@ -76,11 +63,11 @@ Usage Examples
76
63
  # Withdraw 1 BTC from your account
77
64
  MtGox.withdraw! 1.0, "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L"
78
65
 
79
- Contributing
80
- ------------
81
- In the spirit of [free
82
- software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is
83
- encouraged to help improve this project.
66
+ ## <a name="contributing"></a>Contributing
67
+ In the spirit of [free software][free-sw], **everyone** is encouraged to help
68
+ improve this project.
69
+
70
+ [free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
84
71
 
85
72
  Here are some ways *you* can contribute:
86
73
 
@@ -92,48 +79,43 @@ Here are some ways *you* can contribute:
92
79
  * by writing code (**no patch is too small**: fix typos, add comments, clean up
93
80
  inconsistent whitespace)
94
81
  * by refactoring code
95
- * by closing [issues](https://github.com/sferik/mtgox/issues)
82
+ * by closing [issues][]
96
83
  * by reviewing patches
97
- * by financially (please send bitcoin donations to
98
- 1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L)
99
-
100
- Submitting an Issue
101
- -------------------
102
- We use the [GitHub issue tracker](https://github.com/sferik/mtgox/issues) to
103
- track bugs and features. Before submitting a bug report or feature request,
104
- check to make sure it hasn't already been submitted. You can indicate support
105
- for an existing issuse by voting it up. When submitting a bug report, please
106
- include a [Gist](https://gist.github.com/) that includes a stack trace and any
107
- details that may be necessary to reproduce the bug, including your gem version,
108
- Ruby version, and operating system. Ideally, a bug report should include a pull
109
- request with failing specs.
110
-
111
- Submitting a Pull Request
112
- -------------------------
84
+
85
+ [issues]: https://github.com/sferik/mtgox/issues
86
+
87
+ ## <a name="issues"></a>Submitting an Issue
88
+ We use the [GitHub issue tracker][issues] to track bugs and features. Before
89
+ submitting a bug report or feature request, check to make sure it hasn't
90
+ already been submitted. You can indicate support for an existing issue by
91
+ voting it up. When submitting a bug report, please include a [Gist][gist] that
92
+ includes a stack trace and any details that may be necessary to reproduce the
93
+ bug, including your gem version, Ruby version, and operating system. Ideally, a
94
+ bug report should include a pull request with failing specs.
95
+
96
+ [gist]: https://gist.github.com/
97
+
98
+ ## <a name="pulls"></a>Submitting a Pull Request
113
99
  1. Fork the project.
114
100
  2. Create a topic branch.
115
101
  3. Implement your feature or bug fix.
116
102
  4. Add documentation for your feature or bug fix.
117
- 5. Run <tt>bundle exec rake doc:yard</tt>. If your changes are not 100%
118
- documented, go back to step 4.
103
+ 5. Run `bundle exec rake doc:yard`. If your changes are not 100% documented, go
104
+ back to step 4.
119
105
  6. Add specs for your feature or bug fix.
120
- 7. Run <tt>bundle exec rake spec</tt>. If your changes are not 100% covered, go
121
- back to step 6.
106
+ 7. Run `bundle exec rake spec`. If your changes are not 100% covered, go back
107
+ to step 6.
122
108
  8. Commit and push your changes.
123
109
  9. Submit a pull request. Please do not include changes to the gemspec,
124
110
  version, or history file. (If you want to create your own version for some
125
111
  reason, please do so in a separate commit.)
126
112
 
127
- Supported Rubies
128
- ----------------
129
- This library aims to support and is [tested
130
- against](http://travis-ci.org/sferik/mtgox) the following Ruby implementations:
113
+ ## <a name="versions"></a>Supported Ruby Versions
114
+ This library aims to support and is [tested against][ci] the following Ruby
115
+ implementations:
131
116
 
132
- * Ruby 1.8.7
133
- * Ruby 1.9.1
134
117
  * Ruby 1.9.2
135
- * Ruby Enterprise Edition 1.8.7
136
- * JRuby 1.6
118
+ * Ruby 1.9.3
137
119
 
138
120
  If something doesn't work on one of these interpreters, it should be considered
139
121
  a bug.
@@ -149,7 +131,7 @@ implementation, you will be personally responsible for providing patches in a
149
131
  timely fashion. If critical issues for a particular implementation exist at the
150
132
  time of a major release, support for that Ruby version may be dropped.
151
133
 
152
- Copyright
153
- ---------
154
- Copyright (c) 2011 Erik Michaels-Ober.
155
- See [LICENSE](https://github.com/sferik/mtgox/blob/master/LICENSE.md) for details.
134
+ ## <a name="copyright"></a>Copyright
135
+ Copyright (c) 2011 Erik Michaels-Ober. See [LICENSE][] for details.
136
+
137
+ [license]: https://github.com/sferik/mtgox/blob/master/LICENSE.md
data/Rakefile CHANGED
File without changes
@@ -18,6 +18,16 @@ module MtGox
18
18
 
19
19
  ORDER_TYPES = {:sell => 1, :buy => 2}
20
20
 
21
+ # Fetch a deposit address
22
+ # @authenticated true
23
+ # @return [String]
24
+ # @example
25
+ # MtGox.address
26
+ def address
27
+ post('/api/0/btcAddress.php')['addr']
28
+ end
29
+
30
+
21
31
  # Fetch the latest ticker data
22
32
  #
23
33
  # @authenticated false
@@ -25,7 +35,7 @@ module MtGox
25
35
  # @example
26
36
  # MtGox.ticker
27
37
  def ticker
28
- ticker = get('/code/data/ticker.php')['ticker']
38
+ ticker = get('/api/0/data/ticker.php')['ticker']
29
39
  Ticker.instance.buy = ticker['buy'].to_f
30
40
  Ticker.instance.high = ticker['high'].to_f
31
41
  Ticker.instance.price = ticker['last'].to_f
@@ -42,7 +52,7 @@ module MtGox
42
52
  # @example
43
53
  # MtGox.offers
44
54
  def offers
45
- offers = get('/code/data/getDepth.php')
55
+ offers = get('/api/0/data/getDepth.php')
46
56
  asks = offers['asks'].sort_by do |ask|
47
57
  ask[0].to_f
48
58
  end.map! do |ask|
@@ -109,7 +119,7 @@ module MtGox
109
119
  # @example
110
120
  # MtGox.trades
111
121
  def trades
112
- get('/code/data/getTrades.php').sort_by{|trade| trade['date']}.map do |trade|
122
+ get('/api/0/data/getTrades.php').sort_by{|trade| trade['date']}.map do |trade|
113
123
  Trade.new(trade)
114
124
  end
115
125
  end
@@ -121,7 +131,7 @@ module MtGox
121
131
  # @example
122
132
  # MtGox.balance
123
133
  def balance
124
- parse_balance(post('/code/getFunds.php', pass_params))
134
+ parse_balance(post('/api/0/getFunds.php', {}))
125
135
  end
126
136
 
127
137
  # Fetch your open orders, both buys and sells, for network efficiency
@@ -131,7 +141,7 @@ module MtGox
131
141
  # @example
132
142
  # MtGox.orders
133
143
  def orders
134
- parse_orders(post('/code/getOrders.php', pass_params)['orders'])
144
+ parse_orders(post('/api/0/getOrders.php', {})['orders'])
135
145
  end
136
146
 
137
147
  # Fetch your open buys
@@ -164,7 +174,7 @@ module MtGox
164
174
  # # Buy one bitcoin for $0.011
165
175
  # MtGox.buy! 1.0, 0.011
166
176
  def buy!(amount, price)
167
- parse_orders(post('/code/buyBTC.php', pass_params.merge({:amount => amount, :price => price}))['orders'])
177
+ parse_orders(post('/api/0/buyBTC.php', {:amount => amount, :price => price})['orders'])
168
178
  end
169
179
 
170
180
  # Place a limit order to sell BTC
@@ -177,7 +187,7 @@ module MtGox
177
187
  # # Sell one bitcoin for $100
178
188
  # MtGox.sell! 1.0, 100.0
179
189
  def sell!(amount, price)
180
- parse_orders(post('/code/sellBTC.php', pass_params.merge({:amount => amount, :price => price}))['orders'])
190
+ parse_orders(post('/api/0/sellBTC.php', {:amount => amount, :price => price})['orders'])
181
191
  end
182
192
 
183
193
  # Cancel an open order
@@ -200,13 +210,13 @@ module MtGox
200
210
  def cancel(args)
201
211
  if args.is_a?(Hash)
202
212
  order = args.delete_if{|k, v| !['oid', 'type'].include?(k.to_s)}
203
- parse_orders(post('/code/cancelOrder.php', pass_params.merge(order))['orders'])
213
+ parse_orders(post('/api/0/cancelOrder.php', order)['orders'])
204
214
  else
205
- orders = post('/code/getOrders.php', pass_params)['orders']
215
+ orders = post('/api/0/getOrders.php', {})['orders']
206
216
  order = orders.find{|order| order['oid'] == args.to_s}
207
217
  if order
208
218
  order = order.delete_if{|k, v| !['oid', 'type'].include?(k.to_s)}
209
- parse_orders(post('/code/cancelOrder.php', pass_params.merge(order))['orders'])
219
+ parse_orders(post('/api/0/cancelOrder.php', order)['orders'])
210
220
  else
211
221
  raise Faraday::Error::ResourceNotFound, {:status => 404, :headers => {}, :body => 'Order not found.'}
212
222
  end
@@ -223,7 +233,7 @@ module MtGox
223
233
  # # Withdraw 1 BTC from your account
224
234
  # MtGox.withdraw! 1.0, '1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L'
225
235
  def withdraw!(amount, btca)
226
- parse_balance(post('/code/withdraw.php', pass_params.merge({:group1 => 'BTC', :amount => amount, :btca => btca})))
236
+ parse_balance(post('/api/0/withdraw.php', {:group1 => 'BTC', :amount => amount, :btca => btca}))
227
237
  end
228
238
 
229
239
  private
@@ -248,9 +258,5 @@ module MtGox
248
258
  end
249
259
  {:buys => buys, :sells => sells}
250
260
  end
251
-
252
- def pass_params
253
- {:name => MtGox.username, :pass => MtGox.password}
254
- end
255
261
  end
256
262
  end
@@ -5,8 +5,8 @@ module MtGox
5
5
  # An array of valid keys in the options hash when configuring a {MtGox::Client}
6
6
  VALID_OPTIONS_KEYS = [
7
7
  :commission,
8
- :password,
9
- :username,
8
+ :key,
9
+ :secret,
10
10
  ]
11
11
 
12
12
  DEFAULT_COMMISSION = 0.0065.freeze
@@ -33,8 +33,8 @@ module MtGox
33
33
  # Reset all configuration options to defaults
34
34
  def reset
35
35
  self.commission = DEFAULT_COMMISSION
36
- self.password = nil
37
- self.username = nil
36
+ self.key = nil
37
+ self.secret = nil
38
38
  self
39
39
  end
40
40
  end
@@ -14,7 +14,7 @@ module MtGox
14
14
  options = {
15
15
  :headers => {
16
16
  :accept => 'application/json',
17
- :user_agent => "mtgox gem #{MtGox::VERSION}",
17
+ :user_agent => "mtgox gem #{MtGox::Version}",
18
18
  },
19
19
  :ssl => {:verify => false},
20
20
  :url => 'https://mtgox.com',
@@ -1,3 +1,5 @@
1
+ require 'base64'
2
+
1
3
  module MtGox
2
4
  module Request
3
5
  def get(path, options={})
@@ -17,10 +19,28 @@ module MtGox
17
19
  request.url(path, options)
18
20
  when :post
19
21
  request.path = path
20
- request.body = options unless options.empty?
22
+ request.body = body_from_options(options)
23
+ request.headers = headers(request.body)
21
24
  end
22
25
  end
23
26
  response.body
24
27
  end
28
+
29
+ def headers(request)
30
+ signature = Base64.strict_encode64(
31
+ OpenSSL::HMAC.digest 'sha512',
32
+ Base64.decode64(MtGox.secret),
33
+ request
34
+ )
35
+ {'Rest-Key' => MtGox.key, 'Rest-Sign' => signature}
36
+ end
37
+
38
+ def body_from_options(options)
39
+ add_nonce(options).collect{|k, v| "#{k}=#{v}"} * '&'
40
+ end
41
+
42
+ def add_nonce(options)
43
+ options.merge!({:nonce => (Time.now.to_f * 1000000).to_i})
44
+ end
25
45
  end
26
46
  end
@@ -1,3 +1,30 @@
1
1
  module MtGox
2
- VERSION = "0.7.1".freeze unless defined? ::MtGox::VERSION
2
+ class Version
3
+
4
+ # @return [Integer]
5
+ def self.major
6
+ 0
7
+ end
8
+
9
+ # @return [Integer]
10
+ def self.minor
11
+ 7
12
+ end
13
+
14
+ # @return [Integer]
15
+ def self.patch
16
+ 2
17
+ end
18
+
19
+ # @return [String, NilClass]
20
+ def self.pre
21
+ nil
22
+ end
23
+
24
+ # @return [String]
25
+ def self.to_s
26
+ [major, minor, patch, pre].compact.join('.')
27
+ end
28
+
29
+ end
3
30
  end
@@ -1,29 +1,25 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
  require File.expand_path('../lib/mtgox/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.name = 'mtgox'
6
- gem.version = MtGox::VERSION.dup
5
+ gem.add_dependency 'faraday', '~> 0.7'
6
+ gem.add_dependency 'faraday_middleware', '~> 0.7'
7
+ gem.add_dependency 'multi_json', '~> 1.0'
8
+ gem.add_development_dependency 'json'
9
+ gem.add_development_dependency 'rake'
10
+ gem.add_development_dependency 'rdiscount'
11
+ gem.add_development_dependency 'rspec'
12
+ gem.add_development_dependency 'webmock'
13
+ gem.add_development_dependency 'yard'
7
14
  gem.author = "Erik Michaels-Ober"
15
+ gem.description = %q{Ruby wrapper for the Mt. Gox Trade API. Mt. Gox allows you to trade US Dollars (USD) for Bitcoins (BTC) or Bitcoins for US Dollars.}
8
16
  gem.email = 'sferik@gmail.com'
17
+ gem.files = `git ls-files`.split("\n")
9
18
  gem.homepage = 'https://github.com/sferik/mtgox'
10
- gem.summary = %q{Ruby wrapper for the Mt. Gox Trade API}
11
- gem.description = %q{Ruby wrapper for the Mt. Gox Trade API. Mt. Gox allows you to trade US Dollars (USD) for Bitcoins (BTC) or Bitcoins for US Dollars.}
12
-
13
- gem.files = `git ls-files`.split("\n")
14
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
- gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
19
+ gem.name = 'mtgox'
16
20
  gem.require_paths = ['lib']
17
-
18
- gem.add_development_dependency 'ZenTest', '~> 4.5'
19
- gem.add_development_dependency 'maruku', '~> 0.6'
20
- gem.add_development_dependency 'rake', '~> 0.9'
21
- gem.add_development_dependency 'rspec', '~> 2.6'
22
- gem.add_development_dependency 'simplecov', '~> 0.4'
23
- gem.add_development_dependency 'webmock', '~> 1.6'
24
- gem.add_development_dependency 'yard', '~> 0.7'
25
-
26
- gem.add_runtime_dependency 'faraday', '~> 0.7.4'
27
- gem.add_runtime_dependency 'faraday_middleware', '~> 0.7.0'
28
- gem.add_runtime_dependency 'multi_json', '~> 1.0.3'
21
+ gem.required_ruby_version = '>= 1.9.2'
22
+ gem.summary = %q{Ruby wrapper for the Mt. Gox Trade API}
23
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ gem.version = MtGox::Version.to_s
29
25
  end
@@ -2,7 +2,7 @@ require 'helper'
2
2
 
3
3
  describe Faraday::Response do
4
4
  before do
5
- stub_get('/code/data/getTrades.php').
5
+ stub_get('/api/0/data/getTrades.php').
6
6
  to_return(:status => 200, :body => fixture('mysql_error'))
7
7
  end
8
8
 
@@ -0,0 +1 @@
1
+ {"addr": "171dH9Uum6wWLSwH2g8g2yto6SG7NEGyXG"}
@@ -2,6 +2,7 @@ $:.unshift File.expand_path('..', __FILE__)
2
2
  $:.unshift File.expand_path('../../lib', __FILE__)
3
3
  require 'simplecov'
4
4
  SimpleCov.start
5
+ require 'base64'
5
6
  require 'mtgox'
6
7
  require 'rspec'
7
8
  require 'webmock/rspec'
@@ -29,3 +30,35 @@ end
29
30
  def fixture(file)
30
31
  File.new(fixture_path + '/' + file)
31
32
  end
33
+
34
+ module MtGox
35
+ module Request
36
+ private
37
+ def add_nonce(options)
38
+ options.merge!({:nonce => 1321745961249676})
39
+ end
40
+ end
41
+ end
42
+
43
+ def test_headers(body=test_body)
44
+ signed_headers(body).merge!(
45
+ {
46
+ 'Accept' => 'application/json',
47
+ 'Content-Type' => 'application/x-www-form-urlencoded',
48
+ 'User-Agent' => "mtgox gem #{MtGox::Version}",
49
+ }
50
+ )
51
+ end
52
+
53
+ def signed_headers(body)
54
+ signature = Base64.strict_encode64(
55
+ OpenSSL::HMAC.digest 'sha512',
56
+ Base64.decode64(MtGox.secret),
57
+ body
58
+ )
59
+ {'Rest-Key' => MtGox.key, 'Rest-Sign' => signature}
60
+ end
61
+
62
+ def test_body(options={})
63
+ options.merge!({:nonce => 1321745961249676}).collect{|k, v| "#{k}=#{v}"} * '&'
64
+ end
@@ -4,20 +4,34 @@ describe MtGox::Client do
4
4
  before do
5
5
  @client = MtGox::Client.new
6
6
  MtGox.configure do |config|
7
- config.username = "my_name"
8
- config.password = "my_password"
7
+ config.key = "key"
8
+ config.secret = "secret"
9
9
  end
10
10
  end
11
11
 
12
+ describe '#address' do
13
+ before do
14
+ stub_post('/api/0/btcAddress.php').
15
+ to_return(:status => 200, :body => fixture('address.json'))
16
+ end
17
+
18
+ it "should fetch a deposit address" do
19
+ address = @client.address
20
+ a_post('/api/0/btcAddress.php').
21
+ should have_been_made
22
+ address.should == '171dH9Uum6wWLSwH2g8g2yto6SG7NEGyXG'
23
+ end
24
+ end
25
+
12
26
  describe '#ticker' do
13
27
  before do
14
- stub_get('/code/data/ticker.php').
28
+ stub_get('/api/0/data/ticker.php').
15
29
  to_return(:status => 200, :body => fixture('ticker.json'))
16
30
  end
17
31
 
18
32
  it "should fetch the ticker" do
19
33
  ticker = @client.ticker
20
- a_get('/code/data/ticker.php').
34
+ a_get('/api/0/data/ticker.php').
21
35
  should have_been_made
22
36
  ticker.buy.should == 26.4
23
37
  ticker.sell.should == 26.6099
@@ -30,14 +44,14 @@ describe MtGox::Client do
30
44
 
31
45
  describe 'depth methods' do
32
46
  before :each do
33
- stub_get('/code/data/getDepth.php').
47
+ stub_get('/api/0/data/getDepth.php').
34
48
  to_return(:status => 200, :body => fixture('depth.json'))
35
49
  end
36
50
 
37
51
  describe '#asks' do
38
52
  it "should fetch open asks" do
39
53
  asks = @client.asks
40
- a_get('/code/data/getDepth.php').
54
+ a_get('/api/0/data/getDepth.php').
41
55
  should have_been_made
42
56
  asks.last.price.should == 23.75
43
57
  asks.last.eprice.should == 23.905385002516354
@@ -54,7 +68,7 @@ describe MtGox::Client do
54
68
  describe "#bids" do
55
69
  it "should fetch open bids" do
56
70
  bids = @client.bids
57
- a_get('/code/data/getDepth.php').
71
+ a_get('/api/0/data/getDepth.php').
58
72
  should have_been_made
59
73
  bids.last.price.should == 14.62101
60
74
  bids.last.eprice.should == 14.525973435000001
@@ -70,7 +84,7 @@ describe MtGox::Client do
70
84
  describe "#offers" do
71
85
  it "should fetch both bids and asks, with only one call" do
72
86
  offers = @client.offers
73
- a_get('/code/data/getDepth.php').
87
+ a_get('/api/0/data/getDepth.php').
74
88
  should have_been_made.once
75
89
  offers[:asks].last.price.should == 23.75
76
90
  offers[:asks].last.eprice.should == 23.905385002516354
@@ -84,7 +98,7 @@ describe MtGox::Client do
84
98
  describe '#min_ask' do
85
99
  it "should fetch the lowest priced ask" do
86
100
  min_ask = @client.min_ask
87
- a_get('/code/data/getDepth.php').
101
+ a_get('/api/0/data/getDepth.php').
88
102
  should have_been_made.once
89
103
  min_ask.price.should == 17.00009
90
104
  min_ask.eprice.should == 17.11131353799698
@@ -95,7 +109,7 @@ describe MtGox::Client do
95
109
  describe '#max_bid' do
96
110
  it "should fetch the highest priced bid" do
97
111
  max_bid = @client.max_bid
98
- a_get('/code/data/getDepth.php').
112
+ a_get('/api/0/data/getDepth.php').
99
113
  should have_been_made.once
100
114
  max_bid.price.should == 17.0
101
115
  max_bid.eprice.should == 16.8895
@@ -107,37 +121,32 @@ describe MtGox::Client do
107
121
 
108
122
  describe '#trades' do
109
123
  before do
110
- stub_get('/code/data/getTrades.php').
124
+ stub_get('/api/0/data/getTrades.php').
111
125
  to_return(:status => 200, :body => fixture('trades.json'))
112
126
  end
113
127
 
114
128
  it "should fetch trades" do
115
129
  trades = @client.trades
116
- a_get('/code/data/getTrades.php').
130
+ a_get('/api/0/data/getTrades.php').
117
131
  should have_been_made
118
132
  trades.last.date.should == Time.utc(2011, 6, 27, 18, 28, 8)
119
133
  trades.last.price.should == 17.00009
120
134
  trades.last.amount.should == 0.5
121
135
  trades.last.id.should == 1309199288687054
122
136
  end
123
-
124
- it "should be sorted in chronological order" do
125
- trades = @client.trades
126
- trades.sort_by(&:date).should == trades
127
- end
128
137
  end
129
138
 
130
139
  describe '#balance' do
131
140
  before do
132
- stub_post('/code/getFunds.php').
133
- with(:body => {"name" => "my_name", "pass" => "my_password"}).
141
+ stub_post('/api/0/getFunds.php').
142
+ with(:body => test_body, :headers => test_headers).
134
143
  to_return(:status => 200, :body => fixture('balance.json'))
135
144
  end
136
145
 
137
146
  it "should fetch balance" do
138
147
  balance = @client.balance
139
- a_post("/code/getFunds.php").
140
- with(:body => {"name" => "my_name", "pass" => "my_password"}).
148
+ a_post("/api/0/getFunds.php").
149
+ with(:body => test_body, :headers => test_headers).
141
150
  should have_been_made
142
151
  balance.first.currency.should == "BTC"
143
152
  balance.first.amount.should == 22.0
@@ -148,16 +157,16 @@ describe MtGox::Client do
148
157
 
149
158
  describe "order methods" do
150
159
  before :each do
151
- stub_post('/code/getOrders.php').
152
- with(:body => {"name" => "my_name", "pass" => "my_password"}).
160
+ stub_post('/api/0/getOrders.php').
161
+ with(:body => test_body, :headers => test_headers).
153
162
  to_return(:status => 200, :body => fixture('orders.json'))
154
163
  end
155
164
 
156
165
  describe "#buys" do
157
166
  it "should fetch orders" do
158
167
  buys = @client.buys
159
- a_post("/code/getOrders.php").
160
- with(:body => {"name" => "my_name", "pass" => "my_password"}).
168
+ a_post("/api/0/getOrders.php").
169
+ with(:body => test_body, :headers => test_headers).
161
170
  should have_been_made
162
171
  buys.last.price.should == 7
163
172
  buys.last.date.should == Time.utc(2011, 6, 27, 18, 20, 38)
@@ -167,8 +176,8 @@ describe MtGox::Client do
167
176
  describe "#sells" do
168
177
  it "should fetch sells" do
169
178
  sells = @client.sells
170
- a_post("/code/getOrders.php").
171
- with(:body => {"name" => "my_name", "pass" => "my_password"}).
179
+ a_post("/api/0/getOrders.php").
180
+ with(:body => test_body, :headers => test_headers).
172
181
  should have_been_made
173
182
  sells.last.price.should == 99.0
174
183
  sells.last.date.should == Time.utc(2011, 6, 27, 18, 20, 20)
@@ -178,8 +187,8 @@ describe MtGox::Client do
178
187
  describe "#orders" do
179
188
  it "should fetch both buys and sells, with only one call" do
180
189
  orders = @client.orders
181
- a_post("/code/getOrders.php").
182
- with(:body => {"name" => "my_name", "pass" => "my_password"}).
190
+ a_post("/api/0/getOrders.php").
191
+ with(:body => test_body, :headers => test_headers).
183
192
  should have_been_made
184
193
  orders[:buys].last.price.should == 7.0
185
194
  orders[:buys].last.date.should == Time.utc(2011, 6, 27, 18, 20, 38)
@@ -191,15 +200,17 @@ describe MtGox::Client do
191
200
 
192
201
  describe "#buy!" do
193
202
  before do
194
- stub_post('/code/buyBTC.php').
195
- with(:body => {"name" => "my_name", "pass" => "my_password", "amount" => "0.88", "price" => "0.89"}).
203
+ body = test_body({"amount" => "0.88", "price" => "0.89"})
204
+ stub_post('/api/0/buyBTC.php').
205
+ with(:body => body, :headers => test_headers(body)).
196
206
  to_return(:status => 200, :body => fixture('buy.json'))
197
207
  end
198
208
 
199
209
  it "should place a bid" do
200
210
  buy = @client.buy!(0.88, 0.89)
201
- a_post("/code/buyBTC.php").
202
- with(:body => {"name" => "my_name", "pass" => "my_password", "amount" => "0.88", "price" => "0.89"}).
211
+ body = test_body({"amount" => "0.88", "price" => "0.89"})
212
+ a_post("/api/0/buyBTC.php").
213
+ with(:body => body, :headers => test_headers(body)).
203
214
  should have_been_made
204
215
  buy[:buys].last.price.should == 2.0
205
216
  buy[:buys].last.date.should == Time.utc(2011, 6, 27, 18, 26, 21)
@@ -210,15 +221,17 @@ describe MtGox::Client do
210
221
 
211
222
  describe "#sell!" do
212
223
  before do
213
- stub_post('/code/sellBTC.php').
214
- with(:body => {"name" => "my_name", "pass" => "my_password", "amount" => "0.88", "price" => "89.0"}).
224
+ body = test_body({"amount" => "0.88", "price" => "89.0"})
225
+ stub_post('/api/0/sellBTC.php').
226
+ with(:body => body, :headers => test_headers(body)).
215
227
  to_return(:status => 200, :body => fixture('sell.json'))
216
228
  end
217
229
 
218
230
  it "should place an ask" do
231
+ body = test_body({"amount" => "0.88", "price" => "89.0"})
219
232
  sell = @client.sell!(0.88, 89.0)
220
- a_post("/code/sellBTC.php").
221
- with(:body => {"name" => "my_name", "pass" => "my_password", "amount" => "0.88", "price" => "89.0"}).
233
+ a_post("/api/0/sellBTC.php").
234
+ with(:body => body, :headers => test_headers(body)).
222
235
  should have_been_made
223
236
  sell[:buys].last.price.should == 2.0
224
237
  sell[:buys].last.date.should == Time.utc(2011, 6, 27, 18, 26, 21)
@@ -229,22 +242,24 @@ describe MtGox::Client do
229
242
 
230
243
  describe "#cancel" do
231
244
  before do
232
- stub_post('/code/getOrders.php').
233
- with(:body => {"name" => "my_name", "pass" => "my_password"}).
245
+ cancel_body = test_body({"oid" => "bddd042c-e837-4a88-a92e-3b7c05e483df", "type" => "2"})
246
+ stub_post('/api/0/getOrders.php').
247
+ with(:body => test_body, :headers => test_headers).
234
248
  to_return(:status => 200, :body => fixture('orders.json'))
235
- stub_post('/code/cancelOrder.php').
236
- with(:body => {"name" => "my_name", "pass" => "my_password", "oid" => "bddd042c-e837-4a88-a92e-3b7c05e483df", "type" => "2"}).
249
+ stub_post('/api/0/cancelOrder.php').
250
+ with(:body => cancel_body, :headers => test_headers(cancel_body)).
237
251
  to_return(:status => 200, :body => fixture('cancel.json'))
238
252
  end
239
253
 
240
254
  context "with a valid oid passed" do
241
255
  it "should cancel an order" do
242
256
  cancel = @client.cancel("bddd042c-e837-4a88-a92e-3b7c05e483df")
243
- a_post("/code/getOrders.php").
244
- with(:body => {"name" => "my_name", "pass" => "my_password"}).
257
+ cancel_body = test_body({"oid" => "bddd042c-e837-4a88-a92e-3b7c05e483df", "type" => "2"})
258
+ a_post("/api/0/getOrders.php").
259
+ with(:body => test_body, :headers => test_headers).
245
260
  should have_been_made.once
246
- a_post('/code/cancelOrder.php').
247
- with(:body => {"name" => "my_name", "pass" => "my_password", "oid" => "bddd042c-e837-4a88-a92e-3b7c05e483df", "type" => "2"}).
261
+ a_post('/api/0/cancelOrder.php').
262
+ with(:body => cancel_body, :headers => test_headers(cancel_body)).
248
263
  should have_been_made
249
264
  cancel[:buys].last.price.should == 7.0
250
265
  cancel[:buys].last.date.should == Time.utc(2011, 6, 27, 18, 20, 38)
@@ -264,8 +279,9 @@ describe MtGox::Client do
264
279
  context "with an order passed" do
265
280
  it "should cancel an order" do
266
281
  cancel = @client.cancel({'oid' => "bddd042c-e837-4a88-a92e-3b7c05e483df", 'type' => 2})
267
- a_post('/code/cancelOrder.php').
268
- with(:body => {"name" => "my_name", "pass" => "my_password", "oid" => "bddd042c-e837-4a88-a92e-3b7c05e483df", "type" => "2"}).
282
+ body = test_body({"oid" => "bddd042c-e837-4a88-a92e-3b7c05e483df", "type" => "2"})
283
+ a_post('/api/0/cancelOrder.php').
284
+ with(:body => body, :headers => test_headers(body)).
269
285
  should have_been_made
270
286
  cancel[:buys].last.price.should == 7.0
271
287
  cancel[:buys].last.date.should == Time.utc(2011, 6, 27, 18, 20, 38)
@@ -277,15 +293,17 @@ describe MtGox::Client do
277
293
 
278
294
  describe "#withdraw!" do
279
295
  before do
280
- stub_post('/code/withdraw.php').
281
- with(:body => {"name" => "my_name", "pass" => "my_password", "group1" => "BTC", "amount" => "1.0", "btca" => "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L"}).
296
+ body = test_body({"group1" => "BTC", "amount" => "1.0", "btca" => "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L"})
297
+ stub_post('/api/0/withdraw.php').
298
+ with(:body => body, :headers => test_headers(body)).
282
299
  to_return(:status => 200, :body => fixture('withdraw.json'))
283
300
  end
284
301
 
285
302
  it "should withdraw funds" do
286
303
  withdraw = @client.withdraw!(1.0, "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L")
287
- a_post("/code/withdraw.php").
288
- with(:body => {"name" => "my_name", "pass" => "my_password", "group1" => "BTC", "amount" => "1.0", "btca" => "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L"}).
304
+ body = test_body({"group1" => "BTC", "amount" => "1.0", "btca" => "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L"})
305
+ a_post("/api/0/withdraw.php").
306
+ with(:body => body, :headers => test_headers(body)).
289
307
  should have_been_made
290
308
  withdraw.first.currency.should == "BTC"
291
309
  withdraw.first.amount.should == 9.0
@@ -8,14 +8,14 @@ describe MtGox do
8
8
  end
9
9
 
10
10
  describe ".configure" do
11
- it "should set 'username' and 'password'" do
11
+ it "should set 'key' and 'secret'" do
12
12
  MtGox.configure do |config|
13
- config.username = "username"
14
- config.password = "password"
13
+ config.key = "key"
14
+ config.secret = "secret"
15
15
  end
16
16
 
17
- MtGox.username.should == "username"
18
- MtGox.password.should == "password"
17
+ MtGox.key.should == "key"
18
+ MtGox.secret.should == "secret"
19
19
  end
20
20
  end
21
21
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtgox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,119 +9,107 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-30 00:00:00.000000000 -07:00
13
- default_executable:
12
+ date: 2011-12-02 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
- name: ZenTest
17
- requirement: &70114478671140 !ruby/object:Gem::Requirement
15
+ name: faraday
16
+ requirement: &70341100916500 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ~>
21
20
  - !ruby/object:Gem::Version
22
- version: '4.5'
23
- type: :development
21
+ version: '0.7'
22
+ type: :runtime
24
23
  prerelease: false
25
- version_requirements: *70114478671140
24
+ version_requirements: *70341100916500
26
25
  - !ruby/object:Gem::Dependency
27
- name: maruku
28
- requirement: &70114478670600 !ruby/object:Gem::Requirement
26
+ name: faraday_middleware
27
+ requirement: &70341100915580 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ~>
32
31
  - !ruby/object:Gem::Version
33
- version: '0.6'
34
- type: :development
32
+ version: '0.7'
33
+ type: :runtime
35
34
  prerelease: false
36
- version_requirements: *70114478670600
35
+ version_requirements: *70341100915580
37
36
  - !ruby/object:Gem::Dependency
38
- name: rake
39
- requirement: &70114478665140 !ruby/object:Gem::Requirement
37
+ name: multi_json
38
+ requirement: &70341100914960 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ~>
43
42
  - !ruby/object:Gem::Version
44
- version: '0.9'
45
- type: :development
43
+ version: '1.0'
44
+ type: :runtime
46
45
  prerelease: false
47
- version_requirements: *70114478665140
46
+ version_requirements: *70341100914960
48
47
  - !ruby/object:Gem::Dependency
49
- name: rspec
50
- requirement: &70114478664560 !ruby/object:Gem::Requirement
48
+ name: json
49
+ requirement: &70341100914260 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
- - - ~>
52
+ - - ! '>='
54
53
  - !ruby/object:Gem::Version
55
- version: '2.6'
54
+ version: '0'
56
55
  type: :development
57
56
  prerelease: false
58
- version_requirements: *70114478664560
57
+ version_requirements: *70341100914260
59
58
  - !ruby/object:Gem::Dependency
60
- name: simplecov
61
- requirement: &70114478664000 !ruby/object:Gem::Requirement
59
+ name: rake
60
+ requirement: &70341100913100 !ruby/object:Gem::Requirement
62
61
  none: false
63
62
  requirements:
64
- - - ~>
63
+ - - ! '>='
65
64
  - !ruby/object:Gem::Version
66
- version: '0.4'
65
+ version: '0'
67
66
  type: :development
68
67
  prerelease: false
69
- version_requirements: *70114478664000
68
+ version_requirements: *70341100913100
70
69
  - !ruby/object:Gem::Dependency
71
- name: webmock
72
- requirement: &70114478663420 !ruby/object:Gem::Requirement
70
+ name: rdiscount
71
+ requirement: &70341100911140 !ruby/object:Gem::Requirement
73
72
  none: false
74
73
  requirements:
75
- - - ~>
74
+ - - ! '>='
76
75
  - !ruby/object:Gem::Version
77
- version: '1.6'
76
+ version: '0'
78
77
  type: :development
79
78
  prerelease: false
80
- version_requirements: *70114478663420
79
+ version_requirements: *70341100911140
81
80
  - !ruby/object:Gem::Dependency
82
- name: yard
83
- requirement: &70114478662860 !ruby/object:Gem::Requirement
81
+ name: rspec
82
+ requirement: &70341100910600 !ruby/object:Gem::Requirement
84
83
  none: false
85
84
  requirements:
86
- - - ~>
85
+ - - ! '>='
87
86
  - !ruby/object:Gem::Version
88
- version: '0.7'
87
+ version: '0'
89
88
  type: :development
90
89
  prerelease: false
91
- version_requirements: *70114478662860
92
- - !ruby/object:Gem::Dependency
93
- name: faraday
94
- requirement: &70114478662280 !ruby/object:Gem::Requirement
95
- none: false
96
- requirements:
97
- - - ~>
98
- - !ruby/object:Gem::Version
99
- version: 0.7.4
100
- type: :runtime
101
- prerelease: false
102
- version_requirements: *70114478662280
90
+ version_requirements: *70341100910600
103
91
  - !ruby/object:Gem::Dependency
104
- name: faraday_middleware
105
- requirement: &70114478661700 !ruby/object:Gem::Requirement
92
+ name: webmock
93
+ requirement: &70341100910040 !ruby/object:Gem::Requirement
106
94
  none: false
107
95
  requirements:
108
- - - ~>
96
+ - - ! '>='
109
97
  - !ruby/object:Gem::Version
110
- version: 0.7.0
111
- type: :runtime
98
+ version: '0'
99
+ type: :development
112
100
  prerelease: false
113
- version_requirements: *70114478661700
101
+ version_requirements: *70341100910040
114
102
  - !ruby/object:Gem::Dependency
115
- name: multi_json
116
- requirement: &70114478661120 !ruby/object:Gem::Requirement
103
+ name: yard
104
+ requirement: &70341100909260 !ruby/object:Gem::Requirement
117
105
  none: false
118
106
  requirements:
119
- - - ~>
107
+ - - ! '>='
120
108
  - !ruby/object:Gem::Version
121
- version: 1.0.3
122
- type: :runtime
109
+ version: '0'
110
+ type: :development
123
111
  prerelease: false
124
- version_requirements: *70114478661120
112
+ version_requirements: *70341100909260
125
113
  description: Ruby wrapper for the Mt. Gox Trade API. Mt. Gox allows you to trade US
126
114
  Dollars (USD) for Bitcoins (BTC) or Bitcoins for US Dollars.
127
115
  email: sferik@gmail.com
@@ -129,7 +117,6 @@ executables: []
129
117
  extensions: []
130
118
  extra_rdoc_files: []
131
119
  files:
132
- - .autotest
133
120
  - .gemtest
134
121
  - .gitignore
135
122
  - .rspec
@@ -161,6 +148,7 @@ files:
161
148
  - lib/mtgox/version.rb
162
149
  - mtgox.gemspec
163
150
  - spec/faraday/response_spec.rb
151
+ - spec/fixtures/address.json
164
152
  - spec/fixtures/balance.json
165
153
  - spec/fixtures/buy.json
166
154
  - spec/fixtures/cancel.json
@@ -175,7 +163,6 @@ files:
175
163
  - spec/helper.rb
176
164
  - spec/mtgox/client_spec.rb
177
165
  - spec/mtgox_spec.rb
178
- has_rdoc: true
179
166
  homepage: https://github.com/sferik/mtgox
180
167
  licenses: []
181
168
  post_install_message:
@@ -187,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
174
  requirements:
188
175
  - - ! '>='
189
176
  - !ruby/object:Gem::Version
190
- version: '0'
177
+ version: 1.9.2
191
178
  required_rubygems_version: !ruby/object:Gem::Requirement
192
179
  none: false
193
180
  requirements:
@@ -196,12 +183,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
183
  version: '0'
197
184
  requirements: []
198
185
  rubyforge_project:
199
- rubygems_version: 1.6.2
186
+ rubygems_version: 1.8.10
200
187
  signing_key:
201
188
  specification_version: 3
202
189
  summary: Ruby wrapper for the Mt. Gox Trade API
203
190
  test_files:
204
191
  - spec/faraday/response_spec.rb
192
+ - spec/fixtures/address.json
205
193
  - spec/fixtures/balance.json
206
194
  - spec/fixtures/buy.json
207
195
  - spec/fixtures/cancel.json
@@ -216,3 +204,4 @@ test_files:
216
204
  - spec/helper.rb
217
205
  - spec/mtgox/client_spec.rb
218
206
  - spec/mtgox_spec.rb
207
+ has_rdoc:
data/.autotest DELETED
@@ -1 +0,0 @@
1
- require 'autotest/bundler'