Class: Wework::Request
- Inherits:
-
Object
- Object
- Wework::Request
- Defined in:
- lib/wework/request.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#httprb ⇒ Object
readonly
Returns the value of attribute httprb.
-
#ssl_context ⇒ Object
readonly
Returns the value of attribute ssl_context.
Instance Method Summary collapse
- #get(path, get_header = {}) ⇒ Object
-
#initialize(base, skip_verify_ssl) ⇒ Request
constructor
A new instance of Request.
- #post(path, post_body, post_header = {}) ⇒ Object
- #post_file(path, file, post_header = {}) ⇒ Object
Constructor Details
#initialize(base, skip_verify_ssl) ⇒ Request
Returns a new instance of Request.
9 10 11 12 13 14 15 |
# File 'lib/wework/request.rb', line 9 def initialize(base, skip_verify_ssl) @base = base @httprb = HTTP.timeout(**Wework.) @ssl_context = OpenSSL::SSL::SSLContext.new @ssl_context.ssl_version = :TLSv1 @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE if skip_verify_ssl end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
7 8 9 |
# File 'lib/wework/request.rb', line 7 def base @base end |
#httprb ⇒ Object (readonly)
Returns the value of attribute httprb.
7 8 9 |
# File 'lib/wework/request.rb', line 7 def httprb @httprb end |
#ssl_context ⇒ Object (readonly)
Returns the value of attribute ssl_context.
7 8 9 |
# File 'lib/wework/request.rb', line 7 def ssl_context @ssl_context end |
Instance Method Details
#get(path, get_header = {}) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/wework/request.rb', line 17 def get(path, get_header = {}) request(path, get_header) do |url, header| params = header.delete(:params) httprb.headers(header).get(url, params: params, ssl_context: ssl_context) end end |
#post(path, post_body, post_header = {}) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/wework/request.rb', line 24 def post(path, post_body, post_header = {}) request(path, post_header) do |url, header| params = header.delete(:params) httprb.headers(header).post(url, params: params, json: post_body, ssl_context: ssl_context) end end |
#post_file(path, file, post_header = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wework/request.rb', line 31 def post_file(path, file, post_header = {}) request(path, post_header) do |url, header| params = header.delete(:params) httprb.headers(header) .post(url, params: params, form: { media: HTTP::FormData::File.new(file), hack: 'X' }, # Existing here for http-form_data 1.0.1 handle single param improperly ssl_context: ssl_context) end end |