Module: Snapshot

Extended by:
Snapshot
Included in:
Snapshot
Defined in:
lib/snapshot.rb,
lib/snapshot/url.rb,
lib/snapshot/image.rb,
lib/snapshot/token.rb,
lib/snapshot/version.rb,
lib/snapshot/connection.rb

Defined Under Namespace

Classes: Connection, Image, Token, URL

Constant Summary collapse

VERSION =
'0.3.3'

Instance Method Summary collapse

Instance Method Details

#configure(opts = false) ⇒ Object

Configures and connects to Snapshot.

Parameters

  • opts - String or Hash

  • block - The block is optional and is passed a Connection object

Examples

# Using a String:
Snapshot.configure('http://access_key:[email protected]/')

# Using a Hash:
Snapshot.configure(:access_key => 'access_key', :container => 'subdomain', :secret_key => 'secret_key')

# Using a block:
Snapshot.configure do |config|
  config.access_key = 'access_key'
  config.container = 'subdomain'
  config.secret_key = 'secret_key
end


32
33
34
35
36
37
38
# File 'lib/snapshot.rb', line 32

def configure(opts=false)
  if opts
    connect!(opts)
  else
    yield @connection = Connection.new
  end
end

#connect!(opts = nil) ⇒ Object

Connects the library to Snapshot. If no connection options are given, the method will try to use the environment variable SNAPSHOT_URL.

Parameters

  • opts - (optional) String or Hash

Examples

# Using a String:
Snapshot.connect!('http://access_key:[email protected]/')

# Using a Hash:
Snapshot.connect!(:access_key => 'access_key', :domain => 'subdomain.snapshothq.com', :secret_key => 'secret_key')


55
56
57
58
# File 'lib/snapshot.rb', line 55

def connect!(opts=nil)
  opts = ENV['SNAPSHOT_URL'] if opts.nil?
  @connection = Connection.new(opts)
end

#connectionObject

Returns the connection for the library. Will raise an error if the library has not been connected via the connect! method



63
64
65
66
# File 'lib/snapshot.rb', line 63

def connection
  raise 'Not connected. Please connect! first.' unless @connection
  @connection
end

#disconnect!Object

Terminates the connection to Snapshot



69
70
71
# File 'lib/snapshot.rb', line 69

def disconnect!
  @connection = nil
end

#urlObject

Returns the URL to use for Snapshot.



74
75
76
# File 'lib/snapshot.rb', line 74

def url
  connection.url
end