Class: Snapshot::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/snapshot/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Connection

Creates a new Connection object.

Parameters

  • opts - (optional) String or Hash



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/snapshot/connection.rb', line 17

def initialize(opts={})
  if opts.is_a?(Hash)
    opts.each do |m,v|
      self.send("#{m}=", v)
    end
  else
    uri = URI.parse(opts)
    self.container = uri.host.match(/(.+)\.snapshotapi\.com/)[1]
    self.access_key, self.secret_key = uri.user, uri.password
  end
end

Instance Attribute Details

#access_keyObject

Returns the value of attribute access_key.



9
10
11
# File 'lib/snapshot/connection.rb', line 9

def access_key
  @access_key
end

#containerObject

Returns the value of attribute container.



9
10
11
# File 'lib/snapshot/connection.rb', line 9

def container
  @container
end

#secret_keyObject

Returns the value of attribute secret_key.



9
10
11
# File 'lib/snapshot/connection.rb', line 9

def secret_key
  @secret_key
end

Instance Method Details

#delete(path) ⇒ Object



29
30
31
# File 'lib/snapshot/connection.rb', line 29

def delete(path)
  request(:delete, path)
end

#get(path) ⇒ Object



33
34
35
# File 'lib/snapshot/connection.rb', line 33

def get(path)
  request(:get, path)
end

#post(path, payload = {}) ⇒ Object



37
38
39
# File 'lib/snapshot/connection.rb', line 37

def post(path, payload={})
  request(:post, path, payload)
end

#urlObject

Returns a URL to Snapshot for the connection



43
44
45
# File 'lib/snapshot/connection.rb', line 43

def url
  "http://#{container}.snapshotapi.com"
end