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.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/right_api/http_server.rb', line 8 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| false 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.
5 6 7 |
# File 'lib/right_api/http_server.rb', line 5 def handle_errors @handle_errors end |
#headers ⇒ Object
Returns the value of attribute headers.
5 6 7 |
# File 'lib/right_api/http_server.rb', line 5 def headers @headers end |
#last_response ⇒ Object (readonly)
Returns the value of attribute last_response.
6 7 8 |
# File 'lib/right_api/http_server.rb', line 6 def last_response @last_response end |
#response_error_checker ⇒ Object
Returns the value of attribute response_error_checker.
5 6 7 |
# File 'lib/right_api/http_server.rb', line 5 def response_error_checker @response_error_checker end |
Instance Method Details
#delete(resource, &block) ⇒ Object
26 27 28 |
# File 'lib/right_api/http_server.rb', line 26 def delete(resource, &block) connect(resource, Net::HTTP::Delete, &block) end |
#get(resource, &block) ⇒ Object
30 31 32 |
# File 'lib/right_api/http_server.rb', line 30 def get(resource, &block) connect(resource, Net::HTTP::Get, &block) end |
#get_with_params(resource, params = {}, &block) ⇒ Object
34 35 36 |
# File 'lib/right_api/http_server.rb', line 34 def get_with_params(resource, params={}, &block) connect(resource, Net::HTTP::Get, encode_params(params), &block) end |
#post(resource, params = {}, &block) ⇒ Object
38 39 40 |
# File 'lib/right_api/http_server.rb', line 38 def post(resource, params={}, &block) connect(resource, Net::HTTP::Post, encode_params(params), &block) end |
#put(resource, params = {}, &block) ⇒ Object
42 43 44 |
# File 'lib/right_api/http_server.rb', line 42 def put(resource, params={}, &block) connect(resource, Net::HTTP::Put, encode_params(params), &block) end |
#with_error_handling_disabled ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/right_api/http_server.rb', line 46 def with_error_handling_disabled original_handle_errors = handle_errors self.handle_errors = false result = yield ensure self.handle_errors = original_handle_errors end |