paytunia 0.1.1alpha → 0.1.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.
- data/README.md +30 -5
- data/lib/paytunia/api/account.rb +8 -1
- data/lib/paytunia/api/trading.rb +55 -0
- data/lib/paytunia/api/transfers.rb +11 -0
- data/lib/paytunia/connection_wrappers/basic_auth_wrapper.rb +32 -2
- data/lib/paytunia/models/account_operation.rb +7 -0
- data/lib/paytunia/models/base.rb +12 -0
- data/lib/paytunia/models/depth.rb +7 -0
- data/lib/paytunia/models/ticker.rb +1 -5
- data/lib/paytunia/models/trade.rb +7 -0
- data/lib/paytunia/models/trade_order.rb +7 -0
- data/lib/paytunia/version.rb +2 -2
- data/lib/paytunia.rb +1 -0
- metadata +25 -3
data/README.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
Paytunia
|
1
|
+
Paytunia [](http://travis-ci.org/paytunia/paytunia)
|
2
2
|
=
|
3
3
|
|
4
4
|
The official Ruby gem to integrate your app with [Paytunia](https://paytunia.com).
|
5
5
|
|
6
|
-
[](http://travis-ci.org/paytunia/paytunia)
|
7
|
-
|
8
6
|
## Installation
|
9
7
|
|
10
8
|
```
|
@@ -14,7 +12,7 @@ $ sudo gem install paytunia --pre
|
|
14
12
|
or add it to your `Gemfile`
|
15
13
|
|
16
14
|
```ruby
|
17
|
-
gem 'paytunia', '0.1alpha'
|
15
|
+
gem 'paytunia', '0.1.1alpha'
|
18
16
|
```
|
19
17
|
|
20
18
|
## Usage
|
@@ -23,8 +21,35 @@ gem 'paytunia', '0.1alpha'
|
|
23
21
|
|
24
22
|
### As a command-line executable
|
25
23
|
|
24
|
+
The Paytunia gem can be used directly from the command-line.
|
25
|
+
|
26
|
+
```
|
27
|
+
$ sudo gem install paytunia
|
28
|
+
$ paytunia get_ticker
|
29
|
+
{"high":24.79,"low":23.15, ... ,"currency":"EUR"}
|
30
|
+
```
|
31
|
+
|
26
32
|
## Authentication
|
27
33
|
|
28
34
|
### HTTP Basic
|
29
35
|
|
30
|
-
|
36
|
+
```ruby
|
37
|
+
connection = Paytunia.connect(basic_auth: { username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD')
|
38
|
+
connection.get_ledger
|
39
|
+
```
|
40
|
+
|
41
|
+
### OAuth2
|
42
|
+
|
43
|
+
Connect user the resource-owner credentials flow:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
connection = Paytunia.connect(oauth2: { username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD' })
|
47
|
+
connection.get_ledger
|
48
|
+
```
|
49
|
+
|
50
|
+
Or pass an `access_token` directly:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
connection = Paytunia.connect(oauth2: { access_token: 'YOUR_TOKEN' })
|
54
|
+
connection.get_ledger
|
55
|
+
```
|
data/lib/paytunia/api/account.rb
CHANGED
@@ -3,7 +3,14 @@ module Paytunia
|
|
3
3
|
|
4
4
|
# Returns the list of account operations
|
5
5
|
def get_ledger
|
6
|
-
account.get('/account_operations')
|
6
|
+
account.get('/account_operations').map do |ao|
|
7
|
+
AccountOperation.new(ao)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns a single account operation
|
12
|
+
def get_operation(operation_id)
|
13
|
+
AccountOperation.new(account.get("/account_operations/#{operation_id}"))
|
7
14
|
end
|
8
15
|
|
9
16
|
end
|
data/lib/paytunia/api/trading.rb
CHANGED
@@ -16,5 +16,60 @@ module Paytunia
|
|
16
16
|
Ticker.new(get('/ticker'))
|
17
17
|
end
|
18
18
|
|
19
|
+
# Returns the full market depth
|
20
|
+
def get_depth(currency = :eur)
|
21
|
+
depth = get("/depth/#{currency}").parsed_response
|
22
|
+
|
23
|
+
%w{ bids asks }.each do |category|
|
24
|
+
depth[category].map! { |order| Depth.new(order) }
|
25
|
+
end
|
26
|
+
|
27
|
+
depth
|
28
|
+
end
|
29
|
+
|
30
|
+
# Posts a trade order
|
31
|
+
#
|
32
|
+
# ==== Attributes
|
33
|
+
#
|
34
|
+
# * +amount+ - The amount of Bitcoins to buy or sell
|
35
|
+
# * +currency+ - The currency against which to trade
|
36
|
+
# * +type+ - Whether your order is to buy or sell Bitcoins, legal values are +:buy+ and +:sell+
|
37
|
+
# * +price+ - Limit price, creates a market order if omitted
|
38
|
+
#
|
39
|
+
def post_trade_order(amount, currency, type, price = nil)
|
40
|
+
if !amount.kind_of?(BigDecimal) || (price && !price.kind_of?(BigDecimal))
|
41
|
+
raise TypeError, "Expected BigDecimal, got #{amount.class.name} instead."
|
42
|
+
end
|
43
|
+
|
44
|
+
unless %w{ eur usd gbp }.include?(currency.to_s.downcase)
|
45
|
+
raise 'Illegal currency'
|
46
|
+
end
|
47
|
+
|
48
|
+
unless %w{ buy sell }.include?(type.to_s.downcase)
|
49
|
+
raise 'Illegal type'
|
50
|
+
end
|
51
|
+
|
52
|
+
TradeOrder.new(account.post('/trade_orders', { amount: amount, currency: currency, type: type, price: price } ))
|
53
|
+
end
|
54
|
+
|
55
|
+
# Gets a trade order
|
56
|
+
#
|
57
|
+
# ==== Attributes
|
58
|
+
#
|
59
|
+
# * +trade_order_id+ - UUID of the trade order to fetch
|
60
|
+
#
|
61
|
+
def get_trade_order(uuid)
|
62
|
+
TradeOrder.new(account.get("/trade_orders/#{uuid}"))
|
63
|
+
end
|
64
|
+
|
65
|
+
# Gets the trades that happened in relation to a specific order
|
66
|
+
#
|
67
|
+
# ==== Attributes
|
68
|
+
#
|
69
|
+
# * +trade_order_id+ - UUID of the trade order
|
70
|
+
#
|
71
|
+
def get_trades_for_order(uuid)
|
72
|
+
account.get("/trade_orders/#{uuid}/trades").map { |trade| Trade.new(trade) }
|
73
|
+
end
|
19
74
|
end
|
20
75
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Paytunia
|
2
|
+
module Api
|
3
|
+
|
4
|
+
# Requests Bitcoins to be sent
|
5
|
+
def send_bitcoins(address, amount)
|
6
|
+
raise(TypeError, "Expected BigDecimal, got #{amount.class.name} instead.") unless amount.kind_of? BigDecimal
|
7
|
+
account.post('/transfers/send_bitcoins', amount: amount, address: address)['uuid']
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
@@ -12,7 +12,17 @@ module Paytunia
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def get(path)
|
15
|
+
do_request(:get, path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def post(path, data)
|
19
|
+
do_request(:post, path, data)
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
protected
|
15
24
|
|
25
|
+
def do_request(method, path, data = nil)
|
16
26
|
uri = URI.parse(@site + path)
|
17
27
|
|
18
28
|
https = Net::HTTP.new(uri.host, 443)
|
@@ -22,11 +32,31 @@ module Paytunia
|
|
22
32
|
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
23
33
|
https.ca_file = Paytunia::Connection::CA_FILE
|
24
34
|
|
25
|
-
|
35
|
+
if method == :get
|
36
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
37
|
+
elsif method == :post
|
38
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
39
|
+
request.body = JSON.dump(data)
|
40
|
+
request['Content-Type'] = 'application/json'
|
41
|
+
request['Accept'] = 'application/json'
|
42
|
+
end
|
26
43
|
|
27
44
|
request.basic_auth(@username, @password)
|
28
45
|
|
29
|
-
|
46
|
+
response = https.request(request)
|
47
|
+
status = response.code.to_i
|
48
|
+
|
49
|
+
if status == 200
|
50
|
+
JSON.parse(response.body)
|
51
|
+
elsif status == 422
|
52
|
+
raise JSON.parse(response.body)['error']
|
53
|
+
elsif status == 404
|
54
|
+
raise 'HTTP 404 - Not Found'
|
55
|
+
elsif status == 401
|
56
|
+
raise 'HTTP 403 - Forbidden'
|
57
|
+
else
|
58
|
+
raise 'Unknown response code.'
|
59
|
+
end
|
30
60
|
end
|
31
61
|
end
|
32
62
|
end
|
data/lib/paytunia/version.rb
CHANGED
data/lib/paytunia.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paytunia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Alexis DENEUX
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-02-
|
13
|
+
date: 2013-02-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: oauth2
|
@@ -60,6 +60,22 @@ dependencies:
|
|
60
60
|
- - ! '>='
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: uuidtools
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
63
79
|
- !ruby/object:Gem::Dependency
|
64
80
|
name: rspec
|
65
81
|
requirement: !ruby/object:Gem::Requirement
|
@@ -135,10 +151,16 @@ files:
|
|
135
151
|
- bin/paytunia
|
136
152
|
- lib/paytunia/api/account.rb
|
137
153
|
- lib/paytunia/api/trading.rb
|
154
|
+
- lib/paytunia/api/transfers.rb
|
138
155
|
- lib/paytunia/connection.rb
|
139
156
|
- lib/paytunia/connection_wrappers/basic_auth_wrapper.rb
|
140
157
|
- lib/paytunia/connection_wrappers/oauth_wrapper.rb
|
158
|
+
- lib/paytunia/models/account_operation.rb
|
159
|
+
- lib/paytunia/models/base.rb
|
160
|
+
- lib/paytunia/models/depth.rb
|
141
161
|
- lib/paytunia/models/ticker.rb
|
162
|
+
- lib/paytunia/models/trade.rb
|
163
|
+
- lib/paytunia/models/trade_order.rb
|
142
164
|
- lib/paytunia/version.rb
|
143
165
|
- lib/paytunia.rb
|
144
166
|
- LICENSE
|