ruby_coincheck_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8339a47ca450427548438faaa12b8a362edca833
4
+ data.tar.gz: 0e9fb15674c7a24c520e6830a9851c54100af9e8
5
+ SHA512:
6
+ metadata.gz: 7879d1a6ce03091ab1e53879949d2cbd62ce976732b0194383844c6c883bd5a5c166346c87dc403e0ac2c44eb2e2d2517daad8348233302e0234c2eccecb401d
7
+ data.tar.gz: 42e10cae9c9bf79f2e391e4b4fb665f4678d2e3d76566c23f88605a85241aeb6ee9097393bb96b5370ec3e02e5e233e31922bd931e3686061d78ac1a680163a7
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ test_example.rb
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby_coincheck_client.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # RubyCoincheckClient
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ruby_coincheck_client`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruby_coincheck_client'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ruby_coincheck_client
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ #!/usr/bin/env ruby -Ilib
27
+ require 'ruby_coincheck_client'
28
+
29
+ cc = CoincheckClient.new("YOUR API KEY", "YOUR SECRET KEY")
30
+ response = cc.read_balance()
31
+ response = cc.read_accounts()
32
+ response = cc.read_transactions
33
+ response = cc.read_orders
34
+ response = cc.create_orders("40001", "0.01", "sell")
35
+ response = cc.delete_orders("2503344")
36
+ response = cc.create_send_money("136aHpRdd7eezbEusAKS2GyWx9eXZsEuMz", "0.0005")
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/[my-github-username]/ruby_coincheck_client/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruby_coincheck_client"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require "ruby_coincheck_client/version"
2
+ require "ruby_coincheck_client/coincheck_client"
3
+
4
+ module RubyCoincheckClient
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,106 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'openssl'
4
+ require 'json'
5
+
6
+ class CoincheckClient
7
+ BASE_URL = "https://coincheck.jp/"
8
+
9
+ def initialize(key, secret)
10
+ @key = key
11
+ @secret = secret
12
+ end
13
+
14
+ def read_balance
15
+ uri = URI.parse BASE_URL + "api/accounts/balance"
16
+ headers = get_signature(uri, @key, @secret)
17
+ request_for_get(uri, headers)
18
+ end
19
+
20
+ def read_accounts
21
+ uri = URI.parse BASE_URL + "api/accounts"
22
+ headers = get_signature(uri, @key, @secret)
23
+ request_for_get(uri, headers)
24
+ end
25
+
26
+ def read_transactions
27
+ uri = URI.parse BASE_URL + "api/exchange/orders/transactions"
28
+ headers = get_signature(uri, @key, @secret)
29
+ request_for_get(uri, headers)
30
+ end
31
+
32
+ def read_orders
33
+ uri = URI.parse BASE_URL + "api/exchange/orders/opens"
34
+ headers = get_signature(uri, @key, @secret)
35
+ request_for_get(uri, headers)
36
+ end
37
+
38
+ def create_orders(rate, amount, order_type, pair = "btc_jpy")
39
+ body = {
40
+ rate: rate,
41
+ amount: amount,
42
+ order_type: order_type,
43
+ pair: pair
44
+ }
45
+ uri = URI.parse BASE_URL + "api/exchange/orders"
46
+ headers = get_signature(uri, @key, @secret, body.to_json)
47
+ request_for_post(uri, headers, body)
48
+ end
49
+
50
+ def delete_orders(id)
51
+ body = {
52
+ id: id,
53
+ }
54
+ uri = URI.parse BASE_URL + "api/exchange/orders/#{id}"
55
+ headers = get_signature(uri, @key, @secret)
56
+ request_for_delete(uri, headers)
57
+ end
58
+
59
+ def create_send_money(address, amount)
60
+ body = {
61
+ address: address,
62
+ amount: amount,
63
+ }
64
+ uri = URI.parse BASE_URL + "api/send_money"
65
+ headers = get_signature(uri, @key, @secret, body.to_json)
66
+ request_for_post(uri, headers, body)
67
+ end
68
+
69
+ private
70
+ def http_request(uri, request)
71
+ https = Net::HTTP.new(uri.host, uri.port)
72
+ https.use_ssl = true
73
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
74
+
75
+ response = https.start do |h|
76
+ h.request(request)
77
+ end
78
+ end
79
+
80
+ def request_for_get(uri, headers)
81
+ request = Net::HTTP::Get.new(uri.request_uri, initheader = headers)
82
+ http_request(uri, request)
83
+ end
84
+
85
+ def request_for_delete(uri, headers)
86
+ request = Net::HTTP::Delete.new(uri.request_uri, initheader = headers)
87
+ http_request(uri, request)
88
+ end
89
+ def request_for_post(uri, headers, body)
90
+ request = Net::HTTP::Post.new(uri.request_uri, initheader = headers)
91
+ request.body = body.to_json
92
+ http_request(uri, request)
93
+ end
94
+
95
+ def get_signature(uri, key, secret, body = "")
96
+ nonce = Time.now.to_i.to_s
97
+ message = nonce + uri.to_s + body
98
+ signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), secret, message)
99
+ headers = {
100
+ "Content-Type" => "application/json",
101
+ "ACCESS-KEY" => key,
102
+ "ACCESS-NONCE" => nonce,
103
+ "ACCESS-SIGNATURE" => signature
104
+ }
105
+ end
106
+ end
@@ -0,0 +1,3 @@
1
+ module RubyCoincheckClient
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruby_coincheck_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby_coincheck_client"
8
+ spec.version = RubyCoincheckClient::VERSION
9
+ spec.authors = ["yuma300"]
10
+ spec.email = ["ywakimoto2s@gmail.com"]
11
+
12
+ spec.summary = %q{This is ruby client of coincheck api}
13
+ spec.homepage = "https://github.com/yuma300/ruby-ripple-rest"
14
+
15
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
16
+ # delete this section to allow pushing this gem to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
19
+ else
20
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
21
+ end
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.9"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec"
31
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_coincheck_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - yuma300
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - ywakimoto2s@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - lib/ruby_coincheck_client.rb
71
+ - lib/ruby_coincheck_client/coincheck_client.rb
72
+ - lib/ruby_coincheck_client/version.rb
73
+ - ruby_coincheck_client.gemspec
74
+ homepage: https://github.com/yuma300/ruby-ripple-rest
75
+ licenses: []
76
+ metadata:
77
+ allowed_push_host: https://rubygems.org
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.7
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: This is ruby client of coincheck api
98
+ test_files: []