livejournal 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +17 -0
- data/README +50 -0
- data/Rakefile +60 -0
- data/lib/livejournal/basic.rb +59 -0
- data/lib/livejournal/comment.rb +82 -0
- data/lib/livejournal/comments-xml.rb +158 -0
- data/lib/livejournal/database.rb +292 -0
- data/lib/livejournal/entry.rb +280 -0
- data/lib/livejournal/friends.rb +102 -0
- data/lib/livejournal/login.rb +43 -0
- data/lib/livejournal/logjam.rb +76 -0
- data/lib/livejournal/request.rb +126 -0
- data/lib/livejournal/sync.rb +185 -0
- data/sample/export +154 -0
- data/sample/lj +23 -0
- data/setup.rb +1585 -0
- data/test/checkfriends.rb +29 -0
- data/test/comments-xml.rb +108 -0
- data/test/database.rb +54 -0
- data/test/time.rb +49 -0
- metadata +60 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# Contributed by Dusty Matthews, fixed up by Evan.
|
4
|
+
|
5
|
+
require 'livejournal/login'
|
6
|
+
require 'livejournal/friends'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class TC_CheckFriends < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@user = LiveJournal::User.new('test','test')
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_true
|
15
|
+
# Absurd date that will always be true.
|
16
|
+
checkfriend = LiveJournal::Request::CheckFriends.new(@user, "2000-01-10 12:40:00")
|
17
|
+
new = checkfriend.run
|
18
|
+
assert(new)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_false
|
22
|
+
# Absurd date that will always be false.
|
23
|
+
checkfriend = LiveJournal::Request::CheckFriends.new(@user, "2010-01-10 12:40:00")
|
24
|
+
new = checkfriend.run
|
25
|
+
assert(!new)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# vim: ts=2 sw=2 et :
|
@@ -0,0 +1,108 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#--
|
3
|
+
# ljrb -- LiveJournal Ruby module
|
4
|
+
# Copyright (c) 2005 Evan Martin <martine@danga.com>
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
#++
|
24
|
+
|
25
|
+
require 'livejournal/comments-xml'
|
26
|
+
require 'test/unit'
|
27
|
+
|
28
|
+
TEST_COMMENTS_META = %q{<?xml version="1.0" encoding='utf-8'?>
|
29
|
+
<livejournal>
|
30
|
+
<maxid>421</maxid>
|
31
|
+
<comments>
|
32
|
+
<comment id='421' posterid='1129145' />
|
33
|
+
<comment id='420' />
|
34
|
+
</comments>
|
35
|
+
<usermaps>
|
36
|
+
<usermap id='1129145' user='cumbum' />
|
37
|
+
</usermaps>
|
38
|
+
</livejournal>
|
39
|
+
}
|
40
|
+
|
41
|
+
TEST_COMMENTS_BODY = %q{<?xml version="1.0" encoding='utf-8'?>
|
42
|
+
<livejournal>
|
43
|
+
<comments>
|
44
|
+
<comment id='1' jitemid='1' posterid='157893'>
|
45
|
+
<body>fuck yeah!!!! rock on with your GTK client, man.</body>
|
46
|
+
<date>2001-07-26T18:16:19Z</date>
|
47
|
+
</comment>
|
48
|
+
<comment id='2' jitemid='1' posterid='1571' state='D' parentid='1' />
|
49
|
+
<comment id='4' jitemid='144' posterid='1'>
|
50
|
+
<subject>/me wants</subject>
|
51
|
+
<body>dude, you updating the CVS server? i wanna track these changes....
|
52
|
+
|
53
|
+
and is it going to be resizable?
|
54
|
+
</body>
|
55
|
+
<date>2000-04-01T18:58:01Z</date>
|
56
|
+
</comment>
|
57
|
+
<comment id='999' jitemid='622' posterid='1594' parentid='998'>
|
58
|
+
<body>I agree</body>
|
59
|
+
<date>2000-08-01T15:37:55Z</date>
|
60
|
+
</comment>
|
61
|
+
</comments>
|
62
|
+
</livejournal>
|
63
|
+
}
|
64
|
+
|
65
|
+
class TC_Parsers < Test::Unit::TestCase
|
66
|
+
def run_meta(parser)
|
67
|
+
parser.parse TEST_COMMENTS_META
|
68
|
+
|
69
|
+
assert_equal(421, parser.maxid)
|
70
|
+
|
71
|
+
assert_equal(2, parser.comments.keys.length)
|
72
|
+
assert_equal(1129145, parser.comments[421].posterid)
|
73
|
+
assert_equal(nil, parser.comments[420].posterid)
|
74
|
+
|
75
|
+
assert_equal('cumbum', parser.usermap[1129145])
|
76
|
+
assert_equal(1, parser.usermap.keys.length)
|
77
|
+
end
|
78
|
+
|
79
|
+
def run_body(parser)
|
80
|
+
parser.parse TEST_COMMENTS_BODY
|
81
|
+
|
82
|
+
assert_equal(1, parser.comments[2].itemid)
|
83
|
+
assert_equal(:active, parser.comments[1].state)
|
84
|
+
assert_equal(:deleted, parser.comments[2].state)
|
85
|
+
assert_equal(1, parser.comments[2].parentid)
|
86
|
+
assert_equal('/me wants', parser.comments[4].subject)
|
87
|
+
assert_equal('I agree', parser.comments[999].body)
|
88
|
+
assert_equal(nil, parser.comments[999].subject)
|
89
|
+
|
90
|
+
assert_equal(2001, parser.comments[1].time.year)
|
91
|
+
assert_equal(7, parser.comments[1].time.mon)
|
92
|
+
assert_equal(26, parser.comments[1].time.day)
|
93
|
+
assert_equal(18, parser.comments[1].time.hour)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_rexml
|
97
|
+
run_meta LiveJournal::Sync::CommentsXML::WithREXML.new
|
98
|
+
run_body LiveJournal::Sync::CommentsXML::WithREXML.new
|
99
|
+
end
|
100
|
+
def test_expat
|
101
|
+
if LiveJournal::HAVE_XML_PARSER
|
102
|
+
run_meta LiveJournal::Sync::CommentsXML::WithExpat.new
|
103
|
+
run_body LiveJournal::Sync::CommentsXML::WithExpat.new
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# vim: ts=2 sw=2 et :
|
data/test/database.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'livejournal/database'
|
4
|
+
require 'livejournal/entry'
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class TC_Database < Test::Unit::TestCase
|
8
|
+
FILENAME = '/tmp/test.db'
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@db = LiveJournal::Database.new(FILENAME, true)
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
@db.close
|
16
|
+
File.delete FILENAME
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_metas
|
20
|
+
@db.username = 'foo'
|
21
|
+
assert_equal(@db.username, 'foo')
|
22
|
+
end
|
23
|
+
|
24
|
+
def roundtrip e
|
25
|
+
@db.store_entry e
|
26
|
+
new_e = @db.get_entry e.itemid
|
27
|
+
assert_equal(e, new_e)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_roundtrips
|
31
|
+
e = LiveJournal::Entry.new
|
32
|
+
e.itemid = 1
|
33
|
+
e.anum = 2
|
34
|
+
e.subject = 'subject here'
|
35
|
+
e.event = 'event here'
|
36
|
+
e.time = LiveJournal::coerce_gmt Time.now
|
37
|
+
|
38
|
+
roundtrip e
|
39
|
+
|
40
|
+
e = LiveJournal::Entry.new
|
41
|
+
e.itemid = 1
|
42
|
+
e.anum = 2
|
43
|
+
e.subject = 'subject here'
|
44
|
+
e.event = 'eventblah here'
|
45
|
+
e.time = LiveJournal::coerce_gmt Time.now
|
46
|
+
e.comments = :noemail
|
47
|
+
e.preformatted = true
|
48
|
+
e.security = :friends
|
49
|
+
|
50
|
+
roundtrip e
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# vim: ts=2 sw=2 et :
|
data/test/time.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#--
|
3
|
+
# ljrb -- LiveJournal Ruby module
|
4
|
+
# Copyright (c) 2005 Evan Martin <martine@danga.com>
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
#++
|
24
|
+
|
25
|
+
require 'livejournal/request'
|
26
|
+
require 'test/unit'
|
27
|
+
|
28
|
+
class TC_Times < Test::Unit::TestCase
|
29
|
+
def test_roundtrip
|
30
|
+
now = Time.now
|
31
|
+
ljtime = LiveJournal::Request::time_to_ljtime(now)
|
32
|
+
roundtrip = LiveJournal::Request::ljtime_to_time(ljtime)
|
33
|
+
[:year, :mon, :day, :hour, :min].each do |field|
|
34
|
+
assert_equal(now.send(field), roundtrip.send(field))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_parse
|
39
|
+
ljtime = "2005-12-27 14:50"
|
40
|
+
time = LiveJournal::Request::ljtime_to_time(ljtime)
|
41
|
+
assert_equal(time.year, 2005)
|
42
|
+
assert_equal(time.mon, 12)
|
43
|
+
assert_equal(time.day, 27)
|
44
|
+
assert_equal(time.hour, 14)
|
45
|
+
assert_equal(time.min, 50)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# vim: ts=2 sw=2 et :
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: livejournal
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2006-03-09 00:00:00 +09:00
|
8
|
+
summary: module for interacting with livejournal
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: martine@danga.com
|
12
|
+
homepage: http://neugierig.org/software/livejournal/ruby/
|
13
|
+
rubyforge_project:
|
14
|
+
description: "LiveJournal module. Post to livejournal, retrieve friends lists, edit entries,
|
15
|
+
sync journal to an offline database."
|
16
|
+
autorequire:
|
17
|
+
default_executable:
|
18
|
+
bindir: bin
|
19
|
+
has_rdoc: true
|
20
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
+
requirements:
|
22
|
+
-
|
23
|
+
- ">"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 0.0.0
|
26
|
+
version:
|
27
|
+
platform: ruby
|
28
|
+
signing_key:
|
29
|
+
cert_chain:
|
30
|
+
authors:
|
31
|
+
- Evan Martin
|
32
|
+
files:
|
33
|
+
- Rakefile
|
34
|
+
- README
|
35
|
+
- LICENSE
|
36
|
+
- setup.rb
|
37
|
+
- lib/livejournal
|
38
|
+
- lib/livejournal/database.rb
|
39
|
+
- lib/livejournal/logjam.rb
|
40
|
+
- lib/livejournal/sync.rb
|
41
|
+
- lib/livejournal/request.rb
|
42
|
+
- lib/livejournal/entry.rb
|
43
|
+
- lib/livejournal/comments-xml.rb
|
44
|
+
- lib/livejournal/login.rb
|
45
|
+
- lib/livejournal/comment.rb
|
46
|
+
- lib/livejournal/friends.rb
|
47
|
+
- lib/livejournal/basic.rb
|
48
|
+
- sample/lj
|
49
|
+
- sample/export
|
50
|
+
- test/database.rb
|
51
|
+
- test/time.rb
|
52
|
+
- test/checkfriends.rb
|
53
|
+
- test/comments-xml.rb
|
54
|
+
test_files: []
|
55
|
+
rdoc_options: []
|
56
|
+
extra_rdoc_files: []
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
requirements: []
|
60
|
+
dependencies: []
|