shapeshift_io 0.0.1

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: 354fe2260b9451312bb0359b9307ba905e964532
4
+ data.tar.gz: eb0b1ece969e49d46034512b7992342968bc9fb4
5
+ SHA512:
6
+ metadata.gz: b2dcf911084b41d4a34a459298d61c3c9949eb0b4754cab7a4fec2ae7ad5ab3e5042cc9e4b03afed5c9efc302f0e90e9569929ce9a5d94f3e851f5ed8c933f69
7
+ data.tar.gz: c0a7695205588f20c743f70201b783b8bc8c96f6ebb2ba69efff0eb5e552ddc868b91e68a1329931af5a60c17ec786afb4c2bd0afea1f6c21da919dc6a44cd2c
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ .DS_Store
2
+
3
+ /.bundle/
4
+ /.yardoc
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.15.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in shapeshift_io.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Romanos Fessas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # DISCLAIMER: Test before use
2
+ I have not tested many of these endpoints given my own limited requirements. If you are making real exchanges, especially with more exotic coins, please test this implementation thoroughly.
3
+
4
+ # Ruby implementation of the Shapeshift.io public API
5
+
6
+ - Unofficial implementation
7
+ - Implements public REST API
8
+ - Full docs at [https://info.shapeshift.io/api](https://info.shapeshift.io/api)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ `gem 'shapeshift_io'`
15
+
16
+ And then execute:
17
+
18
+ `$ bundle`
19
+
20
+ Or install it yourself as:
21
+
22
+ `$ gem install shapeshift_io`
23
+
24
+ ## Usage
25
+
26
+ _Extended examples available at [Shapeshift.io](https://info.shapeshift.io/api)_
27
+
28
+ ```
29
+ client = Shapeshift::Client.new
30
+ client.market_info('BTC_ETH')
31
+ ```
32
+
33
+ ### Contributing
34
+ - Fork it ( https://github.com/romanos/shapeshift-io/fork )
35
+ - Create your feature branch (`git checkout -b my-new-feature`)
36
+ - Commit your changes (`git commit -am 'Add some feature'`)
37
+ - Push to the branch (`git push origin my-new-feature`)
38
+ - Create a new Pull Request
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
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 "shapeshift_io"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ module Shapeshift
2
+ class Client
3
+ include HTTParty
4
+ base_uri "https://shapeshift.io"
5
+
6
+ include Shapeshift::Connection
7
+ include Shapeshift::MarketClient
8
+
9
+ def initialize( headers = {} )
10
+ @headers = {}
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ module Shapeshift
2
+ # Network Layer for API Rest client
3
+ module Connection
4
+ private
5
+
6
+ def merge_headers(input = {})
7
+ {
8
+ 'Content-Type' => 'application/json',
9
+ 'Accept' => 'application/json'
10
+ }.merge( input )
11
+ end
12
+
13
+ # Make an HTTP GET request
14
+ def get( url, options = {} )
15
+ headers = merge_headers( options[:headers] || {} )
16
+ resp = self.class.get( url, { headers: headers } )
17
+ end
18
+
19
+ # Make an HTTP POST request
20
+ def post( url, options = {} )
21
+ headers = merge_headers( options[:headers] || {} )
22
+ body = options[:body]
23
+ resp = self.class.get( url, { body: body.to_json, headers: headers } )
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ module Shapeshift
2
+
3
+ class HTTPError < StandardError; end
4
+ class NoDemandError < StandardError; end
5
+
6
+ end
@@ -0,0 +1,96 @@
1
+ module Shapeshift
2
+ # Network Layer for API Rest client
3
+ module MarketClient
4
+ # url: shapeshift.io/rate/[pair]
5
+ # method: GET
6
+ # [pair] is any valid coin pair such as btc_ltc or ltc_btc
7
+ def rate( pair )
8
+ get("/rate/#{pair}")
9
+ end
10
+
11
+ # url: shapeshift.io/limit/[pair]
12
+ # method: GET
13
+ # [pair] is any valid coin pair such as btc_ltc or ltc_btc
14
+ def limit( pair )
15
+ get("/limit/#{pair}")
16
+ end
17
+
18
+ # url: shapeshift.io/marketinfo/[pair]
19
+ # method: GET
20
+ # [pair] (OPTIONAL) is any valid coin pair such as btc_ltc or ltc_btc.
21
+ # The pair is not required and if not specified will return an array of all market infos.
22
+ def market_info( pair = nil )
23
+ get("/marketinfo/#{pair}")
24
+ end
25
+
26
+ # url: shapeshift.io/recenttx/[max]
27
+ # method: GET
28
+ # [max] is an optional maximum number of transactions to return.
29
+ # If [max] is not specified this will return 5 transactions.
30
+ # Also, [max] must be a number between 1 and 50 (inclusive).
31
+ def recent_tx( max = 5 )
32
+ # max = max.clamp( 1, 50 ) # Clamp only available in Ruby 2.4+
33
+ max = [ 1, max, 50 ].sort[1]
34
+ get("/recenttx/#{max}")
35
+ end
36
+
37
+ # url: shapeshift.io/txStat/[address]
38
+ # method: GET
39
+ # [address] is the deposit address to look up.
40
+ def tx_stat( address )
41
+ get("/txStat/#{address}")
42
+ end
43
+
44
+ # url: shapeshift.io/timeremaining/[address]
45
+ # method: GET
46
+ # [address] is the deposit address to look up.
47
+ def time_remaining( address )
48
+ address = encode( address )
49
+ get("/timeremaining/#{address}")
50
+ end
51
+
52
+ # url: shapeshift.io/getcoins
53
+ # method: GET
54
+ def get_coins
55
+ get("/getcoins")
56
+ end
57
+
58
+ # url: shapeshift.io/txbyapikey/[apiKey]
59
+ # method: GET
60
+ # [apiKey] is the affiliate's PRIVATE api key.
61
+ def tx_by_apikey( api_key )
62
+ get("/txbyapikey/#{api_key}")
63
+ end
64
+
65
+ # url: shapeshift.io/txbyaddress/[address]/[apiKey]
66
+ # method: GET
67
+ # [address] the address that output coin was sent to for the shift
68
+ # [apiKey] is the affiliate's PRIVATE api key.
69
+ def tx_by_address( address, api_key )
70
+ address = encode( address )
71
+ get("/txbyaddress/#{address}/#{api_key}")
72
+ end
73
+
74
+ # url: shapeshift.io/validateAddress/[address]/[coinSymbol]
75
+ # method: GET
76
+ # [address] the address that the user wishes to validate
77
+ # [coinSymbol] the currency symbol of the coin
78
+ def validate_address( address, symbol )
79
+ get("/validateAddress/#{address}/#{symbol}")
80
+ end
81
+
82
+
83
+ private
84
+
85
+ # Please note that if the address is a ripple address,
86
+ # it will include the "?dt=destTagNUM" appended on the end,
87
+ # and you will need to use the URIEncodeComponent() function on
88
+ # the address before sending it in as a param, to get a successful response.
89
+ def encode( address )
90
+ address = URI.encode_www_form_component( address ) if address =~ /\?dt\=/i
91
+ return address
92
+ end
93
+
94
+
95
+ end
96
+ end
@@ -0,0 +1,110 @@
1
+ module Shapeshift
2
+ # Network Layer for API Rest client
3
+ module TransactionClient
4
+
5
+ # url: shapeshift.io/shift
6
+ # method: POST
7
+ # data type: JSON
8
+ # data required:
9
+ # withdrawal = the address for resulting coin to be sent to
10
+ # pair = what coins are being exchanged in the form [input coin]_[output coin] ie btc_ltc
11
+ # returnAddress = (Optional) address to return deposit to if anything goes wrong with exchange
12
+ # destTag = (Optional) Destination tag that you want appended to a Ripple payment to you
13
+ # rsAddress = (Optional) For new NXT accounts to be funded, you supply this on NXT payment to you
14
+ # apiKey = (Optional) Your affiliate PUBLIC KEY, for volume tracking, affiliate payments, split-shifts, etc...
15
+ # Success Output:
16
+ # {
17
+ # deposit: [Deposit Address (or memo field if input coin is BTS / BITUSD)],
18
+ # depositType: [Deposit Type (input coin symbol)],
19
+ # withdrawal: [Withdrawal Address], //-- will match address submitted in post
20
+ # withdrawalType: [Withdrawal Type (output coin symbol)],
21
+ # public: [NXT RS-Address pubkey (if input coin is NXT)],
22
+ # xrpDestTag : [xrpDestTag (if input coin is XRP)],
23
+ # apiPubKey: [public API attached to this shift, if one was given]
24
+ # }
25
+ def shift( withdrawal, pair, opts = {} )
26
+ body = { withdrawal: withdrawal, pair: pair }
27
+ body.merge!( opts )
28
+ post("/shift", { body: body } )
29
+ end
30
+
31
+ # url: shapeshift.io/mail
32
+ # method: POST
33
+ # data type: JSON
34
+ # data required:
35
+ # email = the address for receipt email to be sent to
36
+ # txid = the transaction id of the transaction TO the user (ie the txid for the withdrawal NOT the deposit)
37
+ # example data {"email":"mail@example.com", "txid":"123ABC"}
38
+ def mail( email, txid )
39
+ body = { email: email, txid: txid }
40
+ post("/mail", { body: body } )
41
+ end
42
+
43
+ # url: shapeshift.io/sendamount
44
+ # method: POST
45
+ # data type: JSON
46
+
47
+ # 1. Send amount request
48
+ #
49
+ # Data required:
50
+ # amount = the amount to be sent to the withdrawal address
51
+ # withdrawal = the address for coin to be sent to
52
+ # pair = what coins are being exchanged in the form [input coin]_[output coin] ie ltc_btc
53
+ # returnAddress = (Optional) address to return deposit to if anything goes wrong with exchange
54
+ # destTag = (Optional) Destination tag that you want appended to a Ripple payment to you
55
+ # rsAddress = (Optional) For new NXT accounts to be funded, supply this on NXT payment to you
56
+ # apiKey = (Optional) Your affiliate PUBLIC KEY, for volume tracking, affiliate payments, split-shifts, etc...
57
+ # {
58
+ # success:
59
+ # {
60
+ # pair: [pair],
61
+ # withdrawal: [Withdrawal Address], //-- will match address submitted in post
62
+ # withdrawalAmount: [Withdrawal Amount], // Amount of the output coin you will receive
63
+ # deposit: [Deposit Address (or memo field if input coin is BTS / BITUSD)],
64
+ # depositAmount: [Deposit Amount], // Exact amount of input coin to send in
65
+ # expiration: [timestamp when this will expire],
66
+ # quotedRate: [the exchange rate to be honored]
67
+ # apiPubKey: [public API attached to this shift, if one was given]
68
+ # }
69
+ # }
70
+ def send_amount( withdrawal, pair, amount, opts = {} )
71
+ body = { withdrawal: withdrawal, pair: pair, amount: amount }
72
+ body.merge!( opts )
73
+ post("/sendamount", { body: body })
74
+ end
75
+
76
+ # 2. Quoted Price request
77
+ #
78
+ # Note : This request will only return information about a quoted rate
79
+ # This request will NOT generate the deposit address.
80
+ # Data required:
81
+ # amount = the amount to be sent to the withdrawal address
82
+ # pair = what coins are being exchanged in the form [input coin]_[output coin] ie ltc_btc
83
+ # {
84
+ # success:
85
+ # {
86
+ # pair: [pair],
87
+ # withdrawalAmount: [Withdrawal Amount], // Amount of the output coin you will receive
88
+ # depositAmount: [Deposit Amount], // Exact amount of input coin to send in
89
+ # expiration: [timestamp when this will expire],
90
+ # quotedRate: [the exchange rate to be honored]
91
+ # minerFee: [miner fee for this transaction]
92
+ # }
93
+ # }
94
+ def quote_price( pair, amount )
95
+ body = { pair: pair, amount: amount }
96
+ post("/sendamount", { body: body })
97
+ end
98
+
99
+
100
+ # url: shapeshift.io/cancelpending
101
+ # method: POST
102
+ # data type: JSON
103
+ # data required: address = The deposit address associated with the pending transaction
104
+ def cancel( address )
105
+ body = { address: address }
106
+ post("/cancelpending", { body: body } )
107
+ end
108
+
109
+ end
110
+ end
@@ -0,0 +1,3 @@
1
+ module Shapeshift
2
+ VERSION = "0.0.1"
3
+ end
data/lib/shapeshift.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'uri'
2
+ require 'json'
3
+ require 'yaml'
4
+
5
+ require 'httparty'
6
+
7
+ require 'shapeshift/version'
8
+ require 'shapeshift/errors'
9
+ require 'shapeshift/connections'
10
+ require 'shapeshift/market'
11
+ require 'shapeshift/transactions'
12
+ require 'shapeshift/client'
@@ -0,0 +1 @@
1
+ require "shapeshift"
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "shapeshift/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shapeshift_io"
8
+ spec.version = Shapeshift::VERSION
9
+ spec.authors = ["Romanos Fessas"]
10
+ spec.email = ["romanos@fessas.com"]
11
+
12
+ spec.summary = %q{Shapeshift IO API Wrapper}
13
+ spec.description = %q{Simple Shapeshift API ruby wrapper}
14
+ spec.homepage = 'https://github.com/romanos/shapeshift-io'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.15"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+
28
+ spec.add_dependency 'httparty', '>= 0.13'
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shapeshift_io
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Romanos Fessas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-14 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0.13'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0.13'
69
+ description: Simple Shapeshift API ruby wrapper
70
+ email:
71
+ - romanos@fessas.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/shapeshift.rb
86
+ - lib/shapeshift/client.rb
87
+ - lib/shapeshift/connections.rb
88
+ - lib/shapeshift/errors.rb
89
+ - lib/shapeshift/market.rb
90
+ - lib/shapeshift/transactions.rb
91
+ - lib/shapeshift/version.rb
92
+ - lib/shapeshift_io.rb
93
+ - shapeshift_io.gemspec
94
+ homepage: https://github.com/romanos/shapeshift-io
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.5.1
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Shapeshift IO API Wrapper
118
+ test_files: []