kippt 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -111,12 +111,10 @@ You can get next and previous set of results:
111
111
  ```ruby
112
112
  clips.next_page? #=> true
113
113
  clips.next_page # Returns new Kippt::ClipCollection
114
- clips.prev_page? #=> true
115
- clips.prev_page # Returns new Kippt::ClipCollection
114
+ clips.previous_page? #=> true
115
+ clips.previous_page # Returns new Kippt::ClipCollection
116
116
  ```
117
117
 
118
- There's also `#previous\_page?` and `#previous\_page`.
119
-
120
118
  Limit and offset can be controlled manually:
121
119
 
122
120
  ```ruby
@@ -173,6 +171,8 @@ clip.destroy #=> true
173
171
 
174
172
  1. Fork it
175
173
  2. Create your feature branch (`git checkout -b my-new-feature`)
176
- 3. Commit your changes (`git commit -am 'Added some feature'`)
177
- 4. Push to the branch (`git push origin my-new-feature`)
178
- 5. Create new Pull Request
174
+ 3. Do your changes
175
+ 4. Run the tests (`rspec spec`)
176
+ 5. Commit your changes (`git commit -am 'Added some feature'`)
177
+ 6. Push to the branch (`git push origin my-new-feature`)
178
+ 7. Create new Pull Request (`https://github.com/vesan/kippt/pulls`)
data/kippt.gemspec CHANGED
@@ -21,4 +21,5 @@ Gem::Specification.new do |gem|
21
21
 
22
22
  gem.add_development_dependency "rspec", "~> 2.9.0"
23
23
  gem.add_development_dependency "webmock", "~> 1.8.6"
24
+ gem.add_development_dependency "simplecov", "~> 0.6.4"
24
25
  end
@@ -6,7 +6,7 @@ module Kippt::Collection
6
6
  @limit = meta.fetch("limit")
7
7
  @offset = meta.fetch("offset")
8
8
  @next = meta.fetch("next") { nil }
9
- @prev = meta.fetch("prev") { nil }
9
+ @previous = meta.fetch("previous") { nil }
10
10
  @total_count = meta.fetch("total_count")
11
11
 
12
12
  @collection_resource = collection_resource
@@ -31,16 +31,20 @@ module Kippt::Collection
31
31
  end
32
32
 
33
33
  def next_page
34
- # TODO: Raise error if there is no page
34
+ raise Kippt::APIError.new("There is no next page") if @next.nil? || @next == ""
35
+
35
36
  @collection_resource.collection_from_url(@next)
36
37
  end
37
38
 
38
- def prev_page?
39
- @prev
39
+ def previous_page?
40
+ @previous
40
41
  end
42
+ alias_method :prev_page?, :previous_page?
43
+
44
+ def previous_page
45
+ raise Kippt::APIError.new("There is no previous page") if @previous.nil? || @previous == ""
41
46
 
42
- def prev_page
43
- # TODO: Raise error if there is no page
44
- @collection_resource.collection_from_url(@prev)
47
+ @collection_resource.collection_from_url(@previous)
45
48
  end
49
+ alias_method :prev_page, :previous_page
46
50
  end
@@ -14,6 +14,8 @@ module Kippt::CollectionResource
14
14
  end
15
15
 
16
16
  def collection_from_url(url)
17
+ raise ArgumentError.new("The parameter URL can't be blank") if url.nil? || url == ""
18
+
17
19
  collection_class.new(@client.get(url).body, self)
18
20
  end
19
21
 
data/lib/kippt/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kippt
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1 @@
1
+ {"meta": {"next": "/api/clips/?limit=2&offset=4", "total_count": 10, "previous": "/api/clips/?limit=2&offset=0", "limit": 2, "offset": 2}, "objects": [{"url_domain": "karrisaarinen.com", "updated": "1335090586", "is_starred": false, "title": "Karri Saarinen", "url": "http://karrisaarinen.com/", "notes": "Cool site, bro", "created": "1335090567", "list": "/api/lists/44525/", "id": 1589450, "resource_uri": "/api/clips/1589450/"}]}
@@ -0,0 +1 @@
1
+ {"meta": {"next": "/api/lists/?limit=2&offset=4", "total_count": 40, "previous": "/api/lists/?limit=2&offset=0", "limit": 2, "offset": 2}, "objects": [{"rss_url": "https://kippt.com/feed/vesan/0VLW0SSjVBRJ1oQEpe9OmSf1q2Q6lvq/inspiration", "updated": "1335090586", "title": "Inspiration", "created": "1335090037", "slug": "inspiration", "id": 10, "resource_uri": "/api/lists/10/"}, {"rss_url": "https://kippt.com/feed/vesan/0VLW0SSjVBRJ1oQEpe9OmSf1q2Q6lvq/moikka-vesa", "updated": "1319441679", "title": "Moikka Vesa!", "created": "1319435972", "slug": "moikka-vesa", "id": 134, "resource_uri": "/api/lists/134/"}, {"rss_url": "https://kippt.com/feed/vesan/0VLW0SSjVBRJ1oQEpe9OmSf1q2Q6lvq/read-later", "updated": "1319434196", "title": "Read Later", "created": "1319434196", "slug": "read-later", "id": 133, "resource_uri": "/api/lists/133/"}, {"rss_url": "https://kippt.com/feed/vesan/0VLW0SSjVBRJ1oQEpe9OmSf1q2Q6lvq/inbox", "updated": "1319434196", "title": "Inbox", "created": "1319434196", "slug": "inbox", "id": 132, "resource_uri": "/api/lists/132/"}]}
@@ -4,11 +4,19 @@ require "kippt/client"
4
4
  describe Kippt::Client do
5
5
  describe "#initialize" do
6
6
  context "when there is no username" do
7
- it "raises error"
7
+ it "raises error" do
8
+ lambda {
9
+ Kippt::Client.new(password: "secret")
10
+ }.should raise_error(ArgumentError, "username is required")
11
+ end
8
12
  end
9
13
 
10
14
  context "when there is no password or token" do
11
- it "raises error"
15
+ it "raises error" do
16
+ lambda {
17
+ Kippt::Client.new(username: "vesan")
18
+ }.should raise_error(ArgumentError, "password or token is required")
19
+ end
12
20
  end
13
21
  end
14
22
 
@@ -22,8 +30,48 @@ describe Kippt::Client do
22
30
  subject.get("/foobar")
23
31
  end
24
32
  end
33
+
34
+ describe "error handling" do
35
+ context "when response status is 401" do
36
+ it "raises Kippt::APIError with message received from the server" do
37
+ stub_request(:get, "https://bob:secret@kippt.com/error_path").
38
+ to_return(:status => 401, :body => "{\"message\": \"Something horrible.\"}")
39
+
40
+ lambda {
41
+ subject.get("/error_path")
42
+ }.should raise_error(Kippt::APIError, "Something horrible.")
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "#account" do
49
+ subject { Kippt::Client.new(:username => "bob", :password => "secret") }
50
+
51
+ it "returns a Kippt::Account instance" do
52
+ subject.should_receive(:get).with("account").and_return(
53
+ stub body: {}
54
+ )
55
+ account = subject.account
56
+ account.should be_a(Kippt::Account)
57
+ end
25
58
  end
26
59
 
27
60
  describe "#lists" do
61
+ subject { Kippt::Client.new(:username => "bob", :password => "secret") }
62
+
63
+ it "returns a Kippt::Lists instance" do
64
+ lists = subject.lists
65
+ lists.should be_a(Kippt::Lists)
66
+ end
67
+ end
68
+
69
+ describe "#clips" do
70
+ subject { Kippt::Client.new(:username => "bob", :password => "secret") }
71
+
72
+ it "returns a Kippt::Clips instance" do
73
+ clips = subject.clips
74
+ clips.should be_a(Kippt::Clips)
75
+ end
28
76
  end
29
77
  end
@@ -3,7 +3,12 @@ require "kippt/clip_collection"
3
3
 
4
4
  describe Kippt::ClipCollection do
5
5
  let(:data) { MultiJson.load(fixture("clips.json").read) }
6
+ let(:data_with_multiple_pages) {
7
+ MultiJson.load(fixture("clips_with_multiple_pages.json").read)
8
+ }
6
9
  subject { Kippt::ClipCollection.new(data) }
10
+ let(:subject_with_multiple_pages) { Kippt::ClipCollection.new(data_with_multiple_pages, collection_resource) }
11
+ let(:collection_resource) { nil }
7
12
 
8
13
  it_behaves_like "collection"
9
14
  end
@@ -2,7 +2,12 @@ require "spec_helper"
2
2
 
3
3
  describe Kippt::ListCollection do
4
4
  let(:data) { MultiJson.load(fixture("lists.json").read) }
5
+ let(:data_with_multiple_pages) {
6
+ MultiJson.load(fixture("lists_with_multiple_pages.json").read)
7
+ }
5
8
  subject { Kippt::ListCollection.new(data) }
9
+ let(:subject_with_multiple_pages) { Kippt::ListCollection.new(data_with_multiple_pages, collection_resource) }
10
+ let(:collection_resource) { nil }
6
11
 
7
12
  it_behaves_like "collection"
8
13
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require "simplecov"
2
+ SimpleCov.start
3
+
1
4
  require "kippt"
2
5
  require "rspec"
3
6
  require "webmock/rspec"
@@ -65,6 +68,17 @@ shared_examples_for "collection resource" do
65
68
  collection = subject.collection_from_url("/api/#{base_uri}/?limit=20&offset=20")
66
69
  collection.should be_a(collection_class)
67
70
  end
71
+
72
+ context "when passed URL is blank" do
73
+ it "raises ArgumentError" do
74
+ lambda {
75
+ subject.collection_from_url("")
76
+ }.should raise_error(ArgumentError, "The parameter URL can't be blank")
77
+ lambda {
78
+ subject.collection_from_url(nil)
79
+ }.should raise_error(ArgumentError, "The parameter URL can't be blank")
80
+ end
81
+ end
68
82
  end
69
83
 
70
84
  describe "#build" do
@@ -92,6 +106,102 @@ shared_examples_for "collection" do
92
106
  subject.limit.should eq 20
93
107
  end
94
108
  end
109
+
110
+ describe "#objects" do
111
+ it "returns the objects generated from the data" do
112
+ subject.objects.each do |object|
113
+ object.should be_a(subject.object_class)
114
+ end
115
+ end
116
+ end
117
+
118
+ describe "#[]" do
119
+ it "returns a object by index" do
120
+ subject[0].id.should eq data["objects"][0]["id"]
121
+ end
122
+ end
123
+
124
+ describe "#each" do
125
+ it "loops through the objects" do
126
+ ids = []
127
+ subject.each {|object| ids << object.id }
128
+ ids.should eq data["objects"].map { |node| node["id"] }
129
+ end
130
+ end
131
+
132
+ describe "#next_page?" do
133
+ context "there is a next page" do
134
+ it "returns url of the page" do
135
+ subject_with_multiple_pages.next_page?.should eq data_with_multiple_pages["meta"]["next"]
136
+ end
137
+ end
138
+
139
+ context "there is no next page" do
140
+ it "returns nil" do
141
+ subject.next_page?.should eq nil
142
+ end
143
+ end
144
+ end
145
+
146
+ describe "#next_page" do
147
+ context "if there is a next page" do
148
+ let(:collection_resource) { stub }
149
+
150
+ it "gets the next page of results from the collection resource" do
151
+ results = stub
152
+ collection_resource.should_receive(:collection_from_url).
153
+ with(data_with_multiple_pages["meta"]["next"]).
154
+ and_return(results)
155
+
156
+ subject_with_multiple_pages.next_page.should eq results
157
+ end
158
+ end
159
+
160
+ context "if there is no next page" do
161
+ it "raises an error" do
162
+ lambda {
163
+ subject.next_page
164
+ }.should raise_error(Kippt::APIError, "There is no next page")
165
+ end
166
+ end
167
+ end
168
+
169
+ describe "#previous_page?" do
170
+ context "there is a previous page" do
171
+ it "returns url of the page" do
172
+ subject_with_multiple_pages.previous_page?.should eq data_with_multiple_pages["meta"]["previous"]
173
+ end
174
+ end
175
+
176
+ context "there is no previous page" do
177
+ it "returns nil" do
178
+ subject.previous_page?.should be_nil
179
+ end
180
+ end
181
+ end
182
+
183
+ describe "#previous_page" do
184
+ context "if there is a previous page" do
185
+ let(:collection_resource) { stub }
186
+
187
+ it "gets the previous page of results from the collection resource" do
188
+ results = stub
189
+ collection_resource.should_receive(:collection_from_url).
190
+ with(data_with_multiple_pages["meta"]["previous"]).
191
+ and_return(results)
192
+
193
+ subject_with_multiple_pages.previous_page.should eq results
194
+ end
195
+ end
196
+
197
+ context "if there is no previous page" do
198
+ it "raises an error" do
199
+ lambda {
200
+ subject.previous_page
201
+ }.should raise_error(Kippt::APIError, "There is no previous page")
202
+ end
203
+ end
204
+ end
95
205
  end
96
206
 
97
207
  shared_examples_for "resource" do
@@ -103,6 +213,13 @@ shared_examples_for "resource" do
103
213
  end
104
214
  end
105
215
 
216
+ describe "#destroy" do
217
+ it "sends delete request to the server" do
218
+ collection_resource.should_receive(:destroy_resource).with(subject).and_return(true)
219
+ subject.destroy.should be_true
220
+ end
221
+ end
222
+
106
223
  describe "#save" do
107
224
  context "with valid parameters" do
108
225
  it "sends POST request to server" do
metadata CHANGED
@@ -1,115 +1,119 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: kippt
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
13
- - !binary |
14
- VmVzYSBWw6Ruc2vDpA==
15
-
7
+ authors:
8
+ - Vesa Vänskä
16
9
  autorequire:
17
10
  bindir: bin
18
11
  cert_chain: []
19
-
20
- date: 2012-04-29 00:00:00 +03:00
21
- default_executable:
22
- dependencies:
23
- - !ruby/object:Gem::Dependency
12
+ date: 2012-06-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
24
15
  name: faraday
25
- prerelease: false
26
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
27
17
  none: false
28
- requirements:
18
+ requirements:
29
19
  - - ~>
30
- - !ruby/object:Gem::Version
31
- hash: 15
32
- segments:
33
- - 0
34
- - 7
35
- - 6
20
+ - !ruby/object:Gem::Version
36
21
  version: 0.7.6
37
22
  type: :runtime
38
- version_requirements: *id001
39
- - !ruby/object:Gem::Dependency
40
- name: faraday_middleware
41
23
  prerelease: false
42
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.7.6
30
+ - !ruby/object:Gem::Dependency
31
+ name: faraday_middleware
32
+ requirement: !ruby/object:Gem::Requirement
43
33
  none: false
44
- requirements:
34
+ requirements:
45
35
  - - ~>
46
- - !ruby/object:Gem::Version
47
- hash: 49
48
- segments:
49
- - 0
50
- - 8
51
- - 7
36
+ - !ruby/object:Gem::Version
52
37
  version: 0.8.7
53
38
  type: :runtime
54
- version_requirements: *id002
55
- - !ruby/object:Gem::Dependency
56
- name: multi_json
57
39
  prerelease: false
58
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
59
41
  none: false
60
- requirements:
42
+ requirements:
61
43
  - - ~>
62
- - !ruby/object:Gem::Version
63
- hash: 19
64
- segments:
65
- - 1
66
- - 3
67
- - 4
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.7
46
+ - !ruby/object:Gem::Dependency
47
+ name: multi_json
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
68
53
  version: 1.3.4
69
54
  type: :runtime
70
- version_requirements: *id003
71
- - !ruby/object:Gem::Dependency
72
- name: rspec
73
55
  prerelease: false
74
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.4
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
75
65
  none: false
76
- requirements:
66
+ requirements:
77
67
  - - ~>
78
- - !ruby/object:Gem::Version
79
- hash: 43
80
- segments:
81
- - 2
82
- - 9
83
- - 0
68
+ - !ruby/object:Gem::Version
84
69
  version: 2.9.0
85
70
  type: :development
86
- version_requirements: *id004
87
- - !ruby/object:Gem::Dependency
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.9.0
78
+ - !ruby/object:Gem::Dependency
88
79
  name: webmock
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.8.6
86
+ type: :development
89
87
  prerelease: false
90
- requirement: &id005 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
91
89
  none: false
92
- requirements:
90
+ requirements:
93
91
  - - ~>
94
- - !ruby/object:Gem::Version
95
- hash: 59
96
- segments:
97
- - 1
98
- - 8
99
- - 6
92
+ - !ruby/object:Gem::Version
100
93
  version: 1.8.6
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.6.4
101
102
  type: :development
102
- version_requirements: *id005
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.6.4
103
110
  description: Client library for using Kippt.com API
104
- email:
111
+ email:
105
112
  - vesa@vesavanska.com
106
113
  executables: []
107
-
108
114
  extensions: []
109
-
110
115
  extra_rdoc_files: []
111
-
112
- files:
116
+ files:
113
117
  - .gitignore
114
118
  - .rspec
115
119
  - .travis.yml
@@ -135,8 +139,10 @@ files:
135
139
  - lib/kippt/version.rb
136
140
  - spec/fixtures/clip.json
137
141
  - spec/fixtures/clips.json
142
+ - spec/fixtures/clips_with_multiple_pages.json
138
143
  - spec/fixtures/list.json
139
144
  - spec/fixtures/lists.json
145
+ - spec/fixtures/lists_with_multiple_pages.json
140
146
  - spec/kippt/account_spec.rb
141
147
  - spec/kippt/client_spec.rb
142
148
  - spec/kippt/clip_collection_spec.rb
@@ -146,45 +152,37 @@ files:
146
152
  - spec/kippt/list_spec.rb
147
153
  - spec/kippt/lists_spec.rb
148
154
  - spec/spec_helper.rb
149
- has_rdoc: true
150
155
  homepage: https://github.com/vesan/kippt
151
156
  licenses: []
152
-
153
157
  post_install_message:
154
158
  rdoc_options: []
155
-
156
- require_paths:
159
+ require_paths:
157
160
  - lib
158
- required_ruby_version: !ruby/object:Gem::Requirement
161
+ required_ruby_version: !ruby/object:Gem::Requirement
159
162
  none: false
160
- requirements:
161
- - - ">="
162
- - !ruby/object:Gem::Version
163
- hash: 3
164
- segments:
165
- - 0
166
- version: "0"
167
- required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  none: false
169
- requirements:
170
- - - ">="
171
- - !ruby/object:Gem::Version
172
- hash: 3
173
- segments:
174
- - 0
175
- version: "0"
169
+ requirements:
170
+ - - ! '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
176
173
  requirements: []
177
-
178
174
  rubyforge_project:
179
- rubygems_version: 1.3.7
175
+ rubygems_version: 1.8.24
180
176
  signing_key:
181
177
  specification_version: 3
182
178
  summary: Client library for using Kippt.com API
183
- test_files:
179
+ test_files:
184
180
  - spec/fixtures/clip.json
185
181
  - spec/fixtures/clips.json
182
+ - spec/fixtures/clips_with_multiple_pages.json
186
183
  - spec/fixtures/list.json
187
184
  - spec/fixtures/lists.json
185
+ - spec/fixtures/lists_with_multiple_pages.json
188
186
  - spec/kippt/account_spec.rb
189
187
  - spec/kippt/client_spec.rb
190
188
  - spec/kippt/clip_collection_spec.rb