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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripple-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,56 +27,19 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
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
30
  description: A ruby wrapper for Ripple REST API.
47
31
  email: ripple-rest@orzfly.com
48
32
  executables: []
49
33
  extensions: []
50
34
  extra_rdoc_files: []
51
35
  files:
52
- - lib/ripple-rest/schemas/json/_generate.rb
53
- - lib/ripple-rest/schemas/json.rb
54
- - lib/ripple-rest/schemas/trustlines.rb
55
- - lib/ripple-rest/schemas/payments.rb
56
- - lib/ripple-rest/schemas/amount.rb
57
- - lib/ripple-rest/schemas/account_settings.rb
58
- - lib/ripple-rest/schemas/balance.rb
59
- - lib/ripple-rest/schemas/notifications.rb
60
- - lib/ripple-rest/schemas/account.rb
36
+ - lib/ripple-rest/generated-schemas.rb
37
+ - lib/ripple-rest/schemas.rb
61
38
  - lib/ripple-rest/version.rb
62
39
  - lib/ripple-rest/errors.rb
40
+ - lib/ripple-rest/helpers.rb
41
+ - lib/ripple-rest/rest-object.rb
63
42
  - 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
43
  - LICENSE
81
44
  - ROADMAP.md
82
45
  - CHANGELOG.md
@@ -95,7 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
58
  version: '0'
96
59
  segments:
97
60
  - 0
98
- hash: 9938735
61
+ hash: -728632721
99
62
  required_rubygems_version: !ruby/object:Gem::Requirement
100
63
  none: false
101
64
  requirements:
@@ -1,84 +0,0 @@
1
- module RippleRest
2
- class Account
3
- # Account's Address (rXXXXXX...)
4
- # @return [String]
5
- attr_accessor :address
6
-
7
- # Account's secret
8
- # @return [String]
9
- attr_accessor :secret
10
-
11
- def initialize address, secret = nil
12
- @address = address
13
- @secret = secret
14
- end
15
-
16
- # Get an account's existing balances.
17
- # This includes XRP balance (which does not include a counterparty) and trustline balances.
18
- # @return [Array<Balance>]
19
- # @raise [RippleRestError] if RippleRest server returns an error
20
- # @raise [ProtocolError] if protocol is wrong or network is down
21
- def balances
22
- RippleRest
23
- .get("v1/accounts/#{@address}/balances")["balances"]
24
- .map(&Balance.method(:new))
25
- end
26
-
27
- # Returns a Trustlines object for this account.
28
- # @return [Trustlines]
29
- # @raise [RippleRestError] if RippleRest server returns an error
30
- # @raise [ProtocolError] if protocol is wrong or network is down
31
- def trustlines
32
- data = RippleRest
33
- .get("v1/accounts/#{@address}/trustlines")["trustlines"]
34
- .map(&Trustline.method(:new))
35
- obj = Trustlines.new data
36
- obj.account = self
37
- obj
38
- end
39
-
40
- # Returns a AccountSettings object for this account.
41
- # @return [AccountSettings]
42
- # @raise [RippleRestError] if RippleRest server returns an error
43
- # @raise [ProtocolError] if protocol is wrong or network is down
44
- def settings
45
- data = RippleRest.get("v1/accounts/#{@address}/settings")["settings"]
46
- obj = AccountSettings.new data
47
- obj.account = self
48
- obj
49
- end
50
-
51
- # Returns a Notifications object for this account.
52
- # @return [Notifications]
53
- def notifications
54
- @notifications ||= lambda {
55
- obj = Notifications.new
56
- obj.account = self
57
- obj
58
- }.call
59
- end
60
-
61
- # Returns a Payments object for this account.
62
- # @return [Payments]
63
- def payments
64
- payments ||= lambda {
65
- obj = Payments.new
66
- obj.account = self
67
- obj
68
- }.call
69
- end
70
-
71
- # Returns the address of attribute address.
72
- # @return [String]
73
- def to_s
74
- address
75
- end
76
-
77
- # @!group Private APIs
78
- # @api private
79
- def require_secret
80
- raise ArgumentError.new("Secret is required for this operation.") unless secret
81
- end
82
- # @!endgroup
83
- end
84
- end
@@ -1,22 +0,0 @@
1
- module RippleRest
2
- class AccountSettings
3
- # @return [Account]
4
- attr_accessor :account
5
-
6
- # Save the account settings
7
- # @raise [ArgumentError] if secret is missing from the Account object
8
- # @raise [RippleRestError] if RippleRest server returns an error
9
- # @raise [ProtocolError] if protocol is wrong or network is down
10
- # @return [void]
11
- def save
12
- raise ArgumentError.new("Account is missing.") unless account
13
-
14
- account.require_secret
15
-
16
- hash = to_hash
17
- hash["secret"] = account.secret
18
-
19
- RippleRest.post "v1/accounts/#{account.address}/settings", hash
20
- end
21
- end
22
- end
@@ -1,21 +0,0 @@
1
- module RippleRest
2
- class Amount
3
- # @return [String]
4
- def to_s
5
- "#{value}+#{currency}#{issuer.to_s.size > 0 ? ("+" + issuer) : ""}"
6
- end
7
-
8
- # @param s [String, Amount] an Amount object or a String like "1+XRP" or "1+USD+r..."
9
- # @return [Amount]
10
- def self.from_string s
11
- return s if s.is_a?(Amount)
12
-
13
- arr = s.split("+")
14
- Amount.new({
15
- "value" => arr[0],
16
- "currency" => arr[1],
17
- "issuer" => arr[2]
18
- })
19
- end
20
- end
21
- end
@@ -1,8 +0,0 @@
1
- module RippleRest
2
- class Balance
3
- # @return [String]
4
- def inspect
5
- "#{value.to_s} #{currency}#{counterparty.to_s.size > 0 ? " (#{counterparty})" : ""}"
6
- end
7
- end
8
- end
@@ -1,63 +0,0 @@
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
- }
@@ -1,28 +0,0 @@
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
- }
@@ -1,23 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
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
- }
@@ -1,58 +0,0 @@
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
- }
@@ -1,82 +0,0 @@
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
- }