Class: Octopi::User
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.find(username) ⇒ Object
Finds a single user identified by the given username.
-
.find_all(username) ⇒ Object
Finds all users whose username matches a given string.
Instance Method Summary collapse
-
#add_key(title, key) ⇒ Object
Adds an SSH Public Key to the user.
- #create_repository(name, opts = {}) ⇒ Object
-
#keys ⇒ Object
Returns a list of Key objects containing all SSH Public Keys this user currently has.
-
#repositories ⇒ Object
Returns a collection of Repository objects, containing all repositories of the user.
-
#repository(name) ⇒ Object
Searches for user Repository identified by name.
- #user_property(property, deep) ⇒ Object
Methods included from Resource
Methods inherited from Base
Constructor Details
This class inherits a constructor from Octopi::Base
Class Method Details
.find(username) ⇒ Object
Finds a single user identified by the given username
Example:
user = User.find("fcoury")
puts user.login # should return 'fcoury'
14 15 16 17 |
# File 'lib/octopi/user.rb', line 14 def self.find(username) self.validate_args(username => :user) super username end |
.find_all(username) ⇒ Object
Finds all users whose username matches a given string
Example:
User.find_all("oe") # Matches joe, moe and monroe
25 26 27 28 |
# File 'lib/octopi/user.rb', line 25 def self.find_all(username) self.validate_args(username => :user) super username end |
Instance Method Details
#add_key(title, key) ⇒ Object
Adds an SSH Public Key to the user. Requires authentication.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/octopi/user.rb', line 55 def add_key(title, key) raise APIError, "To add a key, you must be authenticated" if @api.read_only? result = @api.post("/user/key/add", :title => title, :key => key) return if !result["public_keys"] key_params = result["public_keys"].select { |k| k["title"] == title } return if !key_params or key_params.empty? Key.new(@api, key_params.first, self) end |
#create_repository(name, opts = {}) ⇒ Object
48 49 50 51 |
# File 'lib/octopi/user.rb', line 48 def create_repository(name, opts = {}) self.class.validate_args(name => :repo) Repository.create(self, name, opts) end |
#keys ⇒ Object
Returns a list of Key objects containing all SSH Public Keys this user currently has. Requires authentication.
68 69 70 71 72 73 74 75 |
# File 'lib/octopi/user.rb', line 68 def keys raise APIError, "To add a key, you must be authenticated" if @api.read_only? result = @api.get("/user/keys") return unless result and result["public_keys"] result["public_keys"].inject([]) { |result, element| result << Key.new(@api, element) } end |
#repositories ⇒ Object
Returns a collection of Repository objects, containing all repositories of the user.
If user is the current authenticated user, some additional information will be provided for the Repositories.
36 37 38 39 |
# File 'lib/octopi/user.rb', line 36 def repositories api = self.api || ANONYMOUS_API Repository.find_by_user(login,api) end |
#repository(name) ⇒ Object
Searches for user Repository identified by name
43 44 45 46 |
# File 'lib/octopi/user.rb', line 43 def repository(name) self.class.validate_args(name => :repo) Repository.find(login, name) end |