ripple-rest 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/CHANGELOG.md +0 -0
  2. data/LICENSE +20 -0
  3. data/README.md +0 -0
  4. data/ROADMAP.md +0 -0
  5. data/lib/ripple-rest.rb +72 -0
  6. data/lib/ripple-rest/errors.rb +17 -0
  7. data/lib/ripple-rest/schemas/account.rb +57 -0
  8. data/lib/ripple-rest/schemas/account_settings.rb +18 -0
  9. data/lib/ripple-rest/schemas/amount.rb +20 -0
  10. data/lib/ripple-rest/schemas/balance.rb +9 -0
  11. data/lib/ripple-rest/schemas/json.rb +17 -0
  12. data/lib/ripple-rest/schemas/json/AccountSettings.json +63 -0
  13. data/lib/ripple-rest/schemas/json/Amount.json +28 -0
  14. data/lib/ripple-rest/schemas/json/Balance.json +23 -0
  15. data/lib/ripple-rest/schemas/json/Currency.json +7 -0
  16. data/lib/ripple-rest/schemas/json/FloatString.json +7 -0
  17. data/lib/ripple-rest/schemas/json/Hash128.json +7 -0
  18. data/lib/ripple-rest/schemas/json/Hash256.json +7 -0
  19. data/lib/ripple-rest/schemas/json/Notification.json +58 -0
  20. data/lib/ripple-rest/schemas/json/Order.json +82 -0
  21. data/lib/ripple-rest/schemas/json/Payment.json +98 -0
  22. data/lib/ripple-rest/schemas/json/ResourceId.json +7 -0
  23. data/lib/ripple-rest/schemas/json/RippleAddress.json +7 -0
  24. data/lib/ripple-rest/schemas/json/Timestamp.json +7 -0
  25. data/lib/ripple-rest/schemas/json/Trustline.json +58 -0
  26. data/lib/ripple-rest/schemas/json/UINT32.json +7 -0
  27. data/lib/ripple-rest/schemas/json/URL.json +7 -0
  28. data/lib/ripple-rest/schemas/notifications.rb +12 -0
  29. data/lib/ripple-rest/schemas/order.rb +6 -0
  30. data/lib/ripple-rest/schemas/payments.rb +72 -0
  31. data/lib/ripple-rest/schemas/trustlines.rb +33 -0
  32. data/lib/ripple-rest/version.rb +3 -0
  33. metadata +111 -0
data/CHANGELOG.md ADDED
File without changes
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Yeechan Lu
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
File without changes
data/ROADMAP.md ADDED
File without changes
@@ -0,0 +1,72 @@
1
+ module RippleRest; end
2
+
3
+ require 'json'
4
+ require 'cgi'
5
+ require 'bigdecimal'
6
+ require 'autoparse'
7
+ require 'rest-client'
8
+ require 'ripple-rest/version'
9
+ require 'ripple-rest/errors'
10
+ require 'ripple-rest/schemas/json'
11
+ require 'ripple-rest/schemas/account'
12
+ require 'ripple-rest/schemas/account_settings'
13
+ require 'ripple-rest/schemas/trustlines'
14
+ require 'ripple-rest/schemas/balance'
15
+ require 'ripple-rest/schemas/notifications'
16
+ require 'ripple-rest/schemas/order'
17
+ require 'ripple-rest/schemas/amount'
18
+ require 'ripple-rest/schemas/payments'
19
+
20
+ class << RippleRest
21
+ def setup endpoint
22
+ @endpoint = endpoint.gsub %r|/$|, ""
23
+ end
24
+
25
+ def get uri, args = {}
26
+ wrap_error { RestClient.get "#{@endpoint}/#{uri}", args }
27
+ end
28
+
29
+ def post uri, args = {}
30
+ wrap_error { RestClient.post "#{@endpoint}/#{uri}", args, :content_type => :json }
31
+ end
32
+
33
+ def wrap_error
34
+ unless @endpoint
35
+ raise ArgumentError.new "You have to setup RippleRest first."
36
+ end
37
+
38
+ begin
39
+ response = yield
40
+ rescue => e
41
+ response = e.response if e.respond_to? :response
42
+ end
43
+
44
+ json = JSON.parse response.to_str rescue nil
45
+ if json
46
+ raise RippleRest::RippleRestError.new(json["message"], json) unless json["success"]
47
+ end
48
+
49
+ if !response || response.code != 200
50
+ raise RippleRest::ProtocolError.new "Protocol is wrong or network is down", response
51
+ end
52
+
53
+ json || response.to_str
54
+ end
55
+
56
+ def get_transaction hash
57
+ get("v1/transactions/#{hash}")["transaction"]
58
+ end
59
+
60
+ def server_connected?
61
+ get("v1/server/connected")["connected"]
62
+ end
63
+
64
+ def server_info
65
+ get("v1/server")
66
+ end
67
+
68
+ def next_uuid
69
+ get("v1/uuid")["uuid"]
70
+ end
71
+ end
72
+
@@ -0,0 +1,17 @@
1
+ module RippleRest
2
+ class ProtocolError < RuntimeError
3
+ attr_accessor :response
4
+ def initialize message, response
5
+ super message
6
+ @response = response
7
+ end
8
+ end
9
+
10
+ class RippleRestError < RuntimeError
11
+ attr_accessor :response
12
+ def initialize message, response
13
+ super message
14
+ @response = response
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,57 @@
1
+ module RippleRest
2
+ class Account
3
+ attr_accessor :address
4
+ attr_accessor :secret
5
+
6
+ def initialize address, secret = nil
7
+ @address = address
8
+ @secret = secret
9
+ end
10
+
11
+ def balances
12
+ RippleRest
13
+ .get("v1/accounts/#{@address}/balances")["balances"]
14
+ .map(&Balance.method(:new))
15
+ end
16
+
17
+ def trustlines
18
+ data = RippleRest
19
+ .get("v1/accounts/#{@address}/trustlines")["trustlines"]
20
+ .map(&Trustline.method(:new))
21
+ obj = Trustlines.new data
22
+ obj.account = self
23
+ obj
24
+ end
25
+
26
+ def settings
27
+ data = RippleRest.get("v1/accounts/#{@address}/settings")["settings"]
28
+ obj = AccountSettings.new data
29
+ obj.account = self
30
+ obj
31
+ end
32
+
33
+ def notifications
34
+ @notifications ||= lambda {
35
+ obj = Notifications.new
36
+ obj.account = self
37
+ obj
38
+ }.call
39
+ end
40
+
41
+ def require_secret
42
+ raise ArgumentError.new("Secret is required for this operation.") unless secret
43
+ end
44
+
45
+ def payments
46
+ payments ||= lambda {
47
+ obj = Payments.new
48
+ obj.account = self
49
+ obj
50
+ }.call
51
+ end
52
+
53
+ def to_s
54
+ address
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,18 @@
1
+ module RippleRest
2
+ generate_schema :AccountSettings
3
+
4
+ class AccountSettings
5
+ attr_accessor :account
6
+
7
+ def save
8
+ raise ArgumentError.new("Account is missing.") unless account
9
+
10
+ account.require_secret
11
+
12
+ hash = to_hash
13
+ hash["secret"] = account.secret
14
+
15
+ RippleRest.post "v1/accounts/#{account.address}/settings", hash
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ module RippleRest
2
+ generate_schema :Amount
3
+
4
+ class Amount
5
+ def to_s
6
+ "#{value}+#{currency}#{issuer.to_s.size > 0 ? ("+" + issuer) : ""}"
7
+ end
8
+
9
+ def self.from_string s
10
+ return s if s.is_a?(Amount)
11
+
12
+ arr = s.split("+")
13
+ Amount.new({
14
+ "value" => arr[0],
15
+ "currency" => arr[1],
16
+ "issuer" => arr[2]
17
+ })
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ module RippleRest
2
+ generate_schema :Balance
3
+
4
+ class Balance
5
+ def inspect
6
+ "#{value.to_s} #{currency}#{counterparty.to_s.size > 0 ? " (#{counterparty})" : ""}"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module RippleRest
2
+ SCHEMA_ROOT = File.join(File.dirname(__FILE__), "json")
3
+
4
+ def self.generate_schema(fn)
5
+ RippleRest.const_set fn, AutoParse.generate(JSON.parse(File.read(File.join(SCHEMA_ROOT, "#{fn}.json"))), :uri => "#{fn}")
6
+ end
7
+
8
+ generate_schema :Currency
9
+ generate_schema :FloatString
10
+ generate_schema :Hash128
11
+ generate_schema :Hash256
12
+ generate_schema :ResourceId
13
+ generate_schema :RippleAddress
14
+ generate_schema :Timestamp
15
+ generate_schema :UINT32
16
+ generate_schema :URL
17
+ end
@@ -0,0 +1,63 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "AccountSettings",
4
+ "description": "An object ",
5
+ "type": "object",
6
+ "properties": {
7
+ "account": {
8
+ "description": "The Ripple address of the account in question",
9
+ "$ref": "RippleAddress"
10
+ },
11
+ "regular_key": {
12
+ "description": "The hash of an optional additional public key that can be used for signing and verifying transactions",
13
+ "$ref": "RippleAddress"
14
+ },
15
+ "url": {
16
+ "description": "The domain associated with this account. The ripple.txt file can be looked up to verify this information",
17
+ "$ref": "URL"
18
+ },
19
+ "email_hash": {
20
+ "description": "The MD5 128-bit hash of the account owner's email address",
21
+ "$ref": "Hash128"
22
+ },
23
+ "message_key": {
24
+ "description": "An optional public key, represented as hex, that can be set to allow others to send encrypted messages to the account owner",
25
+ "type": "string",
26
+ "pattern": "^([0-9a-fA-F]{2}){0,33}$"
27
+ },
28
+ "transfer_rate": {
29
+ "description": "A number representation of the rate charged each time a holder of currency issued by this account transfers it. By default the rate is 100. A rate of 101 is a 1% charge on top of the amount being transferred. Up to nine decimal places are supported",
30
+ "type": "float"
31
+ },
32
+ "require_destination_tag": {
33
+ "description": "If set to true incoming payments will only be validated if they include a destination_tag. This may be used primarily by gateways that operate exclusively with hosted wallets",
34
+ "type": "boolean"
35
+ },
36
+ "require_authorization": {
37
+ "description": "If set to true incoming trustlines will only be validated if this account first creates a trustline to the counterparty with the authorized flag set to true. This may be used by gateways to prevent accounts unknown to them from holding currencies they issue",
38
+ "type": "boolean"
39
+ },
40
+ "disallow_xrp": {
41
+ "description": "If set to true incoming XRP payments will be allowed",
42
+ "type": "boolean"
43
+ },
44
+ "transaction_sequence": {
45
+ "description": "A string representation of the last sequence number of a validated transaction created by this account",
46
+ "$ref": "UINT32"
47
+ },
48
+ "trustline_count": {
49
+ "description": "The number of trustlines owned by this account. This value does not include incoming trustlines where this account has not explicitly reciprocated trust",
50
+ "$ref": "UINT32"
51
+ },
52
+ "ledger": {
53
+ "description": "The string representation of the index number of the ledger containing these account settings or, in the case of historical queries, of the transaction that modified these settings",
54
+ "type": "string",
55
+ "pattern": "^[0-9]+$"
56
+ },
57
+ "hash": {
58
+ "description": "If this object was returned by a historical query this value will be the hash of the transaction that modified these settings. The transaction hash is used throughout the Ripple Protocol to uniquely identify a particular transaction",
59
+ "$ref": "Hash256"
60
+ }
61
+ },
62
+ "required": ["account"]
63
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "Amount",
4
+ "description": "An Amount on the Ripple Protocol, used also for XRP in the ripple-rest API",
5
+ "type": "object",
6
+ "properties": {
7
+ "value": {
8
+ "description": "The quantity of the currency, denoted as a string to retain floating point precision",
9
+ "type": "string",
10
+ "$ref": "FloatString"
11
+ },
12
+ "currency": {
13
+ "description": "The currency expressed as a three-character code",
14
+ "$ref": "Currency"
15
+ },
16
+ "issuer": {
17
+ "description": "The Ripple account address of the currency's issuer or gateway, or an empty string if the currency is XRP",
18
+ "type": "string",
19
+ "pattern": "^$|^r[1-9A-HJ-NP-Za-km-z]{25,33}$"
20
+ },
21
+ "counterparty": {
22
+ "description": "The Ripple account address of the currency's issuer or gateway, or an empty string if the currency is XRP",
23
+ "type": "string",
24
+ "pattern": "^$|^r[1-9A-HJ-NP-Za-km-z]{25,33}$"
25
+ }
26
+ },
27
+ "required": ["value", "currency"]
28
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "Balance",
4
+ "description": "A simplified representation of an account Balance",
5
+ "type": "object",
6
+ "properties": {
7
+ "value": {
8
+ "description": "The quantity of the currency, denoted as a string to retain floating point precision",
9
+ "type": "string",
10
+ "$ref": "FloatString"
11
+ },
12
+ "currency": {
13
+ "description": "The currency expressed as a three-character code",
14
+ "$ref": "Currency"
15
+ },
16
+ "counterparty": {
17
+ "description": "The Ripple account address of the currency's issuer or gateway, or an empty string if the currency is XRP",
18
+ "type": "string",
19
+ "pattern": "^$|^r[1-9A-HJ-NP-Za-km-z]{25,33}$"
20
+ }
21
+ },
22
+ "required": [ "value", "currency" ]
23
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "Currency",
4
+ "description": "The three-character code or hex string used to denote currencies",
5
+ "type": "string",
6
+ "pattern": "^([a-zA-Z0-9]{3}|[A-Fa-f0-9]{40})$"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "FloatString",
4
+ "description": "A string representation of a floating point number",
5
+ "type": "string",
6
+ "pattern": "^[-+]?[0-9]*[.]?[0-9]+([eE][-+]?[0-9]+)?$"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "Hash128",
4
+ "description": "The hex representation of a 128-bit hash",
5
+ "type": "string",
6
+ "pattern": "^$|^[A-Fa-f0-9]{32}$"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "Hash256",
4
+ "description": "The hex representation of a 256-bit hash",
5
+ "type": "string",
6
+ "pattern": "^$|^[A-Fa-f0-9]{64}$"
7
+ }
@@ -0,0 +1,58 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "Notification",
4
+ "description": "A ",
5
+ "type": "object",
6
+ "properties": {
7
+ "account": {
8
+ "description": "The Ripple address of the account to which the notification pertains",
9
+ "$ref": "RippleAddress"
10
+ },
11
+ "type": {
12
+ "description": "The resource type this notification corresponds to. Possible values are \"payment\", \"order\", \"trustline\", \"accountsettings\"",
13
+ "type": "string",
14
+ "pattern": "^payment|order|trustline|accountsettings$"
15
+ },
16
+ "direction": {
17
+ "description": "The direction of the transaction, from the perspective of the account being queried. Possible values are \"incoming\", \"outgoing\", and \"passthrough\"",
18
+ "type": "string",
19
+ "pattern": "^incoming|outgoing|passthrough$"
20
+ },
21
+ "state": {
22
+ "description": "The state of the transaction from the perspective of the Ripple Ledger. Possible values are \"validated\" and \"failed\"",
23
+ "type": "string",
24
+ "pattern": "^validated|failed$"
25
+ },
26
+ "result": {
27
+ "description": "The rippled code indicating the success or failure type of the transaction. The code \"tesSUCCESS\" indicates that the transaction was successfully validated and written into the Ripple Ledger. All other codes will begin with the following prefixes: \"tec\", \"tef\", \"tel\", or \"tej\"",
28
+ "type": "string",
29
+ "pattern": "te[cfjlms][A-Za-z_]+"
30
+ },
31
+ "ledger": {
32
+ "description": "The string representation of the index number of the ledger containing the validated or failed transaction. Failed payments will only be written into the Ripple Ledger if they fail after submission to a rippled and a Ripple Network fee is claimed",
33
+ "type": "string",
34
+ "pattern": "^[0-9]+$"
35
+ },
36
+ "hash": {
37
+ "description": "The 256-bit hash of the transaction. This is used throughout the Ripple protocol as the unique identifier for the transaction",
38
+ "$ref": "Hash256"
39
+ },
40
+ "timestamp": {
41
+ "description": "The timestamp representing when the transaction was validated and written into the Ripple ledger",
42
+ "$ref": "Timestamp"
43
+ },
44
+ "transaction_url": {
45
+ "description": "A URL that can be used to fetch the full resource this notification corresponds to",
46
+ "type": "string"
47
+ },
48
+ "previous_notification_url": {
49
+ "description": "A URL that can be used to fetch the notification that preceded this one chronologically",
50
+ "type": "string"
51
+ },
52
+ "next_notification_url": {
53
+ "description": "A URL that can be used to fetch the notification that followed this one chronologically",
54
+ "type": "string"
55
+ }
56
+ },
57
+ "required": []
58
+ }
@@ -0,0 +1,82 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "Order",
4
+ "description": "A simplified Order object used by the ripple-rest API (note that \"orders\" are referred to elsewhere in the Ripple protocol as \"offers\")",
5
+ "type": "object",
6
+ "properties": {
7
+ "account": {
8
+ "description": "The Ripple account address of the order's creator",
9
+ "$ref": "RippleAddress"
10
+ },
11
+ "buy": {
12
+ "description": "If set to true the order it indicates that the creator is looking to receive the base_amount in exchange for the counter_amount. If undefined or set to false it indicates that the creator is looking to sell the base_amount to receive the counter_amount",
13
+ "type": "boolean"
14
+ },
15
+ "base_amount": {
16
+ "description": "The amount of currency the seller_account is seeking to buy. If other orders take part of this one, this value will change to represent the amount left in the order. This may be specified along with the counter_amount OR exchange_rate but not both. When the order is parsed from the Ripple Ledger the base currency will be determined according to the Priority Ranking of Currencies (XRP,EUR,GBP,AUD,NZD,USD,CAD,CHF,JPY,CNY) and if neither currency is listed in the ranking the base currency will be the one that is alphabetically first",
17
+ "$ref": "Amount"
18
+ },
19
+ "counter_amount": {
20
+ "description": "The amount of currency being sold. If other orders take part of this one, this value will change to represent the amount left in the order. This may be specified along with the base_amount OR the exchange_rate but not both",
21
+ "$ref": "Amount"
22
+ },
23
+ "exchange_rate": {
24
+ "description": "A string representation of the order price, defined as the cost one unit of the base currency in terms of the counter currency. This may be specified along with the base_amount OR the counter_amount but not both. If it is unspecified it will be computed automatically based on the counter_amount divided by the base_amount",
25
+ "$ref": "FloatString"
26
+ },
27
+ "expiration_timestamp": {
28
+ "description": "The ISO combined date and time string representing the point beyond which the order will no longer be considered active or valid",
29
+ "$ref": "Timestamp"
30
+ },
31
+ "ledger_timeout": {
32
+ "description": "A string representation of the number of ledger closes after submission during which the order should be considered active",
33
+ "type": "string",
34
+ "pattern": "^[0-9]*$"
35
+ },
36
+ "immediate_or_cancel": {
37
+ "description": "If set to true this order will only take orders that are available at the time of execution and will not create an entry in the Ripple Ledger",
38
+ "type": "boolean"
39
+ },
40
+ "fill_or_kill": {
41
+ "description": "If set to true this order will only take orders that fill the base_amount and are available at the time of execution and will not create an entry in the Ripple Ledger",
42
+ "type": "boolean"
43
+ },
44
+ "maximize_buy_or_sell": {
45
+ "description": "If set to true and it is a buy order it will buy up to the base_amount even if the counter_amount is exceeded, if it is a sell order it will sell up to the counter_amount even if the base_amount is exceeded",
46
+ "type": "boolean"
47
+ },
48
+ "cancel_replace": {
49
+ "description": "If this is set to the sequence number of an outstanding order, that order will be cancelled and replaced with this one",
50
+ "type": "string",
51
+ "pattern": "^d*$"
52
+ },
53
+ "sequence": {
54
+ "description": "The sequence number of this order from the perspective of the seller_account. The seller_account and the sequence number uniquely identify the order in the Ripple Ledger",
55
+ "type": "string",
56
+ "pattern": "^[0-9]*$"
57
+ },
58
+ "fee": {
59
+ "description": "The Ripple Network transaction fee, represented in whole XRP (NOT \"drops\", or millionths of an XRP, which is used elsewhere in the Ripple protocol) used to create the order",
60
+ "$ref": "FloatString"
61
+ },
62
+ "state": {
63
+ "description": "If the order is active the state will be \"active\". If this object represents a historical order the state will be \"validated\", \"filled\" if the order was removed because it was fully filled, \"cancelled\" if it was deleted by the owner, \"expired\" if it reached the expiration_timestamp, or \"failed\" if there was an error with the initial attempt to place the order",
64
+ "type": "string",
65
+ "pattern": "^active|validated|filled|cancelled|expired|failed$"
66
+ },
67
+ "ledger": {
68
+ "description": "The string representation of the index number of the ledger containing this order or, in the case of historical queries, of the transaction that modified this Order. ",
69
+ "type": "string",
70
+ "pattern": "^[0-9]+$"
71
+ },
72
+ "hash": {
73
+ "description": "When returned as the result of a historical query this will be the hash of Ripple transaction that created, modified, or deleted this order. The transaction hash is used throughout the Ripple Protocol to uniquely identify a particular transaction",
74
+ "$ref": "Hash256"
75
+ },
76
+ "previous": {
77
+ "description": "If the order was modified or partially filled this will be a full Order object. If the previous object also had a previous object that will be removed to reduce data complexity. Order changes can be walked backwards by querying the API for previous.hash repeatedly",
78
+ "$ref": "Order"
79
+ }
80
+ },
81
+ "required": ["account"]
82
+ }
@@ -0,0 +1,98 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "Payment",
4
+ "description": "A flattened Payment object used by the ripple-rest API",
5
+ "type": "object",
6
+ "properties": {
7
+ "source_account": {
8
+ "description": "The Ripple account address of the Payment sender",
9
+ "$ref": "RippleAddress"
10
+ },
11
+ "source_tag": {
12
+ "description": "A string representing an unsigned 32-bit integer most commonly used to refer to a sender's hosted account at a Ripple gateway",
13
+ "$ref": "UINT32"
14
+ },
15
+ "source_amount": {
16
+ "description": "An optional amount that can be specified to constrain cross-currency payments",
17
+ "$ref": "Amount"
18
+ },
19
+ "source_slippage": {
20
+ "description": "An optional cushion for the source_amount to increase the likelihood that the payment will succeed. The source_account will never be charged more than source_amount.value + source_slippage",
21
+ "$ref": "FloatString"
22
+ },
23
+ "destination_account": {
24
+ "$ref": "RippleAddress"
25
+ },
26
+ "destination_tag": {
27
+ "description": "A string representing an unsigned 32-bit integer most commonly used to refer to a receiver's hosted account at a Ripple gateway",
28
+ "$ref": "UINT32"
29
+ },
30
+ "destination_amount": {
31
+ "description": "The amount the destination_account will receive",
32
+ "$ref": "Amount"
33
+ },
34
+ "invoice_id": {
35
+ "description": "A 256-bit hash that can be used to identify a particular payment",
36
+ "$ref": "Hash256"
37
+ },
38
+ "paths ": {
39
+ "description": "A \"stringified\" version of the Ripple PathSet structure that users should treat as opaque",
40
+ "type": "string"
41
+ },
42
+ "partial_payment": {
43
+ "description": "A boolean that, if set to true, indicates that this payment should go through even if the whole amount cannot be delivered because of a lack of liquidity or funds in the source_account account",
44
+ "type": "boolean"
45
+ },
46
+ "no_direct_ripple": {
47
+ "description": "A boolean that can be set to true if paths are specified and the sender would like the Ripple Network to disregard any direct paths from the source_account to the destination_account. This may be used to take advantage of an arbitrage opportunity or by gateways wishing to issue balances from a hot wallet to a user who has mistakenly set a trustline directly to the hot wallet",
48
+ "type": "boolean"
49
+ },
50
+ "direction": {
51
+ "description": "The direction of the payment, from the perspective of the account being queried. Possible values are \"incoming\", \"outgoing\", and \"passthrough\"",
52
+ "type": "string",
53
+ "pattern": "^incoming|outgoing|passthrough$"
54
+ },
55
+ "state": {
56
+ "description": "The state of the payment from the perspective of the Ripple Ledger. Possible values are \"validated\" and \"failed\" and \"new\" if the payment has not been submitted yet",
57
+ "type": "string",
58
+ "pattern": "^validated|failed|new$"
59
+ },
60
+ "result": {
61
+ "description": "The rippled code indicating the success or failure type of the payment. The code \"tesSUCCESS\" indicates that the payment was successfully validated and written into the Ripple Ledger. All other codes will begin with the following prefixes: \"tec\", \"tef\", \"tel\", or \"tej\"",
62
+ "type": "string",
63
+ "pattern": "te[cfjlms][A-Za-z_]+"
64
+ },
65
+ "ledger": {
66
+ "description": "The string representation of the index number of the ledger containing the validated or failed payment. Failed payments will only be written into the Ripple Ledger if they fail after submission to a rippled and a Ripple Network fee is claimed",
67
+ "type": "string",
68
+ "pattern": "^[0-9]+$"
69
+ },
70
+ "hash": {
71
+ "description": "The 256-bit hash of the payment. This is used throughout the Ripple protocol as the unique identifier for the transaction",
72
+ "$ref": "Hash256"
73
+ },
74
+ "timestamp": {
75
+ "description": "The timestamp representing when the payment was validated and written into the Ripple ledger",
76
+ "$ref": "Timestamp"
77
+ },
78
+ "fee": {
79
+ "description": "The Ripple Network transaction fee, represented in whole XRP (NOT \"drops\", or millionths of an XRP, which is used elsewhere in the Ripple protocol)",
80
+ "$ref": "FloatString"
81
+ },
82
+ "source_balance_changes": {
83
+ "description": "Parsed from the validated transaction metadata, this array represents all of the changes to balances held by the source_account. Most often this will have one amount representing the Ripple Network fee and, if the source_amount was not XRP, one amount representing the actual source_amount that was sent",
84
+ "type": "array",
85
+ "items": {
86
+ "$ref": "Amount"
87
+ }
88
+ },
89
+ "destination_balance_changes": {
90
+ "description": "Parsed from the validated transaction metadata, this array represents the changes to balances held by the destination_account. For those receiving payments this is important to check because if the partial_payment flag is set this value may be less than the destination_amount",
91
+ "type": "array",
92
+ "items": {
93
+ "$ref": "Amount"
94
+ }
95
+ }
96
+ },
97
+ "required": ["source_account", "destination_account", "destination_amount"]
98
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "ResourceId",
4
+ "description": "A client-supplied unique identifier (ideally a UUID) for this transaction used to prevent duplicate payments and help confirm the transaction's final status. All ASCII printable characters are allowed. Note that 256-bit hex strings are disallowed because of the potential confusion with transaction hashes.",
5
+ "type": "string",
6
+ "pattern": "^(?!$|^[A-Fa-f0-9]{64})[ -~]{1,255}$"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "RippleAddress",
4
+ "description": "A Ripple account address",
5
+ "type": "string",
6
+ "pattern": "^r[1-9A-HJ-NP-Za-km-z]{25,33}$"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "Timestamp",
4
+ "description": "An ISO 8601 combined date and time timestamp",
5
+ "type": "string",
6
+ "pattern": "^$|^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T(2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9](Z|[+](2[0-3]|[01][0-9]):[0-5][0-9])$"
7
+ }
@@ -0,0 +1,58 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "Trustline",
4
+ "description": "A simplified Trustline object used by the ripple-rest API",
5
+ "type": "object",
6
+ "properties": {
7
+ "account": {
8
+ "description": "The account from whose perspective this trustline is being viewed",
9
+ "$ref": "RippleAddress"
10
+ },
11
+ "counterparty": {
12
+ "description": "The other party in this trustline",
13
+ "$ref": "RippleAddress"
14
+ },
15
+ "currency": {
16
+ "description": "The code of the currency in which this trustline denotes trust",
17
+ "$ref": "Currency"
18
+ },
19
+ "limit": {
20
+ "description": "The maximum value of the currency that the account may hold issued by the counterparty",
21
+ "$ref": "FloatString"
22
+ },
23
+ "reciprocated_limit": {
24
+ "description": "The maximum value of the currency that the counterparty may hold issued by the account",
25
+ "$ref": "FloatString"
26
+ },
27
+ "authorized_by_account": {
28
+ "description": "Set to true if the account has explicitly authorized the counterparty to hold currency it issues. This is only necessary if the account's settings include require_authorization_for_incoming_trustlines",
29
+ "type": "boolean"
30
+ },
31
+ "authorized_by_counterparty": {
32
+ "description": "Set to true if the counterparty has explicitly authorized the account to hold currency it issues. This is only necessary if the counterparty's settings include require_authorization_for_incoming_trustlines",
33
+ "type": "boolean"
34
+ },
35
+ "account_allows_rippling": {
36
+ "description": "If true it indicates that the account allows pairwise rippling out through this trustline",
37
+ "type": "boolean"
38
+ },
39
+ "counterparty_allows_rippling": {
40
+ "description": "If true it indicates that the counterparty allows pairwise rippling out through this trustline",
41
+ "type": "boolean"
42
+ },
43
+ "ledger": {
44
+ "description": "The string representation of the index number of the ledger containing this trustline or, in the case of historical queries, of the transaction that modified this Trustline",
45
+ "type": "string",
46
+ "pattern": "^[0-9]+$"
47
+ },
48
+ "hash": {
49
+ "description": "If this object was returned by a historical query this value will be the hash of the transaction that modified this Trustline. The transaction hash is used throughout the Ripple Protocol to uniquely identify a particular transaction",
50
+ "$ref": "Hash256"
51
+ },
52
+ "previous": {
53
+ "description": "If the trustline was changed this will be a full Trustline object representing the previous values. If the previous object also had a previous object that will be removed to reduce data complexity. Trustline changes can be walked backwards by querying the API for previous.hash repeatedly",
54
+ "$ref": "Trustline"
55
+ }
56
+ },
57
+ "required": ["account", "limit"]
58
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "UINT32",
4
+ "description": "A string representation of an unsigned 32-bit integer (0-4294967295)",
5
+ "type": "string",
6
+ "pattern": "^$|^(429496729[0-5]|42949672[0-8][0-9]|4294967[01][0-9]{2}|429496[0-6][0-9]{3}|42949[0-5][0-9]{4}|4294[0-8][0-9]{5}|429[0-3][0-9]{6}|42[0-8][0-9]{7}|4[01][0-9]{8}|[1-3][0-9]{9}|[1-9][0-9]{8}|[1-9][0-9]{7}|[1-9][0-9]{6}|[1-9][0-9]{5}|[1-9][0-9]{4}|[1-9][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[0-9])$"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "URL",
4
+ "description": "A standard URL",
5
+ "type": "string",
6
+ "pattern": "^(ftp:\/\/|http:\/\/|https:\/\/)?([A-Za-z0-9_]+:{0,1}[A-Za-z0-9_]*@)?(^([ \t\r\n\f])+)(:[0-9]+)?(\/|\/([[A-Za-z0-9_]#!:.?+=&%@!-\/]))?$"
7
+ }
@@ -0,0 +1,12 @@
1
+ module RippleRest
2
+ generate_schema :Notification
3
+
4
+ class Notifications
5
+ attr_accessor :account
6
+
7
+ def [] hash
8
+ Notification.new RippleRest
9
+ .get("v1/accounts/#{account.address}/notifications/#{hash}")["notification"]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ module RippleRest
2
+ generate_schema :Order
3
+
4
+ class Order
5
+ end
6
+ end
@@ -0,0 +1,72 @@
1
+ module RippleRest
2
+ generate_schema :Payment
3
+
4
+ class Payment
5
+ def account
6
+ @account
7
+ end
8
+
9
+ def account= val
10
+ @account = val
11
+ self.source_account = val.address
12
+ end
13
+
14
+ def submit
15
+ @account.require_secret
16
+
17
+ hash = {}
18
+ hash["payment"] = self.to_hash
19
+ hash["secret"] = @account.secret
20
+ hash["client_resource_id"] = client_resource_id = RippleRest.next_uuid
21
+
22
+ RippleRest.post("v1/payments", hash)["client_resource_id"]
23
+ end
24
+
25
+ attr_accessor :client_resource_id
26
+ end
27
+
28
+ class Payments
29
+ attr_accessor :account
30
+
31
+ def [] hash
32
+ Payment.new RippleRest
33
+ .get("v1/accounts/#{account.address}/payments/#{hash}")["payment"]
34
+ end
35
+
36
+ def find_path destination_account, destination_amount, source_currencies = nil
37
+ uri = "v1/accounts/#{account.address}/payments/paths/#{destination_account.to_s}/#{destination_amount.to_s}"
38
+
39
+ if source_currencies
40
+ cur = source_currencies.join(",")
41
+ uri += "?#{cur}"
42
+ end
43
+
44
+ RippleRest.get(uri)["payments"].map(&Payment.method(:new)).map do |i|
45
+ i.account = account
46
+ end
47
+ end
48
+
49
+ def create destination_account, destination_amount
50
+ payment = Payment.new
51
+ payment.account = account
52
+ payment.destination_account = destination_account.to_s
53
+ payment.destination_amount = Amount.from_string(destination_amount)
54
+ payment
55
+ end
56
+
57
+ def query options = {}
58
+ qs = ""
59
+ if options && options.size > 0
60
+ qs = "?" + options.map { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')
61
+ end
62
+
63
+ uri = "v1/accounts/#{account.address}/payments#{qs}"
64
+
65
+ RippleRest.get(uri)["payments"].map do |i|
66
+ payment = Payment.new(i["payment"])
67
+ payment.client_resource_id = i["client_resource_id"]
68
+ payment
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,33 @@
1
+ module RippleRest
2
+
3
+ generate_schema :Trustline
4
+ class Trustlines
5
+ include Enumerable
6
+
7
+ attr_accessor :account
8
+
9
+ def initialize data
10
+ @data = data
11
+ end
12
+
13
+ def each *args, &block
14
+ @data.each *args, &block
15
+ end
16
+
17
+ def add obj
18
+ raise ArgumentError.new("Account is missing.") unless account
19
+ account.require_secret
20
+
21
+ hash = {}
22
+ hash["secret"] = account.secret
23
+
24
+ if obj.is_a? String
25
+ hash["trustline"] = { "limit" => obj }
26
+ else
27
+ hash["trustline"] = obj.to_hash
28
+ end
29
+
30
+ RippleRest.post "v1/accounts/#{account.address}/trustlines", hash
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module RippleRest
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ripple-rest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yeechan Lu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.7
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.6.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: autoparse
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.3.3
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.3.3
46
+ description: A ruby wrapper for Ripple REST API.
47
+ email: ripple-rest@orzfly.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - lib/ripple-rest/schemas/json.rb
53
+ - lib/ripple-rest/schemas/trustlines.rb
54
+ - lib/ripple-rest/schemas/payments.rb
55
+ - lib/ripple-rest/schemas/amount.rb
56
+ - lib/ripple-rest/schemas/account_settings.rb
57
+ - lib/ripple-rest/schemas/balance.rb
58
+ - lib/ripple-rest/schemas/notifications.rb
59
+ - lib/ripple-rest/schemas/order.rb
60
+ - lib/ripple-rest/schemas/account.rb
61
+ - lib/ripple-rest/version.rb
62
+ - lib/ripple-rest/errors.rb
63
+ - lib/ripple-rest.rb
64
+ - lib/ripple-rest/schemas/json/Notification.json
65
+ - lib/ripple-rest/schemas/json/Hash256.json
66
+ - lib/ripple-rest/schemas/json/Hash128.json
67
+ - lib/ripple-rest/schemas/json/Order.json
68
+ - lib/ripple-rest/schemas/json/Timestamp.json
69
+ - lib/ripple-rest/schemas/json/RippleAddress.json
70
+ - lib/ripple-rest/schemas/json/ResourceId.json
71
+ - lib/ripple-rest/schemas/json/FloatString.json
72
+ - lib/ripple-rest/schemas/json/AccountSettings.json
73
+ - lib/ripple-rest/schemas/json/Payment.json
74
+ - lib/ripple-rest/schemas/json/Balance.json
75
+ - lib/ripple-rest/schemas/json/Amount.json
76
+ - lib/ripple-rest/schemas/json/Trustline.json
77
+ - lib/ripple-rest/schemas/json/URL.json
78
+ - lib/ripple-rest/schemas/json/Currency.json
79
+ - lib/ripple-rest/schemas/json/UINT32.json
80
+ - LICENSE
81
+ - ROADMAP.md
82
+ - CHANGELOG.md
83
+ - README.md
84
+ homepage: http://github.com/orzFly/ruby-ripple-rest
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ segments:
97
+ - 0
98
+ hash: -284765535
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: 1.3.6
105
+ requirements: []
106
+ rubyforge_project: ripple-rest
107
+ rubygems_version: 1.8.23
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: A ruby wrapper for Ripple REST API.
111
+ test_files: []