itbit 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- itbit (0.0.3)
4
+ itbit (0.0.4)
5
5
  activesupport
6
6
  rest_client
7
7
 
data/README.md CHANGED
@@ -57,7 +57,7 @@ fetching all public market data available.
57
57
 
58
58
  ### Trades
59
59
 
60
- ruby > Itbit::XBTUSDMarketData.transactions
60
+ ruby > Itbit::XBTUSDMarketData.trades
61
61
  => [ {date: unix_timestamp, price: 123.5, amount: 1.97, tid: 98375},
62
62
  {date: unix_timestamp, price: 123.5, amount: 1.97, tid: 98376},
63
63
  ...]
@@ -6,10 +6,9 @@ module Itbit
6
6
  def self.request(verb, path, options = { })
7
7
  timestamp = (Time.now.to_f * 1000).round.to_s
8
8
  nonce = timestamp
9
- prefix = Itbit.sandbox ? 'beta-api' : 'api'
10
9
  payload = options.empty? || verb == :get ? nil : JSON.dump(options)
11
10
  query = options.any? && verb == :get ? "?#{options.to_query}" : ''
12
- url = "https://#{prefix}.itbit.com/v1#{path}#{query}"
11
+ url = "#{api_url}#{path}#{query}"
13
12
 
14
13
  signature = sign_message(verb, url, payload, nonce, timestamp)
15
14
  headers = {
@@ -22,6 +21,11 @@ module Itbit
22
21
  .execute(:method => verb, :url => url, :payload => payload, :headers => headers)
23
22
  JSON.parse(response.to_str) if response.to_str.presence
24
23
  end
24
+
25
+ def self.api_url
26
+ prefix = Itbit.sandbox ? 'beta-api' : 'api'
27
+ "https://#{prefix}.itbit.com/v1"
28
+ end
25
29
 
26
30
  def self.sign_message(verb, url, json_body, nonce, timestamp)
27
31
  message = JSON.dump([verb.upcase, url, json_body || '', nonce, timestamp])
@@ -7,7 +7,7 @@ module Itbit
7
7
  # The symbol ticker conveniently formatted as a ruby Hash with
8
8
  # symbolized keys.
9
9
  def self.ticker
10
- raw_ticker = Api.request(:get, "/markets/#{self.symbol}/ticker")
10
+ raw_ticker = JSON.parse(RestClient.get("#{Api.api_url}/markets/#{symbol.upcase}/ticker"))
11
11
  raw_ticker.reduce({}) do |ticker, pair|
12
12
  key = pair.first.underscore.to_sym
13
13
  value = case key
@@ -23,7 +23,7 @@ module Itbit
23
23
  # The symbol order book as a Hash with two keys: bids and asks.
24
24
  # Each of them is a list of list consisting of [price, quantity]
25
25
  def self.orders
26
- order_book = old_request("/markets/#{self.symbol.upcase}/orders").symbolize_keys
26
+ order_book = old_request("/markets/#{symbol.upcase}/orders").symbolize_keys
27
27
  order_book.each do |key, value|
28
28
  order_book[key] = value.collect { |tuple| tuple.collect(&:to_d) }
29
29
  end
@@ -1,3 +1,3 @@
1
1
  module Itbit
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -8,7 +8,7 @@ describe Itbit::MarketData do
8
8
  }.each do |symbol, market_data|
9
9
  describe "when getting #{symbol} market data" do
10
10
  it "gets the ticker" do
11
- stub_get("/markets/#{symbol}/ticker", "market_ticker_#{symbol}")
11
+ stub_get("/markets/#{symbol.upcase}/ticker", "market_ticker_#{symbol}")
12
12
  market_data.ticker.should == {
13
13
  ask: "641.29".to_d,
14
14
  ask_amt: "0.5".to_d,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-11-29 00:00:00.000000000 Z
13
+ date: 2014-12-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport