ripple-rest 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/README.md +8 -0
  2. data/lib/ripple-rest.rb +4 -8
  3. data/lib/ripple-rest/{schemas/json.rb → generated-schemas.rb} +154 -149
  4. data/lib/ripple-rest/{schemas/payments.rb → helpers.rb} +129 -22
  5. data/lib/ripple-rest/rest-object.rb +191 -0
  6. data/lib/ripple-rest/schemas.rb +82 -0
  7. data/lib/ripple-rest/version.rb +2 -2
  8. metadata +6 -43
  9. data/lib/ripple-rest/schemas/account.rb +0 -84
  10. data/lib/ripple-rest/schemas/account_settings.rb +0 -22
  11. data/lib/ripple-rest/schemas/amount.rb +0 -21
  12. data/lib/ripple-rest/schemas/balance.rb +0 -8
  13. data/lib/ripple-rest/schemas/json/AccountSettings.json +0 -63
  14. data/lib/ripple-rest/schemas/json/Amount.json +0 -28
  15. data/lib/ripple-rest/schemas/json/Balance.json +0 -23
  16. data/lib/ripple-rest/schemas/json/Currency.json +0 -7
  17. data/lib/ripple-rest/schemas/json/FloatString.json +0 -7
  18. data/lib/ripple-rest/schemas/json/Hash128.json +0 -7
  19. data/lib/ripple-rest/schemas/json/Hash256.json +0 -7
  20. data/lib/ripple-rest/schemas/json/Notification.json +0 -58
  21. data/lib/ripple-rest/schemas/json/Order.json +0 -82
  22. data/lib/ripple-rest/schemas/json/Payment.json +0 -98
  23. data/lib/ripple-rest/schemas/json/ResourceId.json +0 -7
  24. data/lib/ripple-rest/schemas/json/RippleAddress.json +0 -7
  25. data/lib/ripple-rest/schemas/json/Timestamp.json +0 -7
  26. data/lib/ripple-rest/schemas/json/Trustline.json +0 -58
  27. data/lib/ripple-rest/schemas/json/UINT32.json +0 -7
  28. data/lib/ripple-rest/schemas/json/URL.json +0 -7
  29. data/lib/ripple-rest/schemas/json/_generate.rb +0 -73
  30. data/lib/ripple-rest/schemas/notifications.rb +0 -19
  31. data/lib/ripple-rest/schemas/trustlines.rb +0 -40
@@ -1,98 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
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
- }
@@ -1,58 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
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
- }
@@ -1,73 +0,0 @@
1
- require 'json'
2
- schemas = {}
3
- Dir["*.json"].each do |i|
4
- key = File.basename(i, ".json")
5
- schemas[key] = JSON.parse File.read i
6
- end
7
-
8
- puts <<'EOF'
9
- require 'autoparse'
10
-
11
- module RippleRest
12
- # @!group Private APIs
13
- # @api private
14
- def self.generate_schema(fn)
15
- RippleRest.const_set fn, AutoParse.generate(JSON.parse(File.read(File.join(File.join(File.dirname(__FILE__), "json"), "#{fn}.json"))), :uri => "#{fn}")
16
- end
17
- # @!endgroup
18
-
19
- generate_schema :Currency
20
- generate_schema :FloatString
21
- generate_schema :Hash128
22
- generate_schema :Hash256
23
- generate_schema :ResourceId
24
- generate_schema :RippleAddress
25
- generate_schema :Timestamp
26
- generate_schema :UINT32
27
- generate_schema :URL
28
-
29
- generate_schema :Order
30
- generate_schema :Balance
31
- generate_schema :Notification
32
- generate_schema :Payment
33
- generate_schema :Trustline
34
- generate_schema :AccountSettings
35
- generate_schema :Amount
36
-
37
- EOF
38
- schemas.values.select{|i|i["type"] == "object"}.each do |json|
39
- key = json["title"]
40
- puts " # #{json["description"]}"
41
- puts " class #{key} < AutoParse::Instance"
42
-
43
- json["properties"].each do |k, v|
44
- type = ""
45
- if v["type"] == "string" && v["pattern"]
46
- type = "[String] +#{v["pattern"].inspect}+"
47
- elsif v["type"] == "string"
48
- type = "[String]"
49
- elsif v["type"] == "boolean"
50
- type = "[Boolean]"
51
- elsif v["type"] == "float"
52
- type = "[Float]"
53
- elsif v["$ref"] == "FloatString"
54
- type = "[String<FloatString>]" # BigDecimal
55
- elsif v["$ref"] == "UInt32"
56
- type = "[UInt32]"
57
- elsif v["$ref"] && schemas[v["$ref"]]["type"] == "string"
58
- type = "[String<#{v["$ref"]}>] +#{schemas[v["$ref"]]["pattern"].inspect}+"
59
- elsif v["$ref"]
60
- type = "[#{v["$ref"]}]"
61
- elsif
62
- type = "[#{v["type"]}]"
63
- end
64
-
65
- puts " # @!attribute #{k}"
66
- puts " # #{v["description"]}"
67
- puts " # @return #{type}"
68
- puts
69
- puts
70
- end
71
- puts " end"
72
- end
73
- puts "end"
@@ -1,19 +0,0 @@
1
- module RippleRest
2
- class Notifications
3
- # @return [Account]
4
- attr_accessor :account
5
-
6
- # Get notifications.
7
- #
8
- # Clients using notifications to monitor their account activity should pay particular attention to the `state` and `result` fields. The `state` field will either be `validated` or `failed` and represents the finalized status of that transaction. The `result` field will be `tesSUCCESS` if the `state` was validated. If the transaction failed, `result` will contain the `rippled` or `ripple-lib` error code.
9
- #
10
- # Notifications have `next_notification_url` and `previous_notification_url`'s. Account notifications can be polled by continuously following the `next_notification_url`, and handling the resultant notifications, until the `next_notification_url` is an empty string. This means that there are no new notifications but, as soon as there are, querying the same URL that produced this notification in the first place will return the same notification but with the `next_notification_url` set.
11
- # @raise [RippleRestError] if RippleRest server returns an error
12
- # @raise [ProtocolError] if protocol is wrong or network is down
13
- # @return [Notification]
14
- def [] hash
15
- Notification.new RippleRest
16
- .get("v1/accounts/#{account.address}/notifications/#{hash}")["notification"]
17
- end
18
- end
19
- end
@@ -1,40 +0,0 @@
1
- module RippleRest
2
- class Trustlines
3
- include Enumerable
4
-
5
- # @return [Account]
6
- attr_accessor :account
7
-
8
- def initialize data
9
- @data = data
10
- end
11
-
12
- # Use with Enumerable
13
- def each *args, &block
14
- @data.each *args, &block
15
- end
16
-
17
- # Add trustline
18
- # @param obj [String, Hash] Either a string representation of trustline limit, Hash containing value, currency, counterparty or a string form value/currency/counterparty.
19
- # @param allow_rippling [Boolean] See [here](https://ripple.com/wiki/No_Ripple) for details
20
- # @raise [ArgumentError] if secret is missing from the Account object
21
- # @raise [RippleRestError] if RippleRest server returns an error
22
- # @raise [ProtocolError] if protocol is wrong or network is down
23
- def add obj, allow_rippling = true
24
- raise ArgumentError.new("Account is missing.") unless account
25
- account.require_secret
26
-
27
- hash = {}
28
- hash["allow_rippling"] = allow_rippling
29
- hash["secret"] = account.secret
30
-
31
- if obj.is_a? String
32
- hash["trustline"] = { "limit" => obj }
33
- else
34
- hash["trustline"] = obj.to_hash
35
- end
36
-
37
- RippleRest.post "v1/accounts/#{account.address}/trustlines", hash
38
- end
39
- end
40
- end