arweave 1.0.3 → 1.1.0

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
  SHA256:
3
- metadata.gz: df6c4a7ec670a6671f84a3e7e480eeae4a9169523944c50696d2b46aa5818e26
4
- data.tar.gz: 11bfed6127a26a338a28c480b0c6b97490a09bbef275aec75f9fa3a8d9424117
3
+ metadata.gz: 1b5d27312d0da2f5857127b809dca34c0f1006e313ca0735f3caed5ea8799706
4
+ data.tar.gz: e089e33e425386c2c09e1a46a775915b2fcc9af70c78cb4836080bbcd672d17a
5
5
  SHA512:
6
- metadata.gz: accb1b93ee65e402799bcc882d6961327cf51e3dd2492120b6c14c52c882385d13f36754f0440d39f0070847b4fc8da5bba6706d6065f2a55d85ac71c9032253
7
- data.tar.gz: 9694281e4f4a6b57f15536f4d779bdd3fdd16833fe864ee7efe5e0d19359c2dcec613c44a099e8917337dfd7425c72b506b36c5ee68df90bf7aa79ae878f100d
6
+ metadata.gz: 32adbb4d74b2089454c47830e00f8a7ea7d48cda4c04bfe3aa9cd77f6b28a60e5e84bd6c41fcb8a8365fa00f6923fefe44a5360032f75d7e00944c22311cef9e
7
+ data.tar.gz: 3f5dda23ca893584111fac85393c0d4fafb9406b33ff37e52e5671165724ab517c6ee1f2e0e03671eea276333ff04e8c3f82e1f2753a97e4aa7e72deab2fb81c
data/README.md CHANGED
@@ -130,3 +130,47 @@ balance.winston.to_i # => 249891527825
130
130
  ```ruby
131
131
  wallet.last_transaction_id # => "BsHjWHBwSlmW_VgOcgLmsQacQjpohmvVDLMMVyuAkie"
132
132
  ```
133
+
134
+ ## Directories
135
+ Directories are an abstract logical grouping around transactions which is implemented using path manifests. For more information, you can take a look at [path manifests](https://github.com/ArweaveTeam/arweave/wiki/Path-Manifests) documentation.
136
+
137
+ ### Create a directory
138
+ To create a directory, first you must have transaction ids you want to put under the new directory and then specify a name for them.
139
+ ```ruby
140
+ directory = Arweave::Directory.new(paths: { 'index.html' => 'BsHjWHBwSlmW_VgOcgLmsQacQjpohmvVDLMMVyuAkie' })
141
+ # => #<Arweave::Directory:0x00007ff3400b2350 @paths={...}>
142
+ ```
143
+ Then you should get the transaction out of the directory instance and commit it.
144
+ ```ruby
145
+ transaction = directory.transaction
146
+ # => #<Arweavev::Transaction:0x00007f9b61299330 @attributes={...}>
147
+ transaction.sign(wallet).commit
148
+ # => #<Arweavev::Transaction:0x00007f9b61299330 @attributes={...}>
149
+ ```
150
+ Then you can check your files in the directory using the name you've specified for the files. The endpoint for checking directory files is `/:dir_transaction_id/:filename`. For example
151
+ ```
152
+ https:/arweave.net/JxiKsfr2es55AuCTSZg5oJLz7j4phRgireZt5SpChE/index.html
153
+ ```
154
+
155
+ ### Directory index
156
+ Arweave creates an HTML file to index your files in a directory, but if you like, you can set one of the files in the paths argument as index file.
157
+ ```ruby
158
+ directory =
159
+ Arweave::Directory.new(
160
+ index: 'index.html',
161
+ paths: {
162
+ 'index.html' => 'BsHjWHBwSlmW_VgOcgLmsQacQjpohmvVDLMMVyuAkie',
163
+ 'contact.html' => '-3U2-Oks289pQPH0Umz9Fy0G1Ti2UMlQYIr7NGIYL_M',
164
+ }
165
+ ) # => #<Arweave::Directory:0x00007ff3400b2350 @index="...", @paths={...}>
166
+ ```
167
+
168
+ ### Adding files to a directory
169
+ You can add files to a directory using the `add` method on a directory instance.
170
+ ```ruby
171
+ directory.add('about.html' => 'LhT2WHBwFbv9_Pey67LmsQacQjpZxsyjDLMMVyuAkie')
172
+ # => #<Arweave::Directory:0x00007ff3400b2350 @index="...", @paths={...}>
173
+ ```
174
+ **NOTE**: You should add the files to the directory before commiting the transaction,
175
+ else nothing will be added to the directory. In case you want to modify your directory,
176
+ you should create a new transaction for that.
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.summary = %q{Arweave SDK}
10
10
  spec.description = %q{Ruby SDK for Arweave decentralized services}
11
11
  spec.homepage = 'https://github.com/LicenseRocks/arweave-ruby'
12
- spec.license = 'GPL v3'
12
+ spec.license = 'GPL-3.0'
13
13
  spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
14
 
15
15
  spec.metadata['homepage_uri'] = spec.homepage
@@ -3,4 +3,5 @@ require 'arweave/client'
3
3
  require 'arweave/api'
4
4
  require 'arweave/transaction'
5
5
  require 'arweave/wallet'
6
+ require 'arweave/directory'
6
7
  require 'arweave/errors'
@@ -0,0 +1,39 @@
1
+ module Arweave
2
+ class Directory
3
+ MANIFEST = 'arweave/paths'
4
+ VERSION = '0.1.0'
5
+
6
+ def initialize(index: nil, paths: {})
7
+ if index && !paths.keys.include?(index)
8
+ raise PathDoesNotExist.new('`index` path should be included in `paths` argument')
9
+ end
10
+
11
+ @index = index
12
+ @paths = paths
13
+ end
14
+
15
+ def add(paths)
16
+ @paths.merge!(paths)
17
+ self
18
+ end
19
+
20
+ def paths
21
+ @paths.reduce({}) do |acc, (key, value)|
22
+ acc.merge(key => { id: value })
23
+ end
24
+ end
25
+
26
+ def as_json(options = {})
27
+ {
28
+ manifest: MANIFEST,
29
+ version: VERSION,
30
+ **(@index ? { index: { path: @index } } : {}),
31
+ paths: paths
32
+ }
33
+ end
34
+
35
+ def transaction
36
+ Transaction.new(data: self.to_json).add_tag(name: 'Content-Type', value: 'application/x.arweave-manifest+json')
37
+ end
38
+ end
39
+ end
@@ -1,4 +1,5 @@
1
1
  module Arweave
2
2
  class TransactionNotFound < StandardError; end
3
3
  class TransactionNotSigned < StandardError; end
4
+ class PathDoesNotExist < StandardError; end
4
5
  end
@@ -1,3 +1,3 @@
1
1
  module Arweave
2
- VERSION = '1.0.3'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arweave
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aref Aslani
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-30 00:00:00.000000000 Z
11
+ date: 2020-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-jwt
@@ -73,13 +73,14 @@ files:
73
73
  - lib/arweave.rb
74
74
  - lib/arweave/api.rb
75
75
  - lib/arweave/client.rb
76
+ - lib/arweave/directory.rb
76
77
  - lib/arweave/errors.rb
77
78
  - lib/arweave/transaction.rb
78
79
  - lib/arweave/version.rb
79
80
  - lib/arweave/wallet.rb
80
81
  homepage: https://github.com/LicenseRocks/arweave-ruby
81
82
  licenses:
82
- - GPL v3
83
+ - GPL-3.0
83
84
  metadata:
84
85
  homepage_uri: https://github.com/LicenseRocks/arweave-ruby
85
86
  source_code_uri: https://github.com/LicenseRocks/arweave-ruby