Class: HttpServer
- Inherits:
-
Object
- Object
- HttpServer
- Defined in:
- lib/right_api/http_server.rb
Instance Attribute Summary collapse
-
#handle_errors ⇒ Object
Returns the value of attribute handle_errors.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
-
#response_error_checker ⇒ Object
Returns the value of attribute response_error_checker.
Instance Method Summary collapse
- #delete(resource, &block) ⇒ Object
- #get(resource, &block) ⇒ Object
- #get_with_params(resource, params = {}, &block) ⇒ Object
-
#initialize(server_config, timeout) ⇒ HttpServer
constructor
A new instance of HttpServer.
- #post(resource, params = {}, &block) ⇒ Object
- #put(resource, params = {}, &block) ⇒ Object
- #with_error_handling_disabled ⇒ Object
Constructor Details
#initialize(server_config, timeout) ⇒ HttpServer
Returns a new instance of HttpServer.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/right_api/http_server.rb', line 5 def initialize(server_config, timeout) @server_url, @port, @username, @password = server_config['server_url'], server_config['port'], server_config['username'], server_config['password'] @timeout = timeout raise 'No configuration for timeout length' if @timeout.nil? @handle_errors = true @response_error_checker = Proc.new do |response, path| response.include? 'errors' if response end @headers = { 'User-Agent' => 'Mozilla/4.0', 'Content-Type' => 'application/x-www-form-urlencoded', 'Connection' => 'Keep-Alive', 'X-API-VERSION' => RightScale::API_VERSION } end |
Instance Attribute Details
#handle_errors ⇒ Object
Returns the value of attribute handle_errors.
2 3 4 |
# File 'lib/right_api/http_server.rb', line 2 def handle_errors @handle_errors end |
#headers ⇒ Object
Returns the value of attribute headers.
2 3 4 |
# File 'lib/right_api/http_server.rb', line 2 def headers @headers end |
#last_response ⇒ Object (readonly)
Returns the value of attribute last_response.
3 4 5 |
# File 'lib/right_api/http_server.rb', line 3 def last_response @last_response end |
#response_error_checker ⇒ Object
Returns the value of attribute response_error_checker.
2 3 4 |
# File 'lib/right_api/http_server.rb', line 2 def response_error_checker @response_error_checker end |
Instance Method Details
#delete(resource, &block) ⇒ Object
23 24 25 |
# File 'lib/right_api/http_server.rb', line 23 def delete(resource, &block) connect(resource, Net::HTTP::Delete, &block) end |
#get(resource, &block) ⇒ Object
27 28 29 |
# File 'lib/right_api/http_server.rb', line 27 def get(resource, &block) connect(resource, Net::HTTP::Get, &block) end |
#get_with_params(resource, params = {}, &block) ⇒ Object
31 32 33 |
# File 'lib/right_api/http_server.rb', line 31 def get_with_params(resource, params={}, &block) connect(resource, Net::HTTP::Get, encode_params(params), &block) end |
#post(resource, params = {}, &block) ⇒ Object
35 36 37 |
# File 'lib/right_api/http_server.rb', line 35 def post(resource, params={}, &block) connect(resource, Net::HTTP::Post, encode_params(params), &block) end |
#put(resource, params = {}, &block) ⇒ Object
39 40 41 |
# File 'lib/right_api/http_server.rb', line 39 def put(resource, params={}, &block) connect(resource, Net::HTTP::Put, encode_params(params), &block) end |
#with_error_handling_disabled ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/right_api/http_server.rb', line 43 def with_error_handling_disabled original_handle_errors = handle_errors self.handle_errors = false result = yield ensure self.handle_errors = original_handle_errors end |