socialcastr 0.0.1 → 0.1.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.
- data/.gitignore +1 -0
- data/README.markdown +29 -6
- data/examples/parse_messages.rb +16 -0
- data/examples/post_comment.rb +11 -0
- data/examples/post_message.rb +15 -0
- data/examples/search.rb +19 -0
- data/lib/socialcastr/api.rb +70 -78
- data/lib/socialcastr/base.rb +151 -0
- data/lib/socialcastr/collection.rb +30 -0
- data/lib/socialcastr/comment.rb +2 -2
- data/lib/socialcastr/exceptions.rb +75 -0
- data/lib/socialcastr/external_resource.rb +2 -2
- data/lib/socialcastr/flag.rb +5 -0
- data/lib/socialcastr/like.rb +1 -1
- data/lib/socialcastr/message.rb +45 -11
- data/lib/socialcastr/version.rb +2 -2
- data/lib/socialcastr.rb +19 -11
- data/socialcastr.gemspec +2 -0
- data/spec/api_spec.rb +167 -0
- data/spec/base_spec.rb +235 -0
- data/spec/comment_spec.rb +4 -0
- data/spec/configuration_spec.rb +97 -0
- data/spec/fixtures/demo_config.yml +3 -0
- data/spec/fixtures/message.xml +69 -0
- data/spec/fixtures/messages.xml +3338 -0
- data/spec/message_spec.rb +173 -0
- data/spec/socialcastr_spec.rb +58 -0
- data/spec/spec_helper.rb +54 -0
- metadata +62 -19
- data/lib/socialcastr/attachment_list.rb +0 -5
- data/lib/socialcastr/comment_list.rb +0 -5
- data/lib/socialcastr/external_resource_list.rb +0 -5
- data/lib/socialcastr/group_list.rb +0 -5
- data/lib/socialcastr/group_membership_list.rb +0 -5
- data/lib/socialcastr/like_list.rb +0 -5
- data/lib/socialcastr/media_file_list.rb +0 -5
- data/lib/socialcastr/message_list.rb +0 -5
- data/lib/socialcastr/recipient_list.rb +0 -6
- data/lib/socialcastr/stream_list.rb +0 -5
- data/lib/socialcastr/tag_list.rb +0 -5
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialcastr::Message do
|
4
|
+
context "fetching a specific message from socialcast" do
|
5
|
+
before :all do
|
6
|
+
fake_socialcast_api_for(:message) do
|
7
|
+
@message = Socialcastr::Message.find(425)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return a Message object" do
|
12
|
+
@message.class.should == Socialcastr::Message
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have a proper title" do
|
16
|
+
@message.title.should == "trying out the api"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have an id" do
|
20
|
+
@message.id.should_not be_nil
|
21
|
+
@message.id.should == 425
|
22
|
+
end
|
23
|
+
it "should have a body" do
|
24
|
+
@message.body.should_not be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should have a user" do
|
28
|
+
@message.user.should_not be_nil
|
29
|
+
@message.user.class.should == Socialcastr::User
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have a collection of groups" do
|
33
|
+
@message.groups.class.should == Array
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should belong to a well formed group" do
|
37
|
+
@message.groups.first.class.should == Socialcastr::Group
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have a source" do
|
41
|
+
@message.source.should_not be_nil
|
42
|
+
@message.source.class.should == Socialcastr::Source
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
context "fetching a page's worth of messages" do
|
48
|
+
before :each do
|
49
|
+
fake_socialcast_api_for(:messages) do
|
50
|
+
@messages = Socialcastr::Message.all
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should be an instance of MessageList" do
|
55
|
+
@messages.class.should == MessageList
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should be a collection of 20 Socialcastr::Message objects" do
|
59
|
+
@messages.size.should == 20
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should be possible to fetch the first item" do
|
63
|
+
@messages.first.should_not be_nil
|
64
|
+
@messages.first.class.should == Socialcastr::Message
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should contain well formed Message objects" do
|
68
|
+
@messages.first.title.should == "trying out the api"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'flagging a message' do
|
73
|
+
before :each do
|
74
|
+
fake_socialcast_api_for(:message) do
|
75
|
+
@message = Socialcastr::Message.find(425)
|
76
|
+
end
|
77
|
+
@api = mock(:api)
|
78
|
+
response = "<flag><id>3333</id></flag>"
|
79
|
+
Socialcastr::Message.stub!(:api).and_return(@api)
|
80
|
+
@api.stub!(:post).and_return(response)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should assign an id to the Flag" do
|
84
|
+
@message.flag!
|
85
|
+
@message.flag.id.should == 3333
|
86
|
+
end
|
87
|
+
|
88
|
+
context "unflagging the message" do
|
89
|
+
before :each do
|
90
|
+
@message.flag!
|
91
|
+
@api.should_receive(:delete).with("/messages/425/flags/3333").and_return("")
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should not have a flag afterwards" do
|
95
|
+
@message.unflag!
|
96
|
+
@message.flag.id.should be_nil
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'liking a message' do
|
102
|
+
before :each do
|
103
|
+
fake_socialcast_api_for :message do
|
104
|
+
@message = Socialcastr::Message.find(425)
|
105
|
+
end
|
106
|
+
|
107
|
+
@api = mock(:api)
|
108
|
+
response = "<like><id>2222</id><unlikable>true</unlikable></like>"
|
109
|
+
Socialcastr::Message.stub!(:api).and_return(@api)
|
110
|
+
@api.stub!(:post).and_return(response)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should create a new like' do
|
114
|
+
old_count = @message.likes.count
|
115
|
+
@message.like!
|
116
|
+
@message.likes.count.should == old_count + 1
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should assign an id the the new like' do
|
120
|
+
@message.like!
|
121
|
+
@message.likes.last.id.should == 2222
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "unliking a message" do
|
126
|
+
before :each do
|
127
|
+
fake_socialcast_api_for :message do
|
128
|
+
@message = Socialcastr::Message.find(425)
|
129
|
+
end
|
130
|
+
|
131
|
+
@api = mock(:api)
|
132
|
+
response = "<like><id>2222</id><unlikable>true</unlikable></like>"
|
133
|
+
Socialcastr::Message.stub!(:api).and_return(@api)
|
134
|
+
@api.stub!(:post).and_return(response)
|
135
|
+
@api.stub!(:delete).and_return("")
|
136
|
+
@message.like!
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should remove a like" do
|
140
|
+
old_count = @message.likes.count
|
141
|
+
@message.unlike!
|
142
|
+
@message.likes.count.should == old_count -1
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context "searching for messages matching 'trying'" do
|
147
|
+
before :each do
|
148
|
+
fake_socialcast_api_for :message
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should return a message" do
|
152
|
+
@messages = Socialcastr::Message.search(:q=>"trying")
|
153
|
+
@messages.size.should == 1
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "commenting a message" do
|
158
|
+
before :each do
|
159
|
+
fake_socialcast_api_for :message do
|
160
|
+
@message = Socialcastr::Message.find(425)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should post to messages/425/comments.xml" do
|
165
|
+
@api = mock(:api)
|
166
|
+
response = "<comment></comment>"
|
167
|
+
Socialcastr::Message.stub!(:api).and_return(@api)
|
168
|
+
@api.should_receive(:post).with("/messages/425/comments", {:text => "hallo world"}).and_return(response)
|
169
|
+
@message.comment! :text => "hallo world"
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialcastr do
|
4
|
+
context 'configuration' do
|
5
|
+
context 'called without a block' do
|
6
|
+
before :each do
|
7
|
+
@config = Socialcastr.configuration
|
8
|
+
end
|
9
|
+
it 'should return a Socialcastr::Configuration instance' do
|
10
|
+
@config.class.should == Socialcastr::Configuration
|
11
|
+
end
|
12
|
+
end
|
13
|
+
context 'called with a block' do
|
14
|
+
before :each do
|
15
|
+
@called = nil
|
16
|
+
Socialcastr.configuration do |config|
|
17
|
+
@called = config
|
18
|
+
end
|
19
|
+
end
|
20
|
+
it 'should call the block' do
|
21
|
+
@called.should_not be_nil
|
22
|
+
end
|
23
|
+
it 'should pass a configuration instance to the block' do
|
24
|
+
@called.equal?(Socialcastr::Configuration.instance).should be_true
|
25
|
+
end
|
26
|
+
context 'pointing to a yaml ile' do
|
27
|
+
before :each do
|
28
|
+
Socialcastr.configuration do |config|
|
29
|
+
config.config_file = File.join(File.dirname(__FILE__), 'fixtures', 'demo_config.yml')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should load the configuration attributes from the file' do
|
34
|
+
Socialcastr.configuration.username.should == "file_demo"
|
35
|
+
Socialcastr.configuration.password.should == "password"
|
36
|
+
Socialcastr.configuration.domain.should == "demo.socialcast.com"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'api' do
|
43
|
+
context 'called without having configured Socialcastr' do
|
44
|
+
it 'should raise an error' do
|
45
|
+
lambda { Socialcastr.api }.should raise_error
|
46
|
+
end
|
47
|
+
end
|
48
|
+
context 'called after configuring Socialcastr' do
|
49
|
+
before :each do
|
50
|
+
configure_socialcastr
|
51
|
+
@api = Socialcastr.api
|
52
|
+
end
|
53
|
+
it 'should return a new Socialcastr::API instance' do
|
54
|
+
@api.class.should == Socialcastr::API
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
|
+
Bundler.setup
|
4
|
+
|
5
|
+
require 'rspec'
|
6
|
+
require 'artifice'
|
7
|
+
|
8
|
+
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
9
|
+
require 'socialcastr'
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.before :each do
|
13
|
+
Socialcastr.configuration.reset
|
14
|
+
end
|
15
|
+
end
|
16
|
+
def generate_fake_endpoint(response, code=200)
|
17
|
+
return proc { |env|
|
18
|
+
[code, {"Content-Type" => "text/html",
|
19
|
+
"X-Test-Method" => env["REQUEST_METHOD"],
|
20
|
+
"X-Test-Input" => env["rack.input"].read,
|
21
|
+
"X-Test-Scheme" => env["rack.url_scheme"],
|
22
|
+
"X-Test-Host" => env["HTTP_HOST"] || env["SERVER_NAME"],
|
23
|
+
"X-Test-Port" => env["SERVER_PORT"]},
|
24
|
+
[response]
|
25
|
+
]
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def configure_socialcastr
|
30
|
+
Socialcastr.configuration do |c|
|
31
|
+
c.username = "demo"
|
32
|
+
c.password = "password"
|
33
|
+
c.domain = "demo.socialcast.com"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def fake_socialcast_api_for(type, &block)
|
38
|
+
configure_socialcastr
|
39
|
+
case type
|
40
|
+
when :message
|
41
|
+
responsefile = "message.xml"
|
42
|
+
when :messages
|
43
|
+
responsefile = "messages.xml"
|
44
|
+
end
|
45
|
+
response = File.read(File.join(File.dirname(__FILE__), 'fixtures', responsefile))
|
46
|
+
endpoint = generate_fake_endpoint(response)
|
47
|
+
if block
|
48
|
+
Artifice.activate_with(generate_fake_endpoint(response)) do
|
49
|
+
block.call
|
50
|
+
end
|
51
|
+
else
|
52
|
+
Artifice.activate_with(generate_fake_endpoint(response))
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: socialcastr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Riccardo Cambiassi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-10 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
type: :development
|
50
50
|
version_requirements: *id002
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
|
-
name:
|
52
|
+
name: yard
|
53
53
|
prerelease: false
|
54
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
55
|
none: false
|
@@ -60,8 +60,36 @@ dependencies:
|
|
60
60
|
segments:
|
61
61
|
- 0
|
62
62
|
version: "0"
|
63
|
-
type: :
|
63
|
+
type: :development
|
64
64
|
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: artifice
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
type: :development
|
78
|
+
version_requirements: *id004
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: sax-machine
|
81
|
+
prerelease: false
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
type: :runtime
|
92
|
+
version_requirements: *id005
|
65
93
|
description: A Ruby wrapper for the Socialcast REST API
|
66
94
|
email:
|
67
95
|
- bru@codewitch.org
|
@@ -77,37 +105,43 @@ files:
|
|
77
105
|
- LICENSE.markdown
|
78
106
|
- README.markdown
|
79
107
|
- Rakefile
|
108
|
+
- examples/parse_messages.rb
|
109
|
+
- examples/post_comment.rb
|
110
|
+
- examples/post_message.rb
|
111
|
+
- examples/search.rb
|
80
112
|
- lib/socialcastr.rb
|
81
113
|
- lib/socialcastr/api.rb
|
82
114
|
- lib/socialcastr/attachment.rb
|
83
|
-
- lib/socialcastr/attachment_list.rb
|
84
115
|
- lib/socialcastr/avatar_list.rb
|
85
116
|
- lib/socialcastr/base.rb
|
117
|
+
- lib/socialcastr/collection.rb
|
86
118
|
- lib/socialcastr/comment.rb
|
87
|
-
- lib/socialcastr/
|
119
|
+
- lib/socialcastr/exceptions.rb
|
88
120
|
- lib/socialcastr/external_resource.rb
|
89
|
-
- lib/socialcastr/
|
121
|
+
- lib/socialcastr/flag.rb
|
90
122
|
- lib/socialcastr/group.rb
|
91
|
-
- lib/socialcastr/group_list.rb
|
92
123
|
- lib/socialcastr/group_membership.rb
|
93
|
-
- lib/socialcastr/group_membership_list.rb
|
94
124
|
- lib/socialcastr/like.rb
|
95
|
-
- lib/socialcastr/like_list.rb
|
96
125
|
- lib/socialcastr/media_file.rb
|
97
|
-
- lib/socialcastr/media_file_list.rb
|
98
126
|
- lib/socialcastr/message.rb
|
99
|
-
- lib/socialcastr/message_list.rb
|
100
127
|
- lib/socialcastr/recipient.rb
|
101
|
-
- lib/socialcastr/recipient_list.rb
|
102
128
|
- lib/socialcastr/source.rb
|
103
129
|
- lib/socialcastr/stream.rb
|
104
|
-
- lib/socialcastr/stream_list.rb
|
105
130
|
- lib/socialcastr/tag.rb
|
106
|
-
- lib/socialcastr/tag_list.rb
|
107
131
|
- lib/socialcastr/thumbnail_list.rb
|
108
132
|
- lib/socialcastr/user.rb
|
109
133
|
- lib/socialcastr/version.rb
|
110
134
|
- socialcastr.gemspec
|
135
|
+
- spec/api_spec.rb
|
136
|
+
- spec/base_spec.rb
|
137
|
+
- spec/comment_spec.rb
|
138
|
+
- spec/configuration_spec.rb
|
139
|
+
- spec/fixtures/demo_config.yml
|
140
|
+
- spec/fixtures/message.xml
|
141
|
+
- spec/fixtures/messages.xml
|
142
|
+
- spec/message_spec.rb
|
143
|
+
- spec/socialcastr_spec.rb
|
144
|
+
- spec/spec_helper.rb
|
111
145
|
has_rdoc: true
|
112
146
|
homepage: https://github.com/bru/socialcastr
|
113
147
|
licenses: []
|
@@ -153,5 +187,14 @@ rubygems_version: 1.5.3
|
|
153
187
|
signing_key:
|
154
188
|
specification_version: 3
|
155
189
|
summary: Ruby wrapper for the Socialcast API
|
156
|
-
test_files:
|
157
|
-
|
190
|
+
test_files:
|
191
|
+
- spec/api_spec.rb
|
192
|
+
- spec/base_spec.rb
|
193
|
+
- spec/comment_spec.rb
|
194
|
+
- spec/configuration_spec.rb
|
195
|
+
- spec/fixtures/demo_config.yml
|
196
|
+
- spec/fixtures/message.xml
|
197
|
+
- spec/fixtures/messages.xml
|
198
|
+
- spec/message_spec.rb
|
199
|
+
- spec/socialcastr_spec.rb
|
200
|
+
- spec/spec_helper.rb
|