Class: Plagscan::Request
- Inherits:
-
Object
- Object
- Plagscan::Request
- Defined in:
- lib/plagscan/request.rb
Overview
PlagScan HTTP request service
Constant Summary collapse
- DEFAULT_REQUEST_OPTIONS =
{ method: :get, body: nil, headers: nil, ssl_verify_mode: OpenSSL::SSL::VERIFY_PEER, ssl_ca_file: nil }.freeze
Class Method Summary collapse
- .api_url(path = '') ⇒ Object
- .json_request(path, options = {}) ⇒ Object
- .request(path, options = {}) ⇒ Object
- .user_agent ⇒ Object
Class Method Details
.api_url(path = '') ⇒ Object
17 18 19 |
# File 'lib/plagscan/request.rb', line 17 def api_url(path = '') Plagscan.api_base + path end |
.json_request(path, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/plagscan/request.rb', line 32 def json_request(path, = {}) response = Plagscan::Request.request(path, ) unless response.is_a?([:expected_result] || Net::HTTPSuccess) raise Plagscan::HTTPError, "Invalid http response: #{response.code} - #{response.body}" end JSON.parse response.body, symbolize_names: true rescue JSON::ParserError raise Plagscan::JsonParseError, "PlagScan response parse error: #{response.body}" end |
.request(path, options = {}) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/plagscan/request.rb', line 25 def request(path, = {}) = DEFAULT_REQUEST_OPTIONS.merge() http = create_http() req = create_request(path, ) http.start { http.request(req) } end |