Class: Swivel2::Connection
- Inherits:
-
Object
- Object
- Swivel2::Connection
- Defined in:
- lib/swivel2/connection.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #call(path, params = {}, method = :get, headers = {}) ⇒ Object
- #delete(path, params = {}, headers = {}) ⇒ Object
- #error(exception) ⇒ Object
- #get(path, params = {}, headers = {}) ⇒ Object
-
#initialize(config = Config.default) ⇒ Connection
constructor
A new instance of Connection.
- #post(path, params = {}, headers = {}) ⇒ Object
- #put(path, params = {}, headers = {}) ⇒ Object
Constructor Details
#initialize(config = Config.default) ⇒ Connection
Returns a new instance of Connection.
19 20 21 22 23 24 |
# File 'lib/swivel2/connection.rb', line 19 def initialize config = Config.default @config = config.is_a?(Hash) ? Config.new(config) : config @resource = Resource.new @config.site @resource.read_timeout = @config.timeout_read if @config.timeout_read @format = Swivel2::Formats::XmlFormat end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
17 18 19 |
# File 'lib/swivel2/connection.rb', line 17 def config @config end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
17 18 19 |
# File 'lib/swivel2/connection.rb', line 17 def format @format end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
17 18 19 |
# File 'lib/swivel2/connection.rb', line 17 def resource @resource end |
Instance Method Details
#call(path, params = {}, method = :get, headers = {}) ⇒ Object
42 43 44 |
# File 'lib/swivel2/connection.rb', line 42 def call path, params = {}, method = :get, headers = {} request method, path, params, headers end |
#delete(path, params = {}, headers = {}) ⇒ Object
38 39 40 |
# File 'lib/swivel2/connection.rb', line 38 def delete path, params = {}, headers = {} request :delete, path, params, headers end |
#error(exception) ⇒ Object
56 57 58 |
# File 'lib/swivel2/connection.rb', line 56 def error exception build format.decode(exception.response.body) end |
#get(path, params = {}, headers = {}) ⇒ Object
30 31 32 |
# File 'lib/swivel2/connection.rb', line 30 def get path, params = {}, headers = {} request :get, path, params, headers end |
#post(path, params = {}, headers = {}) ⇒ Object
26 27 28 |
# File 'lib/swivel2/connection.rb', line 26 def post path, params = {}, headers = {} request :post, path, params, headers end |
#put(path, params = {}, headers = {}) ⇒ Object
34 35 36 |
# File 'lib/swivel2/connection.rb', line 34 def put path, params = {}, headers = {} request :put, path, params, headers end |