ruby-safenet 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +18 -1
 - data/lib/safenet.rb +32 -2
 - data/lib/safenet/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 4d8672d7bee04b6dc531d7b333157ec41ea7eb4a
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 07e73624093f756e27961f46df9bb8371a63ad92
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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 
     | 
    
         
            -
            | 
     | 
| 
      
 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  
     | 
| 
      
 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
         
     | 
    
        data/lib/safenet/version.rb
    CHANGED