Class: Wechat::HttpClient
- Inherits:
-
Object
- Object
- Wechat::HttpClient
- Defined in:
- lib/wechat/http_client.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#ssl_context ⇒ Object
readonly
Returns the value of attribute ssl_context.
Instance Method Summary collapse
- #get(path, get_header = {}) ⇒ Object
-
#initialize(base, timeout, skip_verify_ssl) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #post(path, payload, post_header = {}) ⇒ Object
- #post_file(path, file, post_header = {}) ⇒ Object
Constructor Details
#initialize(base, timeout, skip_verify_ssl) ⇒ HttpClient
Returns a new instance of HttpClient.
7 8 9 10 11 12 13 |
# File 'lib/wechat/http_client.rb', line 7 def initialize(base, timeout, skip_verify_ssl) @base = base HTTP.timeout(:global, write: timeout, connect: timeout, read: timeout) @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.
5 6 7 |
# File 'lib/wechat/http_client.rb', line 5 def base @base end |
#ssl_context ⇒ Object (readonly)
Returns the value of attribute ssl_context.
5 6 7 |
# File 'lib/wechat/http_client.rb', line 5 def ssl_context @ssl_context end |
Instance Method Details
#get(path, get_header = {}) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/wechat/http_client.rb', line 15 def get(path, get_header = {}) request(path, get_header) do |url, header| params = header.delete(:params) HTTP.headers(header).get(url, params: params, ssl_context: ssl_context) end end |
#post(path, payload, post_header = {}) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/wechat/http_client.rb', line 22 def post(path, payload, post_header = {}) request(path, post_header) do |url, header| params = header.delete(:params) HTTP.headers(header).post(url, params: params, body: payload, ssl_context: ssl_context) end end |
#post_file(path, file, post_header = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/wechat/http_client.rb', line 29 def post_file(path, file, post_header = {}) request(path, post_header) do |url, header| params = header.delete(:params) HTTP.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 |