module Gobbler

Constants

VERSION

Public Class Methods

config(opts) click to toggle source

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
dashboard() click to toggle source

Alias for {Gobbler::Dashboard.get} @return [Dashboard] Metrics for your account

# File lib/gobbler/dashboard.rb, line 5
def self.dashboard; Dashboard.get; end
folder(guid) click to toggle source

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
folders(opts = {}) click to toggle source

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
login!() click to toggle source

@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
machine(guid) click to toggle source

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
machines(opts = {}) click to toggle source

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
project(guid) click to toggle source

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
projects(opts = {}) click to toggle source

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
quota() click to toggle source

Alias for {Quota.get}

# File lib/gobbler/quota.rb, line 4
def self.quota; Quota.get; end
referrals() click to toggle source

Alias for {Referral.list} @return [Array<Referral>] All referrals

# File lib/gobbler/referral.rb, line 5
def self.referrals; Referral.list; end
request(uri, body = nil) click to toggle source

@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
signed_in?() click to toggle source

@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
unpack(str) click to toggle source

@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
volume(guid) click to toggle source

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
volumes(opts = {}) click to toggle source

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

api_server() click to toggle source
# File lib/gobbler.rb, line 107
def api_server; @@api_server; end
client_key() click to toggle source
# File lib/gobbler.rb, line 108
def client_key; @@keys[:client_key]; end
client_version() click to toggle source
# File lib/gobbler.rb, line 109
def client_version; @@client_version; end
machine_serial() click to toggle source
# File lib/gobbler.rb, line 111
def machine_serial; @@machine_serial; end