Class: Osrc::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/osrc/connection.rb

Instance Method Summary collapse

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_usersObject

returns all connected users



27
28
29
# File 'lib/osrc/connection.rb', line 27

def connected_users
  @response["connected_users"] rescue []
end

#languagesObject

returns languages



47
48
49
# File 'lib/osrc/connection.rb', line 47

def languages
  @response["usage"]["languages"].map {|l| l["language"] } rescue []
end

#repositoriesObject

returns repositories



32
33
34
# File 'lib/osrc/connection.rb', line 32

def repositories
  @response["repositories"] rescue []
end

#response_bodyObject

returns response body



22
23
24
# File 'lib/osrc/connection.rb', line 22

def response_body
  @response
end

#similar_usersObject

returns similar users



37
38
39
# File 'lib/osrc/connection.rb', line 37

def similar_users
  @response["similar_users"] rescue []
end

#usageObject

returns usage stat



42
43
44
# File 'lib/osrc/connection.rb', line 42

def usage
  @response["usage"] rescue {}
end

#usernameObject

returns username



52
53
54
# File 'lib/osrc/connection.rb', line 52

def username
  @response["username"] rescue ''
end