livejournal2 0.4.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.
- checksums.yaml +7 -0
- data/Changes +24 -0
- data/LICENSE +17 -0
- data/README.md +92 -0
- data/Rakefile +39 -0
- data/VERSION +1 -0
- data/lib/livejournal.rb +6 -0
- data/lib/livejournal/basic.rb +98 -0
- data/lib/livejournal/comment.rb +84 -0
- data/lib/livejournal/comments-xml.rb +161 -0
- data/lib/livejournal/database.rb +308 -0
- data/lib/livejournal/entry.rb +385 -0
- data/lib/livejournal/friends.rb +137 -0
- data/lib/livejournal/login.rb +46 -0
- data/lib/livejournal/logjam.rb +78 -0
- data/lib/livejournal/request.rb +142 -0
- data/lib/livejournal/sync.rb +187 -0
- data/sample/export +144 -0
- data/sample/fuse +198 -0
- data/sample/graph +208 -0
- data/sample/progressbar.rb +45 -0
- data/setup.rb +1585 -0
- data/test/checkfriends.rb +29 -0
- data/test/comments-xml.rb +110 -0
- data/test/database.rb +54 -0
- data/test/login.rb +19 -0
- data/test/roundtrip.rb +46 -0
- data/test/time.rb +49 -0
- metadata +74 -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,110 @@
|
|
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
|
+
$:.unshift '../lib'
|
26
|
+
require 'livejournal/comments-xml'
|
27
|
+
require 'rexml/document'
|
28
|
+
require 'test/unit'
|
29
|
+
|
30
|
+
TEST_COMMENTS_META = %q{<?xml version="1.0" encoding='utf-8'?>
|
31
|
+
<livejournal>
|
32
|
+
<maxid>421</maxid>
|
33
|
+
<comments>
|
34
|
+
<comment id='421' posterid='1129145' />
|
35
|
+
<comment id='420' />
|
36
|
+
</comments>
|
37
|
+
<usermaps>
|
38
|
+
<usermap id='1129145' user='cumbum' />
|
39
|
+
</usermaps>
|
40
|
+
</livejournal>
|
41
|
+
}
|
42
|
+
|
43
|
+
TEST_COMMENTS_BODY = %q{<?xml version="1.0" encoding='utf-8'?>
|
44
|
+
<livejournal>
|
45
|
+
<comments>
|
46
|
+
<comment id='1' jitemid='1' posterid='157893'>
|
47
|
+
<body>fuck yeah!!!! rock on with your GTK client, man.</body>
|
48
|
+
<date>2001-07-26T18:16:19Z</date>
|
49
|
+
</comment>
|
50
|
+
<comment id='2' jitemid='1' posterid='1571' state='D' parentid='1' />
|
51
|
+
<comment id='4' jitemid='144' posterid='1'>
|
52
|
+
<subject>/me wants</subject>
|
53
|
+
<body>dude, you updating the CVS server? i wanna track these changes....
|
54
|
+
|
55
|
+
and is it going to be resizable?
|
56
|
+
</body>
|
57
|
+
<date>2000-04-01T18:58:01Z</date>
|
58
|
+
</comment>
|
59
|
+
<comment id='999' jitemid='622' posterid='1594' parentid='998'>
|
60
|
+
<body>I agree</body>
|
61
|
+
<date>2000-08-01T15:37:55Z</date>
|
62
|
+
</comment>
|
63
|
+
</comments>
|
64
|
+
</livejournal>
|
65
|
+
}
|
66
|
+
|
67
|
+
class TC_Parsers < Test::Unit::TestCase
|
68
|
+
def run_meta(parser)
|
69
|
+
parser.parse TEST_COMMENTS_META
|
70
|
+
|
71
|
+
assert_equal(421, parser.maxid)
|
72
|
+
|
73
|
+
assert_equal(2, parser.comments.keys.length)
|
74
|
+
assert_equal(1129145, parser.comments[421].posterid)
|
75
|
+
assert_equal(nil, parser.comments[420].posterid)
|
76
|
+
|
77
|
+
assert_equal('cumbum', parser.usermap[1129145])
|
78
|
+
assert_equal(1, parser.usermap.keys.length)
|
79
|
+
end
|
80
|
+
|
81
|
+
def run_body(parser)
|
82
|
+
parser.parse TEST_COMMENTS_BODY
|
83
|
+
|
84
|
+
assert_equal(1, parser.comments[2].itemid)
|
85
|
+
assert_equal(:active, parser.comments[1].state)
|
86
|
+
assert_equal(:deleted, parser.comments[2].state)
|
87
|
+
assert_equal(1, parser.comments[2].parentid)
|
88
|
+
assert_equal('/me wants', parser.comments[4].subject)
|
89
|
+
assert_equal('I agree', parser.comments[999].body)
|
90
|
+
assert_equal(nil, parser.comments[999].subject)
|
91
|
+
|
92
|
+
assert_equal(2001, parser.comments[1].time.year)
|
93
|
+
assert_equal(7, parser.comments[1].time.mon)
|
94
|
+
assert_equal(26, parser.comments[1].time.day)
|
95
|
+
assert_equal(18, parser.comments[1].time.hour)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_rexml
|
99
|
+
run_meta LiveJournal::Sync::CommentsXML::WithREXML.new
|
100
|
+
run_body LiveJournal::Sync::CommentsXML::WithREXML.new
|
101
|
+
end
|
102
|
+
def test_expat
|
103
|
+
if LiveJournal::HAVE_XML_PARSER
|
104
|
+
run_meta LiveJournal::Sync::CommentsXML::WithExpat.new
|
105
|
+
run_body LiveJournal::Sync::CommentsXML::WithExpat.new
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# 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/login.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'livejournal/login'
|
4
|
+
require 'livejournal/entry'
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class TC_Login < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@user = LiveJournal::User.new('test', 'test')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_login
|
13
|
+
login = LiveJournal::Request::Login.new(@user)
|
14
|
+
login.run
|
15
|
+
assert_not_equal(@user.fullname, nil)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# vim: ts=2 sw=2 et :
|
data/test/roundtrip.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift '../lib'
|
4
|
+
|
5
|
+
require 'livejournal/entry'
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
include LiveJournal
|
9
|
+
|
10
|
+
class TC_RoundTrip < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
@user = User.new('ljrb_test', 'test_ljrb')
|
13
|
+
end
|
14
|
+
|
15
|
+
def roundtrip entry
|
16
|
+
postevent = Request::PostEvent.new(@user, entry)
|
17
|
+
postevent.run
|
18
|
+
|
19
|
+
getevents = Request::GetEvents.new(@user, :itemid => entry.itemid)
|
20
|
+
new_entry = getevents.run
|
21
|
+
assert_equal(new_entry, entry)
|
22
|
+
|
23
|
+
delete = Request::EditEvent.new(@user, entry, :delete => true)
|
24
|
+
delete.run
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_roundtrip
|
28
|
+
e = Entry.new
|
29
|
+
e.subject = 'subject'
|
30
|
+
e.event = 'event here'
|
31
|
+
e.time = LiveJournal::coerce_gmt Time.now
|
32
|
+
roundtrip e
|
33
|
+
|
34
|
+
e = Entry.new
|
35
|
+
e.subject = 'subject here'
|
36
|
+
e.event = 'eventblah here'
|
37
|
+
e.time = LiveJournal::coerce_gmt Time.now
|
38
|
+
e.comments = :noemail
|
39
|
+
e.preformatted = true
|
40
|
+
e.security = :friends
|
41
|
+
e.location = "test"
|
42
|
+
roundtrip e
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# vim: set ts=2 sw=2 et cino=(0 :
|
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,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: livejournal2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Evan Martin
|
8
|
+
- Roman Shterenzon
|
9
|
+
- Vitalii Khustochka
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2021-03-27 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: LiveJournal API client. Post to livejournal, retrieve friends lists,
|
16
|
+
edit entries, sync journal to an offline database.
|
17
|
+
email:
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files:
|
21
|
+
- LICENSE
|
22
|
+
- README.md
|
23
|
+
files:
|
24
|
+
- Changes
|
25
|
+
- LICENSE
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- VERSION
|
29
|
+
- lib/livejournal.rb
|
30
|
+
- lib/livejournal/basic.rb
|
31
|
+
- lib/livejournal/comment.rb
|
32
|
+
- lib/livejournal/comments-xml.rb
|
33
|
+
- lib/livejournal/database.rb
|
34
|
+
- lib/livejournal/entry.rb
|
35
|
+
- lib/livejournal/friends.rb
|
36
|
+
- lib/livejournal/login.rb
|
37
|
+
- lib/livejournal/logjam.rb
|
38
|
+
- lib/livejournal/request.rb
|
39
|
+
- lib/livejournal/sync.rb
|
40
|
+
- sample/export
|
41
|
+
- sample/fuse
|
42
|
+
- sample/graph
|
43
|
+
- sample/progressbar.rb
|
44
|
+
- setup.rb
|
45
|
+
- test/checkfriends.rb
|
46
|
+
- test/comments-xml.rb
|
47
|
+
- test/database.rb
|
48
|
+
- test/login.rb
|
49
|
+
- test/roundtrip.rb
|
50
|
+
- test/time.rb
|
51
|
+
homepage: https://github.com/khustochka/livejournal2
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubygems_version: 3.0.9
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: Module for interacting with Livejournal API
|
74
|
+
test_files: []
|