kippt 0.0.4 → 1.0.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.
@@ -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 [:limit, :offset].include?(key)
46
+ unless self.class.valid_filter_parameters.include?(key)
47
47
  raise ArgumentError.new("Unrecognized argument: #{key}")
48
48
  end
49
49
  end
@@ -10,6 +10,10 @@ class Kippt::Lists
10
10
  @client = client
11
11
  end
12
12
 
13
+ def self.valid_filter_parameters
14
+ [:limit, :offset]
15
+ end
16
+
13
17
  def object_class
14
18
  Kippt::List
15
19
  end
@@ -1,3 +1,3 @@
1
1
  module Kippt
2
- VERSION = "0.0.4"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -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: "secret")
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: "vesan")
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)
@@ -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
- it "accepts String" do
18
- stub_get("/search/clips?q=bunny").
19
- to_return(:status => 200, :body => fixture("clips.json"))
20
- subject.search("bunny")
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
- it "accepts Hash" do
24
- stub_get("/search/clips?q=bunny&list=4&is_starred=true").
25
- to_return(:status => 200, :body => fixture("clips.json"))
26
- subject.search(:q => "bunny", :list => 4, :is_starred => true)
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
 
@@ -1,5 +1,7 @@
1
- require "simplecov"
2
- SimpleCov.start
1
+ unless ENV["CI"] == "true"
2
+ require "simplecov"
3
+ SimpleCov.start
4
+ end
3
5
 
4
6
  require "kippt"
5
7
  require "rspec"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kippt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: