livejournal 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/rdoctask'
5
5
  require 'rake/testtask'
6
6
 
7
7
  PKG_NAME = 'livejournal'
8
- PKG_VERSION = '0.2.0'
8
+ PKG_VERSION = '0.3.0'
9
9
 
10
10
  FILES = FileList[
11
11
  'Rakefile', 'README', 'LICENSE', 'setup.rb',
@@ -27,24 +27,24 @@
27
27
  require 'sqlite3'
28
28
 
29
29
  module LiveJournal
30
- class DatabaseError < RuntimeError; end
31
-
32
30
  # An interface for an SQLite database dump.
33
31
  class Database
34
- EXPECTED_DATABASE_VERSION = "2"
32
+ class Error < RuntimeError; end
33
+
34
+ EXPECTED_DATABASE_VERSION = "3"
35
35
  SCHEMA = %q{
36
36
  CREATE TABLE meta (
37
37
  key TEXT PRIMARY KEY,
38
- value TEXT
38
+ value TEXT
39
39
  );
40
40
  CREATE TABLE entry (
41
41
  itemid INTEGER PRIMARY KEY,
42
42
  anum INTEGER,
43
43
  subject TEXT,
44
44
  event TEXT,
45
- moodid INTEGER, mood TEXT, music TEXT, taglist TEXT,
46
- pickeyword TEXT, preformatted INTEGER, backdated INTEGER,
47
- comments INTEGER, year INTEGER, month INTEGER, day INTEGER,
45
+ moodid INTEGER, mood TEXT, music TEXT, location TEXT, taglist TEXT,
46
+ pickeyword TEXT, preformatted INTEGER, backdated INTEGER,
47
+ comments INTEGER, year INTEGER, month INTEGER, day INTEGER,
48
48
  timestamp INTEGER, security INTEGER
49
49
  );
50
50
  CREATE INDEX dateindex ON entry (year, month, day);
@@ -92,7 +92,7 @@ module LiveJournal
92
92
  # Existing database!
93
93
  version = self.version
94
94
  unless version == EXPECTED_DATABASE_VERSION
95
- raise DatabaseError, "Database version mismatch -- db has #{version.inspect}, expected #{EXPECTED_DATABASE_VERSION.inspect}"
95
+ raise Error, "Database version mismatch -- db has #{version.inspect}, expected #{EXPECTED_DATABASE_VERSION.inspect}"
96
96
  end
97
97
  end
98
98
 
@@ -178,7 +178,7 @@ module LiveJournal
178
178
 
179
179
  # Store an Entry.
180
180
  def store_entry entry
181
- sql = 'INSERT OR REPLACE INTO entry VALUES (' + ("?, " * 16) + '?)'
181
+ sql = 'INSERT OR REPLACE INTO entry VALUES (' + ("?, " * 17) + '?)'
182
182
  @db.execute(sql, *entry.to_database_row)
183
183
  end
184
184
 
@@ -244,19 +244,19 @@ module LiveJournal
244
244
  @itemid, @anum = row[0].to_i, row[1].to_i
245
245
  @subject, @event = row[2], row[3]
246
246
  @moodid, @mood = row[4].nil? ? nil : row[4].to_i, row[5]
247
- @music, @taglist, @pickeyword = row[6], row[7], row[8]
247
+ @music, @location, @taglist, @pickeyword = row[6], row[7], row[8], row[9]
248
248
  @taglist = if @taglist then @taglist.split(/, /) else [] end
249
- @preformatted, @backdated = !row[9].nil?, !row[10].nil?
250
- @comments = case Database::optional_to_i(row[11])
249
+ @preformatted, @backdated = !row[10].nil?, !row[11].nil?
250
+ @comments = case Database::optional_to_i(row[12])
251
251
  when nil; :normal
252
252
  when 1; :none
253
253
  when 2; :noemail
254
- else raise DatabaseError, "Bad comments value: #{row[11].inspect}"
254
+ else raise Database::Error, "Bad comments value: #{row[12].inspect}"
255
255
  end
256
256
 
257
- @time = Time.at(row[15].to_i).utc
257
+ @time = Time.at(row[16].to_i).utc
258
258
 
259
- case Database::optional_to_i(row[16])
259
+ case Database::optional_to_i(row[17])
260
260
  when nil
261
261
  @security = :public
262
262
  when 0
@@ -265,7 +265,7 @@ module LiveJournal
265
265
  @security = :friends
266
266
  else
267
267
  @security = :custom
268
- @allowmask = row[16]
268
+ @allowmask = row[17]
269
269
  end
270
270
 
271
271
  self
@@ -283,7 +283,7 @@ module LiveJournal
283
283
  when :custom; @allowmask
284
284
  end
285
285
  [@itemid, @anum, @subject, @event,
286
- @moodid, @mood, @music, @taglist.join(', '), @pickeyword,
286
+ @moodid, @mood, @music, @location, @taglist.join(', '), @pickeyword,
287
287
  @preformatted ? 1 : nil, @backdated ? 1 : nil, comments,
288
288
  @time.year, @time.mon, @time.day, @time.to_i, security]
289
289
  end
@@ -46,7 +46,8 @@ module LiveJournal
46
46
 
47
47
  class Entry
48
48
  attr_accessor :itemid, :anum, :subject, :event, :moodid, :mood
49
- attr_accessor :music, :taglist, :pickeyword, :preformatted, :backdated
49
+ attr_accessor :music, :location, :taglist, :pickeyword
50
+ attr_accessor :preformatted, :backdated
50
51
  attr_accessor :comments # values: {:normal, :none, :noemail}
51
52
  attr_reader :time # a Ruby Time object
52
53
  attr_accessor :security # values: {:public, :private, :friends, :custom}
@@ -60,6 +61,7 @@ module LiveJournal
60
61
  @moodid = nil
61
62
  @mood = nil
62
63
  @music = nil
64
+ @location = nil
63
65
  @taglist = []
64
66
  @pickeyword = nil
65
67
  @preformatted = false
@@ -72,23 +74,21 @@ module LiveJournal
72
74
  @props = {}
73
75
  end
74
76
 
75
- def ==(other)
76
- [:subject, :event, :moodid, :mood, :music, :taglist, :pickeyword,
77
- :preformatted, :backdated, :comments, :security, :allowmask,
77
+ def equivalent_to?(other)
78
+ [:subject, :event, :moodid,
79
+ :mood, :music, :location, :taglist, :pickeyword,
80
+ :preformatted, :backdated, :comments, :time, :security, :allowmask,
78
81
  :screening, :props].each do |attr|
79
82
  return false if send(attr) != other.send(attr)
80
83
  end
81
- # compare time fields one-by-one because livejournal ignores the
82
- # "seconds" field.
83
- [:year, :mon, :day, :hour, :min, :zone].each do |attr|
84
- return false if @time.send(attr) != other.time.send(attr)
85
- end
86
84
  return true
87
85
  end
88
86
 
89
87
  def time=(time)
90
88
  raise RuntimeError, "Must use GMT times everywhere to reduce confusion. See LiveJournal::coerce_gmt for details." unless time.gmt?
91
- @time = time
89
+ components = time.to_a
90
+ components[0] = 0 # set seconds to zero
91
+ @time = Time.gm *components
92
92
  end
93
93
 
94
94
  def from_request(req)
@@ -123,6 +123,8 @@ module LiveJournal
123
123
  @moodid = value.to_i
124
124
  when 'current_music'
125
125
  @music = value
126
+ when 'current_location'
127
+ @location = value
126
128
  when 'taglist'
127
129
  @taglist = value.split(/, /).sort
128
130
  when 'picture_keyword'
@@ -213,6 +215,7 @@ module LiveJournal
213
215
  { 'current_mood' => self.mood,
214
216
  'current_moodid' => self.moodid,
215
217
  'current_music' => self.music,
218
+ 'current_location' => self.location,
216
219
  'picture_keyword' => self.pickeyword,
217
220
  'taglist' => self.taglist.join(', '),
218
221
  'opt_preformatted' => self.preformatted ? 1 : 0,
@@ -29,7 +29,12 @@ module LiveJournal
29
29
  # See LiveJournal::Request::Friends to get an array of these.
30
30
  class Friend
31
31
  attr_accessor :username, :fullname
32
- attr_accessor :background, :foreground, :groupmask, :type
32
+ # as HTML color, like '#ff0000'
33
+ attr_accessor :background, :foreground
34
+ # bitfield of friend groups this friend is a member of
35
+ attr_accessor :groupmask
36
+ # friend type. possible values: :community, :news, :syndicated, :shared, :user
37
+ attr_accessor :type
33
38
  def initialize
34
39
  @username = nil
35
40
  @fullname = nil
@@ -44,7 +49,16 @@ module LiveJournal
44
49
  @foreground = req['fg']
45
50
  @background = req['bg']
46
51
  @groupmask = req['groupmask']
47
- @type = req['type']
52
+ @type =
53
+ case req['type']
54
+ when 'community'; :community
55
+ when 'news'; :news
56
+ when 'syndicated'; :syndicated
57
+ when 'shared'; :shared
58
+ when nil; :user
59
+ else raise LiveJournal::Request::ProtocolException.new(
60
+ "unknown friend type: #{req['type']}")
61
+ end
48
62
  self
49
63
  end
50
64
  def to_s
@@ -54,18 +68,25 @@ module LiveJournal
54
68
 
55
69
  module Request
56
70
  class Friends < Req
57
- attr_reader :friends
58
- def initialize(user)
71
+ attr_reader :friends, :friendofs
72
+ # Allowed options:
73
+ # :include_friendofs => true:: also fill out @friendofs in single request
74
+ def initialize(user, opts={})
59
75
  super(user, 'getfriends')
60
76
  @friends = nil
77
+ @friendofs = nil
78
+ @request['includefriendof'] = true if opts.has_key? :include_friendofs
61
79
  end
62
80
  # Returns an array of LiveJournal::Friend.
63
81
  def run
64
82
  super
65
83
  @friends = build_array('friend') { |r| Friend.new.from_request(r) }
84
+ @friendofs = build_array('friendof') { |r| Friend.new.from_request(r) }
66
85
  @friends
67
86
  end
68
87
  end
88
+
89
+ # See Friends to fetch both friends and friend-ofs in one request.
69
90
  class FriendOfs < Req
70
91
  attr_reader :friendofs
71
92
  def initialize(user)
data/test/comments-xml.rb CHANGED
@@ -22,7 +22,9 @@
22
22
  # SOFTWARE.
23
23
  #++
24
24
 
25
+ $:.unshift '../lib'
25
26
  require 'livejournal/comments-xml'
27
+ require 'rexml/document'
26
28
  require 'test/unit'
27
29
 
28
30
  TEST_COMMENTS_META = %q{<?xml version="1.0" encoding='utf-8'?>
data/test/database.rb CHANGED
@@ -24,7 +24,7 @@ class TC_Database < Test::Unit::TestCase
24
24
  def roundtrip e
25
25
  @db.store_entry e
26
26
  new_e = @db.get_entry e.itemid
27
- assert_equal(e, new_e)
27
+ assert(e.equivalent_to?(new_e), "#{e.inspect}\n=>\n#{new_e.inspect}")
28
28
  end
29
29
 
30
30
  def test_roundtrips
data/test/roundtrip.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- require 'livejournal/login'
3
+ $:.unshift '../lib'
4
+
4
5
  require 'livejournal/entry'
5
6
  require 'test/unit'
6
7
 
@@ -15,10 +16,9 @@ class TC_RoundTrip < Test::Unit::TestCase
15
16
  postevent = Request::PostEvent.new(@user, entry)
16
17
  postevent.run
17
18
 
18
- getevents = Request::GetEvents.new(@user,
19
- :itemid => entry.itemid)
19
+ getevents = Request::GetEvents.new(@user, :itemid => entry.itemid)
20
20
  new_entry = getevents.run
21
- assert_equal(new_entry, entry)
21
+ assert(entry.equivalent_to?(new_entry), "#{entry.inspect}\n=>\n#{new_entry.inspect}")
22
22
 
23
23
  delete = Request::EditEvent.new(@user, entry, :delete => true)
24
24
  delete.run
@@ -27,7 +27,7 @@ class TC_RoundTrip < Test::Unit::TestCase
27
27
  def test_roundtrip
28
28
  e = Entry.new
29
29
  e.subject = 'subject'
30
- e.event = 'event here'
30
+ e.event = 'event here ' + Time.now.to_s
31
31
  e.time = LiveJournal::coerce_gmt Time.now
32
32
  roundtrip e
33
33
 
@@ -38,6 +38,7 @@ class TC_RoundTrip < Test::Unit::TestCase
38
38
  e.comments = :noemail
39
39
  e.preformatted = true
40
40
  e.security = :friends
41
+ e.location = "test"
41
42
  roundtrip e
42
43
  end
43
44
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: livejournal
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2006-05-13 00:00:00 +09:00
6
+ version: 0.3.0
7
+ date: 2006-07-25 00:00:00 +09:00
8
8
  summary: module for interacting with livejournal
9
9
  require_paths:
10
10
  - lib