nl-gatecoin 0.0.1

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 (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/nl-gatecoin.rb +61 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84b886686f2691c47e859901bfb1ddc22cd8d06f
4
+ data.tar.gz: b855340dde6bc46890d27ed480c0a937097d1624
5
+ SHA512:
6
+ metadata.gz: 0809fed9bd99b04f81950a13591b7f9ed37b5b23582f30d6b5c1dca7c820df228c9b441a564fce5fbf9297beb9abbc878ba543a0d84c72f16bcf217d1e07fc63
7
+ data.tar.gz: 128eb84a9d1ec239ff918de9e279d835268fad24d62f070a2427e00921fe267a4a8e632b3986456aaf50bd35bdf1e50a1914b49f530da0ca073937b5d7986755
@@ -0,0 +1,61 @@
1
+ require 'base64'
2
+ require 'cgi'
3
+ require 'openssl'
4
+ require 'json'
5
+ require 'digest/md5'
6
+ require 'httparty'
7
+
8
+ class Gatecoin
9
+ include HTTParty
10
+ base_uri 'https://www.gatecoin.com/api'
11
+
12
+ def initialize(options={})
13
+ @apisecret = ENV['gc_private_key']
14
+ @apikey = ENV['gc_public_key']
15
+ end
16
+
17
+ def method_missing(method_sym, *arguments, &block)
18
+ convert_undercores_to_slashes = method_sym.to_s.gsub('_','/')
19
+ method_type = convert_undercores_to_slashes.split('/')[0]
20
+ convert_undercores_to_slashes = convert_undercores_to_slashes.gsub(method_type + '/','')
21
+
22
+ nonce = (Time.now).to_f.to_s # generate a new one each time
23
+ if method_type.downcase == 'get' then
24
+ content_type = ''
25
+ elsif method_type.downcase == 'post'
26
+ content_type = 'multipart/form-data'
27
+ else
28
+ # No content type
29
+ content_type = ''
30
+ end
31
+ @parameters = ''
32
+ if arguments.length == 1 then
33
+ if arguments[0].kind_of? Hash
34
+ arguments[0].each{|key, value|
35
+ if @parameters.length > 0 then
36
+ @parameters = "#{@parameters}&#{key.capitalize}=#{CGI::escape(value)}"
37
+ else
38
+ @parameters = "#{key}=#{CGI::escape(value)}"
39
+ end
40
+ }
41
+ end
42
+ end
43
+ if @parameters.length > 0 then
44
+ convert_undercores_to_slashes = "#{convert_undercores_to_slashes}?#{@parameters}"
45
+ end
46
+ encode_message = (method_type.upcase + 'https://www.gatecoin.com/api/' + convert_undercores_to_slashes + content_type + nonce).downcase
47
+ if @apisecret.length > 0 and @apikey.length > 0 then
48
+ ssl_sign = OpenSSL::HMAC.digest('sha256', @apisecret, encode_message)
49
+ ssl_sign_encoded = Base64.encode64(ssl_sign).to_s.gsub("\n",'')
50
+ if method_type.downcase == "get" then
51
+ self.class.get('/' + convert_undercores_to_slashes, :headers => {'Accept' => 'application/json', 'Content-Type' => 'application/json', 'API_PUBLIC_KEY' => @apikey , 'API_REQUEST_SIGNATURE' => ssl_sign_encoded, 'API_REQUEST_DATE' => nonce}).to_json
52
+ elsif method_type.downcase == "post"
53
+ self.class.post('/' + convert_undercores_to_slashes, :body => @parameters.to_s, :headers => {'Accept' => 'application/json', 'Content-Type' => content_type, 'API_PUBLIC_KEY' => @apikey , 'API_REQUEST_SIGNATURE' => ssl_sign_encoded, 'API_REQUEST_DATE' => nonce}).to_json
54
+ else
55
+ "Unsupported method"
56
+ end
57
+ else
58
+ "Invalid API key and secret"
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nl-gatecoin
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: 2016-03-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A ruby class to talk to the BTC Markets API (Work in progress!)
14
+ email: hello@barryteoh.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/nl-gatecoin.rb
20
+ homepage: https://github.com/nolim1t/nl-gatecoin
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.5.1
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Gatecoin initial gem
44
+ test_files: []