Class: CmQuiz::ProjectAPI
- Inherits:
-
Object
- Object
- CmQuiz::ProjectAPI
- Defined in:
- lib/cm_quiz/project_api.rb
Defined Under Namespace
Classes: PerformFailed
Constant Summary collapse
- REQUEST_TIMEOUT =
5
Instance Method Summary collapse
-
#initialize(endpoint) ⇒ ProjectAPI
constructor
A new instance of ProjectAPI.
- #request(verb, path, options = {}) ⇒ Object
Constructor Details
#initialize(endpoint) ⇒ ProjectAPI
Returns a new instance of ProjectAPI.
16 17 18 |
# File 'lib/cm_quiz/project_api.rb', line 16 def initialize(endpoint) @endpoint = endpoint end |
Instance Method Details
#request(verb, path, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cm_quiz/project_api.rb', line 20 def request(verb, path, = {}) url = @endpoint + path query = [:query] body = [:body] ? [:body].to_json : [:body] headers = { 'Content-Type' => 'application/json' }.merge([:headers] || {}) = { query: query, body: body, headers: headers, timeout: REQUEST_TIMEOUT } res = HTTParty.send(verb, url, ) raise PerformFailed.new("[#{res.code}]: #{res.body}", res) unless res.success? res end |