coinfresh 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/coinfresh.gemspec +27 -0
- data/lib/coinfresh.rb +59 -0
- data/lib/coinfresh/api/base.rb +18 -0
- data/lib/coinfresh/api/cash_flow.rb +20 -0
- data/lib/coinfresh/api/currency.rb +19 -0
- data/lib/coinfresh/api/market.rb +25 -0
- data/lib/coinfresh/api/order.rb +43 -0
- data/lib/coinfresh/api/wallet.rb +21 -0
- data/lib/coinfresh/api/withdraw.rb +21 -0
- data/lib/coinfresh/api_operation/create.rb +12 -0
- data/lib/coinfresh/api_operation/destroy.rb +11 -0
- data/lib/coinfresh/api_operation/find.rb +16 -0
- data/lib/coinfresh/api_operation/list.rb +13 -0
- data/lib/coinfresh/api_operation/new.rb +11 -0
- data/lib/coinfresh/api_operation/update.rb +12 -0
- data/lib/coinfresh/client.rb +39 -0
- data/lib/coinfresh/http.rb +106 -0
- data/lib/coinfresh/model/base.rb +175 -0
- data/lib/coinfresh/model/cash_flow.rb +17 -0
- data/lib/coinfresh/model/currency.rb +18 -0
- data/lib/coinfresh/model/market.rb +18 -0
- data/lib/coinfresh/model/order.rb +22 -0
- data/lib/coinfresh/model/trade.rb +18 -0
- data/lib/coinfresh/model/wallet.rb +22 -0
- data/lib/coinfresh/model/withdraw.rb +21 -0
- data/lib/coinfresh/version.rb +3 -0
- data/spec/api/cash_flow_spec.rb +23 -0
- data/spec/api/currency_spec.rb +24 -0
- data/spec/api/market_spec.rb +52 -0
- data/spec/api/order_spec.rb +55 -0
- data/spec/api/wallet_spec.rb +40 -0
- data/spec/api/withdraw_spec.rb +43 -0
- data/spec/cassettes/Coinfresh_Api_CashFlow/_list/gets_all_the_cashflows_for_currency.yml +64 -0
- data/spec/cassettes/Coinfresh_Api_Currency/_list/gets_all_the_currencies.yml +64 -0
- data/spec/cassettes/Coinfresh_Api_Market/_find/gets_a_market_with_the_given_id.yml +64 -0
- data/spec/cassettes/Coinfresh_Api_Market/_list/gets_all_the_markets.yml +64 -0
- data/spec/cassettes/Coinfresh_Api_Market/_trades/gets_all_trades_for_a_market.yml +64 -0
- data/spec/cassettes/Coinfresh_Api_Order/_cancel/cancels_an_order.yml +65 -0
- data/spec/cassettes/Coinfresh_Api_Order/_create/creates_an_order.yml +64 -0
- data/spec/cassettes/Coinfresh_Api_Order/_list/gets_all_the_orders.yml +67 -0
- data/spec/cassettes/Coinfresh_Api_Order/_my/gets_all_the_orders.yml +67 -0
- data/spec/cassettes/Coinfresh_Api_Wallet/_create/creates_a_wallet_with_the_given_id.yml +64 -0
- data/spec/cassettes/Coinfresh_Api_Wallet/_list/gets_all_the_wallets.yml +64 -0
- data/spec/cassettes/Coinfresh_Api_Withdraw/_create/creates_a_wallet_with_the_given_id.yml +64 -0
- data/spec/cassettes/Coinfresh_Api_Withdraw/_list/gets_all_the_wallets.yml +64 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/common_let_helpers.rb +62 -0
- data/spec/support/json_api_helpers.rb +5 -0
- metadata +190 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 670527694b3a5ef6656ca7979dd3db659da4013c
|
4
|
+
data.tar.gz: 3ae09e3ab99c351d166d0eaa100ec89b8ee2f9d7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 25d7ce487ce52e4728c75e7b30c31db2aef47eca3321edc827caf4a481412066c35276198ee9908200f8d341bc40e8744e40f0c50c8009f42503a6ed125544cf
|
7
|
+
data.tar.gz: f899fa6761d6f13f6ae54a44d2a479f596ef7e1a43bbe76ab8e92e6618d479c0d758a2c35606b735f9a2bc9d4d99a1522877df45ff1bb5f015139597d36c3eae
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Coinfresh
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'coinfresh'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install coinfresh
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/coinfresh.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'coinfresh/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "coinfresh"
|
8
|
+
spec.version = Coinfresh::VERSION
|
9
|
+
spec.authors = ["Pouyan T. Bibalan", "Ricky Gu"]
|
10
|
+
spec.email = ["pouyan@coinfresh.com"]
|
11
|
+
spec.description = %q{CoinFresh API Client}
|
12
|
+
spec.summary = %q{A ruby wrapper library to interact with CoinFresh API}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "vcr"
|
24
|
+
spec.add_development_dependency 'webmock'
|
25
|
+
|
26
|
+
spec.add_dependency 'api-auth'
|
27
|
+
end
|
data/lib/coinfresh.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "coinfresh/version"
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Coinfresh
|
6
|
+
|
7
|
+
{
|
8
|
+
:Http => 'http',
|
9
|
+
:Client => 'client'
|
10
|
+
}.each_pair do |klass, file|
|
11
|
+
autoload klass, "coinfresh/#{file}"
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
module Model
|
16
|
+
{
|
17
|
+
:Base => 'base',
|
18
|
+
:Currency => 'currency',
|
19
|
+
:Market => 'market',
|
20
|
+
:Order => 'order',
|
21
|
+
:Wallet => 'wallet',
|
22
|
+
:Trade => 'trade',
|
23
|
+
:Withdraw => 'withdraw',
|
24
|
+
:CashFlow => 'cash_flow'
|
25
|
+
}.each_pair do |klass, file|
|
26
|
+
autoload klass, "coinfresh/model/#{file}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module ApiOperation
|
31
|
+
{
|
32
|
+
:Create => 'create',
|
33
|
+
:Destroy => 'destroy',
|
34
|
+
:Find => 'find',
|
35
|
+
:List => 'list',
|
36
|
+
:Update => 'update',
|
37
|
+
:New => 'new'
|
38
|
+
}.each_pair do |klass, file|
|
39
|
+
autoload klass, "coinfresh/api_operation/#{file}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module Api
|
44
|
+
|
45
|
+
{
|
46
|
+
:Base => 'base',
|
47
|
+
:Currency => 'currency',
|
48
|
+
:Market => 'market',
|
49
|
+
:Order => 'order',
|
50
|
+
:Wallet => 'wallet',
|
51
|
+
:Withdraw => 'withdraw',
|
52
|
+
:CashFlow => 'cash_flow'
|
53
|
+
}.each_pair do |klass, file|
|
54
|
+
autoload klass, "coinfresh/api/#{file}"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Coinfresh
|
2
|
+
module Api
|
3
|
+
class CashFlow < Base
|
4
|
+
|
5
|
+
include Coinfresh::ApiOperation::List
|
6
|
+
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def data_klass(*args)
|
11
|
+
Coinfresh::Model::CashFlow
|
12
|
+
end
|
13
|
+
|
14
|
+
def end_point_url; 'cash_flows'; end
|
15
|
+
def plural_resource; 'cash_flows'; end
|
16
|
+
def singular_resource; 'cash_flow'; end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Coinfresh
|
2
|
+
module Api
|
3
|
+
class Currency < Base
|
4
|
+
|
5
|
+
include Coinfresh::ApiOperation::List
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def data_klass(*args)
|
10
|
+
Coinfresh::Model::Currency
|
11
|
+
end
|
12
|
+
|
13
|
+
def end_point_url; 'currencies'; end
|
14
|
+
def plural_resource; 'currencies'; end
|
15
|
+
def singular_resource; 'currency'; end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Coinfresh
|
2
|
+
module Api
|
3
|
+
class Market < Base
|
4
|
+
|
5
|
+
include Coinfresh::ApiOperation::List
|
6
|
+
include Coinfresh::ApiOperation::Find
|
7
|
+
|
8
|
+
def trades(id)
|
9
|
+
response = client.get("#{end_point_url}/#{id}/trades")
|
10
|
+
response['trades'].collect {|r| Coinfresh::Model::Trade.new(r, client) }
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def data_klass(*args)
|
16
|
+
Coinfresh::Model::Market
|
17
|
+
end
|
18
|
+
|
19
|
+
def end_point_url; 'markets'; end
|
20
|
+
def plural_resource; 'markets'; end
|
21
|
+
def singular_resource; 'market'; end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Coinfresh
|
2
|
+
module Api
|
3
|
+
class Order < Base
|
4
|
+
|
5
|
+
include Coinfresh::ApiOperation::List
|
6
|
+
include Coinfresh::ApiOperation::Find
|
7
|
+
include Coinfresh::ApiOperation::Create
|
8
|
+
include Coinfresh::ApiOperation::New
|
9
|
+
|
10
|
+
def my(params = {})
|
11
|
+
response = client.get("#{end_point_url}/my", params)
|
12
|
+
response[plural_resource].collect{ |r| data_item(r) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def cancel(id)
|
16
|
+
response = client.post("#{end_point_url}/#{id}/cancel")
|
17
|
+
data_item(response[singular_resource])
|
18
|
+
end
|
19
|
+
|
20
|
+
def cancel_market(market_id)
|
21
|
+
params = { market_id: market_id }
|
22
|
+
response = client.put("#{end_point_url}/cancel_all")
|
23
|
+
response[plural_resource].collect{ |r| data_item(r) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def cancel_all
|
27
|
+
response = client.put("#{end_point_url}/cancel_all")
|
28
|
+
response[plural_resource].collect{ |r| data_item(r) }
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def data_klass(*args)
|
34
|
+
Coinfresh::Model::Order
|
35
|
+
end
|
36
|
+
|
37
|
+
def end_point_url; 'orders'; end
|
38
|
+
def plural_resource; 'orders'; end
|
39
|
+
def singular_resource; 'order'; end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Coinfresh
|
2
|
+
module Api
|
3
|
+
class Wallet < Base
|
4
|
+
|
5
|
+
include Coinfresh::ApiOperation::List
|
6
|
+
include Coinfresh::ApiOperation::Create
|
7
|
+
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def data_klass(*args)
|
12
|
+
Coinfresh::Model::Wallet
|
13
|
+
end
|
14
|
+
|
15
|
+
def end_point_url; 'wallets'; end
|
16
|
+
def plural_resource; 'wallets'; end
|
17
|
+
def singular_resource; 'wallet'; end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Coinfresh
|
2
|
+
module Api
|
3
|
+
class Withdraw < Base
|
4
|
+
|
5
|
+
include Coinfresh::ApiOperation::List
|
6
|
+
include Coinfresh::ApiOperation::Create
|
7
|
+
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def data_klass(*args)
|
12
|
+
Coinfresh::Model::Withdraw
|
13
|
+
end
|
14
|
+
|
15
|
+
def end_point_url; 'withdraws'; end
|
16
|
+
def plural_resource; 'withdraws'; end
|
17
|
+
def singular_resource; 'withdraw'; end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Coinfresh
|
2
|
+
module ApiOperation
|
3
|
+
module Create
|
4
|
+
|
5
|
+
def create(params = {}, params_extra={})
|
6
|
+
response = client.post(end_point_url, {singular_resource => params}.merge(params_extra).to_json)
|
7
|
+
data_item(response[singular_resource])
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Coinfresh
|
2
|
+
module ApiOperation
|
3
|
+
module Find
|
4
|
+
|
5
|
+
def find(id)
|
6
|
+
begin
|
7
|
+
response = client.get("#{end_point_url}/#{id}")
|
8
|
+
data_item(response[singular_resource])
|
9
|
+
rescue Coinfresh::Model::ResourceNotFound
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Coinfresh
|
2
|
+
|
3
|
+
class Client
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :base_scope_url
|
7
|
+
end
|
8
|
+
|
9
|
+
self.base_scope_url = 'https://coinfresh.com' #ENV["coinfresh_base_url"]
|
10
|
+
|
11
|
+
include Coinfresh::Http
|
12
|
+
|
13
|
+
attr_accessor :access_token
|
14
|
+
attr_accessor :secret_key
|
15
|
+
attr_accessor :end_points
|
16
|
+
|
17
|
+
def initialize(options = {})
|
18
|
+
self.access_token = options[:access_token]
|
19
|
+
self.secret_key = options[:secret_key]
|
20
|
+
Coinfresh::Client.base_scope_url = options[:base_uri] if options[:base_uri]
|
21
|
+
self.end_points = {}
|
22
|
+
end
|
23
|
+
|
24
|
+
{
|
25
|
+
markets: Coinfresh::Api::Market,
|
26
|
+
orders: Coinfresh::Api::Order,
|
27
|
+
currencies: Coinfresh::Api::Currency,
|
28
|
+
wallets: Coinfresh::Api::Wallet,
|
29
|
+
withdraws: Coinfresh::Api::Withdraw,
|
30
|
+
cash_flows: Coinfresh::Api::CashFlow
|
31
|
+
}.each_pair do |method, klass|
|
32
|
+
define_method method do
|
33
|
+
end_points[method] ||= klass.new(self)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|