Class: Dydra::Account

Inherits:
Resource show all
Includes:
Enumerable
Defined in:
lib/dydra/account.rb

Overview

Represents a Dydra.com user account.

Examples:

Enumerating repositories belonging to an account

.each_repository do |repository|
  puts repository.inspect
end

Accessing account information

 = Dydra::Account.new('jhacker')
.url       #=> #<RDF::URI(http://api.dydra.com/jhacker)>
.name      #=> "jhacker"
.fullname  #=> "J. Random Hacker"

Accessing a repository belonging to an account

repository = [:foaf]

See Also:

Constant Summary

SPEC =

/account

%r(^([^/]+)$)

Constants inherited from Resource

Resource::HEADERS

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Resource

#<=>, #eql?, #exists?, #get, #head, #inspect, #inspect!, new, #to_rdf, #to_uri

Constructor Details

- (Account) initialize(name)

Initializes an account instance.

Parameters:

  • name (String, #to_s)

    a valid account name



114
115
116
117
# File 'lib/dydra/account.rb', line 114

def initialize(name)
  @name = name.to_s
  super(Dydra::URL.join(@name))
end

Instance Attribute Details

- (String) email (readonly)

The account holder's email address.

Note that you can only access the email address associated with your own account(s); for any other accounts, this will always return nil.

Examples:

Dydra::Account.new('jhacker').email     #=> "jhacker@dydra.com"

Returns:

  • (String)


92
93
94
# File 'lib/dydra/account.rb', line 92

def email
  @email
end

- (String) fullname (readonly)

The account holder's full name.

Examples:

Dydra::Account.new('jhacker').fullname  #=> "J. Random Hacker"

Returns:

  • (String)


101
102
103
# File 'lib/dydra/account.rb', line 101

def fullname
  @fullname
end

- (String) name (readonly)

The account name.

Examples:

Dydra::Account.new('jhacker').name      #=> "jhacker"

Returns:

  • (String)


80
81
82
# File 'lib/dydra/account.rb', line 80

def name
  @name
end

- (String) path (readonly)

The resource path, relative to http://dydra.com/.

Examples:

Dydra::Account.new('jhacker').path      #=> "jhacker"

Returns:

  • (String)


68
69
70
# File 'lib/dydra/account.rb', line 68

def path
  @path
end

- (RDF::URI) url (readonly)

The account URL.

Examples:

Dydra::Account.new('jhacker').url       #=> #<RDF::URI(http://api.dydra.com/jhacker)>

Returns:

  • (RDF::URI)


56
57
58
# File 'lib/dydra/account.rb', line 56

def url
  @url
end

Class Method Details

+ (Boolean) exists?(name)

Returns true if an account with the given name exists on Dydra.com.

Parameters:

  • name (String, #to_s)

Returns:

  • (Boolean)

    true or false



31
32
33
# File 'lib/dydra/account.rb', line 31

def self.exists?(name)
  Account.new(name).exists?
end

+ (Account) register!(name, options = {})

Registers a new user account with Dydra.com.

Parameters:

  • name (String)
  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :email (String)
  • :password (String)

Returns:

Raises:

  • (NotImplementedError)


43
44
45
46
47
# File 'lib/dydra/account.rb', line 43

def self.register!(name, options = {})
  raise NotImplementedError, "#{self.class}.register!"
  #Dydra::Client.rpc.call('dydra.account.register', name, options[:email], options[:password]) # FIXME
  #self.new(name)
end

Instance Method Details

- (Enumerator) each_repository(options = {}) {|repository| ... } Also known as: each

Enumerates each repository belonging to this account.

Examples:

 = Dydra::Account.new('jhacker')
.each_repository do |repository|
  puts repository.inspect
end

Yields:

  • (repository)

Yield Parameters:

Yield Returns:

  • (void)

Returns:

  • (Enumerator)

Since:

  • 0.0.4



168
169
170
171
172
173
174
175
176
# File 'lib/dydra/account.rb', line 168

def each_repository(options = {}, &block)
  if block_given?
    result = Dydra::Client.rpc.call('dydra.repository.list', name)
    result.each do |(, repository_name)|
      block.call(Repository.new(self, repository_name))
    end
  end
  enum_for(:each_repository, options)
end

- (Hash) info

Returns basic account info.

Returns:

  • (Hash)


123
124
125
# File 'lib/dydra/account.rb', line 123

def info
  Dydra::Client.get_json(name)
end

- (Array<Repository>) repositories

Returns the list of repositories belonging to this account.

Examples:

 = Dydra::Account.new('jhacker')
.repositories.count              #=> 1

Returns:



150
151
152
# File 'lib/dydra/account.rb', line 150

def repositories
  each_repository.to_a
end

- (Repository) repository(name) Also known as: []

Returns a given repository belonging to this account.

Examples:

 = Dydra::Account.new('jhacker')
.repository('foaf')              #=> #<Dydra::Repository(jhacker/foaf)>
['foaf']                         #=> #<Dydra::Repository(jhacker/foaf)>

Parameters:

  • name (String, #to_s)

Returns:



137
138
139
# File 'lib/dydra/account.rb', line 137

def repository(name)
  Repository.new(self, name)
end

- (String) to_s

Returns a string representation of the account name.

Examples:

 = Dydra::Account.new('jhacker')
.to_s                            #=> "jhacker"

Returns:

  • (String)


187
188
189
# File 'lib/dydra/account.rb', line 187

def to_s
  name
end