livefyre 0.0.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.
@@ -0,0 +1,211 @@
1
+ require 'spec_helper'
2
+
3
+ describe Livefyre::Site do
4
+ context "an instance" do
5
+ subject { Livefyre::Site.new("my.site") }
6
+
7
+ describe "#properties" do
8
+ context "on success" do
9
+ before do
10
+ body = {:id => "bar", :api_secret => "secret"}.to_json
11
+ client = double( :get => double(:success? => true, :body => body), :system_token => "x" )
12
+ subject.stub(:client).and_return(client)
13
+ subject.properties
14
+ end
15
+
16
+ its(:options) { should == {"id" => "bar", "api_secret" => "secret"} }
17
+ its(:secret) { should == "secret" }
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.properties }.to raise_error(Livefyre::APIException)
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "#set_postback_url" do
33
+ context "on success" do
34
+ before do
35
+ client = double( :post => double(:success? => true), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
36
+ subject.stub(:client).and_return(client)
37
+ end
38
+
39
+ it "should return true" do
40
+ subject.set_postback_url("http://foo.bar/").should be true
41
+ end
42
+ end
43
+
44
+ context "on failure" do
45
+ before do
46
+ response = double(:success? => false, :body => "")
47
+ client = double( :system_token => "x" )
48
+ client.should_receive(:post).with("/site/my.site/", {:actor_token => "x", :postback_url => "http://foo.bar/"}).and_return(response)
49
+ subject.stub(:client).and_return(client)
50
+ end
51
+
52
+ it "should raise an exception" do
53
+ expect { subject.set_postback_url("http://foo.bar/") }.to raise_error(Livefyre::APIException)
54
+ end
55
+ end
56
+ end
57
+
58
+
59
+ describe "#owners" do
60
+ context "on success" do
61
+ before do
62
+ client = double( :get => double(:success? => true, :body => ["foo@bar"].to_json), :system_token => "x" )
63
+ client.should_receive(:user).with("foo").and_return( Livefyre.client.user("foo") )
64
+ subject.stub(:client).and_return(client)
65
+ end
66
+
67
+ its(:owners) { should be_a Array }
68
+
69
+ its("owners.first") { should be_a Livefyre::User }
70
+ its("owners.first.id") { should == "foo" }
71
+ end
72
+
73
+ context "on failure" do
74
+ before do
75
+ client = double( :get => double(:success? => false, :body => ""), :system_token => "x" )
76
+ subject.stub(:client).and_return(client)
77
+ end
78
+
79
+ it "should raise an exception" do
80
+ expect { subject.owners }.to raise_error(Livefyre::APIException)
81
+ end
82
+ end
83
+ end
84
+
85
+ describe "#add_owner" do
86
+ context "on success" do
87
+ before do
88
+ client = double( :post => double(:success? => true), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
89
+ subject.stub(:client).and_return(client)
90
+ end
91
+
92
+ it "should return true" do
93
+ subject.add_owner("some ID").should be true
94
+ end
95
+ end
96
+
97
+ context "on failure" do
98
+ before do
99
+ client = double( :post => double(:success? => false, :body => ""), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
100
+ subject.stub(:client).and_return(client)
101
+ end
102
+
103
+ it "should raise an exception" do
104
+ expect { subject.add_owner("some user ID") }.to raise_error(Livefyre::APIException)
105
+ end
106
+ end
107
+ end
108
+
109
+ describe "#remove_owner" do
110
+ context "on success" do
111
+ before do
112
+ client = double( :delete => double(:success? => true), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
113
+ subject.stub(:client).and_return(client)
114
+ end
115
+
116
+ it "should return true" do
117
+ subject.remove_owner("some ID").should be true
118
+ end
119
+ end
120
+
121
+ context "on failure" do
122
+ before do
123
+ client = double( :delete => double(:success? => false, :body => ""), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
124
+ subject.stub(:client).and_return(client)
125
+ end
126
+
127
+ it "should raise an exception" do
128
+ expect { subject.remove_owner("some user ID") }.to raise_error(Livefyre::APIException)
129
+ end
130
+ end
131
+ end
132
+
133
+ describe "#admins" do
134
+ context "on success" do
135
+ before do
136
+ client = double( :get => double(:success? => true, :body => ["foo@bar"].to_json), :system_token => "x" )
137
+ client.should_receive(:user).with("foo").and_return( Livefyre.client.user("foo") )
138
+ subject.stub(:client).and_return(client)
139
+ end
140
+
141
+ its(:admins) { should be_a Array }
142
+
143
+ its("admins.first") { should be_a Livefyre::User }
144
+ its("admins.first.id") { should == "foo" }
145
+ end
146
+
147
+ context "on failure" do
148
+ before do
149
+ client = double( :get => double(:success? => false, :body => ""), :system_token => "x" )
150
+ subject.stub(:client).and_return(client)
151
+ end
152
+
153
+ it "should raise an exception" do
154
+ expect { subject.admins }.to raise_error(Livefyre::APIException)
155
+ end
156
+ end
157
+ end
158
+
159
+ describe "#add_admin" do
160
+ context "on success" do
161
+ before do
162
+ client = double( :post => double(:success? => true), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
163
+ subject.stub(:client).and_return(client)
164
+ end
165
+
166
+ it "should return true" do
167
+ subject.add_admin("some ID").should be true
168
+ end
169
+ end
170
+
171
+ context "on failure" do
172
+ before do
173
+ client = double( :post => double(:success? => false, :body => ""), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
174
+ subject.stub(:client).and_return(client)
175
+ end
176
+
177
+ it "should raise an exception" do
178
+ expect { subject.add_admin("some user ID") }.to raise_error(Livefyre::APIException)
179
+ end
180
+ end
181
+ end
182
+
183
+ describe "#remove_admin" do
184
+ context "on success" do
185
+ before do
186
+ client = double( :delete => double(:success? => true), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
187
+ subject.stub(:client).and_return(client)
188
+ end
189
+
190
+ it "should return true" do
191
+ subject.remove_admin("some ID").should be true
192
+ end
193
+ end
194
+
195
+ context "on failure" do
196
+ before do
197
+ client = double( :delete => double(:success? => false, :body => ""), :system_token => "x", :host => "some_host", :key => "some_key", :jid => "foo@bar.com" )
198
+ subject.stub(:client).and_return(client)
199
+ end
200
+
201
+ it "should raise an exception" do
202
+ expect { subject.remove_admin("some user ID") }.to raise_error(Livefyre::APIException)
203
+ end
204
+ end
205
+ end
206
+
207
+ it "should have a valid string representation" do
208
+ subject.to_s.should match(/Livefyre::Site.*id='#{subject.id}'/)
209
+ end
210
+ end
211
+ end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+
3
+ describe Livefyre::User do
4
+ describe "#initialize" do
5
+ context "when no client is passed" do
6
+ it "should use the default client" do
7
+ Livefyre::User.new(123).client.should eql(Livefyre.client)
8
+ end
9
+ end
10
+
11
+ context "when a client is passed" do
12
+ it "should use the passed client" do
13
+ client = Livefyre::Client.new(:host => "x", :key => "x", :system_token => "x")
14
+ Livefyre::User.new(123, client).tap do |user|
15
+ user.client.should eql client
16
+ user.client.should_not eql Livefyre.client
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "::get_user_id" do
23
+ it "should return an ID when passed a string" do
24
+ Livefyre::User.get_user_id("foobar").should == "foobar"
25
+ end
26
+
27
+ it "should return an ID when passed a User" do
28
+ Livefyre::User.get_user_id( Livefyre::User.new("foobar") ).should == "foobar"
29
+ end
30
+
31
+ it "should return an ID when passed an integer" do
32
+ Livefyre::User.get_user_id(123).should == 123
33
+ end
34
+
35
+ it "should raise an exception when passed an invalid value" do
36
+ expect { Livefyre::User.get_user_id(nil) }.to raise_error("Invalid user ID")
37
+ end
38
+ end
39
+
40
+ describe "::get_user" do
41
+ context "should return a user when passed a user ID" do
42
+ subject { Livefyre::User.get_user("foobar", Livefyre.client) }
43
+ it { should be_a Livefyre::User }
44
+ its(:id) { should == "foobar" }
45
+ its(:client) { should == Livefyre.client }
46
+ end
47
+
48
+ context "should return a user when passed a User object" do
49
+ subject { Livefyre::User.get_user( Livefyre::User.new("123", Object.new) , Livefyre.client) }
50
+ it { should be_a Livefyre::User }
51
+ its(:id) { should == "123" }
52
+ its(:client) { should == Livefyre.client }
53
+ end
54
+
55
+ it "should raise an exception when passed an invalid value" do
56
+ expect { Livefyre::User.get_user( nil , Livefyre.client ) }.to raise_error("Invalid user ID")
57
+ end
58
+ end
59
+
60
+ context "an instance" do
61
+ subject { Livefyre::User.new(123) }
62
+
63
+ its(:jid) { should == "123@foo.bar" }
64
+ its(:token) { should be_a String }
65
+
66
+ it "should decode a token" do
67
+ subject.client.validate(subject.token)["domain"].should == subject.client.host
68
+ end
69
+
70
+ context "#push" do
71
+ context "on success" do
72
+ before do
73
+ client = double("client")
74
+ client
75
+ .should_receive(:post)
76
+ .with("/profiles/?actor_token=#{subject.client.system_token}&id=#{subject.id}", {:data => {:some => "data"}.to_json})
77
+ .and_return(double(:success? => true))
78
+ subject.client.stub(:http_client).and_return(client)
79
+ end
80
+
81
+ it "returns true" do
82
+ subject.push(:some => "data").should == true
83
+ end
84
+ end
85
+
86
+ context "on failure" do
87
+ before do
88
+ client = double("client")
89
+ client
90
+ .should_receive(:post)
91
+ .with("/profiles/?actor_token=#{subject.client.system_token}&id=#{subject.id}", {:data => {:some => "data"}.to_json})
92
+ .and_return(double(:success? => false, :body => "error"))
93
+ subject.client.stub(:http_client).and_return(client)
94
+ end
95
+
96
+ it "raises an APIException" do
97
+ expect { subject.push(:some => "data") }.to raise_error(Livefyre::APIException)
98
+ end
99
+ end
100
+ end
101
+
102
+ context "#refresh" do
103
+ let(:client) { double("client") }
104
+
105
+ it "should post to the ping-to-pull endpoint" do
106
+ subject.client.should_receive(:post).with("/api/v3_0/user/#{subject.id}/refresh", {:lftoken => subject.client.system_token})
107
+ .and_return( double(:success? => true) )
108
+ subject.refresh.should == true
109
+ end
110
+
111
+ it "should raise an exception when it fails to post to the ping-to-pull endpoint" do
112
+ subject.client.should_receive(:post).with("/api/v3_0/user/#{subject.id}/refresh", {:lftoken => subject.client.system_token})
113
+ .and_return( double(:success? => false, :body => "Temporal failure in the primary quantum induction matrix") )
114
+ expect { subject.refresh.should }.to raise_error(Livefyre::APIException)
115
+ end
116
+ end
117
+
118
+ it "should have a valid string representation" do
119
+ subject.to_s.should match(/Livefyre::User.*id='#{subject.id}'/)
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ begin
5
+ require 'rails'
6
+ require 'resque'
7
+ rescue LoadError
8
+ end
9
+
10
+ if ENV['COVERAGE']
11
+ require 'simplecov'
12
+ if ENV['RCOV']
13
+ require 'simplecov-rcov'
14
+ SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
15
+ end
16
+ SimpleCov.start do
17
+ add_group 'Gem', 'lib'
18
+ add_filter "spec"
19
+ end
20
+ end
21
+
22
+ require 'livefyre'
23
+ Livefyre.config = {:host => "foo.bar", :key => "x", :system_token => "x"}
24
+
25
+ RSpec.configure do |config|
26
+ end
metadata ADDED
@@ -0,0 +1,196 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: livefyre
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mashable
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: jwt
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov-rcov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rails
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: resque
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Interface library for Livefyre's comment API with Rails helpers
127
+ email:
128
+ - cheald@mashable.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - Gemfile
135
+ - LICENSE
136
+ - README.md
137
+ - Rakefile
138
+ - app/assets/javascripts/livefyre.js.coffee
139
+ - app/assets/javascripts/livefyre.js.js
140
+ - lib/livefyre.rb
141
+ - lib/livefyre/client.rb
142
+ - lib/livefyre/controller_extensions.rb
143
+ - lib/livefyre/domain.rb
144
+ - lib/livefyre/engine.rb
145
+ - lib/livefyre/helpers.rb
146
+ - lib/livefyre/model_extensions.rb
147
+ - lib/livefyre/site.rb
148
+ - lib/livefyre/user.rb
149
+ - lib/livefyre/version.rb
150
+ - livefyre.gemspec
151
+ - railties/railtie.rb
152
+ - spec/livefyre/client_spec.rb
153
+ - spec/livefyre/domain_spec.rb
154
+ - spec/livefyre/livefyre_spec.rb
155
+ - spec/livefyre/model_spec.rb
156
+ - spec/livefyre/site_spec.rb
157
+ - spec/livefyre/user_spec.rb
158
+ - spec/spec_helper.rb
159
+ homepage: http://github.com/mashable/livefyre
160
+ licenses: []
161
+ post_install_message:
162
+ rdoc_options: []
163
+ require_paths:
164
+ - lib
165
+ required_ruby_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ! '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ segments:
172
+ - 0
173
+ hash: -772164143543349371
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ none: false
176
+ requirements:
177
+ - - ! '>='
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ segments:
181
+ - 0
182
+ hash: -772164143543349371
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 1.8.24
186
+ signing_key:
187
+ specification_version: 3
188
+ summary: Interface library for Livefyre's comment API with Rails helpers
189
+ test_files:
190
+ - spec/livefyre/client_spec.rb
191
+ - spec/livefyre/domain_spec.rb
192
+ - spec/livefyre/livefyre_spec.rb
193
+ - spec/livefyre/model_spec.rb
194
+ - spec/livefyre/site_spec.rb
195
+ - spec/livefyre/user_spec.rb
196
+ - spec/spec_helper.rb