ruby-safenet 0.2.0 → 0.2.1

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: 3da1bbf0bd8ef4702c376d3a285b747da5ebe8d6
4
- data.tar.gz: 0a2c39886bf3935eb36f7bcd11ddffeabcb4e223
3
+ metadata.gz: 4d8672d7bee04b6dc531d7b333157ec41ea7eb4a
4
+ data.tar.gz: 07e73624093f756e27961f46df9bb8371a63ad92
5
5
  SHA512:
6
- metadata.gz: ed01af92d3c24a9330a176339af88f1519da6dc4b5aa5be1fc84b23aaff6c558a329bee7ec2259f9132ffadfb1bff74deaf76935b117f5321a53cd20b09f1f0b
7
- data.tar.gz: 5c672bfa76fec86cb219b619f0f315f259c99c47cd74d9386291963f45296fb1db72a07f22dabca81748d73019659708c30d03fb4ede0e0bef714b0242c9b980
6
+ metadata.gz: 07442a257f9a0bbe5e52c77cce19656074fb1de846beead178dc0f97ce106246e6df57666b7b885a00a7028d9d62da8a3d9af4c4bd33cfbc6c5a21f6410a0e75
7
+ data.tar.gz: 9f8c5050b9248d2067e5debf8efa0d03b702b950d8386361ceb36f84a86f49715bdef3947c42b5375c59e3ca1814e91fa20603191601d749b8e627cbb546cbb3
data/README.md CHANGED
@@ -51,10 +51,27 @@ my_client.nfs.get_directory("/mydir")["files"].each do |file|
51
51
  end
52
52
  ```
53
53
 
54
+ ## Structured Data (SD): **EMULATED**
55
+ SD's have not been officially implemented by MaidSafe, but we provide a sub-module (sd) that emulates it.
56
+ All the information are stored in the Safe Network, through DNS/NFS sub-systems.
57
+
58
+ Example:
59
+ ```ruby
60
+ my_client.sd.create(37267, 102, "Hello World") # 37267 = id, 102 = tag_type
61
+ my_client.sd.get(37267, 102)
62
+ my_client.sd.update(37267, 102, "Hello World!")
63
+ ```
64
+
65
+ For more information see:
66
+ https://github.com/maidsafe/rfcs/blob/master/proposed/0028-launcher-low-level-api/0028-launcher-low-level-api.md
67
+
54
68
  ## Supported methods:
55
69
  |Module|Method|Arguments|Optional|Doc|
56
70
  |------|------|---------|--------|---|
57
- |nfs|create_directory|dir_path|is_private, is_versioned, is_path_shared|Reference: https://maidsafe.readme.io/docs/nfs-create-directory|
71
+ |sd|create|id, tag_type, contents|||
72
+ |sd|update|id, tag_type, contents|||
73
+ |sd|get|id, tag_type|||
74
+ |nfs|create_directory|dir_path|is_private, is_versioned, is_path_shared|https://maidsafe.readme.io/docs/nfs-create-directory|
58
75
  |nfs|get_directory|dir_path|is_path_shared|https://maidsafe.readme.io/docs/nfs-get-directory|
59
76
  |nfs|delete_directory|dir_path|is_path_shared|https://maidsafe.readme.io/docs/nfs-create-directory|
60
77
  |nfs|file|file_path|is_private, is_versioned, is_path_shared|https://maidsafe.readme.io/docs/nfsfile|
data/lib/safenet.rb CHANGED
@@ -13,7 +13,7 @@ require "cgi" # CGI.escape method
13
13
  module SafeNet
14
14
 
15
15
  class Client
16
- attr_reader :auth, :nfs, :dns, :app_info, :key_helper
16
+ attr_reader :auth, :nfs, :dns, :sd, :app_info, :key_helper
17
17
 
18
18
  def initialize(options = {})
19
19
  @app_info = defaults()
@@ -22,6 +22,7 @@ module SafeNet
22
22
  @auth = SafeNet::Auth.new(self)
23
23
  @nfs = SafeNet::NFS.new(self)
24
24
  @dns = SafeNet::DNS.new(self)
25
+ @sd = SafeNet::SD.new(self)
25
26
  end
26
27
 
27
28
  def set_app_info(options = {})
@@ -545,7 +546,7 @@ module SafeNet
545
546
 
546
547
  # https://maidsafe.readme.io/docs/dns-get-file-unauth
547
548
  # get_file_unauth("thegoogle", "www", "index.html", offset: 3, length: 5)
548
- def self.get_file_unauth(long_name, service_name, file_path, options = {})
549
+ def get_file_unauth(long_name, service_name, file_path, options = {})
549
550
  # default values
550
551
  options[:offset] = 0 if ! options.has_key?(:offset)
551
552
 
@@ -566,4 +567,33 @@ module SafeNet
566
567
  res.code == "200" ? res.body : JSON.parse(res.body)
567
568
  end
568
569
  end
570
+
571
+ class SD
572
+ def initialize(client_obj)
573
+ @client = client_obj
574
+ end
575
+
576
+ def create(id, tag_type, contents)
577
+ version = 1
578
+ new_id = Digest::SHA2.new(512).hexdigest("#{id}#{tag_type}")
579
+ res = @client.nfs.create_directory("/#{new_id}", is_private: false) == true
580
+ res &&= @client.nfs.file("/#{new_id}/data.#{version}", is_private: false) == true
581
+ res &&= @client.nfs.update_file_content("/#{new_id}/data.#{version}", contents) == true
582
+ res &&= @client.dns.register_service("#{new_id}", "sd", "/#{new_id}") == true
583
+ res
584
+ end
585
+
586
+ def update(id, tag_type, contents)
587
+ version = 1
588
+ new_id = Digest::SHA2.new(512).hexdigest("#{id}#{tag_type}")
589
+ res = @client.nfs.update_file_content("/#{new_id}/data.#{version}", contents) == true
590
+ res
591
+ end
592
+
593
+ def get(id, tag_type)
594
+ version = 1
595
+ new_id = Digest::SHA2.new(512).hexdigest("#{id}#{tag_type}")
596
+ @client.dns.get_file_unauth("#{new_id}", "sd", "data.#{version}")
597
+ end
598
+ end
569
599
  end
@@ -1,3 +1,3 @@
1
1
  module Safenet
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-safenet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Loureiro