Class: Vzaar::Connection

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/vzaar/connection.rb

Constant Summary collapse

SERVER =
"vzaar.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

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={})
  @options = options
  @application_token = options[:application_token]
  @force_http = options[:force_http]
  @login = options[:login]
  @timeout = options[:timeout]
  @open_timeout = options[:open_timeout]
end

Instance Attribute Details

#application_tokenObject (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_httpObject (readonly)

Returns the value of attribute force_http.



6
7
8
# File 'lib/vzaar/connection.rb', line 6

def force_http
  @force_http
end

#loginObject (readonly)

Returns the value of attribute login.



6
7
8
# File 'lib/vzaar/connection.rb', line 6

def 
  @login
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/vzaar/connection.rb', line 6

def options
  @options
end

Instance Method Details

#serverObject



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] ? authorised_connection : 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