ruby-safenet 0.2.4 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +116 -0
- data/README.md +85 -25
- data/lib/safenet.rb +525 -63
- data/lib/safenet/version.rb +1 -1
- data/ruby-safenet.gemspec +3 -1
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d19872be0e8e5b424ad1d294cb7e1995ef94e5fb
|
4
|
+
data.tar.gz: ee22a0a1939f51c5f5cca9286432511c5bb51035
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd9425061291ce3644048530842316121962937b4413810d0bfca1f273623b2149b067a9439fe7fdff97893c8feee6f7a2361f77db0eac7bda46b314b77176ee
|
7
|
+
data.tar.gz: 041aa3a0e7e08cf270ad3bb4e93f9248d0f3fa412e5376d9db78da914a8597c48e0e5f22470ce65f14242e53c6cac68fa3c86b3d049f33977a0d37f7bb863b33
|
data/LICENSE
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
CC0 1.0 Universal
|
2
|
+
|
3
|
+
Statement of Purpose
|
4
|
+
|
5
|
+
The laws of most jurisdictions throughout the world automatically confer
|
6
|
+
exclusive Copyright and Related Rights (defined below) upon the creator and
|
7
|
+
subsequent owner(s) (each and all, an "owner") of an original work of
|
8
|
+
authorship and/or a database (each, a "Work").
|
9
|
+
|
10
|
+
Certain owners wish to permanently relinquish those rights to a Work for the
|
11
|
+
purpose of contributing to a commons of creative, cultural and scientific
|
12
|
+
works ("Commons") that the public can reliably and without fear of later
|
13
|
+
claims of infringement build upon, modify, incorporate in other works, reuse
|
14
|
+
and redistribute as freely as possible in any form whatsoever and for any
|
15
|
+
purposes, including without limitation commercial purposes. These owners may
|
16
|
+
contribute to the Commons to promote the ideal of a free culture and the
|
17
|
+
further production of creative, cultural and scientific works, or to gain
|
18
|
+
reputation or greater distribution for their Work in part through the use and
|
19
|
+
efforts of others.
|
20
|
+
|
21
|
+
For these and/or other purposes and motivations, and without any expectation
|
22
|
+
of additional consideration or compensation, the person associating CC0 with a
|
23
|
+
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
|
24
|
+
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
|
25
|
+
and publicly distribute the Work under its terms, with knowledge of his or her
|
26
|
+
Copyright and Related Rights in the Work and the meaning and intended legal
|
27
|
+
effect of CC0 on those rights.
|
28
|
+
|
29
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
30
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
31
|
+
Related Rights"). Copyright and Related Rights include, but are not limited
|
32
|
+
to, the following:
|
33
|
+
|
34
|
+
i. the right to reproduce, adapt, distribute, perform, display, communicate,
|
35
|
+
and translate a Work;
|
36
|
+
|
37
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
38
|
+
|
39
|
+
iii. publicity and privacy rights pertaining to a person's image or likeness
|
40
|
+
depicted in a Work;
|
41
|
+
|
42
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
43
|
+
subject to the limitations in paragraph 4(a), below;
|
44
|
+
|
45
|
+
v. rights protecting the extraction, dissemination, use and reuse of data in
|
46
|
+
a Work;
|
47
|
+
|
48
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
49
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
50
|
+
protection of databases, and under any national implementation thereof,
|
51
|
+
including any amended or successor version of such directive); and
|
52
|
+
|
53
|
+
vii. other similar, equivalent or corresponding rights throughout the world
|
54
|
+
based on applicable law or treaty, and any national implementations thereof.
|
55
|
+
|
56
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
57
|
+
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
58
|
+
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
|
59
|
+
and Related Rights and associated claims and causes of action, whether now
|
60
|
+
known or unknown (including existing as well as future claims and causes of
|
61
|
+
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
62
|
+
duration provided by applicable law or treaty (including future time
|
63
|
+
extensions), (iii) in any current or future medium and for any number of
|
64
|
+
copies, and (iv) for any purpose whatsoever, including without limitation
|
65
|
+
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
|
66
|
+
the Waiver for the benefit of each member of the public at large and to the
|
67
|
+
detriment of Affirmer's heirs and successors, fully intending that such Waiver
|
68
|
+
shall not be subject to revocation, rescission, cancellation, termination, or
|
69
|
+
any other legal or equitable action to disrupt the quiet enjoyment of the Work
|
70
|
+
by the public as contemplated by Affirmer's express Statement of Purpose.
|
71
|
+
|
72
|
+
3. Public License Fallback. Should any part of the Waiver for any reason be
|
73
|
+
judged legally invalid or ineffective under applicable law, then the Waiver
|
74
|
+
shall be preserved to the maximum extent permitted taking into account
|
75
|
+
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
|
76
|
+
is so judged Affirmer hereby grants to each affected person a royalty-free,
|
77
|
+
non transferable, non sublicensable, non exclusive, irrevocable and
|
78
|
+
unconditional license to exercise Affirmer's Copyright and Related Rights in
|
79
|
+
the Work (i) in all territories worldwide, (ii) for the maximum duration
|
80
|
+
provided by applicable law or treaty (including future time extensions), (iii)
|
81
|
+
in any current or future medium and for any number of copies, and (iv) for any
|
82
|
+
purpose whatsoever, including without limitation commercial, advertising or
|
83
|
+
promotional purposes (the "License"). The License shall be deemed effective as
|
84
|
+
of the date CC0 was applied by Affirmer to the Work. Should any part of the
|
85
|
+
License for any reason be judged legally invalid or ineffective under
|
86
|
+
applicable law, such partial invalidity or ineffectiveness shall not
|
87
|
+
invalidate the remainder of the License, and in such case Affirmer hereby
|
88
|
+
affirms that he or she will not (i) exercise any of his or her remaining
|
89
|
+
Copyright and Related Rights in the Work or (ii) assert any associated claims
|
90
|
+
and causes of action with respect to the Work, in either case contrary to
|
91
|
+
Affirmer's express Statement of Purpose.
|
92
|
+
|
93
|
+
4. Limitations and Disclaimers.
|
94
|
+
|
95
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
96
|
+
surrendered, licensed or otherwise affected by this document.
|
97
|
+
|
98
|
+
b. Affirmer offers the Work as-is and makes no representations or warranties
|
99
|
+
of any kind concerning the Work, express, implied, statutory or otherwise,
|
100
|
+
including without limitation warranties of title, merchantability, fitness
|
101
|
+
for a particular purpose, non infringement, or the absence of latent or
|
102
|
+
other defects, accuracy, or the present or absence of errors, whether or not
|
103
|
+
discoverable, all to the greatest extent permissible under applicable law.
|
104
|
+
|
105
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
106
|
+
that may apply to the Work or any use thereof, including without limitation
|
107
|
+
any person's Copyright and Related Rights in the Work. Further, Affirmer
|
108
|
+
disclaims responsibility for obtaining any necessary consents, permissions
|
109
|
+
or other rights required for any use of the Work.
|
110
|
+
|
111
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
112
|
+
party to this document and has no duty or obligation with respect to this
|
113
|
+
CC0 or use of the Work.
|
114
|
+
|
115
|
+
For more information, please see
|
116
|
+
<http://creativecommons.org/publicdomain/zero/1.0/>
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
A simple SAFE API wrapper written in Ruby.
|
4
4
|
|
5
|
-
**Tested
|
5
|
+
**Tested Feb 24, 2017. Working with SAFE version 0.5.**
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
```
|
@@ -14,18 +14,18 @@ A simple SAFE API wrapper written in Ruby.
|
|
14
14
|
```ruby
|
15
15
|
require "safenet"
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
safe = SafeNet::Client.new(permissions: ["SAFE_DRIVE_ACCESS"])
|
18
|
+
safe.nfs.create_public_directory("/mydir")
|
19
|
+
safe.nfs.create_file("/mydir/index.html", "Hello world!<br>I'm a webpage :D")
|
20
|
+
safe.dns.register_service("my-wonderful-app", "www", "/mydir")
|
21
|
+
safe.nfs.get_file("/mydir/index.html")
|
22
22
|
|
23
23
|
# Then, open http://www.my-wonderful-app.safenet/
|
24
24
|
```
|
25
25
|
|
26
26
|
You can also set a more detailed App info:
|
27
27
|
```
|
28
|
-
|
28
|
+
safe = SafeNet::Client.new({
|
29
29
|
name: "Ruby Demo App",
|
30
30
|
version: "0.0.1",
|
31
31
|
vendor: "Vendor's Name",
|
@@ -36,46 +36,100 @@ my_client = SafeNet::Client.new({
|
|
36
36
|
*File Upload / Download:*
|
37
37
|
```ruby
|
38
38
|
# upload
|
39
|
-
|
39
|
+
safe.nfs.create_file("/mydir/dog.jpg", File.read("/home/daniel/Pictures/dog.jpg"), content_type: "image/jpeg")
|
40
40
|
|
41
41
|
# download
|
42
42
|
File.open("/home/daniel/Pictures/dog-new.jpg", "w") do |file|
|
43
|
-
file.write(
|
43
|
+
file.write(safe.nfs.get_file("/mydir/dog.jpg")["body"])
|
44
44
|
end
|
45
45
|
```
|
46
46
|
|
47
47
|
*Directory's file list:*
|
48
48
|
```ruby
|
49
|
-
|
49
|
+
safe.nfs.get_directory("/mydir")["files"].each do |file|
|
50
50
|
puts file["name"]
|
51
51
|
end
|
52
52
|
```
|
53
53
|
|
54
|
-
## Structured Data (SD):
|
55
|
-
Although SD has not been officially implemented by MaidSafe yet, we provide a sub-module (sd) that emulates it.
|
56
|
-
All the information are stored in the Safe Network, through DNS/NFS sub-systems.
|
54
|
+
## Structured Data (SD):
|
57
55
|
|
58
|
-
Example:
|
59
56
|
```ruby
|
60
|
-
|
61
|
-
|
62
|
-
|
57
|
+
# client
|
58
|
+
safe = SafeNet::Client.new(permissions: ["LOW_LEVEL_API"])
|
59
|
+
|
60
|
+
# plain (not encrypted)
|
61
|
+
hnd_cipher = safe.cipher.get_handle
|
62
|
+
|
63
|
+
# create
|
64
|
+
name = SafeNet::s2h("my_sd")
|
65
|
+
hnd = safe.sd.create(name, 500, hnd_cipher, IO.binread("#{Rails.root}/my_file.txt"))
|
66
|
+
safe.sd.put(hnd) # saves on the network
|
67
|
+
safe.sd.drop_handle(hnd) # release handler
|
68
|
+
|
69
|
+
# release cipher handler
|
70
|
+
safe.cipher.drop_handle(hnd_cipher)
|
71
|
+
|
72
|
+
# read
|
73
|
+
name = SafeNet::s2h("my_sd")
|
74
|
+
hnd_sd_data_id = safe.data_id.get_data_id_sd(name)
|
75
|
+
hnd_sd = safe.sd.get_handle(hnd_sd_data_id)['handleId']
|
76
|
+
contents = safe.sd.read(hnd_sd)
|
77
|
+
safe.sd.drop_handle(hnd_sd)
|
78
|
+
safe.data_id.drop_handle(hnd_sd_data_id)
|
79
|
+
puts contents # print SD contents on screen
|
80
|
+
```
|
81
|
+
|
82
|
+
## Immutable Data:
|
63
83
|
|
64
|
-
|
65
|
-
|
66
|
-
|
84
|
+
```ruby
|
85
|
+
# client
|
86
|
+
safe = SafeNet::Client.new(permissions: ["LOW_LEVEL_API"])
|
87
|
+
|
88
|
+
# plain (not encrypted)
|
89
|
+
hnd_cipher = safe.cipher.get_handle
|
90
|
+
|
91
|
+
# write
|
92
|
+
hnd_w = safe.immutable.get_writer_handle
|
93
|
+
safe.immutable.write_data(hnd_w, 'Hello World')
|
94
|
+
hnd_data_id = safe.immutable.close_writer(hnd_w, hnd_cipher)
|
95
|
+
name = safe.data_id.serialize(hnd_data_id) # IMMUTABLE NAME
|
96
|
+
safe.immutable.drop_writer_handle(hnd_w)
|
97
|
+
safe.data_id.drop_handle(hnd_data_id)
|
98
|
+
puts "Immutable name: #{name}"
|
99
|
+
|
100
|
+
# read
|
101
|
+
hnd_data_id = safe.data_id.deserialize(name)
|
102
|
+
hnd_r = safe.immutable.get_reader_handle(hnd_data_id)
|
103
|
+
contents = safe.immutable.read(hnd_r)
|
104
|
+
safe.immutable.drop_reader_handle(hnd_r)
|
105
|
+
safe.data_id.drop_handle(hnd_data_id)
|
106
|
+
puts contents
|
107
|
+
|
108
|
+
# read - seek position
|
109
|
+
chunk_pos = 0
|
110
|
+
max_chunk_size = 100_000
|
111
|
+
|
112
|
+
hnd_data_id = safe.data_id.deserialize(name)
|
113
|
+
hnd_r = safe.immutable.get_reader_handle(hnd_data_id)
|
114
|
+
contents = safe.immutable.read(hnd_r, "bytes=#{chunk_pos}-#{chunk_pos+max_chunk_size}")
|
115
|
+
safe.immutable.drop_reader_handle(hnd_r)
|
116
|
+
safe.data_id.drop_handle(hnd_data_id)
|
117
|
+
puts contents
|
67
118
|
```
|
68
119
|
|
69
|
-
|
120
|
+
<!-- id = SafeNet.s2h("my_sd")
|
121
|
+
safe.sd.update(id, 500, "Hi John")
|
122
|
+
safe.sd.get(id, 500)
|
123
|
+
safe.sd.update(id, 500, "Hello World!") -->
|
70
124
|
|
71
|
-
|
72
|
-
|
125
|
+
<!-- id = safe.immutable.create("Hello World!") # => "861844d6704e8573fec34d967e20bcfef3d424cf48be04e6dc08f2bd58c729743371015ead891cc3cf1c9d34b49264b510751b1ff9e537937bc46b5d6ff4ecc8"
|
126
|
+
safe.immutable.create_from_file("/home/daniel/dog.jpg")
|
127
|
+
safe.immutable.get(id) # => "Hello World!" -->
|
128
|
+
```
|
73
129
|
|
74
130
|
## Supported methods:
|
75
131
|
|Module|Method|Arguments|Optional|Doc|
|
76
132
|
|------|------|---------|--------|---|
|
77
|
-
|sd|update|id (_int_), tag_type (_int_), contents (_string_\|_binary_)|||
|
78
|
-
|sd|get|id (_int_), tag_type (_int_)|||
|
79
133
|
|nfs|create_public_directory|dir_path (_string_)|root_path ("_app_" or "_drive_"), meta (_string_)|* _Alias to "create_directory"_|
|
80
134
|
|nfs|create_private_directory|dir_path (_string_)|root_path ("_app_" or "_drive_"), meta (_string_)|* _Alias to "create_directory"_|
|
81
135
|
|nfs|create_directory|dir_path (_string_)|is_private (_bool_), root_path ("_app_" or "_drive_"), meta (_string_)|https://maidsafe.readme.io/docs/nfs-create-directory|
|
@@ -95,3 +149,9 @@ https://github.com/maidsafe/rfcs/blob/master/text/0028-launcher-low-level-api/00
|
|
95
149
|
|dns|list_services|long_name (_string_)||https://maidsafe.readme.io/docs/dns-list-services|
|
96
150
|
|dns|get_home_dir|long_name (_string_), service_name (_string_)||https://maidsafe.readme.io/docs/dns-get-home-dir|
|
97
151
|
|dns|get_file_unauth|long_name (_string_), service_name (_string_), file_path (_string_)||https://maidsafe.readme.io/docs/dns-get-file-unauth|
|
152
|
+
|
153
|
+
## TODO
|
154
|
+
* Improve test suite
|
155
|
+
* Improve documentation
|
156
|
+
* Use FFI instead of REST
|
157
|
+
* Use the same interface (same method names) as [safe_app_nodejs](https://github.com/maidsafe/safe_app_nodejs)
|
data/lib/safenet.rb
CHANGED
@@ -4,10 +4,13 @@ require "base64"
|
|
4
4
|
require "json"
|
5
5
|
require "cgi" # CGI.escape method
|
6
6
|
|
7
|
+
API_VERSION = 0.5
|
8
|
+
API_ENDPOINT = "http://localhost:8100/"
|
9
|
+
|
7
10
|
module SafeNet
|
8
11
|
|
9
12
|
class Client
|
10
|
-
attr_reader :auth, :nfs, :dns, :sd, :
|
13
|
+
attr_reader :auth, :nfs, :dns, :sd, :ad, :immutable, :cipher, :data_id, :app_info, :key_helper
|
11
14
|
|
12
15
|
def initialize(options = {})
|
13
16
|
@app_info = defaults()
|
@@ -17,10 +20,14 @@ module SafeNet
|
|
17
20
|
@nfs = SafeNet::NFS.new(self)
|
18
21
|
@dns = SafeNet::DNS.new(self)
|
19
22
|
@sd = SafeNet::SD.new(self)
|
20
|
-
@
|
23
|
+
@ad = SafeNet::AD.new(self)
|
24
|
+
@immutable = SafeNet::Immutable.new(self)
|
25
|
+
@cipher = SafeNet::Cipher.new(self)
|
26
|
+
@data_id = SafeNet::DataId.new(self)
|
21
27
|
end
|
22
28
|
|
23
29
|
def set_app_info(options = {})
|
30
|
+
@app_info[:permissions] = options[:permissions] if options.has_key?(:permissions)
|
24
31
|
@app_info[:name] = options[:name] if options.has_key?(:name)
|
25
32
|
@app_info[:version] = options[:version] if options.has_key?(:version)
|
26
33
|
@app_info[:vendor] = options[:vendor] if options.has_key?(:vendor)
|
@@ -38,7 +45,7 @@ module SafeNet
|
|
38
45
|
version: "0.0.1",
|
39
46
|
vendor: "Vendor's Name",
|
40
47
|
id: "org.thevendor.demo",
|
41
|
-
launcher_server:
|
48
|
+
launcher_server: API_ENDPOINT,
|
42
49
|
conf_path: File.join(File.expand_path('..', __FILE__), "conf.json")
|
43
50
|
}
|
44
51
|
end
|
@@ -91,9 +98,9 @@ module SafeNet
|
|
91
98
|
#
|
92
99
|
# Reference: https://maidsafe.readme.io/docs/auth
|
93
100
|
#
|
94
|
-
def auth(
|
101
|
+
def auth()
|
95
102
|
# entry point
|
96
|
-
url = "#{@client.app_info[:launcher_server]}auth"
|
103
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/auth"
|
97
104
|
|
98
105
|
# payload
|
99
106
|
payload = {
|
@@ -103,7 +110,7 @@ module SafeNet
|
|
103
110
|
vendor: @client.app_info[:vendor],
|
104
111
|
id: @client.app_info[:id]
|
105
112
|
},
|
106
|
-
permissions: permissions
|
113
|
+
permissions: @client.app_info[:permissions]
|
107
114
|
}
|
108
115
|
|
109
116
|
# api call
|
@@ -142,7 +149,7 @@ module SafeNet
|
|
142
149
|
#
|
143
150
|
def is_token_valid
|
144
151
|
# entry point
|
145
|
-
url = "#{@client.app_info[:launcher_server]}auth"
|
152
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/auth"
|
146
153
|
|
147
154
|
# api call
|
148
155
|
uri = URI(url)
|
@@ -166,7 +173,7 @@ module SafeNet
|
|
166
173
|
#
|
167
174
|
def revoke_token
|
168
175
|
# entry point
|
169
|
-
url = "#{@client.app_info[:launcher_server]}auth"
|
176
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/auth"
|
170
177
|
|
171
178
|
# api call
|
172
179
|
uri = URI(url)
|
@@ -203,7 +210,7 @@ module SafeNet
|
|
203
210
|
options[:is_private] = true if ! options.has_key?(:is_private)
|
204
211
|
|
205
212
|
# Entry point
|
206
|
-
url = "#{@client.app_info[:launcher_server]}nfs/directory/#{options[:root_path]}/#{CGI.escape(dir_path)}"
|
213
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/directory/#{options[:root_path]}/#{CGI.escape(dir_path)}"
|
207
214
|
|
208
215
|
# Payload
|
209
216
|
payload = {
|
@@ -252,7 +259,7 @@ module SafeNet
|
|
252
259
|
options[:root_path] = 'app' if ! options.has_key?(:root_path)
|
253
260
|
|
254
261
|
# Entry point
|
255
|
-
url = "#{@client.app_info[:launcher_server]}nfs/directory/#{options[:root_path]}/#{CGI.escape(dir_path)}"
|
262
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/directory/#{options[:root_path]}/#{CGI.escape(dir_path)}"
|
256
263
|
|
257
264
|
# API call
|
258
265
|
uri = URI(url)
|
@@ -281,7 +288,7 @@ module SafeNet
|
|
281
288
|
options[:root_path] = 'app' if ! options.has_key?(:root_path)
|
282
289
|
|
283
290
|
# Entry point
|
284
|
-
url = "#{@client.app_info[:launcher_server]}nfs/directory/#{options[:root_path]}/#{CGI.escape(dir_path)}"
|
291
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/directory/#{options[:root_path]}/#{CGI.escape(dir_path)}"
|
285
292
|
|
286
293
|
# Optional payload
|
287
294
|
payload = {}
|
@@ -322,7 +329,7 @@ module SafeNet
|
|
322
329
|
options[:root_path] = 'app' if ! options.has_key?(:root_path)
|
323
330
|
|
324
331
|
# Entry point
|
325
|
-
url = "#{@client.app_info[:launcher_server]}nfs/directory/#{options[:root_path]}/#{CGI.escape(dir_path)}"
|
332
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/directory/#{options[:root_path]}/#{CGI.escape(dir_path)}"
|
326
333
|
|
327
334
|
# API call
|
328
335
|
uri = URI(url)
|
@@ -352,7 +359,7 @@ module SafeNet
|
|
352
359
|
contents ||= ""
|
353
360
|
|
354
361
|
# Entry point
|
355
|
-
url = "#{@client.app_info[:launcher_server]}nfs/file/#{options[:root_path]}/#{CGI.escape(file_path)}"
|
362
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/file/#{options[:root_path]}/#{CGI.escape(file_path)}"
|
356
363
|
|
357
364
|
# API call
|
358
365
|
uri = URI(url)
|
@@ -386,7 +393,7 @@ module SafeNet
|
|
386
393
|
options[:root_path] = 'app' if ! options.has_key?(:root_path)
|
387
394
|
|
388
395
|
# Entry point
|
389
|
-
url = "#{@client.app_info[:launcher_server]}nfs/file/#{options[:root_path]}/#{CGI.escape(file_path)}"
|
396
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/file/#{options[:root_path]}/#{CGI.escape(file_path)}"
|
390
397
|
|
391
398
|
# API call
|
392
399
|
uri = URI(url)
|
@@ -422,7 +429,7 @@ module SafeNet
|
|
422
429
|
options[:root_path] = 'app' if ! options.has_key?(:root_path)
|
423
430
|
|
424
431
|
# Entry point
|
425
|
-
url = "#{@client.app_info[:launcher_server]}nfs/file/#{options[:root_path]}/#{CGI.escape(file_path)}?"
|
432
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/file/#{options[:root_path]}/#{CGI.escape(file_path)}?"
|
426
433
|
|
427
434
|
# Query params
|
428
435
|
query = []
|
@@ -461,7 +468,7 @@ module SafeNet
|
|
461
468
|
options[:root_path] = 'app' if ! options.has_key?(:root_path)
|
462
469
|
|
463
470
|
# Entry point
|
464
|
-
url = "#{@client.app_info[:launcher_server]}nfs/file/metadata/#{options[:root_path]}/#{CGI.escape(file_path)}"
|
471
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/file/metadata/#{options[:root_path]}/#{CGI.escape(file_path)}"
|
465
472
|
|
466
473
|
# Optional payload
|
467
474
|
payload = {}
|
@@ -503,7 +510,7 @@ module SafeNet
|
|
503
510
|
options[:root_path] = 'app' if ! options.has_key?(:root_path)
|
504
511
|
|
505
512
|
# Entry point
|
506
|
-
url = "#{@client.app_info[:launcher_server]}nfs/file/#{options[:root_path]}/#{CGI.escape(file_path)}"
|
513
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/file/#{options[:root_path]}/#{CGI.escape(file_path)}"
|
507
514
|
|
508
515
|
# API call
|
509
516
|
uri = URI(url)
|
@@ -534,7 +541,7 @@ module SafeNet
|
|
534
541
|
#
|
535
542
|
def create_long_name(long_name)
|
536
543
|
# entry point
|
537
|
-
url = "#{@client.app_info[:launcher_server]}dns/#{CGI.escape(long_name)}"
|
544
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/dns/#{CGI.escape(long_name)}"
|
538
545
|
|
539
546
|
# api call
|
540
547
|
uri = URI(url)
|
@@ -560,7 +567,7 @@ module SafeNet
|
|
560
567
|
#
|
561
568
|
def register_service(long_name, service_name, service_home_dir_path, options = {})
|
562
569
|
# Entry point
|
563
|
-
url = "#{@client.app_info[:launcher_server]}dns"
|
570
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/dns"
|
564
571
|
|
565
572
|
# Payload
|
566
573
|
payload = {
|
@@ -598,7 +605,7 @@ module SafeNet
|
|
598
605
|
#
|
599
606
|
def add_service(long_name, service_name, service_home_dir_path)
|
600
607
|
# Entry point
|
601
|
-
url = "#{@client.app_info[:launcher_server]}dns"
|
608
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/dns"
|
602
609
|
|
603
610
|
# Payload
|
604
611
|
payload = {
|
@@ -624,7 +631,7 @@ module SafeNet
|
|
624
631
|
# https://maidsafe.readme.io/docs/dns-list-long-names
|
625
632
|
def list_long_names
|
626
633
|
# entry point
|
627
|
-
url = "#{@client.app_info[:launcher_server]}dns"
|
634
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/dns"
|
628
635
|
|
629
636
|
# api call
|
630
637
|
uri = URI(url)
|
@@ -639,7 +646,7 @@ module SafeNet
|
|
639
646
|
# https://maidsafe.readme.io/docs/dns-list-services
|
640
647
|
def list_services(long_name)
|
641
648
|
# entry point
|
642
|
-
url = "#{@client.app_info[:launcher_server]}dns/#{CGI.escape(long_name)}"
|
649
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/dns/#{CGI.escape(long_name)}"
|
643
650
|
|
644
651
|
# api call
|
645
652
|
uri = URI(url)
|
@@ -655,7 +662,7 @@ module SafeNet
|
|
655
662
|
# https://maidsafe.readme.io/docs/dns-get-home-dir
|
656
663
|
def get_home_dir(long_name, service_name)
|
657
664
|
# entry point
|
658
|
-
url = "#{@client.app_info[:launcher_server]}dns/#{CGI.escape(service_name)}/#{CGI.escape(long_name)}"
|
665
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/dns/#{CGI.escape(service_name)}/#{CGI.escape(long_name)}"
|
659
666
|
|
660
667
|
# api call
|
661
668
|
uri = URI(url)
|
@@ -672,7 +679,7 @@ module SafeNet
|
|
672
679
|
# get_file_unauth("thegoogle", "www", "index.html")
|
673
680
|
def get_file_unauth(long_name, service_name, file_path)
|
674
681
|
# entry point
|
675
|
-
url = "#{@client.app_info[:launcher_server]}dns/#{CGI.escape(service_name)}/#{CGI.escape(long_name)}/#{CGI.escape(file_path)}"
|
682
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/dns/#{CGI.escape(service_name)}/#{CGI.escape(long_name)}/#{CGI.escape(file_path)}"
|
676
683
|
|
677
684
|
# api call
|
678
685
|
uri = URI(url)
|
@@ -685,65 +692,520 @@ module SafeNet
|
|
685
692
|
end
|
686
693
|
end
|
687
694
|
|
695
|
+
class AD
|
696
|
+
def initialize(client_obj)
|
697
|
+
@client = client_obj
|
698
|
+
end
|
699
|
+
|
700
|
+
def create(name, is_private = false, filter_type = 'BLACK_LIST', filter_key = nil)
|
701
|
+
# Entry point
|
702
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/appendable-data"
|
703
|
+
|
704
|
+
# Payload
|
705
|
+
payload = {
|
706
|
+
name: name,
|
707
|
+
isPrivate: is_private,
|
708
|
+
filterType: filter_type,
|
709
|
+
filterKey: filter_key
|
710
|
+
}
|
711
|
+
|
712
|
+
# API call
|
713
|
+
uri = URI(url)
|
714
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
715
|
+
req = Net::HTTP::Post.new(uri.path, {
|
716
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}",
|
717
|
+
'Content-Type' => 'application/json'
|
718
|
+
})
|
719
|
+
req.body = payload.to_json
|
720
|
+
res = http.request(req)
|
721
|
+
res.code == "200" ? JSON.parse(res.body)['handleId'] : JSON.parse(res.body)
|
722
|
+
end
|
723
|
+
|
724
|
+
def put(handle_id)
|
725
|
+
# Entry point
|
726
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/appendable-data/#{handle_id}"
|
727
|
+
|
728
|
+
# API call
|
729
|
+
uri = URI(url)
|
730
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
731
|
+
req = Net::HTTP::Put.new(uri.path, {
|
732
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
|
733
|
+
})
|
734
|
+
res = http.request(req)
|
735
|
+
res.code == "200" ? true : JSON.parse(res.body)
|
736
|
+
end
|
737
|
+
|
738
|
+
def post(handle_id)
|
739
|
+
# Entry point
|
740
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/appendable-data/#{handle_id}"
|
741
|
+
|
742
|
+
# API call
|
743
|
+
uri = URI(url)
|
744
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
745
|
+
req = Net::HTTP::Post.new(uri.path, {
|
746
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
|
747
|
+
})
|
748
|
+
res = http.request(req)
|
749
|
+
res.code == "200" ? true : JSON.parse(res.body)
|
750
|
+
end
|
751
|
+
|
752
|
+
def get_handle(data_id_handle)
|
753
|
+
# entry point
|
754
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/appendable-data/handle/#{data_id_handle}"
|
755
|
+
|
756
|
+
# api call
|
757
|
+
uri = URI(url)
|
758
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
759
|
+
req = Net::HTTP::Get.new(uri.path, {
|
760
|
+
'Authorization' => "Bearer #{@client.key_helper.get_token()}"
|
761
|
+
})
|
762
|
+
res = http.request(req)
|
763
|
+
JSON.parse(res.body)
|
764
|
+
end
|
765
|
+
|
766
|
+
def get_data_id_handle(handle_id)
|
767
|
+
# entry point
|
768
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/appendable-data/data-id/#{handle_id}"
|
769
|
+
|
770
|
+
# api call
|
771
|
+
uri = URI(url)
|
772
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
773
|
+
req = Net::HTTP::Get.new(uri.path, {
|
774
|
+
'Authorization' => "Bearer #{@client.key_helper.get_token()}"
|
775
|
+
})
|
776
|
+
res = http.request(req)
|
777
|
+
res.code == "200" ? JSON.parse(res.body)['handleId'] : JSON.parse(res.body)
|
778
|
+
end
|
779
|
+
|
780
|
+
def get_metadata(handle_id)
|
781
|
+
# entry point
|
782
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/appendable-data/metadata/#{handle_id}"
|
783
|
+
|
784
|
+
# api call
|
785
|
+
uri = URI(url)
|
786
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
787
|
+
req = Net::HTTP::Get.new(uri.path, {
|
788
|
+
'Authorization' => "Bearer #{@client.key_helper.get_token()}"
|
789
|
+
})
|
790
|
+
res = http.request(req)
|
791
|
+
JSON.parse(res.body)
|
792
|
+
end
|
793
|
+
|
794
|
+
def drop_handle(handle_id)
|
795
|
+
# entry point
|
796
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/appendable-data/handle/#{handle_id}"
|
797
|
+
|
798
|
+
# api call
|
799
|
+
uri = URI(url)
|
800
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
801
|
+
req = Net::HTTP::Delete.new(uri.path)
|
802
|
+
res = http.request(req)
|
803
|
+
res.code == "200" ? true : JSON.parse(res.body)
|
804
|
+
end
|
805
|
+
|
806
|
+
def append(handle_id, handle_data_id)
|
807
|
+
# Entry point
|
808
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/appendable-data/#{handle_id}/#{handle_data_id}"
|
809
|
+
|
810
|
+
# API call
|
811
|
+
uri = URI(url)
|
812
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
813
|
+
req = Net::HTTP::Put.new(uri.path, {
|
814
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
|
815
|
+
})
|
816
|
+
res = http.request(req)
|
817
|
+
res.code == "200" ? true : JSON.parse(res.body)
|
818
|
+
end
|
819
|
+
|
820
|
+
def get_data_id_at_index(handle_id, index)
|
821
|
+
# Entry point
|
822
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/appendable-data/#{handle_id}/#{index}"
|
823
|
+
|
824
|
+
# API call
|
825
|
+
uri = URI(url)
|
826
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
827
|
+
req = Net::HTTP::Get.new(uri.path, {
|
828
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
|
829
|
+
})
|
830
|
+
res = http.request(req)
|
831
|
+
res.code == "200" ? JSON.parse(res.body)["handleId"] : JSON.parse(res.body)
|
832
|
+
end
|
833
|
+
|
834
|
+
end
|
835
|
+
|
688
836
|
class SD
|
689
837
|
def initialize(client_obj)
|
690
838
|
@client = client_obj
|
691
839
|
end
|
692
840
|
|
693
|
-
def create(
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
841
|
+
def create(name, type_tag = 500, hnd_cipher_opts = nil, data = nil, version = 0)
|
842
|
+
# Entry point
|
843
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/structured-data"
|
844
|
+
|
845
|
+
# Payload
|
846
|
+
payload = {
|
847
|
+
name: name,
|
848
|
+
typeTag: type_tag,
|
849
|
+
cipherOpts: hnd_cipher_opts,
|
850
|
+
data: Base64.encode64(data),
|
851
|
+
version: version
|
852
|
+
}
|
853
|
+
|
854
|
+
# API call
|
855
|
+
uri = URI(url)
|
856
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
857
|
+
req = Net::HTTP::Post.new(uri.path, {
|
858
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}",
|
859
|
+
'Content-Type' => 'application/json'
|
860
|
+
})
|
861
|
+
req.body = payload.to_json
|
862
|
+
res = http.request(req)
|
863
|
+
res.code == "200" ? JSON.parse(res.body)['handleId'] : JSON.parse(res.body)
|
707
864
|
end
|
708
865
|
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
866
|
+
|
867
|
+
def put(handle_id)
|
868
|
+
# Entry point
|
869
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/structured-data/#{handle_id}"
|
870
|
+
|
871
|
+
# API call
|
872
|
+
uri = URI(url)
|
873
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
874
|
+
req = Net::HTTP::Put.new(uri.path, {
|
875
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
|
876
|
+
})
|
877
|
+
res = http.request(req)
|
878
|
+
res.code == "200" ? true : JSON.parse(res.body)
|
879
|
+
end
|
880
|
+
|
881
|
+
def post(handle_id)
|
882
|
+
# Entry point
|
883
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/structured-data/#{handle_id}"
|
884
|
+
|
885
|
+
# API call
|
886
|
+
uri = URI(url)
|
887
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
888
|
+
req = Net::HTTP::Post.new(uri.path, {
|
889
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
|
890
|
+
})
|
891
|
+
res = http.request(req)
|
892
|
+
res.code == "200" ? true : JSON.parse(res.body)
|
720
893
|
end
|
721
894
|
|
722
|
-
def
|
723
|
-
|
724
|
-
|
895
|
+
def get_handle(data_id_handle)
|
896
|
+
# entry point
|
897
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/structured-data/handle/#{data_id_handle}"
|
898
|
+
|
899
|
+
# api call
|
900
|
+
uri = URI(url)
|
901
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
902
|
+
req = Net::HTTP::Get.new(uri.path, {
|
903
|
+
'Authorization' => "Bearer #{@client.key_helper.get_token()}"
|
904
|
+
})
|
905
|
+
res = http.request(req)
|
906
|
+
JSON.parse(res.body)
|
907
|
+
end
|
908
|
+
|
909
|
+
def get_data_id_handle(handle_id)
|
910
|
+
# entry point
|
911
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/structured-data/data-id/#{handle_id}"
|
912
|
+
|
913
|
+
# api call
|
914
|
+
uri = URI(url)
|
915
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
916
|
+
req = Net::HTTP::Get.new(uri.path, {
|
917
|
+
'Authorization' => "Bearer #{@client.key_helper.get_token()}"
|
918
|
+
})
|
919
|
+
res = http.request(req)
|
920
|
+
JSON.parse(res.body)
|
921
|
+
end
|
922
|
+
|
923
|
+
def get_metadata(handle_id)
|
924
|
+
# entry point
|
925
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/structured-data/metadata/#{handle_id}"
|
926
|
+
|
927
|
+
# api call
|
928
|
+
uri = URI(url)
|
929
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
930
|
+
req = Net::HTTP::Get.new(uri.path, {
|
931
|
+
'Authorization' => "Bearer #{@client.key_helper.get_token()}"
|
932
|
+
})
|
933
|
+
res = http.request(req)
|
934
|
+
JSON.parse(res.body)
|
935
|
+
end
|
936
|
+
|
937
|
+
def read(handle_id, version = nil)
|
938
|
+
# entry point
|
939
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/structured-data/#{handle_id}"
|
940
|
+
url = "#{url}/#{version}?" if ! version.nil?
|
941
|
+
|
942
|
+
# api call
|
943
|
+
uri = URI(url)
|
944
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
945
|
+
req = Net::HTTP::Get.new(uri.path, {
|
946
|
+
'Authorization' => "Bearer #{@client.key_helper.get_token()}"
|
947
|
+
})
|
948
|
+
res = http.request(req)
|
949
|
+
res.code == "200" ? res.body : JSON.parse(res.body)
|
950
|
+
end
|
951
|
+
|
952
|
+
def drop_handle(handle_id)
|
953
|
+
# entry point
|
954
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/structured-data/handle/#{handle_id}"
|
955
|
+
|
956
|
+
# api call
|
957
|
+
uri = URI(url)
|
958
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
959
|
+
req = Net::HTTP::Delete.new(uri.path)
|
960
|
+
res = http.request(req)
|
961
|
+
res.code == "200" ? true : JSON.parse(res.body)
|
962
|
+
end
|
963
|
+
end
|
964
|
+
|
965
|
+
class Immutable
|
966
|
+
def initialize(client_obj)
|
967
|
+
@client = client_obj
|
968
|
+
end
|
969
|
+
|
970
|
+
def get_reader_handle(handle_id)
|
971
|
+
# entry point
|
972
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/immutable-data/reader/#{handle_id}"
|
973
|
+
|
974
|
+
# api call
|
975
|
+
uri = URI(url)
|
976
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
977
|
+
req = Net::HTTP::Get.new(uri.path, {
|
978
|
+
'Authorization' => "Bearer #{@client.key_helper.get_token()}"
|
979
|
+
})
|
980
|
+
res = http.request(req)
|
981
|
+
res.code == "200" ? JSON.parse(res.body)["handleId"] : JSON.parse(res.body)
|
982
|
+
end
|
983
|
+
|
984
|
+
def get_writer_handle()
|
985
|
+
# entry point
|
986
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/immutable-data/writer"
|
987
|
+
|
988
|
+
# api call
|
989
|
+
uri = URI(url)
|
990
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
991
|
+
req = Net::HTTP::Get.new(uri.path, {
|
992
|
+
'Authorization' => "Bearer #{@client.key_helper.get_token()}"
|
993
|
+
})
|
994
|
+
res = http.request(req)
|
995
|
+
res.code == "200" ? JSON.parse(res.body)["handleId"] : JSON.parse(res.body)
|
996
|
+
end
|
997
|
+
|
998
|
+
# eg range: "bytes=0-1000"
|
999
|
+
def read(handle_id, range = nil)
|
1000
|
+
# entry point
|
1001
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/immutable-data/#{handle_id}"
|
1002
|
+
|
1003
|
+
# api call
|
1004
|
+
uri = URI(url)
|
1005
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
1006
|
+
header = { 'Authorization' => "Bearer #{@client.key_helper.get_token()}", 'Content-Type': 'text/plain' }
|
1007
|
+
header['Range'] = range if range
|
1008
|
+
req = Net::HTTP::Get.new(uri.path, header)
|
1009
|
+
res = http.request(req)
|
1010
|
+
(res.code == "200" || res.code == "206") ? res.body : JSON.parse(res.body)
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
def write_data(handle_id, contents)
|
1014
|
+
# Entry point
|
1015
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/immutable-data/#{handle_id}"
|
1016
|
+
|
1017
|
+
# API call
|
1018
|
+
uri = URI(url)
|
1019
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
1020
|
+
headers = {
|
1021
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}",
|
1022
|
+
'Content-Type': 'text/plain'
|
1023
|
+
}
|
1024
|
+
headers["Content-Length"] = contents.size.to_s
|
1025
|
+
req = Net::HTTP::Post.new(uri.path, headers)
|
1026
|
+
req.body = contents
|
1027
|
+
res = http.request(req)
|
1028
|
+
res.code == "200" ? true : JSON.parse(res.body)
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
def close_writer(handle_id, cipher_opts_handle)
|
1032
|
+
# entry point
|
1033
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/immutable-data/#{handle_id}/#{cipher_opts_handle}"
|
1034
|
+
|
1035
|
+
# api call
|
1036
|
+
uri = URI(url)
|
1037
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
1038
|
+
req = Net::HTTP::Put.new(uri.path, {
|
1039
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
|
1040
|
+
})
|
1041
|
+
res = http.request(req)
|
1042
|
+
res.code == "200" ? JSON.parse(res.body)["handleId"] : JSON.parse(res.body)
|
1043
|
+
end
|
1044
|
+
|
1045
|
+
|
1046
|
+
def drop_reader_handle(handle_id)
|
1047
|
+
# entry point
|
1048
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/immutable-data/reader/#{handle_id}"
|
1049
|
+
|
1050
|
+
# api call
|
1051
|
+
uri = URI(url)
|
1052
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
1053
|
+
req = Net::HTTP::Delete.new(uri.path, {
|
1054
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
|
1055
|
+
})
|
1056
|
+
res = http.request(req)
|
1057
|
+
res.code == "200" ? true : JSON.parse(res.body)
|
1058
|
+
end
|
1059
|
+
|
1060
|
+
def drop_writer_handle(handle_id)
|
1061
|
+
# entry point
|
1062
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/immutable-data/writer/#{handle_id}"
|
1063
|
+
|
1064
|
+
# api call
|
1065
|
+
uri = URI(url)
|
1066
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
1067
|
+
req = Net::HTTP::Delete.new(uri.path, {
|
1068
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
|
1069
|
+
})
|
1070
|
+
res = http.request(req)
|
1071
|
+
res.code == "200" ? true : JSON.parse(res.body)
|
725
1072
|
end
|
726
1073
|
end
|
727
1074
|
|
728
|
-
class
|
1075
|
+
class Cipher
|
729
1076
|
def initialize(client_obj)
|
730
1077
|
@client = client_obj
|
731
1078
|
end
|
732
1079
|
|
733
|
-
def
|
734
|
-
|
735
|
-
@client.
|
736
|
-
|
1080
|
+
def get_handle(enc_type = 'PLAIN', sym_key_handle = nil)
|
1081
|
+
# Entry point
|
1082
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/cipher-opts/#{enc_type}"
|
1083
|
+
url << "/#{sym_key_handle}?" if sym_key_handle
|
1084
|
+
|
1085
|
+
# API call
|
1086
|
+
uri = URI(url)
|
1087
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
1088
|
+
req = Net::HTTP::Get.new(uri.path, {
|
1089
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
|
1090
|
+
})
|
1091
|
+
res = http.request(req)
|
1092
|
+
res.code == "200" ? JSON.parse(res.body)["handleId"] : JSON.parse(res.body)
|
1093
|
+
end
|
1094
|
+
|
1095
|
+
def drop_handle(handle_id)
|
1096
|
+
# entry point
|
1097
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/cipher-opts/#{handle_id}"
|
1098
|
+
|
1099
|
+
# api call
|
1100
|
+
uri = URI(url)
|
1101
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
1102
|
+
req = Net::HTTP::Delete.new(uri.path, {
|
1103
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
|
1104
|
+
})
|
1105
|
+
res = http.request(req)
|
1106
|
+
res.code == "200" ? true : JSON.parse(res.body)
|
1107
|
+
end
|
1108
|
+
end
|
1109
|
+
|
1110
|
+
class DataId
|
1111
|
+
def initialize(client_obj)
|
1112
|
+
@client = client_obj
|
1113
|
+
end
|
1114
|
+
|
1115
|
+
def get_data_id_sd(name, type_tag = 500)
|
1116
|
+
# Entry point
|
1117
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/data-id/structured-data"
|
1118
|
+
|
1119
|
+
# Payload
|
1120
|
+
payload = {
|
1121
|
+
name: name,
|
1122
|
+
typeTag: type_tag
|
1123
|
+
}
|
1124
|
+
|
1125
|
+
# API call
|
1126
|
+
uri = URI(url)
|
1127
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
1128
|
+
req = Net::HTTP::Post.new(uri.path, {
|
1129
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}",
|
1130
|
+
'Content-Type' => 'application/json'
|
1131
|
+
})
|
1132
|
+
req.body = payload.to_json
|
1133
|
+
res = http.request(req)
|
1134
|
+
res.code == "200" ? JSON.parse(res.body)['handleId'] : JSON.parse(res.body)
|
1135
|
+
end
|
1136
|
+
|
1137
|
+
def get_data_id_ad(name, is_private = false)
|
1138
|
+
# Entry point
|
1139
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/data-id/appendable-data"
|
1140
|
+
|
1141
|
+
# Payload
|
1142
|
+
payload = {
|
1143
|
+
name: name,
|
1144
|
+
isPrivate: is_private
|
1145
|
+
}
|
1146
|
+
|
1147
|
+
# API call
|
1148
|
+
uri = URI(url)
|
1149
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
1150
|
+
req = Net::HTTP::Post.new(uri.path, {
|
1151
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}",
|
1152
|
+
'Content-Type' => 'application/json'
|
1153
|
+
})
|
1154
|
+
req.body = payload.to_json
|
1155
|
+
res = http.request(req)
|
1156
|
+
res.code == "200" ? JSON.parse(res.body)['handleId'] : JSON.parse(res.body)
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
def drop_handle(handle_id)
|
1160
|
+
# entry point
|
1161
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/data-id/#{handle_id}"
|
1162
|
+
|
1163
|
+
# api call
|
1164
|
+
uri = URI(url)
|
1165
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
1166
|
+
req = Net::HTTP::Delete.new(uri.path, {
|
1167
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
|
1168
|
+
})
|
1169
|
+
res = http.request(req)
|
1170
|
+
res.code == "200" ? true : JSON.parse(res.body)
|
737
1171
|
end
|
738
1172
|
|
739
|
-
def
|
740
|
-
|
741
|
-
@client.
|
742
|
-
|
1173
|
+
def serialize(handle_id)
|
1174
|
+
# entry point
|
1175
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/data-id/#{handle_id}"
|
1176
|
+
|
1177
|
+
# api call
|
1178
|
+
uri = URI(url)
|
1179
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
1180
|
+
req = Net::HTTP::Get.new(uri.path, {
|
1181
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
|
1182
|
+
})
|
1183
|
+
res = http.request(req)
|
1184
|
+
res.code == "200" ? res.body : JSON.parse(res.body)
|
743
1185
|
end
|
744
1186
|
|
745
|
-
def
|
746
|
-
|
1187
|
+
def deserialize(contents)
|
1188
|
+
# entry point
|
1189
|
+
url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/data-id"
|
1190
|
+
|
1191
|
+
# api call
|
1192
|
+
uri = URI(url)
|
1193
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
1194
|
+
headers = {
|
1195
|
+
'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}",
|
1196
|
+
'Content-Type': 'text/plain'
|
1197
|
+
}
|
1198
|
+
headers["Content-Length"] = contents.size.to_s
|
1199
|
+
req = Net::HTTP::Post.new(uri.path, headers)
|
1200
|
+
req.body = contents
|
1201
|
+
res = http.request(req)
|
1202
|
+
res.code == "200" ? JSON.parse(res.body)['handleId'] : JSON.parse(res.body)
|
747
1203
|
end
|
1204
|
+
|
1205
|
+
end
|
1206
|
+
|
1207
|
+
def self.s2h(str)
|
1208
|
+
# Digest::SHA2.new(256).hexdigest(str)
|
1209
|
+
Digest::SHA2.new(256).base64digest(str)
|
748
1210
|
end
|
749
1211
|
end
|
data/lib/safenet/version.rb
CHANGED
data/ruby-safenet.gemspec
CHANGED
@@ -8,8 +8,9 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Safenet::VERSION
|
9
9
|
spec.authors = ["Daniel Loureiro"]
|
10
10
|
spec.email = ["loureirorg@gmail.com"]
|
11
|
+
spec.licenses = ['CC0-1.0']
|
11
12
|
|
12
|
-
spec.summary = %q{Ruby
|
13
|
+
spec.summary = %q{Ruby wrapper for the SAFE network}
|
13
14
|
spec.description = %q{Ruby library for accessing the SAFE network}
|
14
15
|
spec.homepage = "https://github.com/loureirorg/ruby-safenet"
|
15
16
|
|
@@ -28,4 +29,5 @@ Gem::Specification.new do |spec|
|
|
28
29
|
|
29
30
|
spec.add_development_dependency "bundler", "~> 1.10"
|
30
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-safenet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Loureiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
41
55
|
description: Ruby library for accessing the SAFE network
|
42
56
|
email:
|
43
57
|
- loureirorg@gmail.com
|
@@ -48,6 +62,7 @@ files:
|
|
48
62
|
- ".gitignore"
|
49
63
|
- ".travis.yml"
|
50
64
|
- Gemfile
|
65
|
+
- LICENSE
|
51
66
|
- README.md
|
52
67
|
- Rakefile
|
53
68
|
- bin/console
|
@@ -56,7 +71,8 @@ files:
|
|
56
71
|
- lib/safenet/version.rb
|
57
72
|
- ruby-safenet.gemspec
|
58
73
|
homepage: https://github.com/loureirorg/ruby-safenet
|
59
|
-
licenses:
|
74
|
+
licenses:
|
75
|
+
- CC0-1.0
|
60
76
|
metadata: {}
|
61
77
|
post_install_message:
|
62
78
|
rdoc_options: []
|
@@ -77,5 +93,5 @@ rubyforge_project:
|
|
77
93
|
rubygems_version: 2.5.1
|
78
94
|
signing_key:
|
79
95
|
specification_version: 4
|
80
|
-
summary: Ruby
|
96
|
+
summary: Ruby wrapper for the SAFE network
|
81
97
|
test_files: []
|