Module: Qingting::Utils::Request
Instance Method Summary collapse
- #delete(url, params: nil, headers: {}) ⇒ Object
- #get(url, params: nil, headers: {}) ⇒ Object
- #parse_body(body) ⇒ Object
- #post(url, body: {}, params: {}, headers: {}) ⇒ Object
- #put(url, body: {}, headers: {}) ⇒ Object
- #send_request(method, url, params: nil, body: nil, headers: {}, opts: {}) ⇒ Object
Instance Method Details
#delete(url, params: nil, headers: {}) ⇒ Object
22 23 24 |
# File 'lib/qingting/utils/request.rb', line 22 def delete(url, params: nil, headers: {}) send_request(:delete, url, params: params, headers: headers) end |
#get(url, params: nil, headers: {}) ⇒ Object
10 11 12 |
# File 'lib/qingting/utils/request.rb', line 10 def get(url, params: nil, headers: {}) send_request(:get, url, params: params, headers: headers) end |
#parse_body(body) ⇒ Object
51 52 53 |
# File 'lib/qingting/utils/request.rb', line 51 def parse_body(body) JSON.parse(body) end |
#post(url, body: {}, params: {}, headers: {}) ⇒ Object
14 15 16 |
# File 'lib/qingting/utils/request.rb', line 14 def post(url, body: {}, params: {}, headers: {}) send_request(:post, url, params: params, body: body, headers: headers) end |
#put(url, body: {}, headers: {}) ⇒ Object
18 19 20 |
# File 'lib/qingting/utils/request.rb', line 18 def put(url, body: {}, headers: {}) send_request(:put, url, body: body, headers: headers) end |
#send_request(method, url, params: nil, body: nil, headers: {}, opts: {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/qingting/utils/request.rb', line 26 def send_request(method, url, params: nil, body: nil, headers: {}, opts: {}) # puts ">>>>>>>http start>>>>>>>>>" # puts "<method> #{method}" # puts "<url> #{url}" # puts "<params> #{params}" # puts "<body> #{body}" # puts "<headers> #{headers}" # puts "<opts> #{opts}" # puts ">>>>>>>http end>>>>>>>>>" raw_response = Utils::Http.new( method.to_sym, url, params: params, body: body, headers: headers, opts: opts ).send_request # puts ">>>>>>>>>>.#{raw_response}" parse_body(raw_response.body) end |