nl-btcmarkets 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nl-btcmarkets.rb +26 -7
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc654487a8d3c2eb0f31de429375cc896087bf83
4
- data.tar.gz: d00d58ed1e22b46a2575520c548f09e54d8d4d60
3
+ metadata.gz: 281d9d0c895333bcdbbdf89a5a29fff1f2c9277a
4
+ data.tar.gz: ce19c1a12b1d5c219d5068fd0d2ade2ba2c30d9c
5
5
  SHA512:
6
- metadata.gz: 74eb4939c4a4f0de8599ed5f03ea66b2cda16b4130e08d7c23e58bbc68c7a0845c5f469eae848496e62ca46957b1feab57495188d1e4a8e96ea5d2aa55352d0c
7
- data.tar.gz: 2806df78ea91b2569b7a5a352c9e96893bde3b3af8ce6424d319d87a949c58e9c62b6d412ea7747839d5c2c6a187577af3e5c79774f3a80438657a1b1c3058f0
6
+ metadata.gz: b63d7b7df20426b0c6614ef6d4b095d143c6e43c1406f6ba51a96a9a7f5a3e99a77ffe3280209ca99d7217c76fdaadeedd0f2118f81e1cda5b7a58ade7bb68a6
7
+ data.tar.gz: e869ae1b20cd4790053fff7b44e5d711069303f4d202cea3ee6a37c2dfe3b8f10e86fbd41084eabfc1b76dbe2270d7b999ab7d2b0480a5005a0fd8f589d3df82
data/lib/nl-btcmarkets.rb CHANGED
@@ -10,15 +10,21 @@ class BTCMarkets
10
10
  base_uri 'https://api.btcmarkets.net'
11
11
 
12
12
  def initialize(options={})
13
- @apisecret = Base64.decode64(ENV['btcm_access_secret'])
14
- @apikey = ENV['btcm_access_key']
15
- #@currency = ENV['btcm_currency']
13
+ if ENV['btcm_access_secret'] and ENV['btcm_access_key'] then
14
+ @apisecret = Base64.decode64(ENV['btcm_access_secret'])
15
+ @apikey = ENV['btcm_access_key']
16
+ else
17
+ @apisecret = ''
18
+ @apikey = ''
19
+ end
16
20
  @nonce = (Time.now.to_f * 1000).to_i.to_s
17
21
  @parameters = ''
18
22
  end
19
23
 
20
24
  def method_missing(method_sym, *arguments, &block)
21
25
  convert_undercores_to_slashes = method_sym.to_s.gsub('_','/')
26
+ method_type = convert_undercores_to_slashes.split('/')[0]
27
+ convert_undercores_to_slashes = convert_undercores_to_slashes.gsub(method_type + '/','')
22
28
  if arguments.length == 1 then
23
29
  if arguments[0].kind_of? Hash
24
30
  @parameters = arguments[0].to_json # Its a json thing!
@@ -26,12 +32,25 @@ class BTCMarkets
26
32
  end
27
33
  @nonce = (Time.now.to_f * 1000).to_i.to_s # generate a new one each time
28
34
  if @parameters != ''
29
- to_sign = '/' + convert_undercores_to_slashes + "\n" + @nonce + "\n" + @parameters+ "\n"
35
+ to_sign = '/' + convert_undercores_to_slashes + "\n" + @nonce + "\n" + @parameters.to_s
30
36
  else
31
37
  to_sign = '/' + convert_undercores_to_slashes + "\n" + @nonce + "\n"
32
38
  end
33
- ssl_sign = OpenSSL::HMAC.digest('sha512', @apisecret, to_sign)
34
- ssl_sign_encoded = Base64.encode64(ssl_sign).to_s.gsub("\n",'')
35
- self.class.get('/' + convert_undercores_to_slashes, :headers => {'Content-Type' => 'application/json', 'apikey' => @apikey , 'signature' => ssl_sign_encoded, 'timestamp' => @nonce}).to_json
39
+ if @apisecret != '' and @apikey != '' then
40
+ ssl_sign = OpenSSL::HMAC.digest('sha512', @apisecret, to_sign)
41
+ ssl_sign_encoded = Base64.encode64(ssl_sign).to_s.gsub("\n",'')
42
+ if method_type == "get" then
43
+ self.class.get('/' + convert_undercores_to_slashes, :headers => {'Accept-Charset' => 'UTF-8', 'Accept' => 'application/json','Content-Type' => 'application/json', 'apikey' => @apikey , 'signature' => ssl_sign_encoded, 'timestamp' => @nonce}).to_json
44
+ else
45
+ if method_type == "post" and @parameters != '' then
46
+ self.class.post('/' + convert_undercores_to_slashes, :body => @parameters.to_s, :headers => {'Accept-Charset' => 'UTF-8', 'Accept' => 'application/json','Content-Type' => 'application/json', 'apikey' => @apikey , 'signature' => ssl_sign_encoded, 'timestamp' => @nonce}).to_json
47
+ else
48
+ # No parameters
49
+ self.class.post('/' + convert_undercores_to_slashes, :headers => {'Accept-Charset' => 'UTF-8', 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'apikey' => @apikey , 'signature' => ssl_sign_encoded, 'timestamp' => @nonce}).to_json
50
+ end
51
+ end
52
+ else
53
+ "APISECRET and APIKEY not set"
54
+ end
36
55
  end
37
56
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nl-btcmarkets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Barry Teoh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-21 00:00:00.000000000 Z
11
+ date: 2016-01-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A ruby class to talk to the BTC Markets API (Work in progress!)
14
14
  email: hello@barryteoh.com