nl-independentreserve 0.0.1

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 +7 -0
  2. data/lib/nl-independentreserve.rb +72 -0
  3. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d9cbc5684d30ed1ecf45a38834c266b976762097
4
+ data.tar.gz: 437ae10db26de3adc09d43ccd3a8710fae6ebf85
5
+ SHA512:
6
+ metadata.gz: c936593f0237a71edfcbb4f4d185b2d7dcebf3f0ad48807f3af2a875df09102c78ac75e4fc9fe13101f8ea0dcd0cc3529320d79f61658d036401f34df5ceb168
7
+ data.tar.gz: decd71ac1c56ca839d08c151d4c8b488ccff1a72b145e02a766f694dcc1a79b409fb305e76a3f4495c865335f1553339ff3d8f1ec50f797df1e47c2ada3fa552
@@ -0,0 +1,72 @@
1
+ require 'openssl'
2
+ require 'json'
3
+ require 'digest/md5'
4
+ require 'httparty'
5
+
6
+
7
+ class IndependentReserve
8
+ include HTTParty
9
+ base_uri 'https://api.independentreserve.com'
10
+
11
+ def initialize(options={})
12
+ @apisecret = ENV['ir_access_secret']
13
+ @apikey = ENV['ir_access_key']
14
+ if options[:primaryCurrency] != nil then
15
+ @primaryCurrency = options[:primaryCurrency]
16
+ else
17
+ @primaryCurrency = "XBT"
18
+ end
19
+ if options[:secondaryCurrency] != nil then
20
+ @secondaryCurrency = options[:secondaryCurrency]
21
+ else
22
+ @secondaryCurrency = "AUD"
23
+ end
24
+ end
25
+
26
+ def method_missing(method_sym, *arguments, &block)
27
+ pub_or_priv = 'private'
28
+ if method_sym.to_s.scan("public").length > 0 then
29
+ pub_or_priv = 'public'
30
+ end
31
+
32
+ convert_undercores_to_slashes = method_sym.to_s.gsub('_','/')
33
+ convert_undercores_to_slashes = convert_undercores_to_slashes.gsub('public', 'Public')
34
+ convert_undercores_to_slashes = convert_undercores_to_slashes.gsub('private', 'Private')
35
+ nonce = (Time.now.to_f * 1000).to_i
36
+ to_sign = nonce.to_s + @apikey
37
+ ssl_sign = OpenSSL::HMAC.hexdigest('sha256', @apisecret, to_sign)
38
+ signed = ssl_sign.upcase
39
+
40
+ additionals = ''
41
+ json_to_post = {}
42
+
43
+ if @primaryCurrency != nil
44
+ json_to_post[:primaryCurrencyCode] = @primaryCurrency
45
+ json_to_post[:secondaryCurrencyCode] = @secondaryCurrency
46
+ json_to_post[:nonce] = nonce
47
+ json_to_post[:signature] = signed
48
+ json_to_post[:apiKey] = @apikey
49
+
50
+ additionals = 'nonce=' + nonce.to_s + '&signature=' + signed + '&apiKey=' + @apikey + '&primaryCurrencyCode=' + @primaryCurrency
51
+
52
+ if @secondaryCurrency != nil
53
+ additionals = additionals + '&secondaryCurrencyCode=' + @secondaryCurrency
54
+ end
55
+ end
56
+ if arguments.length == 1 then
57
+ if arguments[0].kind_of? Hash then
58
+ arguments[0].each {|k,v|
59
+ additionals = additionals + "#{@values}&#{k}=#{v}"
60
+ json_to_post["#{k}"] = v
61
+ }
62
+ end
63
+ end
64
+
65
+ headers = {'Content-Type' => 'application/json'}
66
+ if pub_or_priv == 'private' then
67
+ self.class.post('/' + convert_undercores_to_slashes, :body => json_to_post.to_json, :headers => headers).to_json
68
+ else
69
+ self.class.get('/' + convert_undercores_to_slashes + '?' + additionals).to_json
70
+ end
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nl-independentreserve
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Barry Teoh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: nl-anx is a rubygem which interfaces directly with the independentreserve.com
14
+ API. This is unofficial so please use at your own risk
15
+ email: hello@barryteoh.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/nl-independentreserve.rb
21
+ homepage: https://github.com/nolim1t/IndependentReserve
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.5.0
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: nl-independentreserve ruby gem
45
+ test_files: []