Class: LiveJournal::User

Inherits:
Object
  • Object
show all
Defined in:
lib/livejournal/basic.rb

Overview

A LiveJournal user. Given a username, password, and server, running a LiveJournal::Request::Login will fill in the other fields.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username = nil, password = nil, server = nil) ⇒ User

Returns a new instance of User.



71
72
73
74
75
76
# File 'lib/livejournal/basic.rb', line 71

def initialize(username=nil, password=nil, server=nil)
  @username = username
  @password = password
  @usejournal = nil
  @server = server || LiveJournal::DEFAULT_SERVER
end

Instance Attribute Details

#fullnameObject

User’s self-reported name, as retrieved by LiveJournal::Request::Login



67
68
69
# File 'lib/livejournal/basic.rb', line 67

def fullname
  @fullname
end

#journalsObject

Journals the user has posting access to



69
70
71
# File 'lib/livejournal/basic.rb', line 69

def journals
  @journals
end

#passwordObject

parameter when creating a User



62
63
64
# File 'lib/livejournal/basic.rb', line 62

def password
  @password
end

#serverObject

parameter when creating a User



62
63
64
# File 'lib/livejournal/basic.rb', line 62

def server
  @server
end

#usejournalObject

Set usejournal to log in as user username but act as user usejournal. For example, to work with a community you own.



65
66
67
# File 'lib/livejournal/basic.rb', line 65

def usejournal
  @usejournal
end

#usernameObject

parameter when creating a User



62
63
64
# File 'lib/livejournal/basic.rb', line 62

def username
  @username
end

Instance Method Details

#canonical_journal_nameObject



83
84
85
# File 'lib/livejournal/basic.rb', line 83

def canonical_journal_name
  journal.tr("_", "-")
end

#journalObject



77
78
79
# File 'lib/livejournal/basic.rb', line 77

def journal
  @usejournal || @username
end

#journal_urlObject



86
87
88
89
90
91
92
93
94
# File 'lib/livejournal/basic.rb', line 86

def journal_url
  klass = server.use_ssl ? URI::HTTPS : URI::HTTP
  host = server.host.gsub(/^www\./, "")
  if journal[0] == "_"
    klass.build(host: "users.#{host}", port: server.port, path: "/" + canonical_journal_name).to_s
  else
    klass.build(host: "#{canonical_journal_name}.#{host}", port: server.port).to_s
  end
end

#to_sObject



80
81
82
# File 'lib/livejournal/basic.rb', line 80

def to_s
  "#{@username}: '#{@fullname}'"
end