Class: CoderWally::API

Inherits:
Object
  • Object
show all
Defined in:
lib/coder_wally/api.rb

Overview

API Class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAPI

Returns a new instance of API.



8
9
10
# File 'lib/coder_wally/api.rb', line 8

def initialize
  @response = {}
end

Instance Attribute Details

#responseObject (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