Class: HTTPWrapper
- Inherits:
-
Object
- Object
- HTTPWrapper
- Defined in:
- lib/http_wrapper/util.rb,
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: Util Classes: Request
Constant Summary collapse
- Error =
Class.new StandardError
- TooManyRedirectsError =
Class.new Error
- UnknownKeyError =
Class.new Error
- VERSION =
'4.0.0'- USER_AGENT =
"HTTPWrapper/#{HTTPWrapper::VERSION}; Ruby/#{RUBY_VERSION}"- CONTENT_TYPE_HEADER_NAME =
'content-type'- USER_AGENT_HEADER_NAME =
'user-agent'- COOKIE_HEADER_NAME =
'cookie'- AJAX_HEADER_NAME =
'x-requested-with'- DEFAULT_CONTENT_TYPE =
'text/html; charset=UTF-8'- JSON_CONTENT_TYPE =
'application/json; charset=UTF-8'- POST_CONTENT_TYPE =
'application/x-www-form-urlencoded'- MULTIPART_CONTENT_TYPE =
'multipart/form-data'- AJAX_HEADER =
{ AJAX_HEADER_NAME => 'XMLHttpRequest' }.freeze
- JSON_HEADER =
{ CONTENT_TYPE_HEADER_NAME => JSON_CONTENT_TYPE }.freeze
- AJAX_JSON_HEADER =
AJAX_HEADER.dup.merge!(JSON_HEADER).freeze
- KNOWN_OPTIONS_KEYS =
%i[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.
10 11 12 13 14 15 16 17 18 |
# File 'lib/http_wrapper/http_wrapper.rb', line 10 def initialize( = {}) Util.validate_hash_keys , KNOWN_OPTIONS_KEYS @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.
8 9 10 |
# File 'lib/http_wrapper/http_wrapper.rb', line 8 def logger @logger end |
#max_redirects ⇒ Object
Returns the value of attribute max_redirects.
8 9 10 |
# File 'lib/http_wrapper/http_wrapper.rb', line 8 def max_redirects @max_redirects end |
#timeout ⇒ Object
Returns the value of attribute timeout.
8 9 10 |
# File 'lib/http_wrapper/http_wrapper.rb', line 8 def timeout @timeout end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
8 9 10 |
# File 'lib/http_wrapper/http_wrapper.rb', line 8 def user_agent @user_agent end |
#verify_cert ⇒ Object
Returns the value of attribute verify_cert.
8 9 10 |
# File 'lib/http_wrapper/http_wrapper.rb', line 8 def verify_cert @verify_cert end |
Instance Method Details
#execute(request, uri) ⇒ Object
43 44 45 46 |
# File 'lib/http_wrapper/http_wrapper.rb', line 43 def execute(request, uri) connection = create_connection uri connection.request request end |
#post_and_get_cookie(url, params = {}) ⇒ Object
38 39 40 41 |
# File 'lib/http_wrapper/http_wrapper.rb', line 38 def (url, params = {}) response = post url, params response['set-cookie'] end |