Class: Gitrob::Github::User
- Inherits:
-
Object
- Object
- Gitrob::Github::User
- Defined in:
- lib/gitrob/github/user.rb
Instance Attribute Summary collapse
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #avatar_url ⇒ Object
- #bio ⇒ Object
- #email ⇒ Object
-
#initialize(username, http_client) ⇒ User
constructor
A new instance of User.
- #location ⇒ Object
- #name ⇒ Object
- #repositories ⇒ Object
- #save_to_database!(organization) ⇒ Object
- #to_model(organization) ⇒ Object
- #url ⇒ Object
- #website ⇒ Object
Constructor Details
#initialize(username, http_client) ⇒ User
Returns a new instance of User.
7 8 9 |
# File 'lib/gitrob/github/user.rb', line 7 def initialize(username, http_client) @username, @http_client = username, http_client end |
Instance Attribute Details
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
5 6 7 |
# File 'lib/gitrob/github/user.rb', line 5 def http_client @http_client end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
5 6 7 |
# File 'lib/gitrob/github/user.rb', line 5 def username @username end |
Instance Method Details
#avatar_url ⇒ Object
35 36 37 |
# File 'lib/gitrob/github/user.rb', line 35 def avatar_url info['avatar_url'] end |
#bio ⇒ Object
27 28 29 |
# File 'lib/gitrob/github/user.rb', line 27 def bio info['bio'] end |
#email ⇒ Object
15 16 17 |
# File 'lib/gitrob/github/user.rb', line 15 def email info['email'] end |
#location ⇒ Object
23 24 25 |
# File 'lib/gitrob/github/user.rb', line 23 def location info['location'] end |
#name ⇒ Object
11 12 13 |
# File 'lib/gitrob/github/user.rb', line 11 def name info['name'] || username end |
#repositories ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gitrob/github/user.rb', line 39 def repositories if !@repositories @repositories = [] response = JSON.parse(http_client.do_get("/users/#{username}/repos").body) response.each do |repo| next if repo['fork'] @repositories << Repository.new(username, repo['name'], http_client) end end @repositories end |
#save_to_database!(organization) ⇒ Object
64 65 66 |
# File 'lib/gitrob/github/user.rb', line 64 def save_to_database!(organization) self.to_model(organization).tap { |m| m.save } end |
#to_model(organization) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/gitrob/github/user.rb', line 51 def to_model(organization) organization.users.new( :username => self.username, :name => self.name, :website => self.website, :location => self.location, :email => self.email, :bio => self.bio, :url => self.url, :avatar_url => self.avatar_url ) end |
#url ⇒ Object
31 32 33 |
# File 'lib/gitrob/github/user.rb', line 31 def url info['html_url'] end |
#website ⇒ Object
19 20 21 |
# File 'lib/gitrob/github/user.rb', line 19 def website info['blog'] end |