ruby-safenet 0.2.2 → 0.2.3

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: 95000fa0f123dd91f41046aed1f0f5d1d054048e
4
- data.tar.gz: 5611d26b57058c3fa601365c7de12c20a9c8a15c
3
+ metadata.gz: 715ff6f246885377bf8dc67d3e51476966c2a39c
4
+ data.tar.gz: 426547e4d0a810938f6330b93a8c81c9d7dce252
5
5
  SHA512:
6
- metadata.gz: 7887a0fa84e9da8aa679da56006909fa95b20d6d0780840732f77da5c6ddafb046206b4dd13bd6c04187f2ab9b53dcec947e26f175d639eb3c94ec43e943a600
7
- data.tar.gz: d015d021cccc7665d3c299dc9d83c414fa9cdef105a972a1dd4b9d8c01b11b918bc12aae7eda345766457ccecf5fe96f9ebb7627a3adfe18f799b98d8c99a43a
6
+ metadata.gz: 2012bfc016585980a254f1387c7f758fede3de626007846473a49c573768861c102369d19fe727a3777924fdde17cf61852a4a7ec70d02e80044985489b0e969
7
+ data.tar.gz: 1134b7912d810184d156990c8942be6bfa7dfdcedfddf9d8a0f2da099c6dd88803be00e7df535c37729d1f4bf4518019a738c2b11fa1c9516b0ba351978de5ea
data/README.md CHANGED
@@ -52,16 +52,22 @@ end
52
52
  ```
53
53
 
54
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.
55
+ Although SD has not been officially implemented by MaidSafe yet, we provide a sub-module (sd) that emulates it.
56
56
  All the information are stored in the Safe Network, through DNS/NFS sub-systems.
57
57
 
58
58
  Example:
59
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!")
60
+ my_client.sd.create(37267, 11, "Hello World") # 37267 = id, 11 = tag_type
61
+ my_client.sd.get(37267, 11)
62
+ my_client.sd.update(37267, 11, "Hello World!")
63
+
64
+ my_client.raw.create("Hello World!") # => "861844d6704e8573fec34d967e20bcfef3d424cf48be04e6dc08f2bd58c729743371015ead891cc3cf1c9d34b49264b510751b1ff9e537937bc46b5d6ff4ecc8"
65
+ my_client.raw.create_from_file("/home/daniel/dog.jpg")
66
+ my_client.raw.get("861844d6704e8573fec34d967e20bcfef3d424cf48be04e6dc08f2bd58c729743371015ead891cc3cf1c9d34b49264b510751b1ff9e537937bc46b5d6ff4ecc8") # => "Hello World!"
63
67
  ```
64
68
 
69
+ Encryption and versioning are both not supported in this emulated version.
70
+
65
71
  For more information see:
66
72
  https://github.com/maidsafe/rfcs/blob/master/proposed/0028-launcher-low-level-api/0028-launcher-low-level-api.md
67
73
 
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, :sd, :app_info, :key_helper
16
+ attr_reader :auth, :nfs, :dns, :sd, :raw, :app_info, :key_helper
17
17
 
18
18
  def initialize(options = {})
19
19
  @app_info = defaults()
@@ -23,6 +23,7 @@ module SafeNet
23
23
  @nfs = SafeNet::NFS.new(self)
24
24
  @dns = SafeNet::DNS.new(self)
25
25
  @sd = SafeNet::SD.new(self)
26
+ @raw = SafeNet::Raw.new(self)
26
27
  end
27
28
 
28
29
  def set_app_info(options = {})
@@ -596,4 +597,26 @@ module SafeNet
596
597
  @client.dns.get_file_unauth("SD#{new_id}", "sd", "data.#{version}")
597
598
  end
598
599
  end
600
+
601
+ class Raw
602
+ def initialize(client_obj)
603
+ @client = client_obj
604
+ end
605
+
606
+ def create(contents)
607
+ id = Digest::SHA2.new(512).hexdigest(contents)
608
+ @client.sd.create(id, -1, contents)
609
+ id
610
+ end
611
+
612
+ def create_from_file(local_path)
613
+ id = Digest::SHA2.new(512).file(local_path).hexdigest
614
+ @client.sd.create(id, -1, File.read(local_path))
615
+ id
616
+ end
617
+
618
+ def get(id)
619
+ @client.sd.get(id, -1)
620
+ end
621
+ end
599
622
  end
@@ -1,3 +1,3 @@
1
1
  module Safenet
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
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.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Loureiro