kippt 2.0.1 → 3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NzljMzEzMTM0MmY0YTIxNTkwOTMzMDkzYzM4YmM5ZWU0ZmZjODYyYQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTAwMDNhNTJmYzU4NmM2MGVmYzJkNGRkZTNlYTFjZWNkMjFjMTg4ZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YTlhOWNlZWVhNmIxOWIwMDg4NDkxMmY0ZDg5M2ExMmI2YzE1MGJlZDg5OTQz
|
10
|
+
ZDkxMTQ1MDM5MThlYzNlNmQxMDk0MzYxZWM3NDVkN2FmMTY4NWRmZjFkNTBh
|
11
|
+
OWNmYzVlMDQ0ZTdlY2MwOGFhYTZhNWViMTRiY2M2Yzg2NDMwZmE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MjMxZjYxMmU1MjMyNTFjODRlNzQ4MTVkNDZmOTRjYzc3ZWJkNjAyZTgwNGQw
|
14
|
+
MjkwMTdkOWNkYzQyNzNjNjg5NzNiZTQxMGUyNTIzYTdlYTc3YTk0Y2IyZmZi
|
15
|
+
ZWJmMGU3MzA1MTkwMTNhMDUwM2YxNGM2ZWJiYTU1MjBjNjQ4MTg=
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 3.0 / December 23, 2013
|
4
|
+
|
5
|
+
Changes all fetching to paginated HTTP endpoints to return a proxy so that you can control
|
6
|
+
what you load. This causes breaking changes on some parts of the API.
|
7
|
+
|
8
|
+
Adds method to get check if the authenticated user is following a list (`List#following?`).
|
9
|
+
|
10
|
+
Adds support for fetching clips by URL or created after time.
|
11
|
+
|
12
|
+
Adds support for favoriting and unfavoriting a clip.
|
13
|
+
|
14
|
+
Adds new `#fetch` method that works like `#all` but better reflects the use of the method.
|
15
|
+
|
16
|
+
Removes `#total_count` on fetched collections because it's been deprecated:
|
17
|
+
https://github.com/kippt/api-documentation/blob/c104158674e55a4c103b93ccd41233e9a6daea0a/basics/pagination.md
|
18
|
+
|
19
|
+
Improves test coverage.
|
20
|
+
|
21
|
+
Deprecates support for Ruby 1.8.7.
|
22
|
+
|
23
|
+
## 2.0.1 / August 6, 2013
|
24
|
+
|
25
|
+
Adds ability to fetch the clips for a list. Contributed by [Darep](https://github.com/Darep).
|
26
|
+
|
3
27
|
## 2.0 / July 7, 2013
|
4
28
|
|
5
29
|
After being long time in development this update adds support for all the
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -80,7 +80,7 @@ Get all the lists:
|
|
80
80
|
|
81
81
|
```ruby
|
82
82
|
client = Kippt::Client.new(username: "vesan", token: "2544d6bfddf5893ec8617")
|
83
|
-
lists = client.lists.
|
83
|
+
lists = client.lists.fetch # Returns Kippt::ListCollection
|
84
84
|
```
|
85
85
|
|
86
86
|
Get single list:
|
@@ -96,6 +96,10 @@ Get single lists’s clips:
|
|
96
96
|
```ruby
|
97
97
|
client = Kippt::Client.new(username: "vesan", token: "2544d6bfddf5893ec8617")
|
98
98
|
list_id = 10
|
99
|
+
list = client.lists[list_id].clips # Returns a Kippt::ClipCollection
|
100
|
+
|
101
|
+
# OR
|
102
|
+
|
99
103
|
list = Kippt::List.new({ id: list_id }, client)
|
100
104
|
list.clips # Returns a Kippt::ClipCollection
|
101
105
|
```
|
@@ -105,7 +109,13 @@ list.clips # Returns a Kippt::ClipCollection
|
|
105
109
|
|
106
110
|
```ruby
|
107
111
|
client = Kippt::Client.new(username: "vesan", token: "2544d6bfddf5893ec8617")
|
108
|
-
|
112
|
+
client.clips.fetch # Returns Kippt::ClipCollection
|
113
|
+
|
114
|
+
# Returns first page of clips for an URL
|
115
|
+
client.clips.fetch(url: "https://github.com/vesan/kippt")
|
116
|
+
|
117
|
+
# Returns first page of clips added in the last day
|
118
|
+
client.clips.fetch(since: Time.now.to_i - 86400)
|
109
119
|
```
|
110
120
|
|
111
121
|
Both ListCollection and ClipCollection are Enumerable.
|
@@ -117,7 +127,7 @@ Lists and clips are paginated:
|
|
117
127
|
|
118
128
|
```ruby
|
119
129
|
client = Kippt::Client.new(username: "vesan", token: "2544d6bfddf5893ec8617")
|
120
|
-
clips = client.clips.
|
130
|
+
clips = client.clips.fetch
|
121
131
|
|
122
132
|
clips.total_count
|
123
133
|
clips.offset
|
@@ -136,7 +146,7 @@ clips.previous_page # Returns new Kippt::ClipCollection
|
|
136
146
|
Limit and offset can be controlled manually:
|
137
147
|
|
138
148
|
```ruby
|
139
|
-
client.clips.
|
149
|
+
client.clips.fetch(limit: 25, offset: 50)
|
140
150
|
```
|
141
151
|
|
142
152
|
|
data/TODO.md
CHANGED
@@ -2,6 +2,22 @@
|
|
2
2
|
* [DONE] Timestamps as time
|
3
3
|
* Better exceptions
|
4
4
|
|
5
|
+
# 3.0
|
6
|
+
|
7
|
+
* [DONE] Add support for favorites
|
8
|
+
* [DONE] Add support for filtering clips by URL
|
9
|
+
* [DONE] Any other filtering that is missing?
|
10
|
+
* [DONE] Convert to return proxy:
|
11
|
+
** [DONE] list.clips
|
12
|
+
** [DONE] clip.comments
|
13
|
+
** [DONE] clip.likes
|
14
|
+
** [DONE] clip.saves
|
15
|
+
** [DONE] clips.feed
|
16
|
+
** [DONE] user_clips.favorites
|
17
|
+
* [DONE] Check that all end points have the same filtering capabilities
|
18
|
+
* [DONE] Refactors users.search
|
19
|
+
* [DONE] Make sure likes make sense. Now User & Like objects are somehow mixed.
|
20
|
+
|
5
21
|
# Clip
|
6
22
|
|
7
23
|
* [DONE] Getting the feed of authenticated user
|
data/lib/kippt.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
-
|
2
|
-
require "core_ext/open_struct"
|
1
|
+
require_relative "kippt/version"
|
3
2
|
require "faraday"
|
4
3
|
require "faraday_middleware"
|
5
|
-
|
4
|
+
|
5
|
+
require_relative "kippt/helpers"
|
6
|
+
require_relative "kippt/resource"
|
7
|
+
require_relative "kippt/collection_resource"
|
8
|
+
require_relative "kippt/collection"
|
9
|
+
require_relative "kippt/user"
|
10
|
+
require_relative "kippt/client"
|
6
11
|
|
7
12
|
module Kippt
|
8
13
|
class APIError < StandardError; end
|
data/lib/kippt/client.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require_relative "connection"
|
2
|
+
require_relative "root_clips"
|
3
|
+
require_relative "lists"
|
4
|
+
require_relative "users"
|
5
5
|
|
6
6
|
class Kippt::Client
|
7
7
|
include Kippt::Connection
|
@@ -52,7 +52,7 @@ class Kippt::Client
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def clips
|
55
|
-
Kippt::
|
55
|
+
Kippt::RootClips.new(self)
|
56
56
|
end
|
57
57
|
|
58
58
|
def users
|
@@ -60,7 +60,7 @@ class Kippt::Client
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def collection_resource_for(resource_class, *options)
|
63
|
-
resource_class.new(*([self]
|
63
|
+
resource_class.new(*(options + [self]))
|
64
64
|
end
|
65
65
|
|
66
66
|
def resource_from_url(resource_class, url)
|
data/lib/kippt/clip.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
require_relative "comments"
|
2
|
+
require_relative "clip_likes"
|
3
|
+
require_relative "like"
|
4
|
+
require_relative "saves"
|
5
|
+
require_relative "list"
|
6
|
+
require_relative "favorite"
|
7
7
|
|
8
8
|
class Kippt::Clip
|
9
9
|
include Kippt::Resource
|
@@ -53,7 +53,7 @@ class Kippt::Clip
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def likes
|
56
|
-
Kippt::
|
56
|
+
Kippt::ClipLikes.new(client, self)
|
57
57
|
end
|
58
58
|
|
59
59
|
def all_likes_embedded?
|
@@ -81,10 +81,18 @@ class Kippt::Clip
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def like
|
84
|
-
Kippt::Like.new(
|
84
|
+
Kippt::Like.new(self, client).save
|
85
85
|
end
|
86
86
|
|
87
87
|
def unlike
|
88
|
-
Kippt::Like.new(
|
88
|
+
Kippt::Like.new(self, client).destroy
|
89
|
+
end
|
90
|
+
|
91
|
+
def favorite
|
92
|
+
Kippt::Favorite.new(self, client).save
|
93
|
+
end
|
94
|
+
|
95
|
+
def unfavorite
|
96
|
+
Kippt::Favorite.new(self, client).destroy
|
89
97
|
end
|
90
98
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative "read_collection_resource"
|
2
|
+
|
3
|
+
# For fetching clip's likes.
|
4
|
+
class Kippt::ClipLikes
|
5
|
+
include Kippt::ReadCollectionResource
|
6
|
+
|
7
|
+
attr_reader :clip
|
8
|
+
|
9
|
+
def initialize(client, clip)
|
10
|
+
@client = client
|
11
|
+
@clip = clip
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.valid_filter_parameters
|
15
|
+
[:limit, :offset]
|
16
|
+
end
|
17
|
+
|
18
|
+
def object_class
|
19
|
+
Kippt::User
|
20
|
+
end
|
21
|
+
|
22
|
+
def collection_class
|
23
|
+
Kippt::UserCollection
|
24
|
+
end
|
25
|
+
|
26
|
+
def base_uri
|
27
|
+
"clips/#{clip.id}/likes"
|
28
|
+
end
|
29
|
+
end
|
data/lib/kippt/clips.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require "kippt/clip_collection"
|
4
|
-
require "kippt/clip"
|
1
|
+
require_relative "clip_collection"
|
2
|
+
require_relative "clip"
|
5
3
|
|
4
|
+
# Generic clip proxy. Used to wrap endpoints that return clips as JSON.
|
6
5
|
class Kippt::Clips
|
7
6
|
include Kippt::CollectionResource
|
8
|
-
VALID_SEARCH_PARAMETERS = [:q, :list, :is_starred]
|
9
7
|
|
10
|
-
|
8
|
+
attr_reader :base_uri
|
9
|
+
|
10
|
+
def initialize(client, base_uri)
|
11
11
|
@client = client
|
12
|
+
@base_uri = base_uri
|
12
13
|
end
|
13
14
|
|
14
15
|
def self.valid_filter_parameters
|
15
|
-
[:limit, :offset, :is_read_later, :is_starred]
|
16
|
+
[:limit, :offset, :is_read_later, :is_starred, :url, :since, :include_data]
|
16
17
|
end
|
17
18
|
|
18
19
|
def object_class
|
@@ -22,34 +23,4 @@ class Kippt::Clips
|
|
22
23
|
def collection_class
|
23
24
|
Kippt::ClipCollection
|
24
25
|
end
|
25
|
-
|
26
|
-
def base_uri
|
27
|
-
"clips"
|
28
|
-
end
|
29
|
-
|
30
|
-
def feed
|
31
|
-
Kippt::ClipCollection.new(client.get("clips/feed").body, client)
|
32
|
-
end
|
33
|
-
|
34
|
-
def search(parameters)
|
35
|
-
if parameters.is_a?(String)
|
36
|
-
Kippt::ClipCollection.new(
|
37
|
-
client.get("search/clips", {:q => parameters}).body,
|
38
|
-
client)
|
39
|
-
else
|
40
|
-
validate_search_parameters(parameters)
|
41
|
-
|
42
|
-
Kippt::ClipCollection.new(
|
43
|
-
client.get("search/clips", parameters).body,
|
44
|
-
client)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def validate_search_parameters(parameters)
|
51
|
-
parameters.each do |key, value|
|
52
|
-
raise ArgumentError.new("'#{key}' is not a valid search parameter") unless VALID_SEARCH_PARAMETERS.include?(key)
|
53
|
-
end
|
54
|
-
end
|
55
26
|
end
|
data/lib/kippt/collection.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Kippt::Collection
|
2
2
|
include Enumerable
|
3
3
|
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :limit, :offset
|
5
5
|
|
6
6
|
def initialize(data, client = nil)
|
7
7
|
meta = data.fetch("meta") { {} }
|
@@ -9,7 +9,6 @@ module Kippt::Collection
|
|
9
9
|
@offset = meta.fetch("offset") { nil }
|
10
10
|
@next = meta.fetch("next") { nil }
|
11
11
|
@previous = meta.fetch("previous") { nil }
|
12
|
-
@total_count = meta.fetch("total_count") { nil }
|
13
12
|
|
14
13
|
@client = client
|
15
14
|
|
@@ -1,76 +1,60 @@
|
|
1
|
-
|
2
|
-
# For certain objects you can get extra data by giving option `include_data`.
|
3
|
-
# For example with clips you can add `include_data: "list,via"`.
|
4
|
-
def all(options = {})
|
5
|
-
validate_collection_options(options)
|
1
|
+
require_relative "read_collection_resource"
|
6
2
|
|
7
|
-
|
8
|
-
|
3
|
+
module Kippt
|
4
|
+
module CollectionResource
|
5
|
+
include Kippt::ReadCollectionResource
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
end
|
7
|
+
class SaveResponse
|
8
|
+
attr_reader :response
|
13
9
|
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
def initialize(response)
|
11
|
+
@response = response
|
12
|
+
end
|
17
13
|
|
18
|
-
|
19
|
-
|
20
|
-
def [](resource_id, options = {})
|
21
|
-
response = client.get("#{base_uri}/#{resource_id}", options)
|
22
|
-
if response.success?
|
23
|
-
object_class.new(response.body, client)
|
24
|
-
else
|
25
|
-
raise Kippt::APIError.new("Resource could not be loaded: #{response.body["message"]}")
|
26
|
-
end
|
27
|
-
end
|
14
|
+
def [](key)
|
15
|
+
return @save_response[key] if @save_response
|
28
16
|
|
29
|
-
|
17
|
+
@save_response = {success: response.success?, resource: response.body}
|
18
|
+
if response.body["message"]
|
19
|
+
@save_response[:error_message] = response.body["message"]
|
20
|
+
end
|
30
21
|
|
31
|
-
|
32
|
-
|
22
|
+
@save_response[key]
|
23
|
+
end
|
33
24
|
|
34
|
-
|
35
|
-
|
25
|
+
def success?
|
26
|
+
self[:success]
|
27
|
+
end
|
28
|
+
end
|
36
29
|
|
37
|
-
|
38
|
-
|
39
|
-
response = client.put("#{base_uri}/#{object.id}", :data => writable_parameters_from(object))
|
40
|
-
else
|
41
|
-
response = client.post("#{base_uri}", :data => writable_parameters_from(object))
|
30
|
+
def build(attributes = {})
|
31
|
+
object_class.new(attributes, client)
|
42
32
|
end
|
43
33
|
|
44
|
-
|
45
|
-
|
46
|
-
if response.body["message"]
|
47
|
-
save_response[:error_message] = response.body["message"]
|
34
|
+
def create(attributes = {})
|
35
|
+
build(attributes).save
|
48
36
|
end
|
49
37
|
|
50
|
-
|
51
|
-
|
38
|
+
def save_resource(object)
|
39
|
+
if object.id
|
40
|
+
response = client.put("#{base_uri}/#{object.id}", :data => writable_parameters_from(object))
|
41
|
+
else
|
42
|
+
response = client.post("#{base_uri}", :data => writable_parameters_from(object))
|
43
|
+
end
|
52
44
|
|
53
|
-
|
54
|
-
if resource.id
|
55
|
-
client.delete("#{base_uri}/#{resource.id}").success?
|
45
|
+
SaveResponse.new(response)
|
56
46
|
end
|
57
|
-
end
|
58
47
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
options.each do |key, _|
|
63
|
-
unless self.class.valid_filter_parameters.include?(key)
|
64
|
-
raise ArgumentError.new("Unrecognized argument: #{key}")
|
48
|
+
def destroy_resource(resource)
|
49
|
+
if resource.id
|
50
|
+
client.delete("#{base_uri}/#{resource.id}").success?
|
65
51
|
end
|
66
52
|
end
|
67
|
-
end
|
68
53
|
|
69
|
-
|
70
|
-
resource.writable_attributes_hash
|
71
|
-
end
|
54
|
+
private
|
72
55
|
|
73
|
-
|
74
|
-
|
56
|
+
def writable_parameters_from(resource)
|
57
|
+
resource.writable_attributes_hash
|
58
|
+
end
|
75
59
|
end
|
76
60
|
end
|