Class: Vzaar::Connection
- Inherits:
-
Object
- Object
- Vzaar::Connection
- Includes:
- Helper
- Defined in:
- lib/vzaar/connection.rb
Constant Summary collapse
- SERVER =
"vzaar.com"
Instance Attribute Summary collapse
-
#application_token ⇒ Object
readonly
Returns the value of attribute application_token.
-
#force_http ⇒ Object
readonly
Returns the value of attribute force_http.
-
#login ⇒ Object
readonly
Returns the value of attribute login.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #server ⇒ Object
- #using_connection(url, opts = {}, &block) ⇒ Object
Methods included from Helper
#blank?, #hash_to_xml, #symb_keys
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
8 9 10 11 12 13 14 15 |
# File 'lib/vzaar/connection.rb', line 8 def initialize(={}) @options = @application_token = [:application_token] @force_http = [:force_http] @login = [:login] @timeout = [:timeout] @open_timeout = [:open_timeout] end |
Instance Attribute Details
#application_token ⇒ Object (readonly)
Returns the value of attribute application_token.
6 7 8 |
# File 'lib/vzaar/connection.rb', line 6 def application_token @application_token end |
#force_http ⇒ Object (readonly)
Returns the value of attribute force_http.
6 7 8 |
# File 'lib/vzaar/connection.rb', line 6 def force_http @force_http end |
#login ⇒ Object (readonly)
Returns the value of attribute login.
6 7 8 |
# File 'lib/vzaar/connection.rb', line 6 def login @login end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/vzaar/connection.rb', line 6 def @options end |
Instance Method Details
#server ⇒ Object
36 37 38 |
# File 'lib/vzaar/connection.rb', line 36 def server @server ||= blank?(sanitized_url) ? self.class::SERVER : sanitized_url end |
#using_connection(url, opts = {}, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vzaar/connection.rb', line 17 def using_connection(url, opts={}, &block) connection = opts[:authenticated] ? : public_connection case opts[:http_verb] when :get yield handle_response(connection.get(url)) if block_given? when :delete yield handle_response(connection.delete(url)) if block_given? when :post response = connection.post(url, opts[:data], content_type(opts[:format])) yield handle_response(response) if block_given? when :put response = connection.put(url, opts[:data], content_type(opts[:format])) yield handle_response(response) if block_given? else handle_exception :invalid_http_verb end end |