Class: GitHub::User

Inherits:
Base
  • Object
show all
Defined in:
lib/git_hub/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

aliases_for, base_uri, #get, get, post, #post, request, #set_attributes, set_resource, #to_s

Constructor Details

#initialize(opts) ⇒ User

Returns a new instance of User.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/git_hub/user.rb', line 18

def initialize( opts )
  @public_repo_count = opts.delete('repos')  # TODO: find better way without modifying opts?
  @followers_count = opts.delete('followers')
  super
  if @login #need to correct attributes generated by /show/:user
    @name, @fullname = @login, @name
    @id = "user-#{@id}"
  end
  raise "Unable to initialize #{self.class} without name for #{opts}" unless @name
  @created = Time.parse(@created) unless @created.is_a?(Time)
  @pushed = Time.parse(@pushed) if @pushed && !@pushed.is_a?(Time)
  @type ||= "user"
end

Instance Attribute Details

#collaboratorsObject

Returns the value of attribute collaborators.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def collaborators
  @collaborators
end

#companyObject

Returns the value of attribute company.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def company
  @company
end

#createdObject

Returns the value of attribute created.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def created
  @created
end

#disk_usageObject

Returns the value of attribute disk_usage.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def disk_usage
  @disk_usage
end

#emailObject

Returns the value of attribute email.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def email
  @email
end

#followers_countObject

Returns the value of attribute followers_count.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def followers_count
  @followers_count
end

#following_countObject

Returns the value of attribute following_count.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def following_count
  @following_count
end

#fullnameObject

Returns the value of attribute fullname.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def fullname
  @fullname
end

#homepageObject

Returns the value of attribute homepage.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def homepage
  @homepage
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def id
  @id
end

#languageObject

Returns the value of attribute language.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def language
  @language
end

#locationObject

Returns the value of attribute location.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def location
  @location
end

#loginObject

Returns the value of attribute login.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def 
  @login
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def name
  @name
end

#owned_private_repo_countObject

Returns the value of attribute owned_private_repo_count.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def owned_private_repo_count
  @owned_private_repo_count
end

#planObject

Returns the value of attribute plan.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def plan
  @plan
end

#private_gist_countObject

Returns the value of attribute private_gist_count.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def private_gist_count
  @private_gist_count
end

#public_gist_countObject

Returns the value of attribute public_gist_count.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def public_gist_count
  @public_gist_count
end

#public_repo_countObject

Returns the value of attribute public_repo_count.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def public_repo_count
  @public_repo_count
end

#pushedObject

Returns the value of attribute pushed.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def pushed
  @pushed
end

#scoreObject

Returns the value of attribute score.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def score
  @score
end

#total_private_repo_countObject

Returns the value of attribute total_private_repo_count.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def total_private_repo_count
  @total_private_repo_count
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/git_hub/user.rb', line 8

def type
  @type
end

Class Method Details

.find(*args) ⇒ Object

Find github user, accepts Hash with keys:

:user/:username

Github user name

:repo/:repository/:project/:name

Repo name

:query/:search

Array of search terms as Strings or Symbols



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/git_hub/user.rb', line 40

def find( *args )
  user, query = extract args, :user, :query
  path = if query
    "/search/#{query.map(&:to_s).join('+')}"
  elsif user
    "/show/#{user}"
  else
    raise "Unable to find #{self.class}(s) for #{opts}"
  end
  instantiate get(path)
end

Instance Method Details

#follow!(user) ⇒ Object



62
63
64
65
# File 'lib/git_hub/user.rb', line 62

def follow!( user )
  API.ensure_auth
  post("/follow/#{user}")['users'].map {|user| User.find(:user => user )}
end

#followersObject



53
54
55
56
# File 'lib/git_hub/user.rb', line 53

def followers
  res = get("/show/#{@name}/followers")
  res['users'].map {|user| User.find(:user => user )}
end

#followingObject



58
59
60
# File 'lib/git_hub/user.rb', line 58

def following
  get("/show/#{@name}/following")['users'].map {|user| User.find(:user => user )}
end

#unfollow!(user) ⇒ Object

api /user/unfollow/:user is not working properly atm, using http



67
68
69
70
71
72
# File 'lib/git_hub/user.rb', line 67

def unfollow!( user )# api /user/unfollow/:user is not working properly atm, using http
  API.ensure_auth
  res = get 'http://github.com/users/follow', 'target' => user
  raise "User Not Found #{user}" unless res.code == 302.to_s
  following
end

#urlObject



32
# File 'lib/git_hub/user.rb', line 32

def url; "http://github.com/#{@name}" end