kippt 2.0.1 → 3.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 +15 -0
- data/.travis.yml +1 -4
- data/CHANGELOG.md +24 -0
- data/Gemfile +4 -0
- data/README.md +14 -4
- data/TODO.md +16 -0
- data/lib/kippt.rb +8 -3
- data/lib/kippt/client.rb +6 -6
- data/lib/kippt/clip.rb +17 -9
- data/lib/kippt/clip_collection.rb +2 -2
- data/lib/kippt/clip_likes.rb +29 -0
- data/lib/kippt/clips.rb +8 -37
- data/lib/kippt/collection.rb +1 -2
- data/lib/kippt/collection_resource.rb +39 -55
- data/lib/kippt/comment.rb +2 -4
- data/lib/kippt/comment_collection.rb +1 -2
- data/lib/kippt/comments.rb +5 -3
- data/lib/kippt/connection.rb +7 -3
- data/lib/kippt/favorite.rb +46 -0
- data/lib/kippt/favorites.rb +20 -0
- data/lib/kippt/followers.rb +6 -4
- data/lib/kippt/following.rb +6 -4
- data/lib/kippt/helpers.rb +17 -0
- data/lib/kippt/like.rb +4 -6
- data/lib/kippt/like_collection.rb +11 -0
- data/lib/kippt/likes.rb +2 -30
- data/lib/kippt/list.rb +8 -2
- data/lib/kippt/list_collection.rb +2 -2
- data/lib/kippt/lists.rb +2 -4
- data/lib/kippt/read_collection_resource.rb +43 -0
- data/lib/kippt/root_clips.rb +39 -0
- data/lib/kippt/saves.rb +4 -3
- data/lib/kippt/user.rb +10 -6
- data/lib/kippt/user_clips.rb +6 -26
- data/lib/kippt/user_collection.rb +0 -3
- data/lib/kippt/user_likes.rb +29 -0
- data/lib/kippt/user_lists.rb +0 -5
- data/lib/kippt/users.rb +3 -8
- data/lib/kippt/version.rb +1 -1
- data/spec/kippt/client_spec.rb +36 -2
- data/spec/kippt/clip_likes_spec.rb +14 -0
- data/spec/kippt/clip_spec.rb +89 -3
- data/spec/kippt/clips_spec.rb +27 -5
- data/spec/kippt/comment_spec.rb +1 -1
- data/spec/kippt/comments_spec.rb +30 -5
- data/spec/kippt/favorite_spec.rb +38 -0
- data/spec/kippt/favorites_spec.rb +18 -0
- data/spec/kippt/follow_relationship_spec.rb +30 -0
- data/spec/kippt/followers_spec.rb +6 -9
- data/spec/kippt/following_spec.rb +6 -9
- data/spec/kippt/like_spec.rb +38 -0
- data/spec/kippt/likes_spec.rb +21 -0
- data/spec/kippt/list_spec.rb +43 -10
- data/spec/kippt/lists_spec.rb +12 -0
- data/spec/kippt/saves_spec.rb +3 -3
- data/spec/kippt/user_clips_spec.rb +14 -2
- data/spec/kippt/user_likes_spec.rb +14 -0
- data/spec/kippt/user_lists_spec.rb +12 -0
- data/spec/kippt/user_spec.rb +11 -0
- data/spec/kippt/users_spec.rb +2 -1
- data/spec/shared_examples/collection.rb +117 -0
- data/spec/shared_examples/collection_resource.rb +13 -0
- data/spec/shared_examples/read_collection_resource.rb +77 -0
- data/spec/shared_examples/resource.rb +80 -0
- data/spec/spec_helper.rb +2 -298
- metadata +33 -26
- data/lib/core_ext/open_struct.rb +0 -5
data/lib/kippt/user_clips.rb
CHANGED
@@ -1,39 +1,19 @@
|
|
1
|
-
|
2
|
-
require "kippt/collection_resource"
|
3
|
-
require "kippt/clip_collection"
|
4
|
-
require "kippt/clip"
|
5
|
-
|
6
|
-
class Kippt::UserClips
|
7
|
-
include Kippt::CollectionResource
|
1
|
+
require_relative "clips"
|
8
2
|
|
3
|
+
class Kippt::UserClips < Kippt::Clips
|
9
4
|
attr_reader :user
|
10
5
|
|
11
|
-
def self.valid_filter_parameters
|
12
|
-
[:limit, :offset]
|
13
|
-
end
|
14
|
-
|
15
6
|
def initialize(client, user)
|
16
|
-
@
|
17
|
-
@user = user
|
18
|
-
end
|
19
|
-
|
20
|
-
def object_class
|
21
|
-
Kippt::Clip
|
22
|
-
end
|
23
|
-
|
24
|
-
def collection_class
|
25
|
-
Kippt::ClipCollection
|
26
|
-
end
|
7
|
+
@user = user
|
27
8
|
|
28
|
-
|
29
|
-
"users/#{user.id}/clips"
|
9
|
+
super(client, "users/#{user.id}/clips")
|
30
10
|
end
|
31
11
|
|
32
12
|
def favorites
|
33
|
-
Kippt::
|
13
|
+
Kippt::Clips.new(client, "#{base_uri}/favorites")
|
34
14
|
end
|
35
15
|
|
36
16
|
def likes
|
37
|
-
Kippt::
|
17
|
+
Kippt::Clips.new(client, "#{base_uri}/likes")
|
38
18
|
end
|
39
19
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative "read_collection_resource"
|
2
|
+
|
3
|
+
# For fetching user's public likes.
|
4
|
+
class Kippt::UserLikes
|
5
|
+
include Kippt::ReadCollectionResource
|
6
|
+
|
7
|
+
attr_reader :user
|
8
|
+
|
9
|
+
def initialize(client, user)
|
10
|
+
@client = client
|
11
|
+
@user = user
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.valid_filter_parameters
|
15
|
+
[:limit, :offset, :include_data]
|
16
|
+
end
|
17
|
+
|
18
|
+
def object_class
|
19
|
+
Kippt::Clip
|
20
|
+
end
|
21
|
+
|
22
|
+
def collection_class
|
23
|
+
Kippt::ClipCollection
|
24
|
+
end
|
25
|
+
|
26
|
+
def base_uri
|
27
|
+
"users/#{user.id}/clips/likes"
|
28
|
+
end
|
29
|
+
end
|
data/lib/kippt/user_lists.rb
CHANGED
data/lib/kippt/users.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
|
2
|
-
require "kippt/collection_resource"
|
3
|
-
require "kippt/user_collection"
|
4
|
-
require "kippt/user"
|
1
|
+
require_relative "user_collection"
|
5
2
|
|
6
3
|
class Kippt::Users
|
7
|
-
include Kippt::
|
4
|
+
include Kippt::ReadCollectionResource
|
8
5
|
VALID_SEARCH_PARAMETERS = [:q]
|
9
6
|
|
10
7
|
def initialize(client)
|
@@ -29,9 +26,7 @@ class Kippt::Users
|
|
29
26
|
|
30
27
|
def search(parameters)
|
31
28
|
if parameters.is_a?(String)
|
32
|
-
|
33
|
-
client.get("#{base_uri}/search", {:q => parameters}).body,
|
34
|
-
client)
|
29
|
+
search({:q => parameters})
|
35
30
|
else
|
36
31
|
validate_search_parameters(parameters)
|
37
32
|
|
data/lib/kippt/version.rb
CHANGED
data/spec/kippt/client_spec.rb
CHANGED
@@ -67,6 +67,17 @@ describe Kippt::Client do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
70
|
+
|
71
|
+
context "when response status is 500" do
|
72
|
+
it "raises Kippt::APIError with unknown response text" do
|
73
|
+
stub_request(:get, "https://bob:secret@kippt.com/error_path").
|
74
|
+
to_return(:status => 500, :body => "500 Everything is broken")
|
75
|
+
|
76
|
+
expect {
|
77
|
+
subject.get("/error_path")
|
78
|
+
}.to raise_error(Kippt::APIError, "Unknown response from Kippt: 500 Everything is broken")
|
79
|
+
end
|
80
|
+
end
|
70
81
|
end
|
71
82
|
|
72
83
|
describe "#account" do
|
@@ -79,6 +90,15 @@ describe Kippt::Client do
|
|
79
90
|
account = subject.account
|
80
91
|
account.should be_a(Kippt::User)
|
81
92
|
end
|
93
|
+
|
94
|
+
context "when asked for api token" do
|
95
|
+
it "asks for the token from the server" do
|
96
|
+
subject.should_receive(:get).with("account?include_data=api_token").and_return(
|
97
|
+
stub :body => {}
|
98
|
+
)
|
99
|
+
account = subject.account(true)
|
100
|
+
end
|
101
|
+
end
|
82
102
|
end
|
83
103
|
|
84
104
|
describe "#lists" do
|
@@ -93,9 +113,9 @@ describe Kippt::Client do
|
|
93
113
|
describe "#clips" do
|
94
114
|
subject { Kippt::Client.new(:username => "bob", :password => "secret") }
|
95
115
|
|
96
|
-
it "returns a Kippt::
|
116
|
+
it "returns a Kippt::RootClips instance" do
|
97
117
|
clips = subject.clips
|
98
|
-
clips.should be_a(Kippt::
|
118
|
+
clips.should be_a(Kippt::RootClips)
|
99
119
|
end
|
100
120
|
end
|
101
121
|
|
@@ -108,6 +128,20 @@ describe Kippt::Client do
|
|
108
128
|
end
|
109
129
|
end
|
110
130
|
|
131
|
+
describe "#collection_resource_for" do
|
132
|
+
subject { Kippt::Client.new(valid_user_credentials) }
|
133
|
+
|
134
|
+
it "returns instance of the resource class" do
|
135
|
+
subject.collection_resource_for(Kippt::Clip, {}).should be_a(Kippt::Clip)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "passes itself and the passed arguments as parameters" do
|
139
|
+
resource_class = double :resource
|
140
|
+
resource_class.should_receive(:new).with(:option1, :option2, subject)
|
141
|
+
subject.collection_resource_for(resource_class, :option1, :option2)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
111
145
|
describe "#resource_from_url" do
|
112
146
|
subject { Kippt::Client.new(valid_user_credentials) }
|
113
147
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "kippt/clip_likes"
|
3
|
+
|
4
|
+
describe Kippt::ClipLikes do
|
5
|
+
let(:client) { Kippt::Client.new(valid_user_credentials) }
|
6
|
+
subject { Kippt::Clip.new({:id => 10}, client).likes }
|
7
|
+
let(:base_uri) { "clips/10/likes" }
|
8
|
+
let(:singular_fixture) { "user" }
|
9
|
+
let(:collection_fixture) { "users" }
|
10
|
+
let(:collection_class) { Kippt::UserCollection }
|
11
|
+
let(:resource_class) { Kippt::User }
|
12
|
+
|
13
|
+
it_behaves_like "read collection resource"
|
14
|
+
end
|
data/spec/kippt/clip_spec.rb
CHANGED
@@ -92,17 +92,83 @@ describe Kippt::Clip do
|
|
92
92
|
"count" => 2, "data" => [{}]
|
93
93
|
}} }
|
94
94
|
|
95
|
-
it "returns
|
95
|
+
it "returns false" do
|
96
96
|
subject.all_comments_embedded?.should be_false
|
97
97
|
end
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
+
describe "#likes" do
|
102
|
+
it "returns Kippt::ClipLikes" do
|
103
|
+
subject.likes.should be_a Kippt::ClipLikes
|
104
|
+
end
|
105
|
+
|
106
|
+
it "returns object where clip is set" do
|
107
|
+
subject.likes.clip.should eq subject
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#all_likes_embedded?" do
|
112
|
+
context "when like count and number of like objects matches" do
|
113
|
+
let(:data) { {"likes" => {
|
114
|
+
"count" => 2, "data" => [{}, {}]
|
115
|
+
}} }
|
116
|
+
|
117
|
+
it "returns true" do
|
118
|
+
subject.all_likes_embedded?.should be_true
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "when like count and number of like objects doesn't match" do
|
123
|
+
let(:data) { {"likes" => {
|
124
|
+
"count" => 2, "data" => [{}]
|
125
|
+
}} }
|
126
|
+
|
127
|
+
it "returns false" do
|
128
|
+
subject.all_likes_embedded?.should be_false
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "#likes_count" do
|
134
|
+
it "returns the likes count from the response" do
|
135
|
+
subject.likes_count.should eq 0
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "#likes_data" do
|
140
|
+
it "returns the likes data from the response" do
|
141
|
+
subject.likes_data.should eq []
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "#saves" do
|
146
|
+
it "returns Kippt::Saves" do
|
147
|
+
subject.saves.should be_a Kippt::Saves
|
148
|
+
end
|
149
|
+
|
150
|
+
it "returns object where clip is set" do
|
151
|
+
subject.saves.clip.should eq subject
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe "#saves_count" do
|
156
|
+
it "returns the saves count from the response" do
|
157
|
+
subject.saves_count.should eq 0
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "#saves_data" do
|
162
|
+
it "returns the saves data from the response" do
|
163
|
+
subject.saves_data.should eq []
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
101
167
|
describe "#like" do
|
102
168
|
let(:like) { stub :like }
|
103
169
|
|
104
170
|
it "instantiates a Kippt::Like and saves it" do
|
105
|
-
Kippt::Like.should_receive(:new).with(
|
171
|
+
Kippt::Like.should_receive(:new).with(subject, client).and_return(like)
|
106
172
|
like.should_receive(:save)
|
107
173
|
subject.like
|
108
174
|
end
|
@@ -112,9 +178,29 @@ describe Kippt::Clip do
|
|
112
178
|
let(:like) { stub :like }
|
113
179
|
|
114
180
|
it "instantiates a Kippt::Like and destroys it" do
|
115
|
-
Kippt::Like.should_receive(:new).with(
|
181
|
+
Kippt::Like.should_receive(:new).with(subject, client).and_return(like)
|
116
182
|
like.should_receive(:destroy)
|
117
183
|
subject.unlike
|
118
184
|
end
|
119
185
|
end
|
186
|
+
|
187
|
+
describe "#favorite" do
|
188
|
+
let(:favorite) { stub :favorite }
|
189
|
+
|
190
|
+
it "instantiates a Kippt::Favorite and saves it" do
|
191
|
+
Kippt::Favorite.should_receive(:new).with(subject, client).and_return(favorite)
|
192
|
+
favorite.should_receive(:save)
|
193
|
+
subject.favorite
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe "#unlike" do
|
198
|
+
let(:favorite) { stub :favorite }
|
199
|
+
|
200
|
+
it "instantiates a Kippt::Favorite and destroys it" do
|
201
|
+
Kippt::Favorite.should_receive(:new).with(subject, client).and_return(favorite)
|
202
|
+
favorite.should_receive(:destroy)
|
203
|
+
subject.unfavorite
|
204
|
+
end
|
205
|
+
end
|
120
206
|
end
|
data/spec/kippt/clips_spec.rb
CHANGED
@@ -6,18 +6,40 @@ describe Kippt::Clips do
|
|
6
6
|
subject { client.clips }
|
7
7
|
let(:base_uri) { "clips" }
|
8
8
|
let(:singular_fixture) { "clip" }
|
9
|
+
let(:collection_fixture) { "clips" }
|
9
10
|
let(:collection_class) { Kippt::ClipCollection }
|
10
11
|
let(:resource_class) { Kippt::Clip }
|
11
12
|
|
12
13
|
it_behaves_like "collection resource"
|
13
14
|
|
15
|
+
describe "#build" do
|
16
|
+
it "returns new resource" do
|
17
|
+
subject.build.should be_a(resource_class)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "accepts parameters" do
|
21
|
+
subject.object_class.should_receive(:new).with({:an => "attribute"}, client)
|
22
|
+
subject.build(:an => "attribute")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
14
26
|
describe "#feed" do
|
15
27
|
subject { Kippt::Client.new(valid_user_credentials).clips }
|
16
28
|
|
17
|
-
it "returns
|
18
|
-
|
19
|
-
|
20
|
-
|
29
|
+
it "returns Clips" do
|
30
|
+
feed = subject.feed
|
31
|
+
feed.should be_a Kippt::Clips
|
32
|
+
feed.base_uri.should eq "clips/feed"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#favorites" do
|
37
|
+
subject { Kippt::Client.new(valid_user_credentials).clips }
|
38
|
+
|
39
|
+
it "returns Clips" do
|
40
|
+
feed = subject.favorites
|
41
|
+
feed.should be_a Kippt::Clips
|
42
|
+
feed.base_uri.should eq "clips/favorites"
|
21
43
|
end
|
22
44
|
end
|
23
45
|
|
@@ -83,7 +105,7 @@ describe Kippt::Clips do
|
|
83
105
|
|
84
106
|
clip = Kippt::Clip.new(:url => "http://kiskolabs.com")
|
85
107
|
response = subject.save_resource(clip)
|
86
|
-
response
|
108
|
+
response.success?.should be_false
|
87
109
|
response[:error_message].should eq "No good."
|
88
110
|
end
|
89
111
|
end
|
data/spec/kippt/comment_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
require "kippt/comment"
|
3
3
|
|
4
4
|
describe Kippt::Comment do
|
5
|
-
subject { Kippt::Comment.new(data,
|
5
|
+
subject { Kippt::Comment.new(data, clip, client) }
|
6
6
|
let(:client) { Kippt::Client.new(valid_user_credentials) }
|
7
7
|
let(:clip) { stub(:clip) }
|
8
8
|
let(:collection_resource_class) { Kippt::Comments }
|
data/spec/kippt/comments_spec.rb
CHANGED
@@ -10,28 +10,54 @@ describe Kippt::Comments do
|
|
10
10
|
let(:collection_class) { Kippt::CommentCollection }
|
11
11
|
let(:resource_class) { Kippt::Comment }
|
12
12
|
|
13
|
+
it_behaves_like "collection resource"
|
14
|
+
|
13
15
|
def collection_fixture
|
14
16
|
base_uri.split("/").last
|
15
17
|
end
|
16
18
|
|
17
|
-
describe "#
|
19
|
+
describe "#build" do
|
20
|
+
it "returns new resource" do
|
21
|
+
subject.build.should be_a(resource_class)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "accepts parameters" do
|
25
|
+
subject.object_class.should_receive(:new).with({:an => "attribute"}, client, clip)
|
26
|
+
subject.build({:an => "attribute"})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
describe "#fetch" do
|
18
32
|
it "returns collection class" do
|
19
33
|
stub_get("/#{base_uri}").
|
20
34
|
to_return(:status => 200, :body => fixture("#{collection_fixture}.json"))
|
21
|
-
all_resources = subject.
|
35
|
+
all_resources = subject.fetch
|
22
36
|
all_resources.is_a? collection_class
|
23
37
|
end
|
24
38
|
|
25
39
|
it "accepts limit and offset options" do
|
26
40
|
stub_get("/#{base_uri}?limit=10&offset=100").
|
27
41
|
to_return(:status => 200, :body => fixture("#{collection_fixture}.json"))
|
28
|
-
resources = subject.
|
42
|
+
resources = subject.fetch(:limit => 10, :offset => 100)
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when comments are embedded" do
|
46
|
+
let(:clip) { stub :clip,
|
47
|
+
id: 100,
|
48
|
+
all_comments_embedded?: true,
|
49
|
+
comments_data: [{body: "Embedded body"}] }
|
50
|
+
|
51
|
+
it "uses the embedded data to create comments" do
|
52
|
+
comments = subject.fetch
|
53
|
+
comments.first.body.should eq "Embedded body"
|
54
|
+
end
|
29
55
|
end
|
30
56
|
|
31
57
|
context "when passed unrecognized arguments" do
|
32
58
|
it "raises error" do
|
33
59
|
lambda {
|
34
|
-
subject.
|
60
|
+
subject.fetch(:foobar => true)
|
35
61
|
}.should raise_error(
|
36
62
|
ArgumentError, "Unrecognized argument: foobar")
|
37
63
|
end
|
@@ -57,7 +83,6 @@ describe Kippt::Comments do
|
|
57
83
|
to_return(:status => 404, :body => {"message" => "Resource not found."})
|
58
84
|
lambda {
|
59
85
|
subject[10]
|
60
|
-
subject.all(:foobar => true)
|
61
86
|
}.should raise_error(
|
62
87
|
Kippt::APIError, "Resource could not be loaded: Resource not found.")
|
63
88
|
end
|