Module: Gobbler

Defined in:
lib/gobbler.rb,
lib/gobbler/base.rb,
lib/gobbler/quota.rb,
lib/gobbler/folder.rb,
lib/gobbler/volume.rb,
lib/gobbler/machine.rb,
lib/gobbler/project.rb,
lib/gobbler/version.rb,
lib/gobbler/mappable.rb,
lib/gobbler/referral.rb,
lib/gobbler/dashboard.rb,
lib/gobbler/checkpoint.rb,
lib/gobbler/client_version.rb

Defined Under Namespace

Modules: Mappable Classes: Base, Checkpoint, ClientVersion, Dashboard, Folder, Machine, Project, Quota, Referral, Volume

Constant Summary collapse

VERSION =
"0.1.2"
@@api_server =
"api.gobbler.com"
@@client_version =
"dev"
@@machine_serial =
"api"
@@config =
{}
@@keys =
{}

Class Method Summary collapse

Class Method Details

.config(opts) ⇒ Object

Set the configuration

Options are passed as a Hash of symbols

Parameters:

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • :email (String)

    Email of Gobbler account

  • :password (String)

    Password of Gobbler account



35
36
37
38
39
40
41
42
# 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

.dashboardDashboard

Returns:



5
# File 'lib/gobbler/dashboard.rb', line 5

def self.dashboard; Dashboard.get; end

.folder(guid) ⇒ Folder

Alias for Gobbler::Base.get

Parameters:

  • guid (String)

    The guid of the folder

Returns:



6
# File 'lib/gobbler/folder.rb', line 6

def self.folder(guid); Folder.get(guid); end

.folders(opts = {}) ⇒ Array<Folder>

Returns:

  • (Array<Folder>)

    An array of Folders



10
# File 'lib/gobbler/folder.rb', line 10

def self.folders(opts = {}); Folder.list(opts); end

.login!Boolean

Returns Login successful, will raise an error if it was not.

Returns:

  • (Boolean)

    Login successful, will raise an error if it was not



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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) ⇒ Machine

Alias for Gobbler::Base.get

Parameters:

  • guid (String)

    The guid of the machine

Returns:



6
# File 'lib/gobbler/machine.rb', line 6

def self.machine(guid); Machine.get(guid); end

.machines(opts = {}) ⇒ Array<Machine>

Returns:

  • (Array<Machine>)

    An array of Folders



10
# File 'lib/gobbler/machine.rb', line 10

def self.machines(opts = {}); Machine.list(opts); end

.project(guid) ⇒ Project

Alias for Gobbler::Base.get

Parameters:

  • guid (String)

    The guid of the project

Returns:



6
# File 'lib/gobbler/project.rb', line 6

def self.project(guid); Project.get(guid); end

.projects(opts = {}) ⇒ Array<Project>

Returns:

  • (Array<Project>)

    An array of Backed up projects



10
# File 'lib/gobbler/project.rb', line 10

def self.projects(opts = {}); Project.list(opts); end

.quotaObject

Alias for Gobbler::Quota.get



4
# File 'lib/gobbler/quota.rb', line 4

def self.quota; Quota.get; end

.referralsArray<Referral>

Returns:



5
# File 'lib/gobbler/referral.rb', line 5

def self.referrals; Referral.list; end

.request(uri, body = nil) ⇒ Hash

Returns Hash from the JSON API server response.

Returns:

  • (Hash)

    Hash from the JSON API server response



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# 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?Boolean

Returns If you are currently signed into the Gobbler API.

Returns:

  • (Boolean)

    If you are currently signed into the Gobbler API



101
102
103
# File 'lib/gobbler.rb', line 101

def signed_in?
  !client_key.nil? && client_key != ""
end

.unpack(str) ⇒ Hash

Returns The unpacked JSON string.

Returns:

  • (Hash)

    The unpacked JSON string



93
94
95
96
97
98
# 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) ⇒ Volume

Alias for Gobbler::Base.get

Parameters:

  • guid (String)

    The guid of the volume

Returns:



6
# File 'lib/gobbler/volume.rb', line 6

def self.volume(guid); Volume.get(guid); end

.volumes(opts = {}) ⇒ Array<Volume>

Returns:

  • (Array<Volume>)

    An array of Volumes



10
# File 'lib/gobbler/volume.rb', line 10

def self.volumes(opts = {}); Volume.list(opts); end