kippt 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/kippt/clips.rb +15 -1
- data/lib/kippt/collection_resource.rb +1 -1
- data/lib/kippt/lists.rb +4 -0
- data/lib/kippt/version.rb +1 -1
- data/spec/kippt/client_spec.rb +3 -3
- data/spec/kippt/clips_spec.rb +22 -8
- data/spec/spec_helper.rb +4 -2
- metadata +1 -1
data/lib/kippt/clips.rb
CHANGED
@@ -5,11 +5,16 @@ require "kippt/clip"
|
|
5
5
|
|
6
6
|
class Kippt::Clips
|
7
7
|
include Kippt::CollectionResource
|
8
|
+
VALID_SEARCH_PARAMETERS = [:q, :list, :is_starred]
|
8
9
|
|
9
10
|
def initialize(client)
|
10
11
|
@client = client
|
11
12
|
end
|
12
13
|
|
14
|
+
def self.valid_filter_parameters
|
15
|
+
[:limit, :offset, :is_read_later, :is_starred]
|
16
|
+
end
|
17
|
+
|
13
18
|
def object_class
|
14
19
|
Kippt::Clip
|
15
20
|
end
|
@@ -23,15 +28,24 @@ class Kippt::Clips
|
|
23
28
|
end
|
24
29
|
|
25
30
|
def search(parameters)
|
26
|
-
# TODO: Validate parameters
|
27
31
|
if parameters.is_a?(String)
|
28
32
|
Kippt::ClipCollection.new(
|
29
33
|
@client.get("search/clips", {:q => parameters}).body,
|
30
34
|
self)
|
31
35
|
else
|
36
|
+
validate_search_parameters(parameters)
|
37
|
+
|
32
38
|
Kippt::ClipCollection.new(
|
33
39
|
@client.get("search/clips", parameters).body,
|
34
40
|
self)
|
35
41
|
end
|
36
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def validate_search_parameters(parameters)
|
47
|
+
parameters.each do |key, value|
|
48
|
+
raise ArgumentError.new("'#{key}' is not a valid search parameter") unless VALID_SEARCH_PARAMETERS.include?(key)
|
49
|
+
end
|
50
|
+
end
|
37
51
|
end
|
@@ -43,7 +43,7 @@ module Kippt::CollectionResource
|
|
43
43
|
|
44
44
|
def validate_collection_options(options)
|
45
45
|
options.each do |key, _|
|
46
|
-
unless
|
46
|
+
unless self.class.valid_filter_parameters.include?(key)
|
47
47
|
raise ArgumentError.new("Unrecognized argument: #{key}")
|
48
48
|
end
|
49
49
|
end
|
data/lib/kippt/lists.rb
CHANGED
data/lib/kippt/version.rb
CHANGED
data/spec/kippt/client_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Kippt::Client do
|
|
6
6
|
context "when there is no username" do
|
7
7
|
it "raises error" do
|
8
8
|
lambda {
|
9
|
-
Kippt::Client.new(password
|
9
|
+
Kippt::Client.new(:password => "secret")
|
10
10
|
}.should raise_error(ArgumentError, "username is required")
|
11
11
|
end
|
12
12
|
end
|
@@ -14,7 +14,7 @@ describe Kippt::Client do
|
|
14
14
|
context "when there is no password or token" do
|
15
15
|
it "raises error" do
|
16
16
|
lambda {
|
17
|
-
Kippt::Client.new(username
|
17
|
+
Kippt::Client.new(:username => "vesan")
|
18
18
|
}.should raise_error(ArgumentError, "password or token is required")
|
19
19
|
end
|
20
20
|
end
|
@@ -50,7 +50,7 @@ describe Kippt::Client do
|
|
50
50
|
|
51
51
|
it "returns a Kippt::Account instance" do
|
52
52
|
subject.should_receive(:get).with("account").and_return(
|
53
|
-
stub body
|
53
|
+
stub :body => {}
|
54
54
|
)
|
55
55
|
account = subject.account
|
56
56
|
account.should be_a(Kippt::Account)
|
data/spec/kippt/clips_spec.rb
CHANGED
@@ -14,16 +14,30 @@ describe Kippt::Clips do
|
|
14
14
|
subject { Kippt::Client.new(valid_user_credentials).clips }
|
15
15
|
|
16
16
|
describe "parameters" do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
context "when parameter is a String" do
|
18
|
+
it "does the search with the string being q" do
|
19
|
+
stub_get("/search/clips?q=bunny").
|
20
|
+
to_return(:status => 200, :body => fixture("clips.json"))
|
21
|
+
subject.search("bunny")
|
22
|
+
end
|
21
23
|
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
context "when parameter is a Hash" do
|
26
|
+
context "with accepted keys" do
|
27
|
+
it "does the search" do
|
28
|
+
stub_get("/search/clips?q=bunny&list=4&is_starred=true").
|
29
|
+
to_return(:status => 200, :body => fixture("clips.json"))
|
30
|
+
subject.search(:q => "bunny", :list => 4, :is_starred => true)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with invalid keys" do
|
35
|
+
it "raises ArgumentError" do
|
36
|
+
lambda {
|
37
|
+
subject.search(:q => "bunny", :stuff => true)
|
38
|
+
}.should raise_error(ArgumentError, "'stuff' is not a valid search parameter")
|
39
|
+
end
|
40
|
+
end
|
27
41
|
end
|
28
42
|
end
|
29
43
|
|
data/spec/spec_helper.rb
CHANGED