governor_livejournal 0.2.0 → 0.2.1
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/Gemfile +1 -1
- data/Gemfile.lock +5 -5
- data/VERSION +1 -1
- data/config/locales/en.yml +3 -3
- data/governor_livejournal.gemspec +6 -5
- data/lib/governor_livejournal.rb +16 -0
- data/lib/governor_livejournal/instance_methods.rb +2 -44
- data/lib/governor_livejournal/livejournal.rb +50 -0
- data/spec/governor_livejournal_spec.rb +34 -0
- data/spec/rails_app/Gemfile +1 -1
- data/spec/rails_app/Gemfile.lock +4 -4
- data/spec/rails_app/config/initializers/livejournal.rb +2 -2
- data/spec/rails_app/db/migrate/20110425023749_governor_add_livejournal.rb +10 -2
- data/spec/rails_app/db/schema.rb +3 -1
- data/spec/spec_helper.rb +7 -0
- metadata +9 -6
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ./
|
3
3
|
specs:
|
4
|
-
governor_livejournal (0.2.
|
4
|
+
governor_livejournal (0.2.1)
|
5
5
|
governor
|
6
|
-
governor_background
|
6
|
+
governor_background (>= 0.3.0)
|
7
7
|
livejournal
|
8
8
|
|
9
9
|
GEM
|
@@ -60,7 +60,7 @@ GEM
|
|
60
60
|
git (1.2.5)
|
61
61
|
governor (0.3.1)
|
62
62
|
rails (~> 3.0.5)
|
63
|
-
governor_background (0.
|
63
|
+
governor_background (0.3.0)
|
64
64
|
governor
|
65
65
|
i18n (0.5.0)
|
66
66
|
jeweler (1.5.2)
|
@@ -100,7 +100,7 @@ GEM
|
|
100
100
|
rspec-core (~> 2.5.0)
|
101
101
|
rspec-expectations (~> 2.5.0)
|
102
102
|
rspec-mocks (~> 2.5.0)
|
103
|
-
rspec-core (2.5.
|
103
|
+
rspec-core (2.5.2)
|
104
104
|
rspec-expectations (2.5.0)
|
105
105
|
diff-lcs (~> 1.1.2)
|
106
106
|
rspec-mocks (2.5.0)
|
@@ -129,7 +129,7 @@ DEPENDENCIES
|
|
129
129
|
factory_girl (~> 2.0.0.beta)
|
130
130
|
factory_girl_rails (~> 1.1.beta)
|
131
131
|
governor
|
132
|
-
governor_background
|
132
|
+
governor_background (>= 0.3.0)
|
133
133
|
governor_livejournal!
|
134
134
|
jeweler (~> 1.5.2)
|
135
135
|
livejournal
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/config/locales/en.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
en:
|
2
2
|
governor_background:
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
livejournal_post_completed: 'Your article was successfully posted to LiveJournal.'
|
4
|
+
livejournal_post_failed: 'Unable to post to LiveJournal: %{message}.'
|
5
|
+
livejournal_post_killed: 'Your post to LiveJournal was interrupted: %{message}.'
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{governor_livejournal}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Liam Morley"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-05-15}
|
13
13
|
s.description = %q{A plugin for the Rails 3-based Governor blogging system that posts and updates articles to LiveJournal.com.}
|
14
14
|
s.email = %q{liam@carpeliam.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"lib/generators/governor/templates/migrations/add_livejournal.rb",
|
34
34
|
"lib/governor_livejournal.rb",
|
35
35
|
"lib/governor_livejournal/instance_methods.rb",
|
36
|
+
"lib/governor_livejournal/livejournal.rb",
|
36
37
|
"lib/governor_livejournal/rails.rb",
|
37
38
|
"spec/governor_livejournal_spec.rb",
|
38
39
|
"spec/rails_app/.gitignore",
|
@@ -141,7 +142,7 @@ Gem::Specification.new do |s|
|
|
141
142
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
142
143
|
s.add_runtime_dependency(%q<livejournal>, [">= 0"])
|
143
144
|
s.add_runtime_dependency(%q<governor>, [">= 0"])
|
144
|
-
s.add_runtime_dependency(%q<governor_background>, [">= 0"])
|
145
|
+
s.add_runtime_dependency(%q<governor_background>, [">= 0.3.0"])
|
145
146
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
146
147
|
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
147
148
|
s.add_development_dependency(%q<rspec-rails>, [">= 0"])
|
@@ -157,7 +158,7 @@ Gem::Specification.new do |s|
|
|
157
158
|
else
|
158
159
|
s.add_dependency(%q<livejournal>, [">= 0"])
|
159
160
|
s.add_dependency(%q<governor>, [">= 0"])
|
160
|
-
s.add_dependency(%q<governor_background>, [">= 0"])
|
161
|
+
s.add_dependency(%q<governor_background>, [">= 0.3.0"])
|
161
162
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
162
163
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
163
164
|
s.add_dependency(%q<rspec-rails>, [">= 0"])
|
@@ -174,7 +175,7 @@ Gem::Specification.new do |s|
|
|
174
175
|
else
|
175
176
|
s.add_dependency(%q<livejournal>, [">= 0"])
|
176
177
|
s.add_dependency(%q<governor>, [">= 0"])
|
177
|
-
s.add_dependency(%q<governor_background>, [">= 0"])
|
178
|
+
s.add_dependency(%q<governor_background>, [">= 0.3.0"])
|
178
179
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
179
180
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
180
181
|
s.add_dependency(%q<rspec-rails>, [">= 0"])
|
data/lib/governor_livejournal.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'governor_livejournal/rails'
|
2
|
+
require 'governor_livejournal/livejournal'
|
2
3
|
require 'governor_livejournal/instance_methods'
|
3
4
|
|
4
5
|
livejournal = Governor::Plugin.new('livejournal')
|
@@ -17,6 +18,21 @@ livejournal.register_partial :bottom_of_form, 'articles/livejournal_form'
|
|
17
18
|
|
18
19
|
Governor::PluginManager.register livejournal
|
19
20
|
|
21
|
+
GovernorBackground.register('livejournal_post') do |article|
|
22
|
+
lj = GovernorLivejournal::Livejournal.new(article)
|
23
|
+
id = if article.livejournal_id.blank?
|
24
|
+
lj.post
|
25
|
+
else
|
26
|
+
lj.put
|
27
|
+
end
|
28
|
+
article.reload.update_attribute :livejournal_id, id
|
29
|
+
end
|
30
|
+
|
31
|
+
GovernorBackground.register('livejournal_delete') do |livejournal_id|
|
32
|
+
lj = GovernorLivejournal::Livejournal.new(livejournal_id)
|
33
|
+
lj.delete
|
34
|
+
end
|
35
|
+
|
20
36
|
module GovernorLivejournal
|
21
37
|
class Configuration
|
22
38
|
cattr_accessor :username, :password
|
@@ -1,53 +1,11 @@
|
|
1
|
-
require 'livejournal'
|
2
1
|
module GovernorLivejournal
|
3
2
|
module InstanceMethods
|
4
|
-
def post_to_livejournal
|
5
|
-
user = ljlogin
|
6
|
-
if livejournal_id.blank?
|
7
|
-
entry = populate_entry(LiveJournal::Entry.new)
|
8
|
-
post_event = LiveJournal::Request::PostEvent.new(user, entry)
|
9
|
-
post_event.run
|
10
|
-
|
11
|
-
self.update_attribute :livejournal_id, entry.itemid
|
12
|
-
else
|
13
|
-
get_events = LiveJournal::Request::GetEvents.new(user, :itemid => livejournal_id)
|
14
|
-
entry = populate_entry(get_events.run)
|
15
|
-
edit_event = LiveJournal::Request::EditEvent.new(user, entry)
|
16
|
-
edit_event.run
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def remove_from_livejournal
|
21
|
-
user = ljlogin
|
22
|
-
get_events = LiveJournal::Request::GetEvents.new(user, :itemid => livejournal_id)
|
23
|
-
entry = get_events.run
|
24
|
-
delete_event = LiveJournal::Request::EditEvent.new(user, entry, :delete => true)
|
25
|
-
delete_event.run
|
26
|
-
end
|
27
|
-
|
28
3
|
def post_to_livejournal_in_background
|
29
|
-
|
4
|
+
GovernorBackground.run('livejournal_post', self)
|
30
5
|
end
|
31
6
|
|
32
7
|
def remove_from_livejournal_in_background
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
def ljlogin
|
38
|
-
user = LiveJournal::User.new(GovernorLivejournal.config.username, GovernorLivejournal.config.password)
|
39
|
-
login = LiveJournal::Request::Login.new(user)
|
40
|
-
login.run
|
41
|
-
user
|
42
|
-
end
|
43
|
-
|
44
|
-
def populate_entry(entry)
|
45
|
-
entry.subject = self.title
|
46
|
-
entry.event = Governor::Formatters.format_article self
|
47
|
-
entry.time = LiveJournal::coerce_gmt(self.created_at.present? ? self.created_at : Time.now)
|
48
|
-
entry.preformatted = false
|
49
|
-
entry.security = livejournal_security.to_sym
|
50
|
-
entry
|
8
|
+
GovernorBackground.run('livejournal_delete', livejournal_id)
|
51
9
|
end
|
52
10
|
end
|
53
11
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'livejournal'
|
2
|
+
module GovernorLivejournal
|
3
|
+
class Livejournal
|
4
|
+
include ::LiveJournal
|
5
|
+
def initialize(article_or_entry_id)
|
6
|
+
@article = article_or_entry_id
|
7
|
+
@user = User.new(GovernorLivejournal.config.username, GovernorLivejournal.config.password)
|
8
|
+
login = Request::Login.new(@user)
|
9
|
+
login.run
|
10
|
+
end
|
11
|
+
|
12
|
+
def post
|
13
|
+
entry = populate_entry(Entry.new)
|
14
|
+
post_event = Request::PostEvent.new(@user, entry)
|
15
|
+
post_event.run
|
16
|
+
entry.itemid
|
17
|
+
end
|
18
|
+
|
19
|
+
def get
|
20
|
+
get_events = Request::GetEvents.new(@user, :itemid => livejournal_id)
|
21
|
+
get_events.run
|
22
|
+
end
|
23
|
+
|
24
|
+
def put
|
25
|
+
entry = populate_entry(get)
|
26
|
+
edit_event = Request::EditEvent.new(@user, entry)
|
27
|
+
edit_event.run
|
28
|
+
entry.itemid
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete
|
32
|
+
delete_event = Request::EditEvent.new(@user, get, :delete => true)
|
33
|
+
delete_event.run
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def livejournal_id
|
38
|
+
@article.respond_to?(:livejournal_id) ? @article.livejournal_id : @article
|
39
|
+
end
|
40
|
+
|
41
|
+
def populate_entry(entry)
|
42
|
+
entry.subject = @article.title
|
43
|
+
entry.event = Governor::Formatters.format_article @article
|
44
|
+
entry.time = LiveJournal::coerce_gmt(@article.created_at.present? ? @article.created_at : Time.now)
|
45
|
+
entry.preformatted = false
|
46
|
+
entry.security = @article.livejournal_security.to_sym
|
47
|
+
entry
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -4,4 +4,38 @@ describe GovernorLivejournal do
|
|
4
4
|
it "registers the plugin" do
|
5
5
|
Governor::PluginManager.plugins.size == 1
|
6
6
|
end
|
7
|
+
|
8
|
+
it "registers a job with GovernorBackground" do
|
9
|
+
GovernorBackground.retrieve('livejournal_post').should_not be_blank
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can post to livejournal" do
|
13
|
+
article = get_article
|
14
|
+
article.livejournal_id.should == 12345
|
15
|
+
end
|
16
|
+
|
17
|
+
it "can update livejournal" do
|
18
|
+
article = get_article
|
19
|
+
lj = mock()
|
20
|
+
GovernorLivejournal::Livejournal.expects(:new).with(article).returns lj
|
21
|
+
lj.expects(:put).returns 12345
|
22
|
+
article.update_attribute :title, "Some new title"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "can delete from livejournal" do
|
26
|
+
article = get_article
|
27
|
+
lj = mock()
|
28
|
+
GovernorLivejournal::Livejournal.expects(:new).with(12345).returns lj
|
29
|
+
lj.expects(:delete)
|
30
|
+
article.destroy
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_article
|
34
|
+
article = Factory.build(:article, :is_livejournal => true, :author => Factory(:user))
|
35
|
+
lj = mock()
|
36
|
+
GovernorLivejournal::Livejournal.expects(:new).with(article).returns lj
|
37
|
+
lj.expects(:post).returns 12345
|
38
|
+
article.save
|
39
|
+
article
|
40
|
+
end
|
7
41
|
end
|
data/spec/rails_app/Gemfile
CHANGED
data/spec/rails_app/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../..
|
3
3
|
specs:
|
4
|
-
governor_livejournal (0.2.
|
4
|
+
governor_livejournal (0.2.1)
|
5
5
|
governor
|
6
|
-
governor_background
|
6
|
+
governor_background (>= 0.3.0)
|
7
7
|
livejournal
|
8
8
|
|
9
9
|
GEM
|
@@ -52,7 +52,7 @@ GEM
|
|
52
52
|
abstract (>= 1.0.0)
|
53
53
|
governor (0.3.1)
|
54
54
|
rails (~> 3.0.5)
|
55
|
-
governor_background (0.
|
55
|
+
governor_background (0.3.0)
|
56
56
|
governor
|
57
57
|
i18n (0.5.0)
|
58
58
|
livejournal (0.3.4)
|
@@ -100,7 +100,7 @@ DEPENDENCIES
|
|
100
100
|
devise
|
101
101
|
dynamic_form
|
102
102
|
governor
|
103
|
-
governor_background
|
103
|
+
governor_background (= 0.3.0)
|
104
104
|
governor_livejournal!
|
105
105
|
rails (= 3.0.5)
|
106
106
|
sqlite3
|
@@ -1,2 +1,2 @@
|
|
1
|
-
GovernorLivejournal.config.username = ''
|
2
|
-
GovernorLivejournal.config.password = ''
|
1
|
+
GovernorLivejournal.config.username = 'user'
|
2
|
+
GovernorLivejournal.config.password = 'password'
|
@@ -1,9 +1,17 @@
|
|
1
1
|
class GovernorAddLivejournal < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
-
|
3
|
+
change_table :articles do |t|
|
4
|
+
t.boolean :is_livejournal
|
5
|
+
t.string :livejournal_security, :default => 'public'
|
6
|
+
t.references :livejournal
|
7
|
+
end
|
4
8
|
end
|
5
9
|
|
6
10
|
def self.down
|
7
|
-
|
11
|
+
change_table :articles do |t|
|
12
|
+
t.remove :is_livejournal
|
13
|
+
t.remove :livejournal_security
|
14
|
+
t.remove :livejournal_id
|
15
|
+
end
|
8
16
|
end
|
9
17
|
end
|
data/spec/rails_app/db/schema.rb
CHANGED
@@ -15,12 +15,14 @@ ActiveRecord::Schema.define(:version => 20110425023749) do
|
|
15
15
|
create_table "articles", :force => true do |t|
|
16
16
|
t.string "title"
|
17
17
|
t.string "description"
|
18
|
-
t.string "format",
|
18
|
+
t.string "format", :default => "default"
|
19
19
|
t.text "post"
|
20
20
|
t.integer "author_id"
|
21
21
|
t.string "author_type"
|
22
22
|
t.datetime "created_at"
|
23
23
|
t.datetime "updated_at"
|
24
|
+
t.boolean "is_livejournal"
|
25
|
+
t.string "livejournal_security", :default => "public"
|
24
26
|
t.integer "livejournal_id"
|
25
27
|
end
|
26
28
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: governor_livejournal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Liam Morley
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-15 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -55,10 +55,12 @@ dependencies:
|
|
55
55
|
requirements:
|
56
56
|
- - ">="
|
57
57
|
- !ruby/object:Gem::Version
|
58
|
-
hash:
|
58
|
+
hash: 19
|
59
59
|
segments:
|
60
60
|
- 0
|
61
|
-
|
61
|
+
- 3
|
62
|
+
- 0
|
63
|
+
version: 0.3.0
|
62
64
|
requirement: *id003
|
63
65
|
- !ruby/object:Gem::Dependency
|
64
66
|
type: :development
|
@@ -263,6 +265,7 @@ files:
|
|
263
265
|
- lib/generators/governor/templates/migrations/add_livejournal.rb
|
264
266
|
- lib/governor_livejournal.rb
|
265
267
|
- lib/governor_livejournal/instance_methods.rb
|
268
|
+
- lib/governor_livejournal/livejournal.rb
|
266
269
|
- lib/governor_livejournal/rails.rb
|
267
270
|
- spec/governor_livejournal_spec.rb
|
268
271
|
- spec/rails_app/.gitignore
|