module Gobbler
Constants
- VERSION
Public Class Methods
Set the configuration
Options are passed as a Hash of symbols @option opts [String] :email Email of Gobbler
account @option opts [String] :password Password of Gobbler
account
# File lib/gobbler.rb, line 35 def config(opts) opts.each {|k,v| opts[k.to_sym] ||= opts[k]} @@config = opts @@api_server = opts[:api_server] if opts[:api_server] @@client_version = opts[:client_version] if opts[:client_version] @@machine_serial = opts[:machine_serial] if opts[:machine_serial] login! if opts[:email] && opts[:password] end
Alias for {Gobbler::Dashboard.get} @return [Dashboard] Metrics for your account
# File lib/gobbler/dashboard.rb, line 5 def self.dashboard; Dashboard.get; end
Alias for {Folder.get} @param guid [String] The guid of the folder @return [Folder]
# File lib/gobbler/folder.rb, line 6 def self.folder(guid); Folder.get(guid); end
Alias for {Folder.list} @return [Array<Folder>] An array of Folders
# File lib/gobbler/folder.rb, line 10 def self.folders(opts = {}); Folder.list(opts); end
@return [Boolean] Login successful, will raise an error if it was not
# File lib/gobbler.rb, line 45 def login! raise "No credentials" if @@config[:email].nil? || @@config[:password].nil? authentication = { machine_info: { serial: @@machine_serial }, authentication: { provider: "gobbler", credentials: { email: @@config[:email], password: @@config[:password] } } } response = request("client_user/login", authentication) @@keys[:cookie] = response[:http_response]["Set-Cookie"].split('; ')[0] @@keys[:client_key] = response["client_key"] raise "Can't Login" if @@keys[:client_key].nil? return true end
Alias for {Gobbler::Machine.get} @param guid [String] The guid of the machine @return [Machine]
# File lib/gobbler/machine.rb, line 6 def self.machine(guid); Machine.get(guid); end
Alias for {Gobbler::Machine.list} @return [Array<Machine>] An array of Folders
# File lib/gobbler/machine.rb, line 10 def self.machines(opts = {}); Machine.list(opts); end
Alias for {Gobbler::Project.get} @param guid [String] The guid of the project @return [Project]
# File lib/gobbler/project.rb, line 6 def self.project(guid); Project.get(guid); end
Alias for {Gobbler::Project.list} @return [Array<Project>] An array of Backed up projects
# File lib/gobbler/project.rb, line 10 def self.projects(opts = {}); Project.list(opts); end
Alias for {Quota.get}
# File lib/gobbler/quota.rb, line 4 def self.quota; Quota.get; end
Alias for {Referral.list} @return [Array<Referral>] All referrals
# File lib/gobbler/referral.rb, line 5 def self.referrals; Referral.list; end
@return [Hash] Hash from the JSON API server response
# File lib/gobbler.rb, line 69 def request(uri, body = nil) uri = URI.parse("https://#{api_server}/#{uri}") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE if body request = Net::HTTP::Post.new(uri.request_uri) request.body = body.to_json unless body.nil? else request = Net::HTTP::Get.new(uri.request_uri) end request["Content-type"] = "application/json" request["Cookie"] = cookie request["x-mam-client-version"] = client_version request["x-mam-client-key"] = client_key response = http.request(request) raise unless response.code == "200" JSON.parse(response.body).merge(http_response: response) end
@return [Boolean] If you are currently signed into the Gobbler
API
# File lib/gobbler.rb, line 101 def signed_in? !client_key.nil? && client_key != "" end
@return [Hash] The unpacked JSON string
# File lib/gobbler.rb, line 93 def unpack(str) return [] if str.nil? || str == "" decoded = Base64.decode64(str) unzipped = Zlib::GzipReader.new(StringIO.new(decoded)).read JSON.parse(unzipped) end
Alias for {Volume.get} @param guid [String] The guid of the volume @return [Volume]
# File lib/gobbler/volume.rb, line 6 def self.volume(guid); Volume.get(guid); end
Alias for {Volume.list} @return [Array<Volume>] An array of Volumes
# File lib/gobbler/volume.rb, line 10 def self.volumes(opts = {}); Volume.list(opts); end
Private Class Methods
# File lib/gobbler.rb, line 107 def api_server; @@api_server; end
# File lib/gobbler.rb, line 108 def client_key; @@keys[:client_key]; end
# File lib/gobbler.rb, line 109 def client_version; @@client_version; end
# File lib/gobbler.rb, line 111 def machine_serial; @@machine_serial; end