Class: Osrc::Connection
- Inherits:
-
Object
- Object
- Osrc::Connection
- Defined in:
- lib/osrc/connection.rb
Instance Method Summary collapse
-
#connected_users ⇒ Object
returns all connected users.
-
#initialize(git_username) ⇒ Connection
constructor
A new instance of Connection.
-
#languages ⇒ Object
returns languages.
-
#repositories ⇒ Object
returns repositories.
-
#response_body ⇒ Object
returns response body.
-
#similar_users ⇒ Object
returns similar users.
-
#usage ⇒ Object
returns usage stat.
-
#username ⇒ Object
returns username.
Constructor Details
#initialize(git_username) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/osrc/connection.rb', line 7 def initialize(git_username) @connection ||= Faraday.new(:url => 'http://osrc.dfm.io') do |f| f.request :url_encoded # form-encode POST params f.response :logger # log requests to STDOUT f.adapter Faraday.default_adapter # make requests with Net::HTTP f.use Osrc::ParseJSON f.use Osrc::HttpException end response = @connection.get "/#{git_username}.json" @response = response.body end |
Instance Method Details
#connected_users ⇒ Object
returns all connected users
27 28 29 |
# File 'lib/osrc/connection.rb', line 27 def connected_users @response["connected_users"] rescue [] end |
#languages ⇒ Object
returns languages
47 48 49 |
# File 'lib/osrc/connection.rb', line 47 def languages @response["usage"]["languages"].map {|l| l["language"] } rescue [] end |
#repositories ⇒ Object
returns repositories
32 33 34 |
# File 'lib/osrc/connection.rb', line 32 def repositories @response["repositories"] rescue [] end |
#response_body ⇒ Object
returns response body
22 23 24 |
# File 'lib/osrc/connection.rb', line 22 def response_body @response end |
#similar_users ⇒ Object
returns similar users
37 38 39 |
# File 'lib/osrc/connection.rb', line 37 def similar_users @response["similar_users"] rescue [] end |
#usage ⇒ Object
returns usage stat
42 43 44 |
# File 'lib/osrc/connection.rb', line 42 def usage @response["usage"] rescue {} end |
#username ⇒ Object
returns username
52 53 54 |
# File 'lib/osrc/connection.rb', line 52 def username @response["username"] rescue '' end |