Class: GithubApi::User
- Inherits:
-
Object
- Object
- GithubApi::User
- Defined in:
- lib/github-api/user.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #create_repo(name, params) ⇒ Object
- #has_repo?(name) ⇒ Boolean
-
#initialize(token) ⇒ User
constructor
A new instance of User.
- #load_repos ⇒ Object
- #repo(name) ⇒ Object
- #repos ⇒ Object
Constructor Details
#initialize(token) ⇒ User
Returns a new instance of User.
6 7 8 9 10 |
# File 'lib/github-api/user.rb', line 6 def initialize(token) @token = token @data = GithubApi::HTTP.get("/user", :query => {:access_token => @token}) @repos = [] end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/github-api/user.rb', line 4 def data @data end |
#token ⇒ Object
Returns the value of attribute token.
4 5 6 |
# File 'lib/github-api/user.rb', line 4 def token @token end |
Instance Method Details
#create_repo(name, params) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/github-api/user.rb', line 29 def create_repo(name, params) body = {:name => name}.merge(params) response = GithubApi::HTTP.post("/user/repos", :query => { :access_token => @token}, :body => body.to_json ).parsed_response @repos << Repo.new(self, response) @repos.last end |
#has_repo?(name) ⇒ Boolean
12 13 14 15 |
# File 'lib/github-api/user.rb', line 12 def has_repo?(name) load_repos if @repos.empty? @repos.find { |repo| repo.name == name } end |
#load_repos ⇒ Object
22 23 24 25 26 27 |
# File 'lib/github-api/user.rb', line 22 def load_repos response = GithubApi::HTTP.get("/user/repos", :query => {:access_token => @token}).parsed_response response.each do |repo| @repos << Repo.new(self, repo) end end |
#repo(name) ⇒ Object
41 42 43 44 |
# File 'lib/github-api/user.rb', line 41 def repo(name) load_repos if @repos.empty? @repos.find { |repo| repo.name == name } end |
#repos ⇒ Object
17 18 19 20 |
# File 'lib/github-api/user.rb', line 17 def repos load_repos if @repos.empty? @repos end |