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.
8 9 10 11 12 13 14 |
# File 'lib/wework/request.rb', line 8 def initialize(base, skip_verify_ssl) @base = base @httprb = HTTP.timeout(**Wework.) @ssl_context = OpenSSL::SSL::SSLContext.new @ssl_context.ssl_version = :TLSv1_client @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.
6 7 8 |
# File 'lib/wework/request.rb', line 6 def base @base end |
#httprb ⇒ Object (readonly)
Returns the value of attribute httprb.
6 7 8 |
# File 'lib/wework/request.rb', line 6 def httprb @httprb end |
#ssl_context ⇒ Object (readonly)
Returns the value of attribute ssl_context.
6 7 8 |
# File 'lib/wework/request.rb', line 6 def ssl_context @ssl_context end |
Instance Method Details
#get(path, get_header = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/wework/request.rb', line 16 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
23 24 25 26 27 28 |
# File 'lib/wework/request.rb', line 23 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
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wework/request.rb', line 30 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 |