Class: Swivel2::Connection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = Config.default) ⇒ Connection

Returns a new instance of Connection.



6
7
8
9
10
# File 'lib/swivel2/connection.rb', line 6

def initialize config = Config.default
  @config = config.is_a?(Hash) ? Config.new(config) : config
  @resource = ActiveResource::Connection.new @config.site
  @format = Swivel2::Formats::XmlFormat
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/swivel2/connection.rb', line 4

def config
  @config
end

#formatObject (readonly)

Returns the value of attribute format.



4
5
6
# File 'lib/swivel2/connection.rb', line 4

def format
  @format
end

#resourceObject (readonly)

Returns the value of attribute resource.



4
5
6
# File 'lib/swivel2/connection.rb', line 4

def resource
  @resource
end

Instance Method Details

#call(path, params = {}, method = :get, headers = {}) ⇒ Object



28
29
30
# File 'lib/swivel2/connection.rb', line 28

def call path, params = {}, method = :get, headers = {}
  request method, path, params, headers
end

#delete(path, params = {}, headers = {}) ⇒ Object



24
25
26
# File 'lib/swivel2/connection.rb', line 24

def delete path, params = {}, headers = {}
  request :delete, path, params, headers
end

#error(exception) ⇒ Object



42
43
44
# File 'lib/swivel2/connection.rb', line 42

def error exception
  build format.decode(exception.response.body)
end

#get(path, params = {}, headers = {}) ⇒ Object



16
17
18
# File 'lib/swivel2/connection.rb', line 16

def get path, params = {}, headers = {}
  request :get, path, params, headers
end

#post(path, params = {}, headers = {}) ⇒ Object



12
13
14
# File 'lib/swivel2/connection.rb', line 12

def post path, params = {}, headers = {}
  request :post, path, params, headers
end

#put(path, params = {}, headers = {}) ⇒ Object



20
21
22
# File 'lib/swivel2/connection.rb', line 20

def put path, params = {}, headers = {}
  request :put, path, params, headers
end