Class: HTTPWrapper
- Inherits:
-
Object
- Object
- HTTPWrapper
- Defined in:
- lib/http_wrapper/errors.rb,
lib/http_wrapper/request.rb,
lib/http_wrapper/version.rb,
lib/http_wrapper/constants.rb,
lib/http_wrapper/http_wrapper.rb
Defined Under Namespace
Modules: CONTENT_TYPE, HEADER Classes: Request
Constant Summary collapse
- HTTPWrapperError =
Class.new StandardError
- TooManyRedirectsError =
Class.new HTTPWrapperError
- UnknownParameterError =
Class.new HTTPWrapperError
- VERSION =
'2.1.0'.freeze
- USER_AGENT =
"HTTPWrapper/#{HTTPWrapper::VERSION}; Ruby/#{RUBY_VERSION}".freeze
- AJAX_HEADER =
{ HEADER::AJAX => 'XMLHttpRequest'.freeze }.freeze
- JSON_HEADER =
{ HEADER::CONTENT_TYPE => CONTENT_TYPE::JSON }.freeze
- AJAX_JSON_HEADER =
AJAX_HEADER.dup.merge!(JSON_HEADER).freeze
- KNOWN_OPTIONS_KEYS =
[:timeout, :verify_cert, :logger, :max_redirects, :user_agent].freeze
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_redirects ⇒ Object
Returns the value of attribute max_redirects.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
-
#verify_cert ⇒ Object
Returns the value of attribute verify_cert.
Instance Method Summary collapse
- #execute(request, uri) ⇒ Object
-
#initialize(options = {}) ⇒ HTTPWrapper
constructor
A new instance of HTTPWrapper.
- #post_and_get_cookie(url, params = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ HTTPWrapper
Returns a new instance of HTTPWrapper.
8 9 10 11 12 13 14 15 16 |
# File 'lib/http_wrapper/http_wrapper.rb', line 8 def initialize( = {}) @timeout = .fetch(:timeout) { 10 } @verify_cert = .fetch(:verify_cert) { true } @logger = .fetch(:logger) { nil } @max_redirects = .fetch(:max_redirects) { 10 } @user_agent = .fetch(:user_agent) { USER_AGENT } end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/http_wrapper/http_wrapper.rb', line 6 def logger @logger end |
#max_redirects ⇒ Object
Returns the value of attribute max_redirects.
6 7 8 |
# File 'lib/http_wrapper/http_wrapper.rb', line 6 def max_redirects @max_redirects end |
#timeout ⇒ Object
Returns the value of attribute timeout.
6 7 8 |
# File 'lib/http_wrapper/http_wrapper.rb', line 6 def timeout @timeout end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
6 7 8 |
# File 'lib/http_wrapper/http_wrapper.rb', line 6 def user_agent @user_agent end |
#verify_cert ⇒ Object
Returns the value of attribute verify_cert.
6 7 8 |
# File 'lib/http_wrapper/http_wrapper.rb', line 6 def verify_cert @verify_cert end |
Instance Method Details
#execute(request, uri) ⇒ Object
40 41 42 43 |
# File 'lib/http_wrapper/http_wrapper.rb', line 40 def execute(request, uri) connection = create_connection uri connection.request request end |
#post_and_get_cookie(url, params = {}) ⇒ Object
35 36 37 38 |
# File 'lib/http_wrapper/http_wrapper.rb', line 35 def (url, params = {}) response = post url, params response.response['set-cookie'] end |