coinfresh 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/coinfresh.gemspec +27 -0
  8. data/lib/coinfresh.rb +59 -0
  9. data/lib/coinfresh/api/base.rb +18 -0
  10. data/lib/coinfresh/api/cash_flow.rb +20 -0
  11. data/lib/coinfresh/api/currency.rb +19 -0
  12. data/lib/coinfresh/api/market.rb +25 -0
  13. data/lib/coinfresh/api/order.rb +43 -0
  14. data/lib/coinfresh/api/wallet.rb +21 -0
  15. data/lib/coinfresh/api/withdraw.rb +21 -0
  16. data/lib/coinfresh/api_operation/create.rb +12 -0
  17. data/lib/coinfresh/api_operation/destroy.rb +11 -0
  18. data/lib/coinfresh/api_operation/find.rb +16 -0
  19. data/lib/coinfresh/api_operation/list.rb +13 -0
  20. data/lib/coinfresh/api_operation/new.rb +11 -0
  21. data/lib/coinfresh/api_operation/update.rb +12 -0
  22. data/lib/coinfresh/client.rb +39 -0
  23. data/lib/coinfresh/http.rb +106 -0
  24. data/lib/coinfresh/model/base.rb +175 -0
  25. data/lib/coinfresh/model/cash_flow.rb +17 -0
  26. data/lib/coinfresh/model/currency.rb +18 -0
  27. data/lib/coinfresh/model/market.rb +18 -0
  28. data/lib/coinfresh/model/order.rb +22 -0
  29. data/lib/coinfresh/model/trade.rb +18 -0
  30. data/lib/coinfresh/model/wallet.rb +22 -0
  31. data/lib/coinfresh/model/withdraw.rb +21 -0
  32. data/lib/coinfresh/version.rb +3 -0
  33. data/spec/api/cash_flow_spec.rb +23 -0
  34. data/spec/api/currency_spec.rb +24 -0
  35. data/spec/api/market_spec.rb +52 -0
  36. data/spec/api/order_spec.rb +55 -0
  37. data/spec/api/wallet_spec.rb +40 -0
  38. data/spec/api/withdraw_spec.rb +43 -0
  39. data/spec/cassettes/Coinfresh_Api_CashFlow/_list/gets_all_the_cashflows_for_currency.yml +64 -0
  40. data/spec/cassettes/Coinfresh_Api_Currency/_list/gets_all_the_currencies.yml +64 -0
  41. data/spec/cassettes/Coinfresh_Api_Market/_find/gets_a_market_with_the_given_id.yml +64 -0
  42. data/spec/cassettes/Coinfresh_Api_Market/_list/gets_all_the_markets.yml +64 -0
  43. data/spec/cassettes/Coinfresh_Api_Market/_trades/gets_all_trades_for_a_market.yml +64 -0
  44. data/spec/cassettes/Coinfresh_Api_Order/_cancel/cancels_an_order.yml +65 -0
  45. data/spec/cassettes/Coinfresh_Api_Order/_create/creates_an_order.yml +64 -0
  46. data/spec/cassettes/Coinfresh_Api_Order/_list/gets_all_the_orders.yml +67 -0
  47. data/spec/cassettes/Coinfresh_Api_Order/_my/gets_all_the_orders.yml +67 -0
  48. data/spec/cassettes/Coinfresh_Api_Wallet/_create/creates_a_wallet_with_the_given_id.yml +64 -0
  49. data/spec/cassettes/Coinfresh_Api_Wallet/_list/gets_all_the_wallets.yml +64 -0
  50. data/spec/cassettes/Coinfresh_Api_Withdraw/_create/creates_a_wallet_with_the_given_id.yml +64 -0
  51. data/spec/cassettes/Coinfresh_Api_Withdraw/_list/gets_all_the_wallets.yml +64 -0
  52. data/spec/spec_helper.rb +22 -0
  53. data/spec/support/common_let_helpers.rb +62 -0
  54. data/spec/support/json_api_helpers.rb +5 -0
  55. metadata +190 -0
@@ -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
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in coinfresh.gemspec
4
+ gemspec
@@ -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.
@@ -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
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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
@@ -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,18 @@
1
+ module Coinfresh
2
+ module Api
3
+ class Base
4
+
5
+ attr_accessor :client
6
+
7
+ def initialize(client)
8
+ self.client = client
9
+ end
10
+
11
+ private
12
+ def data_item(params)
13
+ data_klass.new(params, client)
14
+ end
15
+
16
+ end
17
+ end
18
+ 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,11 @@
1
+ module Coinfresh
2
+ module ApiOperation
3
+ module Destroy
4
+
5
+ def destroy(id)
6
+ client.delete("#{end_point_url}/#{id}", false)
7
+ end
8
+
9
+ end
10
+ end
11
+ 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,13 @@
1
+ module Coinfresh
2
+ module ApiOperation
3
+ module List
4
+
5
+ def list(params = {})
6
+ response = client.get(end_point_url, params)
7
+ response[plural_resource].collect{ |r| data_item(r) }
8
+ end
9
+
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Coinfresh
2
+ module ApiOperation
3
+ module New
4
+
5
+ def new(params = {})
6
+ data_item(params)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Coinfresh
2
+ module ApiOperation
3
+ module Update
4
+
5
+ def update(id, params = {})
6
+ response = client.put("#{end_point_url}/#{id}", {singular_resource => params}.to_json)
7
+ data_item(response[singular_resource])
8
+ end
9
+
10
+ end
11
+ end
12
+ 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