Class: Fuselage::User

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

Instance Attribute Summary collapse

Attributes inherited from Base

#api

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

delete_method, get, #initialize, post

Constructor Details

This class inherits a constructor from Fuselage::Base

Instance Attribute Details

#blogObject

Returns the value of attribute blog.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def blog
  @blog
end

#collaboratorsObject

Returns the value of attribute collaborators.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def collaborators
  @collaborators
end

#companyObject

Returns the value of attribute company.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def company
  @company
end

#created_atObject

Returns the value of attribute created_at.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def created_at
  @created_at
end

#disk_usageObject

Returns the value of attribute disk_usage.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def disk_usage
  @disk_usage
end

#emailObject

Returns the value of attribute email.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def email
  @email
end

#followers_countObject

Returns the value of attribute followers_count.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def followers_count
  @followers_count
end

#following_countObject

Returns the value of attribute following_count.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def following_count
  @following_count
end

#gravatar_idObject

Returns the value of attribute gravatar_id.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def gravatar_id
  @gravatar_id
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def id
  @id
end

#locationObject

Returns the value of attribute location.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def location
  @location
end

#loginObject

Returns the value of attribute login.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def 
  @login
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def name
  @name
end

#owned_private_repo_countObject

Returns the value of attribute owned_private_repo_count.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def owned_private_repo_count
  @owned_private_repo_count
end

#planObject

Returns the value of attribute plan.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def plan
  @plan
end

#private_gist_countObject

Returns the value of attribute private_gist_count.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def private_gist_count
  @private_gist_count
end

#private_repo_countObject

Returns the value of attribute private_repo_count.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def private_repo_count
  @private_repo_count
end

#public_gist_countObject

Returns the value of attribute public_gist_count.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def public_gist_count
  @public_gist_count
end

#public_repo_countObject

Returns the value of attribute public_repo_count.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def public_repo_count
  @public_repo_count
end

#total_private_repo_countObject

Returns the value of attribute total_private_repo_count.



4
5
6
# File 'lib/fuselage/user.rb', line 4

def total_private_repo_count
  @total_private_repo_count
end

Class Method Details

.currentObject



21
22
23
24
# File 'lib/fuselage/user.rb', line 21

def self.current
  raise AuthenticationRequired unless Api.authenticated
  User.new(get('/user'))
end

.find(username) ⇒ Object

Finds a single user identified by the given username

Example:

user = User.find("fcoury")
puts user. # should return 'fcoury'


32
33
34
# File 'lib/fuselage/user.rb', line 32

def self.find(username)
  User.new(get("/user/#{username}"))
end

.get_access_token(client_id, client_secret, code) ⇒ Object

Raises:



12
13
14
15
16
17
18
19
# File 'lib/fuselage/user.rb', line 12

def self.get_access_token(client_id, client_secret, code)
  responce = Api.api.post("https://github.com/login/oauth/access_token?client_id=#{client_id}&client_secret=#{client_secret}&code=#{code}")
  if responce.body != 'error=bad_verification_code'
    access_token = responce.body.match(/\Aaccess_token=(\S+)&/)[1] rescue nil
    return access_token
  end
  raise RegisterError
end

Instance Method Details

#followersObject



48
49
50
51
52
53
# File 'lib/fuselage/user.rb', line 48

def followers
  raise AuthenticationRequired unless Api.authenticated
  followers = []
  User.get('/user/followers').each { |u| followers << User.new(u) }
  followers
end

#followingObject



41
42
43
44
45
46
# File 'lib/fuselage/user.rb', line 41

def following
  raise AuthenticationRequired unless Api.authenticated
  following = []
  User.get('/user/following').each { |u| following << User.new(u) }
  following
end

#repositories(options = {}) ⇒ Object

Return repositories for user.

Options -

:organization,
:type -> <:all, :public, :private, :member>


61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fuselage/user.rb', line 61

def repositories(options = {})
  options = {:type => :all}.merge(options)
  raise AuthenticationRequired unless Api.authenticated
  repos = []
  if options[:organization].nil?
    User.get('/user/repos', {:type => options[:type].to_s}).each { |r| repos << Repository.new(r) }
  else
    User.get("/orgs/#{options[:organization]}/repos", {:type => options[:type].to_s}).each { |r| repos << Repository.new(r) }
  end
  repos
end

#to_sObject

If a user object is passed into a method, we can use this. It’ll also work if we pass in just the login.



75
76
77
# File 'lib/fuselage/user.rb', line 75

def to_s
  
end