Class: SafeNet::DNS
- Inherits:
-
Object
- Object
- SafeNet::DNS
- Defined in:
- lib/safenet.rb
Instance Method Summary collapse
-
#add_service(long_name, service_name, service_home_dir_path) ⇒ Object
Add a service to a registered long name.
-
#create_long_name(long_name) ⇒ Object
Register a long name.
-
#get_file_unauth(long_name, service_name, file_path) ⇒ Object
maidsafe.readme.io/docs/dns-get-file-unauth get_file_unauth(“thegoogle”, “www”, “index.html”).
- #get_home_dir(long_name, service_name) ⇒ Object
-
#initialize(client_obj) ⇒ DNS
constructor
A new instance of DNS.
- #list_long_names ⇒ Object
- #list_services(long_name) ⇒ Object
-
#register_service(long_name, service_name, service_home_dir_path, options = {}) ⇒ Object
Register a long name and a service.
Constructor Details
#initialize(client_obj) ⇒ DNS
Returns a new instance of DNS.
557 558 559 |
# File 'lib/safenet.rb', line 557 def initialize(client_obj) @client = client_obj end |
Instance Method Details
#add_service(long_name, service_name, service_home_dir_path) ⇒ Object
Add a service to a registered long name. Only authorised requests can invoke the API.
Usage: my_client.dns.add_service(“my-domain”, “www”, “/sources”) Fail: “description”=>“FfiError::InvalidPath” Success: true
Reference: maidsafe.readme.io/docs/dns
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 |
# File 'lib/safenet.rb', line 635 def add_service(long_name, service_name, service_home_dir_path) # Entry point url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/dns" # Payload payload = { longName: long_name, serviceName: service_name, rootPath: 'app', serviceHomeDirPath: service_home_dir_path, } # API call uri = URI(url) http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Put.new(uri.path, { 'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}", 'Content-Type' => 'application/json' }) req.body = payload.to_json res = http.request(req) res.code == "200" ? true : JSON.parse(res.body) end |
#create_long_name(long_name) ⇒ Object
Register a long name. Long names are public names that can be shared. Only authorised requests can invoke the API.
Usage: my_client.dns.create_long_name(“my-domain”) Fail: “description”=>“FfiError::InvalidPath” Success: true
Reference: maidsafe.readme.io/docs/dns-create-long-name
571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
# File 'lib/safenet.rb', line 571 def create_long_name(long_name) # entry point url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/dns/#{SafeNet.escape(long_name)}" # api call uri = URI(url) http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Post.new(uri.path, { 'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}", 'Content-Type' => 'text/plain' }) res = http.request(req) res.code == "200" ? true : JSON.parse(res.body) end |
#get_file_unauth(long_name, service_name, file_path) ⇒ Object
maidsafe.readme.io/docs/dns-get-file-unauth get_file_unauth(“thegoogle”, “www”, “index.html”)
709 710 711 712 713 714 715 716 717 718 719 720 721 |
# File 'lib/safenet.rb', line 709 def get_file_unauth(long_name, service_name, file_path) # entry point url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/dns/#{SafeNet.escape(service_name)}/#{SafeNet.escape(long_name)}/#{SafeNet.escape(file_path)}" # api call uri = URI(url) http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Get.new(uri.path) res = http.request(req) res_headers = {} res.response.each_header {|k,v| res_headers[k] = v} res.code == "200" ? {"headers" => res_headers, "body" => res.body} : JSON.parse(res.body) end |
#get_home_dir(long_name, service_name) ⇒ Object
692 693 694 695 696 697 698 699 700 701 702 703 704 |
# File 'lib/safenet.rb', line 692 def get_home_dir(long_name, service_name) # entry point url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/dns/#{SafeNet.escape(service_name)}/#{SafeNet.escape(long_name)}" # api call uri = URI(url) http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Get.new(uri.path) res = http.request(req) res = JSON.parse(res.body) res["info"]["metadata"] = Base64.strict_decode64(res["info"]["metadata"]) if res.has_key?("info") && res["info"].has_key?("metadata") res end |
#list_long_names ⇒ Object
661 662 663 664 665 666 667 668 669 670 671 672 673 |
# File 'lib/safenet.rb', line 661 def list_long_names # entry point url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/dns" # api call uri = URI(url) http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Get.new(uri.path, { 'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}", }) res = http.request(req) JSON.parse(res.body) end |
#list_services(long_name) ⇒ Object
676 677 678 679 680 681 682 683 684 685 686 687 688 |
# File 'lib/safenet.rb', line 676 def list_services(long_name) # entry point url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/dns/#{SafeNet.escape(long_name)}" # api call uri = URI(url) http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Get.new(uri.path, { 'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}", }) res = http.request(req) JSON.parse(res.body) end |
#register_service(long_name, service_name, service_home_dir_path, options = {}) ⇒ Object
Register a long name and a service. Only authorised requests can invoke the API.
Usage: my_client.dns.register_service(“my-domain”, “www”, “/sources”) Fail: “description”=>“FfiError::InvalidPath” Success: true
Reference: maidsafe.readme.io/docs/dns-register-service
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 |
# File 'lib/safenet.rb', line 597 def register_service(long_name, service_name, service_home_dir_path, = {}) # Entry point url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/dns" # Payload payload = { longName: long_name, serviceName: service_name, rootPath: 'app', serviceHomeDirPath: service_home_dir_path, } # Optional payload["metadata"] = [:meta] if .has_key?(:meta) # API call uri = URI(url) http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Post.new(uri.path, { 'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}", 'Content-Type' => 'application/json' }) req.body = payload.to_json res = http.request(req) res.code == "200" ? true : JSON.parse(res.body) end |