kippt 0.0.1 → 0.0.2
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/README.md +21 -10
- data/kippt.gemspec +2 -2
- data/lib/kippt/clip.rb +5 -23
- data/lib/kippt/clips.rb +0 -26
- data/lib/kippt/collection_resource.rb +18 -0
- data/lib/kippt/connection.rb +12 -2
- data/lib/kippt/list.rb +4 -8
- data/lib/kippt/resource.rb +55 -0
- data/lib/kippt/version.rb +1 -1
- data/spec/fixtures/clip.json +1 -1
- data/spec/kippt/client_spec.rb +12 -0
- data/spec/kippt/clip_spec.rb +10 -46
- data/spec/kippt/clips_spec.rb +11 -53
- data/spec/kippt/list_spec.rb +16 -0
- data/spec/kippt/lists_spec.rb +6 -51
- data/spec/spec_helper.rb +103 -1
- metadata +9 -7
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
Kippt is a gem that provides a client library for using Kippt.com API.
|
4
4
|
|
5
|
+
|
5
6
|
## Installation
|
6
7
|
|
7
8
|
Add this line to your application's Gemfile:
|
@@ -22,12 +23,15 @@ Or install it yourself as:
|
|
22
23
|
$ gem install kippt
|
23
24
|
```
|
24
25
|
|
26
|
+
|
25
27
|
## Usage
|
26
28
|
|
29
|
+
|
27
30
|
### Authentication
|
28
31
|
|
29
32
|
To be able to use the API you need to authenticated. There's two ways to authenticate:
|
30
33
|
|
34
|
+
|
31
35
|
#### With login credentials
|
32
36
|
|
33
37
|
```ruby
|
@@ -35,6 +39,7 @@ client = Kippt::Client.new(username: "vesan", password: "s3cr3t")
|
|
35
39
|
# Methods called on `client` will use the passed credentials
|
36
40
|
```
|
37
41
|
|
42
|
+
|
38
43
|
#### With token
|
39
44
|
|
40
45
|
```ruby
|
@@ -42,8 +47,11 @@ client = Kippt::Client.new(username: "vesan", token: "2544d6bfddf5893ec8617")
|
|
42
47
|
# Methods called on `client` will use the passed credentials
|
43
48
|
```
|
44
49
|
|
50
|
+
|
45
51
|
### Account
|
46
52
|
|
53
|
+
You can get the account details (username and token):
|
54
|
+
|
47
55
|
```ruby
|
48
56
|
client = Kippt::Client.new(username: "vesan", token: "2544d6bfddf5893ec8617")
|
49
57
|
account = client.account
|
@@ -51,10 +59,11 @@ account.username #=> "vesan"
|
|
51
59
|
account.token #=> "2544d6bfddf5893ec8617"
|
52
60
|
```
|
53
61
|
|
62
|
+
Always use token instead of the password if possible because it's more secure.
|
63
|
+
|
64
|
+
|
54
65
|
### Resources
|
55
66
|
|
56
|
-
Currently this client library is read-only! Ability to create and edit
|
57
|
-
resources will be added soon.
|
58
67
|
|
59
68
|
#### Lists
|
60
69
|
|
@@ -73,6 +82,7 @@ list_id = 10
|
|
73
82
|
list = client.lists[list_id] # Returns Kippt::ListItem
|
74
83
|
```
|
75
84
|
|
85
|
+
|
76
86
|
#### Clips
|
77
87
|
|
78
88
|
```ruby
|
@@ -80,6 +90,7 @@ client = Kippt::Client.new(username: "vesan", token: "2544d6bfddf5893ec8617")
|
|
80
90
|
clips = client.clips # Returns Kippt::ClipCollection
|
81
91
|
```
|
82
92
|
|
93
|
+
|
83
94
|
### Pagination
|
84
95
|
|
85
96
|
Lists and clips are paginated:
|
@@ -110,6 +121,7 @@ Limit and offset can be controlled manually:
|
|
110
121
|
client.clips.all(limit: 25, offset: 50)
|
111
122
|
```
|
112
123
|
|
124
|
+
|
113
125
|
### Search
|
114
126
|
|
115
127
|
Clips can be searched:
|
@@ -124,9 +136,10 @@ Other available options are `is\_starred: true` and `list: [list-id]` like:
|
|
124
136
|
client.clips.search(q: "kippt", list: 5, is_starred: true)
|
125
137
|
```
|
126
138
|
|
127
|
-
### Creating, updating and deleting resources
|
128
139
|
|
129
|
-
|
140
|
+
### Creating and updating resources
|
141
|
+
|
142
|
+
You can create new resources, here for example clips:
|
130
143
|
|
131
144
|
```ruby
|
132
145
|
clip = client.clips.build
|
@@ -143,7 +156,9 @@ clip.save #=> false
|
|
143
156
|
clip.errors #=> ["No url."]
|
144
157
|
```
|
145
158
|
|
146
|
-
Deleting
|
159
|
+
### Deleting resources
|
160
|
+
|
161
|
+
Deleting resources is done with `#destroy`:
|
147
162
|
|
148
163
|
```ruby
|
149
164
|
clip_id = 1001
|
@@ -151,6 +166,7 @@ clip = client.clips[clip_id]
|
|
151
166
|
clip.destroy #=> true
|
152
167
|
```
|
153
168
|
|
169
|
+
|
154
170
|
## Contributing
|
155
171
|
|
156
172
|
1. Fork it
|
@@ -158,8 +174,3 @@ clip.destroy #=> true
|
|
158
174
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
159
175
|
4. Push to the branch (`git push origin my-new-feature`)
|
160
176
|
5. Create new Pull Request
|
161
|
-
|
162
|
-
## TODO
|
163
|
-
|
164
|
-
* Ability to create, update and delete resources
|
165
|
-
* Add user agent string
|
data/kippt.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["vesa@vesavanska.com"]
|
7
7
|
gem.description = %q{Client library for using Kippt.com API}
|
8
8
|
gem.summary = %q{Client library for using Kippt.com API}
|
9
|
-
gem.homepage = ""
|
9
|
+
gem.homepage = "https://github.com/vesan/kippt"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
|
18
18
|
gem.add_dependency "faraday", "~> 0.7.6"
|
19
19
|
gem.add_dependency "faraday_middleware", "~> 0.8.7"
|
20
|
-
gem.add_dependency "
|
20
|
+
gem.add_dependency "multi_json", "~> 1.3.4"
|
21
21
|
|
22
22
|
gem.add_development_dependency "rspec", "~> 2.9.0"
|
23
23
|
gem.add_development_dependency "webmock", "~> 1.8.6"
|
data/lib/kippt/clip.rb
CHANGED
@@ -1,29 +1,11 @@
|
|
1
1
|
require "ostruct"
|
2
|
+
require "kippt/resource"
|
2
3
|
|
3
4
|
class Kippt::Clip
|
4
|
-
|
5
|
+
include Resource
|
5
6
|
|
6
|
-
|
7
|
+
attributes :url_domain, :updated, :is_starred, :title,
|
8
|
+
:url, :notes, :created, :list, :id, :resource_uri
|
7
9
|
|
8
|
-
|
9
|
-
:url, :notes, :created, :list, :id, :resource_uri,
|
10
|
-
:is_starred=, :title=, :url=, :notes=, :list=
|
11
|
-
|
12
|
-
def initialize(attributes = {}, collection_resource = nil)
|
13
|
-
@attributes = OpenStruct.new(attributes)
|
14
|
-
@errors = []
|
15
|
-
@collection_resource = collection_resource
|
16
|
-
end
|
17
|
-
|
18
|
-
def destroy
|
19
|
-
@collection_resource.destroy_resource(self)
|
20
|
-
end
|
21
|
-
|
22
|
-
def save
|
23
|
-
response = @collection_resource.save_object(self)
|
24
|
-
if response[:error_message]
|
25
|
-
errors << response[:error_message]
|
26
|
-
end
|
27
|
-
response[:success]
|
28
|
-
end
|
10
|
+
writable_attributes :is_starred, :title, :url, :notes, :list
|
29
11
|
end
|
data/lib/kippt/clips.rb
CHANGED
@@ -34,30 +34,4 @@ class Kippt::Clips
|
|
34
34
|
self)
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
38
|
-
def save_object(object)
|
39
|
-
if object.id
|
40
|
-
response = @client.put("clips/#{object.id}", writable_parameters_from(object))
|
41
|
-
else
|
42
|
-
response = @client.post("clips", writable_parameters_from(object))
|
43
|
-
end
|
44
|
-
|
45
|
-
save_response = {success: response.success?}
|
46
|
-
if response.body["message"]
|
47
|
-
save_response[:error_message] = response.body["message"]
|
48
|
-
end
|
49
|
-
save_response
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def writable_parameters_from(clip)
|
55
|
-
[:url, :title, :list, :notes, :is_starred].
|
56
|
-
inject({}) do |parameters, attribute_name|
|
57
|
-
unless clip.send(attribute_name).nil?
|
58
|
-
parameters[attribute_name] = clip.send(attribute_name)
|
59
|
-
end
|
60
|
-
parameters
|
61
|
-
end
|
62
|
-
end
|
63
37
|
end
|
@@ -17,6 +17,20 @@ module Kippt::CollectionResource
|
|
17
17
|
collection_class.new(@client.get(url).body, self)
|
18
18
|
end
|
19
19
|
|
20
|
+
def save_resource(object)
|
21
|
+
if object.id
|
22
|
+
response = @client.put("#{base_uri}/#{object.id}", data: writable_parameters_from(object))
|
23
|
+
else
|
24
|
+
response = @client.post("#{base_uri}", data: writable_parameters_from(object))
|
25
|
+
end
|
26
|
+
|
27
|
+
save_response = {success: response.success?}
|
28
|
+
if response.body["message"]
|
29
|
+
save_response[:error_message] = response.body["message"]
|
30
|
+
end
|
31
|
+
save_response
|
32
|
+
end
|
33
|
+
|
20
34
|
def destroy_resource(resource)
|
21
35
|
if resource.id
|
22
36
|
@client.delete("#{base_uri}/#{resource.id}").success?
|
@@ -32,4 +46,8 @@ module Kippt::CollectionResource
|
|
32
46
|
end
|
33
47
|
end
|
34
48
|
end
|
49
|
+
|
50
|
+
def writable_parameters_from(resource)
|
51
|
+
resource.writable_attributes_hash
|
52
|
+
end
|
35
53
|
end
|
data/lib/kippt/connection.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "multi_json"
|
2
|
+
|
1
3
|
module Kippt::Connection
|
2
4
|
def get(url, options = {})
|
3
5
|
request(:get, url, options)
|
@@ -19,7 +21,6 @@ module Kippt::Connection
|
|
19
21
|
|
20
22
|
def connection
|
21
23
|
@connection ||= Faraday.new("https://kippt.com/api") do |builder|
|
22
|
-
builder.use Faraday::Request::JSON
|
23
24
|
builder.use FaradayMiddleware::ParseJson
|
24
25
|
# builder.use Faraday::Response::Logger
|
25
26
|
builder.adapter Faraday.default_adapter
|
@@ -28,6 +29,8 @@ module Kippt::Connection
|
|
28
29
|
|
29
30
|
def request(method, url, options)
|
30
31
|
response = connection.send(method) do |req|
|
32
|
+
set_default_headers(req)
|
33
|
+
|
31
34
|
if @password
|
32
35
|
connection.basic_auth(@username, @password)
|
33
36
|
else
|
@@ -39,7 +42,7 @@ module Kippt::Connection
|
|
39
42
|
req.url url, options
|
40
43
|
else
|
41
44
|
req.url url
|
42
|
-
req.body = options
|
45
|
+
req.body = MultiJson.dump(options[:data])
|
43
46
|
end
|
44
47
|
end
|
45
48
|
|
@@ -49,4 +52,11 @@ module Kippt::Connection
|
|
49
52
|
|
50
53
|
response
|
51
54
|
end
|
55
|
+
|
56
|
+
def set_default_headers(req)
|
57
|
+
req.headers["Content-Type"] = "application/vnd.kippt.20120429+json"
|
58
|
+
app_string = "KipptRubyGem #{Kippt::VERSION},vesa@vesavanska.com,https://github.com/vesan/kippt"
|
59
|
+
req.headers["X-Kippt-Client"] = app_string
|
60
|
+
req.headers["User-Agent"] = app_string
|
61
|
+
end
|
52
62
|
end
|
data/lib/kippt/list.rb
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
require "ostruct"
|
2
2
|
|
3
3
|
class Kippt::List
|
4
|
-
|
4
|
+
include Resource
|
5
5
|
|
6
|
-
|
6
|
+
attributes :id, :rss_url, :updated, :title,
|
7
|
+
:created, :slug, :resource_uri
|
7
8
|
|
8
|
-
|
9
|
-
:created, :slug, :id, :resource_uri
|
10
|
-
|
11
|
-
def initialize(attributes)
|
12
|
-
@attributes = OpenStruct.new(attributes)
|
13
|
-
end
|
9
|
+
writable_attributes :title
|
14
10
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Resource
|
2
|
+
def self.included(base)
|
3
|
+
base.instance_eval do
|
4
|
+
extend Forwardable
|
5
|
+
attr_reader :attributes, :errors
|
6
|
+
|
7
|
+
def_delegators "self.class", :writable_attribute_names
|
8
|
+
end
|
9
|
+
|
10
|
+
base.extend(ClassMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
attr_reader :writable_attribute_names
|
15
|
+
|
16
|
+
def attributes(*attribs)
|
17
|
+
def_delegators :attributes, *attribs
|
18
|
+
end
|
19
|
+
|
20
|
+
def writable_attributes(*attribs)
|
21
|
+
@writable_attribute_names = attribs
|
22
|
+
@writable_attribute_names.freeze
|
23
|
+
def_delegators :attributes, *(attribs.map {|attrib| attrib.to_s + "=" })
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(attributes = {}, collection_resource = nil)
|
28
|
+
@attributes = OpenStruct.new(attributes)
|
29
|
+
@errors = []
|
30
|
+
@collection_resource = collection_resource
|
31
|
+
end
|
32
|
+
|
33
|
+
def destroy
|
34
|
+
@collection_resource.destroy_resource(self)
|
35
|
+
end
|
36
|
+
|
37
|
+
def writable_attributes_hash
|
38
|
+
writable_attribute_names.inject({}) do |parameters, attribute_name|
|
39
|
+
value = self.send(attribute_name)
|
40
|
+
unless value.nil?
|
41
|
+
parameters[attribute_name] = value
|
42
|
+
end
|
43
|
+
parameters
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def save
|
48
|
+
@errors = []
|
49
|
+
response = @collection_resource.save_resource(self)
|
50
|
+
if response[:error_message]
|
51
|
+
errors << response[:error_message]
|
52
|
+
end
|
53
|
+
response[:success]
|
54
|
+
end
|
55
|
+
end
|
data/lib/kippt/version.rb
CHANGED
data/spec/fixtures/clip.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"url_domain": "karrisaarinen.com", "updated": "1335090586", "is_starred": false, "title": "Karri Saarinen", "url": "http://karrisaarinen.com/", "notes": "My favorite designer-bro.", "created": "1335090567", "list": "/api/lists/44525/", "id":
|
1
|
+
{"url_domain": "karrisaarinen.com", "updated": "1335090586", "is_starred": false, "title": "Karri Saarinen", "url": "http://karrisaarinen.com/", "notes": "My favorite designer-bro.", "created": "1335090567", "list": "/api/lists/44525/", "id": 10, "resource_uri": "/api/clips/10/"}
|
data/spec/kippt/client_spec.rb
CHANGED
@@ -12,6 +12,18 @@ describe Kippt::Client do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
describe "connection" do
|
16
|
+
subject { Kippt::Client.new(username: "bob", password: "secret") }
|
17
|
+
|
18
|
+
describe "default headers" do
|
19
|
+
it "includes correct mime-type and user-agent" do
|
20
|
+
stub_request(:get, "https://bob:secret@kippt.com/foobar").
|
21
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/vnd.kippt.20120429+json', 'User-Agent'=>"KipptRubyGem #{Kippt::VERSION},vesa@vesavanska.com,https://github.com/vesan/kippt", 'X-Kippt-Client'=>"KipptRubyGem #{Kippt::VERSION},vesa@vesavanska.com,https://github.com/vesan/kippt"})
|
22
|
+
subject.get("/foobar")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
15
27
|
describe "#lists" do
|
16
28
|
end
|
17
29
|
end
|
data/spec/kippt/clip_spec.rb
CHANGED
@@ -1,52 +1,16 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
require "crack/json"
|
3
|
-
require "kippt/
|
3
|
+
require "kippt/clip"
|
4
4
|
|
5
|
-
describe Kippt::
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
describe "attribute accessors" do
|
10
|
-
it "delegates to attributes" do
|
11
|
-
[:url_domain, :updated, :is_starred,
|
12
|
-
:title, :url, :notes, :created, :list, :id,
|
13
|
-
:resource_uri].each do |attribute_name|
|
14
|
-
subject.send(attribute_name).should eq data[attribute_name.to_s]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "#save" do
|
20
|
-
let(:collection_resource) { Kippt::Client.new(valid_user_credentials).clips }
|
21
|
-
subject { Kippt::Clip.new({}, collection_resource) }
|
22
|
-
|
23
|
-
context "with valid parameters" do
|
24
|
-
it "sends POST request to server" do
|
25
|
-
collection_resource.should_receive(:save_object).with(subject).and_return({})
|
26
|
-
subject.url = "http://kiskolabs.com"
|
27
|
-
subject.save
|
28
|
-
end
|
5
|
+
describe Kippt::Clip do
|
6
|
+
subject { Kippt::Clip.new(data, collection_resource) }
|
7
|
+
let(:collection_resource) { Kippt::Client.new(valid_user_credentials).clips }
|
29
8
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
context "with invalid parameters" do
|
38
|
-
before do
|
39
|
-
collection_resource.stub(:save_object).and_return({success: false, error_message: "No url."})
|
40
|
-
end
|
41
|
-
|
42
|
-
it "sets an error messages" do
|
43
|
-
subject.save
|
44
|
-
subject.errors.should eq ["No url."]
|
45
|
-
end
|
9
|
+
let(:data) { Crack::JSON.parse(fixture("clip.json").read) }
|
10
|
+
let(:attributes) {
|
11
|
+
[:url_domain, :updated, :is_starred, :title,
|
12
|
+
:url, :notes, :created, :list, :id, :resource_uri]
|
13
|
+
}
|
46
14
|
|
47
|
-
|
48
|
-
subject.save.should be_false
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
15
|
+
it_behaves_like "resource"
|
52
16
|
end
|
data/spec/kippt/clips_spec.rb
CHANGED
@@ -2,55 +2,13 @@ require "spec_helper"
|
|
2
2
|
require "kippt/clips"
|
3
3
|
|
4
4
|
describe Kippt::Clips do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
to_return(:status => 200, :body => fixture("clips.json"))
|
11
|
-
clips = subject.all
|
12
|
-
clips.is_a? Kippt::ClipCollection
|
13
|
-
end
|
14
|
-
|
15
|
-
it "accepts limit and offset options" do
|
16
|
-
stub_get("/clips?limit=10&offset=100").
|
17
|
-
to_return(:status => 200, :body => fixture("clips.json"))
|
18
|
-
clips = subject.all(:limit => 10, :offset => 100)
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when passed unrecognized arguments" do
|
22
|
-
it "raises error" do
|
23
|
-
lambda {
|
24
|
-
subject.all(:foobar => true)
|
25
|
-
}.should raise_error(
|
26
|
-
ArgumentError, "Unrecognized argument: foobar")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#[]" do
|
32
|
-
subject { Kippt::Client.new(valid_user_credentials).clips }
|
33
|
-
|
34
|
-
it "fetches single list" do
|
35
|
-
stub_get("/clips/10").
|
36
|
-
to_return(:status => 200, :body => fixture("list.json"))
|
37
|
-
subject[10].id.should eq 10
|
38
|
-
end
|
39
|
-
|
40
|
-
it "returns Kippt::Clip" do
|
41
|
-
stub_get("/clips/10").
|
42
|
-
to_return(:status => 200, :body => fixture("list.json"))
|
43
|
-
subject[10].should be_a(Kippt::Clip)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#build" do
|
48
|
-
subject { Kippt::Client.new(valid_user_credentials).clips }
|
5
|
+
subject { Kippt::Client.new(valid_user_credentials).clips }
|
6
|
+
let(:base_uri) { "clips" }
|
7
|
+
let(:singular_fixture) { "clip" }
|
8
|
+
let(:collection_class) { Kippt::ClipCollection }
|
9
|
+
let(:resource_class) { Kippt::Clip }
|
49
10
|
|
50
|
-
|
51
|
-
subject.build.should be_a(Kippt::Clip)
|
52
|
-
end
|
53
|
-
end
|
11
|
+
it_behaves_like "collection resource"
|
54
12
|
|
55
13
|
describe "#search" do
|
56
14
|
subject { Kippt::Client.new(valid_user_credentials).clips }
|
@@ -77,7 +35,7 @@ describe Kippt::Clips do
|
|
77
35
|
end
|
78
36
|
end
|
79
37
|
|
80
|
-
describe "#
|
38
|
+
describe "#save_resource" do
|
81
39
|
subject { Kippt::Client.new(valid_user_credentials).clips }
|
82
40
|
|
83
41
|
context "successful request" do
|
@@ -87,7 +45,7 @@ describe Kippt::Clips do
|
|
87
45
|
to_return(:status => 200, :body => "{}", :headers => {})
|
88
46
|
|
89
47
|
clip = Kippt::Clip.new(:url => "http://kiskolabs.com")
|
90
|
-
response = subject.
|
48
|
+
response = subject.save_resource(clip)
|
91
49
|
response[:success].should be_true
|
92
50
|
end
|
93
51
|
end
|
@@ -99,7 +57,7 @@ describe Kippt::Clips do
|
|
99
57
|
to_return(:status => 400, :body => "{\"message\": \"No good.\"}", :headers => {})
|
100
58
|
|
101
59
|
clip = Kippt::Clip.new(:url => "http://kiskolabs.com")
|
102
|
-
response = subject.
|
60
|
+
response = subject.save_resource(clip)
|
103
61
|
response[:success].should be_false
|
104
62
|
response[:error_message].should eq "No good."
|
105
63
|
end
|
@@ -112,7 +70,7 @@ describe Kippt::Clips do
|
|
112
70
|
to_return(:status => 200, :body => "{}", :headers => {})
|
113
71
|
|
114
72
|
clip = Kippt::Clip.new(:url => "http://kiskolabs.com")
|
115
|
-
subject.
|
73
|
+
subject.save_resource(clip)
|
116
74
|
end
|
117
75
|
end
|
118
76
|
|
@@ -123,7 +81,7 @@ describe Kippt::Clips do
|
|
123
81
|
to_return(:status => 200, :body => "{}", :headers => {})
|
124
82
|
|
125
83
|
clip = Kippt::Clip.new(:id => 22, :url => "http://kiskolabs.com")
|
126
|
-
subject.
|
84
|
+
subject.save_resource(clip)
|
127
85
|
end
|
128
86
|
end
|
129
87
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "crack/json"
|
3
|
+
require "kippt/list"
|
4
|
+
|
5
|
+
describe Kippt::List do
|
6
|
+
subject { Kippt::List.new(data, collection_resource) }
|
7
|
+
let(:collection_resource) { Kippt::Client.new(valid_user_credentials).lists }
|
8
|
+
|
9
|
+
let(:data) { Crack::JSON.parse(fixture("list.json").read) }
|
10
|
+
let(:attributes) {
|
11
|
+
[:id, :rss_url, :updated, :title,
|
12
|
+
:created, :slug, :resource_uri]
|
13
|
+
}
|
14
|
+
|
15
|
+
it_behaves_like "resource"
|
16
|
+
end
|
data/spec/kippt/lists_spec.rb
CHANGED
@@ -2,56 +2,11 @@ require "spec_helper"
|
|
2
2
|
require "kippt/lists"
|
3
3
|
|
4
4
|
describe Kippt::Lists do
|
5
|
-
|
6
|
-
|
5
|
+
subject { Kippt::Client.new(valid_user_credentials).lists }
|
6
|
+
let(:base_uri) { "lists" }
|
7
|
+
let(:singular_fixture) { "list" }
|
8
|
+
let(:collection_class) { Kippt::ListCollection }
|
9
|
+
let(:resource_class) { Kippt::List }
|
7
10
|
|
8
|
-
|
9
|
-
stub_get("/lists").
|
10
|
-
to_return(:status => 200, :body => fixture("lists.json"))
|
11
|
-
lists = subject.all
|
12
|
-
lists.is_a? Kippt::ListCollection
|
13
|
-
end
|
14
|
-
|
15
|
-
it "accepts limit and offset options" do
|
16
|
-
stub_get("/lists?limit=10&offset=100").
|
17
|
-
to_return(:status => 200, :body => fixture("lists.json"))
|
18
|
-
lists = subject.all(:limit => 10, :offset => 100)
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when passed unrecognized arguments" do
|
22
|
-
it "raises error" do
|
23
|
-
lambda {
|
24
|
-
subject.all(:foobar => true)
|
25
|
-
}.should raise_error(
|
26
|
-
ArgumentError, "Unrecognized argument: foobar")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#[]" do
|
32
|
-
subject { Kippt::Client.new(valid_user_credentials).lists }
|
33
|
-
|
34
|
-
it "fetches single list" do
|
35
|
-
stub_get("/lists/10").
|
36
|
-
to_return(:status => 200, :body => fixture("list.json"))
|
37
|
-
subject[10].id.should eq 10
|
38
|
-
end
|
39
|
-
|
40
|
-
it "returns Kippt::List" do
|
41
|
-
stub_get("/lists/10").
|
42
|
-
to_return(:status => 200, :body => fixture("list.json"))
|
43
|
-
subject[10].should be_a(Kippt::List)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#collection_from_url" do
|
48
|
-
subject { Kippt::Client.new(valid_user_credentials).lists }
|
49
|
-
|
50
|
-
it "returns a new ListCollection" do
|
51
|
-
stub_get("/lists/?limit=20&offset=20").
|
52
|
-
to_return(:status => 200, :body => fixture("lists.json"))
|
53
|
-
list = subject.collection_from_url("/api/lists/?limit=20&offset=20")
|
54
|
-
list.should be_a(Kippt::ListCollection)
|
55
|
-
end
|
56
|
-
end
|
11
|
+
it_behaves_like "collection resource"
|
57
12
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -19,9 +19,64 @@ def fixture(file)
|
|
19
19
|
File.new(fixture_path + '/' + file)
|
20
20
|
end
|
21
21
|
|
22
|
+
shared_examples_for "collection resource" do
|
23
|
+
describe "#all" do
|
24
|
+
it "returns collection class" do
|
25
|
+
stub_get("/#{base_uri}").
|
26
|
+
to_return(:status => 200, :body => fixture("#{base_uri}.json"))
|
27
|
+
all_resources = subject.all
|
28
|
+
all_resources.is_a? collection_class
|
29
|
+
end
|
30
|
+
|
31
|
+
it "accepts limit and offset options" do
|
32
|
+
stub_get("/#{base_uri}?limit=10&offset=100").
|
33
|
+
to_return(:status => 200, :body => fixture("#{base_uri}.json"))
|
34
|
+
resources = subject.all(:limit => 10, :offset => 100)
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when passed unrecognized arguments" do
|
38
|
+
it "raises error" do
|
39
|
+
lambda {
|
40
|
+
subject.all(:foobar => true)
|
41
|
+
}.should raise_error(
|
42
|
+
ArgumentError, "Unrecognized argument: foobar")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#[]" do
|
48
|
+
it "fetches single resource" do
|
49
|
+
stub_get("/#{base_uri}/10").
|
50
|
+
to_return(:status => 200, :body => fixture("#{singular_fixture}.json"))
|
51
|
+
subject[10].id.should eq 10
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns resource" do
|
55
|
+
stub_get("/#{base_uri}/10").
|
56
|
+
to_return(:status => 200, :body => fixture("#{singular_fixture}.json"))
|
57
|
+
subject[10].should be_a(resource_class)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#collection_from_url" do
|
62
|
+
it "returns a new collection" do
|
63
|
+
stub_get("/#{base_uri}/?limit=20&offset=20").
|
64
|
+
to_return(:status => 200, :body => fixture("#{base_uri}.json"))
|
65
|
+
collection = subject.collection_from_url("/api/#{base_uri}/?limit=20&offset=20")
|
66
|
+
collection.should be_a(collection_class)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#build" do
|
71
|
+
it "returns new resource" do
|
72
|
+
subject.build.should be_a(resource_class)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
22
77
|
shared_examples_for "collection" do
|
23
78
|
describe "#total_count" do
|
24
|
-
it "returns total count of
|
79
|
+
it "returns total count of resources" do
|
25
80
|
subject.total_count.should eq data["meta"]["total_count"]
|
26
81
|
end
|
27
82
|
end
|
@@ -38,3 +93,50 @@ shared_examples_for "collection" do
|
|
38
93
|
end
|
39
94
|
end
|
40
95
|
end
|
96
|
+
|
97
|
+
shared_examples_for "resource" do
|
98
|
+
describe "attribute accessors" do
|
99
|
+
it "delegates to attributes" do
|
100
|
+
attributes.each do |attribute_name|
|
101
|
+
subject.send(attribute_name).should eq data[attribute_name.to_s]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#save" do
|
107
|
+
context "with valid parameters" do
|
108
|
+
it "sends POST request to server" do
|
109
|
+
collection_resource.should_receive(:save_resource).with(subject).and_return({})
|
110
|
+
subject.save
|
111
|
+
end
|
112
|
+
|
113
|
+
it "returns true" do
|
114
|
+
collection_resource.stub(:save_resource).and_return(
|
115
|
+
{success: true})
|
116
|
+
subject.save.should be_true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "with invalid parameters" do
|
121
|
+
before do
|
122
|
+
collection_resource.stub(:save_resource).and_return({success: false, error_message: "No url."})
|
123
|
+
end
|
124
|
+
|
125
|
+
it "sets an error messages" do
|
126
|
+
subject.save
|
127
|
+
subject.errors.should eq ["No url."]
|
128
|
+
end
|
129
|
+
|
130
|
+
it "returns false" do
|
131
|
+
subject.save.should be_false
|
132
|
+
end
|
133
|
+
|
134
|
+
it "clears previous errors" do
|
135
|
+
subject.save
|
136
|
+
subject.errors.should eq ["No url."]
|
137
|
+
subject.save
|
138
|
+
subject.errors.should eq ["No url."]
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
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
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -44,13 +44,13 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 0.8.7
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: multi_json
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 1.
|
53
|
+
version: 1.3.4
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 1.3.4
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: rspec
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/kippt/list.rb
|
118
118
|
- lib/kippt/list_collection.rb
|
119
119
|
- lib/kippt/lists.rb
|
120
|
+
- lib/kippt/resource.rb
|
120
121
|
- lib/kippt/version.rb
|
121
122
|
- spec/fixtures/clip.json
|
122
123
|
- spec/fixtures/clips.json
|
@@ -128,9 +129,10 @@ files:
|
|
128
129
|
- spec/kippt/clip_spec.rb
|
129
130
|
- spec/kippt/clips_spec.rb
|
130
131
|
- spec/kippt/list_collection_spec.rb
|
132
|
+
- spec/kippt/list_spec.rb
|
131
133
|
- spec/kippt/lists_spec.rb
|
132
134
|
- spec/spec_helper.rb
|
133
|
-
homepage:
|
135
|
+
homepage: https://github.com/vesan/kippt
|
134
136
|
licenses: []
|
135
137
|
post_install_message:
|
136
138
|
rdoc_options: []
|
@@ -150,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
152
|
version: '0'
|
151
153
|
requirements: []
|
152
154
|
rubyforge_project:
|
153
|
-
rubygems_version: 1.8.
|
155
|
+
rubygems_version: 1.8.24
|
154
156
|
signing_key:
|
155
157
|
specification_version: 3
|
156
158
|
summary: Client library for using Kippt.com API
|
@@ -165,6 +167,6 @@ test_files:
|
|
165
167
|
- spec/kippt/clip_spec.rb
|
166
168
|
- spec/kippt/clips_spec.rb
|
167
169
|
- spec/kippt/list_collection_spec.rb
|
170
|
+
- spec/kippt/list_spec.rb
|
168
171
|
- spec/kippt/lists_spec.rb
|
169
172
|
- spec/spec_helper.rb
|
170
|
-
has_rdoc:
|