Class: SchoologyClient::Resource
- Inherits:
-
Object
- Object
- SchoologyClient::Resource
- Defined in:
- lib/schoology_client/resource.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #handle_response(response) ⇒ Object
-
#initialize(client) ⇒ Resource
constructor
A new instance of Resource.
- #post_request(url, body:, headers: {}) ⇒ Object
- #put_request(url, body:, headers: {}) ⇒ Object
Constructor Details
#initialize(client) ⇒ Resource
Returns a new instance of Resource.
7 8 9 |
# File 'lib/schoology_client/resource.rb', line 7 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/schoology_client/resource.rb', line 5 def client @client end |
Instance Method Details
#handle_response(response) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/schoology_client/resource.rb', line 19 def handle_response(response) case response.status when 400 raise Error, "Your request was malformed. #{response.body["error"]}" when 401 raise Error, "You did not supply valid authentication credentials. #{response.body["error"]}" when 403 raise Error, "You are not allowed to perform that action. #{response.body["error"]}" when 404 raise Error, "No results were found for your request. #{response.body["error"]}" when 429 raise Error, "Your request exceeded the API rate limit. #{response.body["error"]}" when 500 raise Error, "We were unable to perform the request due to server-side problems. #{response.body["error"]}" when 503 raise Error, "You have been rate limited for sending more than 20 requests per second. #{response.body["error"]}" end response end |
#post_request(url, body:, headers: {}) ⇒ Object
11 12 13 |
# File 'lib/schoology_client/resource.rb', line 11 def post_request(url, body:, headers: {}) handle_response @client.connection.post(url, body, headers) end |
#put_request(url, body:, headers: {}) ⇒ Object
15 16 17 |
# File 'lib/schoology_client/resource.rb', line 15 def put_request(url, body:, headers: {}) handle_response @client.connection.put(url, body, headers) end |