Class: CoderWally::API
- Inherits:
-
Object
- Object
- CoderWally::API
- Defined in:
- lib/coder_wally/api.rb
Overview
API Class
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#fetch(username) ⇒ Object
Fetch data from CoderWall.
-
#initialize ⇒ API
constructor
A new instance of API.
Constructor Details
#initialize ⇒ API
Returns a new instance of API.
8 9 10 |
# File 'lib/coder_wally/api.rb', line 8 def initialize @response = {} end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/coder_wally/api.rb', line 7 def response @response end |
Instance Method Details
#fetch(username) ⇒ Object
Fetch data from CoderWall
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/coder_wally/api.rb', line 13 def fetch(username) @response.fetch(username) do uri = uri_for_user(username) json = send_request(uri) begin @response[username] = JSON.parse(json.read) rescue JSON::ParserError raise InvalidJson, 'Received invalid json in response' end end end |