sequence-sdk 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13297573e64f55ffcba16f88365a13ee4540d7c3
4
- data.tar.gz: e94b5d7ab7f11a8dfe48140fceea4c921d56b2d9
3
+ metadata.gz: da13e33f0caa12bd428d4a97a545e42603369f68
4
+ data.tar.gz: b660490b8b64779fa01eb22ddfbb94a609946955
5
5
  SHA512:
6
- metadata.gz: f3231c2b04e1e9a99a8318aac330fdd4ea1eb1bb54ab0510c9cbfa49335454fbfaaa8114d823bc70a799ce89ef6617c9502940f33c48ae4dd5240bd2a2939dea
7
- data.tar.gz: dad7408ea6e7c10eb8e793faffa29150e95cdaf39a4c651c7566eea2760c46ed0a16e60a545b6993f3e1aab48921dfd03b624a7fa9c96e2511c528c5f0d311d5
6
+ metadata.gz: 184219f173c60a722b8f8356801f24897c17dc420c114fbf7609285135ae7dbc211bbc1a23fa185d5a97bb97436e401fdd74751f2eca88eff1e910e14117bab2
7
+ data.tar.gz: c7309542abbea40fbbd42a29072a1751b61693f06dd133ea4778ff85638fcc62b177916ded02a84b46c936d0b4c7d197a5ed151dc1ddb2da16dec3372d6599ab
data/README.md CHANGED
@@ -4,14 +4,17 @@
4
4
 
5
5
  ### Get the gem
6
6
 
7
- The Ruby SDK is available [via Rubygems](https://rubygems.org/gems/sequence-sdk).
7
+ The Ruby SDK is available
8
+ [via Rubygems](https://rubygems.org/gems/sequence-sdk).
8
9
 
9
- Ruby 2.0 or greater is required. We strongly recommend upgrading to Ruby 2.1 or greater, as [Ruby 2.0 has reached end-of-life](https://www.ruby-lang.org/en/downloads/branches/) and will no longer receive security updates and bugfixes.
10
+ Ruby >= 2.2 is required. We recommend upgrading to Ruby >= 2.3. See
11
+ [Ruby Maintenance Branches](https://www.ruby-lang.org/en/downloads/branches/)
12
+ for the language's schedule for security and bug fixes.
10
13
 
11
- For most applications, you can simply add the following to your `Gemfile`:
14
+ Add the following to your `Gemfile`:
12
15
 
13
16
  ```
14
- gem 'sequence-sdk', '~> 1.0.0'
17
+ gem 'sequence-sdk'
15
18
  ```
16
19
 
17
20
  ### In your code
@@ -20,11 +23,12 @@ gem 'sequence-sdk', '~> 1.0.0'
20
23
  require 'sequence'
21
24
 
22
25
  ledger = Sequence::Client.new(
23
- url: 'https://example-ledger.sequenceledger.com',
24
- access_token: '...'
26
+ ledger: 'ledger',
27
+ credential: '...'
25
28
  )
26
29
  ```
27
30
 
28
31
  ### Documentation
29
32
 
30
- Comprehensive instructions and examples are available in the [developer documentation](https://dashboard.sequenceledger.com/docs).
33
+ Comprehensive instructions and examples are available in the
34
+ [developer documentation](https://dashboard.seq.com/docs).
data/lib/sequence.rb CHANGED
File without changes
@@ -6,29 +6,30 @@ require_relative './response_object'
6
6
  module Sequence
7
7
  # A container for asset balances on a ledger.
8
8
  class Account < ResponseObject
9
-
10
9
  # @!attribute [r] id
11
- # Unique, auto-generated identifier.
10
+ # Unique, auto-generated identifier.
12
11
  # @return [String]
13
12
  attrib :id
14
13
 
15
14
  # @!attribute [r] alias
16
- # Unique, user-specified identifier.
15
+ # Unique, user-specified identifier.
17
16
  # @return [String]
18
17
  attrib :alias
19
18
 
20
19
  # @!attribute [r] keys
21
- # The set of keys used for signing transactions that spend from the account.
20
+ # The set of keys used for signing transactions that spend from the
21
+ # account.
22
22
  # @return [Array<Key>]
23
23
  attrib(:keys) { |raw| raw.map { |k| Key.new(k) } }
24
24
 
25
25
  # @!attribute [r] quorum
26
- # The number of keys required to sign transactions that spend from the account.
26
+ # The number of keys required to sign transactions that spend from the
27
+ # account.
27
28
  # @return [Integer]
28
29
  attrib :quorum
29
30
 
30
31
  # @!attribute [r] tags
31
- # User-specified key-value data describing the account.
32
+ # User-specified key-value data describing the account.
32
33
  # @return [Hash]
33
34
  attrib :tags
34
35
 
@@ -39,33 +40,65 @@ module Sequence
39
40
 
40
41
  class ClientModule < Sequence::ClientModule
41
42
  # Creates a new account in the ledger.
42
- # @param [Hash] opts Options hash
43
- # @option opts [String] alias Unique, user-specified identifier.
44
- # @option opts [Array<Hash>, Array<Sequence::Key>] keys The set of keys used for signing transactions that spend from the account. A key can be either a key object, or a hash containing either an `id` or `alias` field.
45
- # @option opts [Integer] quorum The number of keys required to sign transactions that spend from the account. Defaults to the number of keys provided.
46
- # @option opts [Hash] tags User-specified key-value data describing the account.
43
+ # @param [Hash] opts
44
+ # Options hash
45
+ # @option opts [String] alias
46
+ # Unique, user-specified identifier.
47
+ # @option opts [Array<Hash>, Array<Sequence::Key>] keys
48
+ # The keys used for signing transactions that spend from the account. A
49
+ # key can be either a key object, or a hash containing either an `id` or
50
+ # `alias` field.
51
+ # @option opts [Integer] quorum
52
+ # The number of keys required to sign transactions that spend from the
53
+ # account. Defaults to the number of keys provided.
54
+ # @option opts [Hash] tags
55
+ # User-specified key-value data describing the account.
47
56
  # @return [Account]
48
- def create(opts)
49
- opts = {client_token: SecureRandom.uuid}.merge(opts)
57
+ def create(opts = {})
58
+ validate_inclusion_of!(opts, :alias, :keys, :quorum, :tags)
59
+ validate_required!(opts, :keys)
50
60
  Account.new(client.session.request('create-account', opts))
51
61
  end
52
62
 
53
63
  # Updates an account's tags.
54
- # @param [Hash] opts Options hash
55
- # @option opts [String] id The ID of the account. Either an ID or alias should be provided, but not both.
56
- # @option opts [String] alias The alias of the account. Either an ID or alias should be provided, but not both.
57
- # @option opts [Hash] tags A new set of tags, which will replace the existing tags.
64
+ # @param [Hash] opts
65
+ # Options hash
66
+ # @option opts [String] id
67
+ # The ID of the account. Either an ID or alias should be provided, but
68
+ # not both.
69
+ # @option opts [String] alias
70
+ # The alias of the account. Either an ID or alias should be provided,
71
+ # but not both.
72
+ # @option opts [Hash] tags
73
+ # A new set of tags, which will replace the existing tags.
58
74
  # @return [void]
59
- def update_tags(opts)
75
+ def update_tags(opts = {})
76
+ validate_inclusion_of!(opts, :id, :alias, :tags)
77
+ if (opts[:id].nil? || opts[:id].empty?) &&
78
+ (opts[:alias].nil? || opts[:alias].empty?)
79
+ raise ArgumentError, ':id or :alias (but not both) must be provided'
80
+ end
60
81
  client.session.request('update-account-tags', opts)
61
82
  end
62
83
 
63
84
  # Executes a query, returning an enumerable over individual accounts.
64
- # @param [Hash] opts Options hash
65
- # @option opts [String] filter A filter expression.
66
- # @option opts [Array<String|Integer>] filter_params A list of values that will be interpolated into the filter expression.
85
+ # @param [Hash] opts
86
+ # Options hash
87
+ # @option opts [String] filter
88
+ # A filter expression.
89
+ # @option opts [Array<String|Integer>] filter_params
90
+ # A list of values that will be interpolated into the filter expression.
91
+ # @option opts [Integer>] page_size
92
+ # The number of items to return in the result set.
67
93
  # @return [Query]
68
94
  def query(opts = {})
95
+ validate_inclusion_of!(
96
+ opts,
97
+ :filter,
98
+ :filter_params,
99
+ :page_size,
100
+ :after,
101
+ )
69
102
  Query.new(client, opts)
70
103
  end
71
104
  end
@@ -79,6 +112,5 @@ module Sequence
79
112
  Account.new(raw)
80
113
  end
81
114
  end
82
-
83
115
  end
84
116
  end
@@ -0,0 +1,158 @@
1
+ require_relative './client_module'
2
+ require_relative './response_object'
3
+ require_relative './query'
4
+
5
+ module Sequence
6
+ # Each transaction contains one or more actions. Action queries are designed
7
+ # to provide insights into those actions. There are two types of queries you
8
+ # can run against them; one is "list", one is "sum". List query simply returns
9
+ # a list of Action objects that match the filter; Sum query sums over the
10
+ # amount fields based on the filter and the group_by param and return
11
+ # ActionSum objects. Different from other regular API objects, the amount
12
+ # field in ActionSum represents the summation of the amount fields of those
13
+ # matching actions, and all other fields represent the parameters by which to
14
+ # group actions.
15
+ class Action < ResponseObject
16
+ # @!attribute [r] amount
17
+ # Summation of action amounts.
18
+ # @return [Integer]
19
+ attrib :amount
20
+
21
+ # @!attribute [r] type
22
+ # The type of the action. Currently, there are three options: "issue",
23
+ # "transfer", "retire".
24
+ # @return [String]
25
+ attrib :type
26
+
27
+ # @!attribute [r] id
28
+ # A unique ID.
29
+ # @return [String]
30
+ attrib :id
31
+
32
+ # @!attribute [r] transaction_id
33
+ # The ID of the transaction in which the action appears.
34
+ # @return [String]
35
+ attrib :transaction_id
36
+
37
+ # @!attribute [r] timestamp
38
+ # Time of the action.
39
+ # @return [Time]
40
+ attrib :timestamp, rfc3339_time: true
41
+
42
+ # @!attribute [r] asset_id
43
+ # The ID of the asset held by the action.
44
+ # @return [String]
45
+ attrib :asset_id
46
+
47
+ # @!attribute [r] asset_alias
48
+ # The alias of the asset held by the action.
49
+ # @return [String]
50
+ attrib :asset_alias
51
+
52
+ # @!attribute [r] asset_tags
53
+ # The tags of the asset held by the action.
54
+ # @return [Hash]
55
+ attrib :asset_tags
56
+
57
+ # @!attribute [r] source_account_id
58
+ # The ID of the source account executing the action.
59
+ # @return [String]
60
+ attrib :source_account_id
61
+
62
+ # @!attribute [r] source_account_alias
63
+ # The alias of the source account executing the action.
64
+ # @return [String]
65
+ attrib :source_account_alias
66
+
67
+ # @!attribute [r] source_account_tags
68
+ # The tags of the source account executing the action.
69
+ # @return [Hash]
70
+ attrib :source_account_tags
71
+
72
+ # @!attribute [r] destination_account_id
73
+ # The ID of the destination account affected by the action.
74
+ # @return [String]
75
+ attrib :destination_account_id
76
+
77
+ # @!attribute [r] destination_account_alias
78
+ # The alias of the destination account affected by the action.
79
+ # @return [String]
80
+ attrib :destination_account_alias
81
+
82
+ # @!attribute [r] destination_account_tags
83
+ # The tags of the destination account affected by the action.
84
+ # @return [Hash]
85
+ attrib :destination_account_tags
86
+
87
+ # @!attribute [r] reference_data
88
+ # User-specified key-value data embedded in the action.
89
+ # @return [Hash]
90
+ attrib :reference_data
91
+
92
+ class ClientModule < Sequence::ClientModule
93
+ # Executes a query, returning an enumerable over individual actions.
94
+ # @param [Hash] opts
95
+ # Options hash
96
+ # @option opts [String] filter
97
+ # A filter expression.
98
+ # @option opts [Array<String|Integer>] filter_params
99
+ # A list of values that will be interpolated into the filter expression.
100
+ # @option opts [Integer>] page_size
101
+ # The number of items to return in the result set.
102
+ # @return [Query]
103
+ def list(opts = {})
104
+ validate_inclusion_of!(
105
+ opts,
106
+ :filter,
107
+ :filter_params,
108
+ :page_size,
109
+ :after,
110
+ )
111
+ ListQuery.new(client, opts)
112
+ end
113
+
114
+ # Executes a query, returning an enumerable over individual actionsums.
115
+ # @param [Hash] opts
116
+ # Options hash
117
+ # @option opts [String] filter
118
+ # A filter expression.
119
+ # @option opts [Array<String|Integer>] filter_params
120
+ # A list of values that will be interpolated into the filter expression.
121
+ # @option opts [Array<String>] group_by
122
+ # A list of fields along which action values will be summed.
123
+ # @option opts [Integer>] page_size
124
+ # The number of items to return in the result set.
125
+ # @return [Query]
126
+ def sum(opts = {})
127
+ validate_inclusion_of!(
128
+ opts,
129
+ :filter,
130
+ :filter_params,
131
+ :group_by,
132
+ :page_size,
133
+ )
134
+ SumQuery.new(client, opts)
135
+ end
136
+ end
137
+
138
+ class ListQuery < Sequence::Query
139
+ def fetch(query)
140
+ client.session.request('list-actions', query)
141
+ end
142
+
143
+ def translate(raw)
144
+ Action.new(raw)
145
+ end
146
+ end
147
+
148
+ class SumQuery < Sequence::Query
149
+ def fetch(query)
150
+ client.session.request('sum-actions', query)
151
+ end
152
+
153
+ def translate(raw)
154
+ Action.new(raw)
155
+ end
156
+ end
157
+ end
158
+ end
@@ -8,29 +8,28 @@ require_relative './response_object'
8
8
  module Sequence
9
9
  # A type or class of value that can be tracked on a ledger.
10
10
  class Asset < ResponseObject
11
-
12
11
  # @!attribute [r] id
13
- # Unique, auto-generated identifier.
12
+ # Unique, auto-generated identifier.
14
13
  # @return [String]
15
14
  attrib :id
16
15
 
17
16
  # @!attribute [r] alias
18
- # Unique, user-specified identifier.
17
+ # Unique, user-specified identifier.
19
18
  # @return [String]
20
19
  attrib :alias
21
20
 
22
21
  # @!attribute [r] keys
23
- # The set of keys used to sign transactions that issue the asset.
22
+ # The set of keys used to sign transactions that issue the asset.
24
23
  # @return [Array<Key>]
25
24
  attrib(:keys) { |raw| raw.map { |k| Key.new(k) } }
26
25
 
27
26
  # @!attribute [r] quorum
28
- # The number of keys required to sign transactions that issue the asset.
27
+ # The number of keys required to sign transactions that issue the asset.
29
28
  # @return [Integer]
30
29
  attrib :quorum
31
30
 
32
31
  # @!attribute [r] tags
33
- # User-specified key-value data describing the asset.
32
+ # User-specified key-value data describing the asset.
34
33
  # @return [Hash]
35
34
  attrib :tags
36
35
 
@@ -41,33 +40,65 @@ module Sequence
41
40
 
42
41
  class ClientModule < Sequence::ClientModule
43
42
  # Creates a new asset in the ledger.
44
- # @param [Hash] opts Options hash
45
- # @option opts [String] alias Unique, user-specified identifier.
46
- # @option opts [Array<Hash>, Array<Sequence::Key>] keys The set of keys used for signing transactions that issue the asset. A key can be either a key object, or a hash containing either an `id` or `alias` field.
47
- # @option opts [Integer] quorum The number of keys required to sign transactions that issue the asset. Defaults to the number of keys provided.
48
- # @option opts [Hash] tags User-specified key-value data describing the asset.
43
+ # @param [Hash] opts
44
+ # Options hash
45
+ # @option opts [String] alias
46
+ # Unique, user-specified identifier.
47
+ # @option opts [Array<Hash>, Array<Sequence::Key>] keys
48
+ # The set of keys used for signing transactions that issue the asset. A
49
+ # key can be either a key object, or a hash containing either an `id` or
50
+ # `alias` field.
51
+ # @option opts [Integer] quorum
52
+ # The number of keys required to sign transactions that issue the asset.
53
+ # Defaults to the number of keys provided.
54
+ # @option opts [Hash] tags
55
+ # User-specified key-value data describing the asset.
49
56
  # @return [Asset]
50
- def create(opts)
51
- opts = {client_token: SecureRandom.uuid}.merge(opts)
57
+ def create(opts = {})
58
+ validate_inclusion_of!(opts, :alias, :keys, :quorum, :tags)
59
+ validate_required!(opts, :keys)
52
60
  Asset.new(client.session.request('create-asset', opts))
53
61
  end
54
62
 
55
63
  # Updates an asset's tags.
56
- # @param [Hash] opts Options hash
57
- # @option opts [String] id The ID of the asset. Either an ID or alias should be provided, but not both.
58
- # @option opts [String] alias The alias of the asset. Either an ID or alias should be provided, but not both.
59
- # @option opts [Hash] tags A new set of tags, which will replace the existing tags.
64
+ # @param [Hash] opts
65
+ # Options hash
66
+ # @option opts [String] id
67
+ # The ID of the asset. Either an ID or alias should be provided, but not
68
+ # both.
69
+ # @option opts [String] alias
70
+ # The alias of the asset. Either an ID or alias should be provided, but
71
+ # not both.
72
+ # @option opts [Hash] tags
73
+ # A new set of tags, which will replace the existing tags.
60
74
  # @return [void]
61
- def update_tags(opts)
75
+ def update_tags(opts = {})
76
+ validate_inclusion_of!(opts, :id, :alias, :tags)
77
+ if (opts[:id].nil? || opts[:id].empty?) &&
78
+ (opts[:alias].nil? || opts[:alias].empty?)
79
+ raise ArgumentError, ':id or :alias (but not both) must be provided'
80
+ end
62
81
  client.session.request('update-asset-tags', opts)
63
82
  end
64
83
 
65
84
  # Executes a query, returning an enumerable over individual assets.
66
- # @param [Hash] opts Options hash
67
- # @option opts [String] filter A filter expression.
68
- # @option opts [Array<String|Integer>] filter_params A list of values that will be interpolated into the filter expression.
85
+ # @param [Hash] opts
86
+ # Options hash
87
+ # @option opts [String] filter
88
+ # A filter expression.
89
+ # @option opts [Array<String|Integer>] filter_params
90
+ # A list of values that will be interpolated into the filter expression.
91
+ # @option opts [Integer>] page_size
92
+ # The number of items to return in the result set.
69
93
  # @return [Query]
70
94
  def query(opts = {})
95
+ validate_inclusion_of!(
96
+ opts,
97
+ :filter,
98
+ :filter_params,
99
+ :page_size,
100
+ :after,
101
+ )
71
102
  Query.new(client, opts)
72
103
  end
73
104
  end
@@ -81,6 +112,5 @@ module Sequence
81
112
  Asset.new(raw)
82
113
  end
83
114
  end
84
-
85
115
  end
86
116
  end