livefyre-mashable 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +3 -0
- data.tar.gz.sig +0 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +169 -0
- data/Rakefile +12 -0
- data/app/assets/javascripts/livefyre.js +180 -0
- data/app/assets/javascripts/livefyre.js.coffee +109 -0
- data/gem-public_cert.pem +21 -0
- data/lib/livefyre.rb +54 -0
- data/lib/livefyre/activity.rb +43 -0
- data/lib/livefyre/client.rb +141 -0
- data/lib/livefyre/comment.rb +190 -0
- data/lib/livefyre/controller_extensions.rb +82 -0
- data/lib/livefyre/conversation.rb +133 -0
- data/lib/livefyre/domain.rb +220 -0
- data/lib/livefyre/engine.rb +6 -0
- data/lib/livefyre/helpers.rb +57 -0
- data/lib/livefyre/model_extensions.rb +64 -0
- data/lib/livefyre/site.rb +237 -0
- data/lib/livefyre/user.rb +162 -0
- data/lib/livefyre/version.rb +3 -0
- data/livefyre.gemspec +39 -0
- data/railties/railtie.rb +9 -0
- data/spec/livefyre/client_spec.rb +104 -0
- data/spec/livefyre/domain_spec.rb +294 -0
- data/spec/livefyre/livefyre_spec.rb +30 -0
- data/spec/livefyre/model_spec.rb +96 -0
- data/spec/livefyre/site_spec.rb +212 -0
- data/spec/livefyre/user_spec.rb +111 -0
- data/spec/spec_helper.rb +26 -0
- metadata +261 -0
- metadata.gz.sig +0 -0
data/livefyre.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/livefyre/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Mashable"]
|
6
|
+
gem.email = ["cheald@mashable.com"]
|
7
|
+
gem.description = %q{Interface library for Livefyre's comment API with Rails helpers}
|
8
|
+
gem.summary = %q{Interface library for Livefyre's comment API with Rails helpers}
|
9
|
+
gem.homepage = "http://github.com/mashable/livefyre"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(spec)/})
|
14
|
+
gem.name = "livefyre-mashable"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Livefyre::VERSION
|
17
|
+
|
18
|
+
gem.signing_key = File.expand_path('~/.gemcert/cheald@mashable.com-private_key.pem')
|
19
|
+
gem.cert_chain = ['gem-public_cert.pem']
|
20
|
+
|
21
|
+
gem.add_dependency "faraday"
|
22
|
+
gem.add_dependency "jwt"
|
23
|
+
gem.add_dependency "ruby-hmac"
|
24
|
+
|
25
|
+
gem.add_development_dependency "rspec"
|
26
|
+
gem.add_development_dependency "simplecov"
|
27
|
+
gem.add_development_dependency "simplecov-rcov"
|
28
|
+
gem.add_development_dependency "rails"
|
29
|
+
gem.add_development_dependency "resque"
|
30
|
+
gem.add_development_dependency "yard"
|
31
|
+
gem.add_development_dependency "yard-tomdoc"
|
32
|
+
gem.add_development_dependency "redcarpet"
|
33
|
+
gem.post_install_message = <<-MESSAGE
|
34
|
+
! The 'livefyre' gem has been deprecated and has been replaced by 'livefyre-mashable'.
|
35
|
+
! An official client library from Livefyre will replace this one in mid-April 2014.
|
36
|
+
! See: https://rubygems.org/gems/livefyre-mashable
|
37
|
+
! And: https://github.com/mashable/livefyre
|
38
|
+
MESSAGE
|
39
|
+
end
|
data/railties/railtie.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
module Livefyre
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer "livefyre.initializer" do
|
4
|
+
ActionController::Base.send :include, Livefyre::Controller
|
5
|
+
ActionView::Base.send :include, Livefyre::Helpers
|
6
|
+
ActiveRecord::Base.send :include, Livefyre::Model if defined?(ActiveRecord)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Livefyre::Client do
|
4
|
+
it "should not initialize without a host" do
|
5
|
+
expect { Livefyre::Client.new(:key => "x", :system_token => "x") }.to raise_error Exception
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should not initialize without a key" do
|
9
|
+
expect { Livefyre::Client.new(:host => "x", :system_token => "x") }.to raise_error Exception
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not initialize without a system token" do
|
13
|
+
expect { Livefyre::Client.new(:key => "x", :host => "x") }.to raise_error Exception
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should initialize with a key, host, and system token" do
|
17
|
+
Livefyre::Client.new(:key => "x", :network => "x", :system_token => "x").should be_a Livefyre::Client
|
18
|
+
end
|
19
|
+
|
20
|
+
context "an instance" do
|
21
|
+
subject { Livefyre::Client.new(:key => "x", :host => "x", :system_token => "x") }
|
22
|
+
|
23
|
+
describe "#sign" do
|
24
|
+
before { @token = subject.sign({:foo => "bar"}) }
|
25
|
+
|
26
|
+
it "should return a string token" do
|
27
|
+
@token.should be_a String
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should validate" do
|
31
|
+
subject.validate(@token).should be_a Hash
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should decode" do
|
35
|
+
subject.validate(@token)["foo"].should == "bar"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#user" do
|
40
|
+
before { @user = subject.user(1234, "foobar") }
|
41
|
+
it "should return a user" do
|
42
|
+
@user.should be_a Livefyre::User
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should have its ID set" do
|
46
|
+
@user.id.should == 1234
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should have a reference to this client" do
|
50
|
+
@user.instance_variable_get("@client").should == subject
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#set_user_role" do
|
55
|
+
context "with a valid role and scope" do
|
56
|
+
let(:client) { double "client" }
|
57
|
+
|
58
|
+
before do
|
59
|
+
subject.stub(:http_client).and_return(client)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should post an affiliation update for a domain" do
|
63
|
+
client.should_receive(:post).with("/api/v1.1/private/management/user/123@x/role/", {:affiliation=>"admin", :lftoken=>"x", :domain_wide=>1}).and_return( double(:success? => true) )
|
64
|
+
subject.set_user_role(123, "admin", "domain").should == true
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when updating a site affiliation" do
|
68
|
+
it "should fail if no scope ID is passed" do
|
69
|
+
client.should_not_receive(:post)
|
70
|
+
expect { subject.set_user_role(123, "admin", "site") }.to raise_error Exception
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should post an affiliation update for a site" do
|
74
|
+
client.should_receive(:post).with("/api/v1.1/private/management/user/123@x/role/", {:affiliation=>"admin", :lftoken=>"x", :site_id=>123}).and_return( double(:success? => true) )
|
75
|
+
subject.set_user_role(123, "admin", "site", 123).should == true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when updating a conversation affiliation" do
|
80
|
+
it "should fail if no scope ID is passed" do
|
81
|
+
client.should_not_receive(:post)
|
82
|
+
expect { subject.set_user_role(123, "admin", "conv") }.to raise_error Exception
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should post an affiliation update for a site" do
|
86
|
+
client.should_receive(:post).with("/api/v1.1/private/management/user/123@x/role/", {:affiliation=>"admin", :lftoken=>"x", :conv_id=>123}).and_return( double(:success? => true) )
|
87
|
+
subject.set_user_role(123, "admin", "conv", 123).should == true
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "when it fails" do
|
92
|
+
it "should raise an exception" do
|
93
|
+
client.should_receive(:post).and_return( double(:success? => false, :body => "Failure due to zombie outbreak") )
|
94
|
+
expect { subject.set_user_role(123, "admin", "domain") }.to raise_error(Livefyre::APIException)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should have a valid string representation" do
|
101
|
+
subject.to_s.should match(/Livefyre::Client/)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,294 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Livefyre::Domain do
|
4
|
+
context "an instance" do
|
5
|
+
subject { Livefyre::Domain.new }
|
6
|
+
|
7
|
+
describe "#sites" do
|
8
|
+
context "on success" do
|
9
|
+
before do
|
10
|
+
client = double( :get => double(:success? => true, :body => [{:id => "foo.com"}].to_json), :system_token => "x" )
|
11
|
+
subject.stub(:client).and_return(client)
|
12
|
+
end
|
13
|
+
|
14
|
+
its(:sites) { should be_a Array }
|
15
|
+
|
16
|
+
its("sites.first") { should be_a Livefyre::Site }
|
17
|
+
its("sites.first.id") { should == "foo.com" }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "on failure" do
|
21
|
+
before do
|
22
|
+
client = double( :get => double(:success? => false, :body => ""), :system_token => "x" )
|
23
|
+
subject.stub(:client).and_return(client)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should raise an exception" do
|
27
|
+
expect { subject.sites }.to raise_error(Livefyre::APIException)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#users" do
|
33
|
+
context "on success" do
|
34
|
+
before do
|
35
|
+
client = double( :get => double(:success? => true, :body => [{:id => "foo"}].to_json), :system_token => "x" )
|
36
|
+
subject.stub(:client).and_return(client)
|
37
|
+
end
|
38
|
+
|
39
|
+
its(:users) { should be_a Array }
|
40
|
+
|
41
|
+
its("users.first") { should be_a Livefyre::User }
|
42
|
+
its("users.first.id") { should == "foo" }
|
43
|
+
end
|
44
|
+
|
45
|
+
context "on failure" do
|
46
|
+
before do
|
47
|
+
client = double( :get => double(:success? => false, :body => ""), :system_token => "x" )
|
48
|
+
subject.stub(:client).and_return(client)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should raise an exception" do
|
52
|
+
expect { subject.users }.to raise_error(Livefyre::APIException)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#add_user" do
|
58
|
+
context "on success" do
|
59
|
+
before do
|
60
|
+
client = double( :post => double(:success? => true), :system_token => "x", :host => "some_host", :key => "some_key" )
|
61
|
+
subject.stub(:client).and_return(client)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return true" do
|
65
|
+
subject.add_user({"id" => "valid ID"}).should be true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "on failure" do
|
70
|
+
before do
|
71
|
+
client = double( :post => double(:success? => false, :body => ""), :system_token => "x" )
|
72
|
+
subject.stub(:client).and_return(client)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should raise an exception" do
|
76
|
+
expect { subject.add_user({"id" => "valid ID"}) }.to raise_error(Livefyre::APIException)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should raise an exception when passed an invalid ID" do
|
80
|
+
expect { subject.add_user({"bad_id" => "invalid ID"}) }.to raise_error("Invalid ID")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#create_site" do
|
86
|
+
context "on success" do
|
87
|
+
before do
|
88
|
+
client = double( :post => double(:success? => true, :body => {"id" => "foo"}.to_json), :system_token => "x", :host => "some_host", :key => "some_key" )
|
89
|
+
subject.stub(:client).and_return(client)
|
90
|
+
@site = subject.create_site("some URL")
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should return a Site" do
|
94
|
+
@site.should be_a Livefyre::Site
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should be prepopulated with the values we just passed" do
|
98
|
+
@site.id.should == "foo"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "on failure" do
|
103
|
+
before do
|
104
|
+
client = double( :post => double(:success? => false, :body => ""), :system_token => "x" )
|
105
|
+
subject.stub(:client).and_return(client)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should raise an exception" do
|
109
|
+
expect { subject.create_site("some_url") }.to raise_error(Livefyre::APIException)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "#owners" do
|
115
|
+
context "on success" do
|
116
|
+
before do
|
117
|
+
client = double( :get => double(:success? => true, :body => ["foo@bar"].to_json), :system_token => "x" )
|
118
|
+
client.should_receive(:user).with("foo").and_return( Livefyre.client.user("foo") )
|
119
|
+
subject.stub(:client).and_return(client)
|
120
|
+
end
|
121
|
+
|
122
|
+
its(:owners) { should be_a Array }
|
123
|
+
|
124
|
+
its("owners.first") { should be_a Livefyre::User }
|
125
|
+
its("owners.first.id") { should == "foo" }
|
126
|
+
end
|
127
|
+
|
128
|
+
context "on failure" do
|
129
|
+
before do
|
130
|
+
client = double( :get => double(:success? => false, :body => ""), :system_token => "x" )
|
131
|
+
subject.stub(:client).and_return(client)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should raise an exception" do
|
135
|
+
expect { subject.owners }.to raise_error(Livefyre::APIException)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "#add_owner" do
|
141
|
+
context "on success" do
|
142
|
+
before do
|
143
|
+
client = double( :post => double(:success? => true), :system_token => "x", :host => "some_host", :key => "some_key" )
|
144
|
+
subject.stub(:client).and_return(client)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should return true" do
|
148
|
+
subject.add_owner("some ID").should be true
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context "on failure" do
|
153
|
+
before do
|
154
|
+
client = double( :post => double(:success? => false, :body => ""), :system_token => "x", :host => "some_host", :key => "some_key" )
|
155
|
+
subject.stub(:client).and_return(client)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should raise an exception" do
|
159
|
+
expect { subject.add_owner("some user ID") }.to raise_error(Livefyre::APIException)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "#remove_owner" do
|
165
|
+
context "on success" do
|
166
|
+
before do
|
167
|
+
client = double( :delete => double(:success? => true), :system_token => "x", :host => "some_host", :key => "some_key" )
|
168
|
+
subject.stub(:client).and_return(client)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should return true" do
|
172
|
+
subject.remove_owner("some ID").should be true
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "on failure" do
|
177
|
+
before do
|
178
|
+
client = double( :delete => double(:success? => false, :body => ""), :system_token => "x", :host => "some_host", :key => "some_key" )
|
179
|
+
subject.stub(:client).and_return(client)
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should raise an exception" do
|
183
|
+
expect { subject.remove_owner("some user ID") }.to raise_error(Livefyre::APIException)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
describe "#admins" do
|
190
|
+
context "on success" do
|
191
|
+
before do
|
192
|
+
client = double( :get => double(:success? => true, :body => ["foo@bar"].to_json), :system_token => "x" )
|
193
|
+
client.should_receive(:user).with("foo").and_return( Livefyre.client.user("foo") )
|
194
|
+
subject.stub(:client).and_return(client)
|
195
|
+
end
|
196
|
+
|
197
|
+
its(:admins) { should be_a Array }
|
198
|
+
|
199
|
+
its("admins.first") { should be_a Livefyre::User }
|
200
|
+
its("admins.first.id") { should == "foo" }
|
201
|
+
end
|
202
|
+
|
203
|
+
context "on failure" do
|
204
|
+
before do
|
205
|
+
client = double( :get => double(:success? => false, :body => ""), :system_token => "x" )
|
206
|
+
subject.stub(:client).and_return(client)
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should raise an exception" do
|
210
|
+
expect { subject.admins }.to raise_error(Livefyre::APIException)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "#add_admin" do
|
216
|
+
context "on success" do
|
217
|
+
before do
|
218
|
+
client = double( :post => double(:success? => true), :system_token => "x", :host => "some_host", :key => "some_key" )
|
219
|
+
subject.stub(:client).and_return(client)
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should return true" do
|
223
|
+
subject.add_admin("some ID").should be true
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context "on failure" do
|
228
|
+
before do
|
229
|
+
client = double( :post => double(:success? => false, :body => ""), :system_token => "x", :host => "some_host", :key => "some_key" )
|
230
|
+
subject.stub(:client).and_return(client)
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should raise an exception" do
|
234
|
+
expect { subject.add_admin("some user ID") }.to raise_error(Livefyre::APIException)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
describe "#remove_admin" do
|
240
|
+
context "on success" do
|
241
|
+
before do
|
242
|
+
client = double( :delete => double(:success? => true), :system_token => "x", :host => "some_host", :key => "some_key" )
|
243
|
+
subject.stub(:client).and_return(client)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should return true" do
|
247
|
+
subject.remove_admin("some ID").should be true
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
context "on failure" do
|
252
|
+
before do
|
253
|
+
client = double( :delete => double(:success? => false, :body => ""), :system_token => "x", :host => "some_host", :key => "some_key" )
|
254
|
+
subject.stub(:client).and_return(client)
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should raise an exception" do
|
258
|
+
expect { subject.remove_admin("some user ID") }.to raise_error(Livefyre::APIException)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe "#set_pull_url" do
|
264
|
+
context "when it succeeds" do
|
265
|
+
before do
|
266
|
+
response = double(:success? => true)
|
267
|
+
client = double(:post => response, :system_token => "x")
|
268
|
+
subject.stub(:client).and_return(client)
|
269
|
+
@response = subject.set_pull_url 'http://foo.bar/{id}/'
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should return true" do
|
273
|
+
@response.should == true
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
context "when it fails" do
|
278
|
+
before do
|
279
|
+
response = double(:success? => false, :body => "failure")
|
280
|
+
client = double(:post => response, :system_token => "x")
|
281
|
+
subject.stub(:client).and_return(client)
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should raise an exception" do
|
285
|
+
expect { subject.set_pull_url 'http://foo.bar/{id}/' }.to raise_error(Livefyre::APIException)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should have a valid string representation" do
|
291
|
+
subject.to_s.should match(/Livefyre::Domain.*host='#{subject.client.host}'/)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|