pocket-api 0.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.
- checksums.yaml +7 -0
- data/LICENSE.md +20 -0
- data/README.md +159 -0
- data/lib/pocket_api.rb +13 -0
- data/lib/pocket_api/client.rb +15 -0
- data/lib/pocket_api/collection.rb +36 -0
- data/lib/pocket_api/configurable.rb +10 -0
- data/lib/pocket_api/item.rb +40 -0
- data/lib/pocket_api/version.rb +17 -0
- data/pocket-api.gemspec +20 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a617b75466441efd28d35e75b2b799a7114292b0
|
4
|
+
data.tar.gz: 0e34bef396c56db192c38d0650009341e41ef525
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75dd4d2bc98ab42039abf647f9a8a287bb193a8817f282fba6841941a2af4ed417fed2a01c431d58296fd6a532e22d33e451e996ec6c278e8e4a1cf82d9e7711
|
7
|
+
data.tar.gz: 8ffb2b62d7b6efb1744db28055eac59108d18cf3c6a3f43c5919ace0582ac1985d03c6a3fe1edf811e5533d47cebcd7f693925a2b87477f5f3de1921e0b99f59
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Tse-Lin Chu (Wayne Chu)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
# Pocket Api
|
2
|
+
|
3
|
+
Non-official Ruby wrapper for [Pocket API](https://getpocket.com/developer/)
|
4
|
+
|
5
|
+
|
6
|
+
## Install
|
7
|
+
|
8
|
+
```
|
9
|
+
gem install pocket-api
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
### Configuration
|
15
|
+
|
16
|
+
```rb
|
17
|
+
PocketAPI.configure do |config|
|
18
|
+
config.consumer_key = 'consumer-key'
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
### Fetch Items (TODO, priority=1)
|
23
|
+
|
24
|
+
#### Make request
|
25
|
+
|
26
|
+
```rb
|
27
|
+
access_token = "UserAccessToken"
|
28
|
+
client = PocketAPI::Client.new(access_token)
|
29
|
+
items = client.retrieve({ detailType: "simple" }) #=> returns Collection of Items
|
30
|
+
```
|
31
|
+
|
32
|
+
#### Play with response
|
33
|
+
|
34
|
+
```rb
|
35
|
+
items.unread #=> Returns PocketAPI::Item Collection with only unread items
|
36
|
+
items.archived #=> Returns PocketAPI::Item Collection with only archived items
|
37
|
+
items.deleted #=> Returns PocketAPI::Item Collection with only deleted items
|
38
|
+
items.where(contentType: "article") #=> Returns PocketAPI::Item Collection with only items tagged as `contentType == "article"`, etc...
|
39
|
+
item.tags #=> Returns PocketAPI::Tag Collection
|
40
|
+
item.authors #=> Returns PocketAPI::Auther Collection
|
41
|
+
item.images #=> Returns PocketAPI::Image Collection
|
42
|
+
item.videos #=> Returns PocketAPI::Video Collection
|
43
|
+
```
|
44
|
+
|
45
|
+
### Create Item (TODO, priority=2)
|
46
|
+
|
47
|
+
```rb
|
48
|
+
PocketAPI::Item.create!(params)
|
49
|
+
#=> PocketAPI::Item
|
50
|
+
```
|
51
|
+
|
52
|
+
### Update Item (TODO, priority=3)
|
53
|
+
|
54
|
+
#### Basic Usage
|
55
|
+
|
56
|
+
follow [https://getpocket.com/developer/docs/v3/modify](https://getpocket.com/developer/docs/v3/modify)
|
57
|
+
|
58
|
+
```rb
|
59
|
+
params = {
|
60
|
+
action: "archive",
|
61
|
+
item_id: "229279689",
|
62
|
+
time: Time.now
|
63
|
+
}
|
64
|
+
item.update!(params)
|
65
|
+
# => true
|
66
|
+
```
|
67
|
+
|
68
|
+
#### Advance Usage
|
69
|
+
|
70
|
+
```rb
|
71
|
+
item.archive!(time=nil)
|
72
|
+
# => true
|
73
|
+
|
74
|
+
item.readd!(time=nil)
|
75
|
+
# => true
|
76
|
+
|
77
|
+
item.favorite!(time=nil)
|
78
|
+
# => true
|
79
|
+
|
80
|
+
item.unfavorite!(time=nil)
|
81
|
+
# => true
|
82
|
+
|
83
|
+
item.delete!(time=nil)
|
84
|
+
# => true
|
85
|
+
|
86
|
+
item.tags.remove!(['first', 'second'])
|
87
|
+
# => true
|
88
|
+
|
89
|
+
item.tags.replace!(['first', 'second'])
|
90
|
+
# => true
|
91
|
+
|
92
|
+
item.tags.clear!(['first', 'second'])
|
93
|
+
# => true
|
94
|
+
|
95
|
+
item.tags.rename!(old_tag, new_tag)
|
96
|
+
# => true
|
97
|
+
|
98
|
+
tag = item.tags.first
|
99
|
+
tag.rename!('haha')
|
100
|
+
# => true
|
101
|
+
```
|
102
|
+
|
103
|
+
### Errors (TODO, priority=unknown)
|
104
|
+
|
105
|
+
[https://getpocket.com/developer/docs/errors](https://getpocket.com/developer/docs/errors)
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
## Development
|
110
|
+
|
111
|
+
First, Make sure you installed ruby and bundler, and then follow steps below:
|
112
|
+
|
113
|
+
```sh
|
114
|
+
git clone https://github.com/wayne5540/pocket_api pocket_api
|
115
|
+
cd pocket_api
|
116
|
+
bundle install
|
117
|
+
```
|
118
|
+
|
119
|
+
### Autoatically run test in shell
|
120
|
+
|
121
|
+
```sh
|
122
|
+
bundle exec guard
|
123
|
+
```
|
124
|
+
|
125
|
+
### Test manually
|
126
|
+
|
127
|
+
```sh
|
128
|
+
bundle exec rspec
|
129
|
+
```
|
130
|
+
|
131
|
+
### Run locally
|
132
|
+
|
133
|
+
```sh
|
134
|
+
gem build build pocket_api.gemspec
|
135
|
+
# =>
|
136
|
+
# Successfully built RubyGem
|
137
|
+
# Name: pocket_api
|
138
|
+
# Version: 0.0.0
|
139
|
+
# File: pocket_api-0.0.0.gem
|
140
|
+
gem install pocket_api-0.0.0.gem
|
141
|
+
irb
|
142
|
+
```
|
143
|
+
|
144
|
+
then
|
145
|
+
|
146
|
+
```rb
|
147
|
+
retuire 'pocket_api'
|
148
|
+
# => true
|
149
|
+
```
|
150
|
+
|
151
|
+
## TODO or not TODO, that is the question...
|
152
|
+
|
153
|
+
* Support [limit header](https://getpocket.com/developer/docs/errors)
|
154
|
+
* Support [Authentication](https://getpocket.com/developer/docs/authentication)
|
155
|
+
* Remove pocket-ruby dependency or add test for it.
|
156
|
+
|
157
|
+
## License
|
158
|
+
|
159
|
+
See [LICENSE](LICENSE.md)
|
data/lib/pocket_api.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'pocket_api/configurable'
|
2
|
+
require 'pocket_api/item'
|
3
|
+
require 'pocket_api/collection'
|
4
|
+
require 'pocket_api/client'
|
5
|
+
|
6
|
+
module PocketAPI
|
7
|
+
class Error < StandardError; end
|
8
|
+
class InvalidAttributeError < Error; end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
include PocketAPI::Configurable
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PocketAPI
|
2
|
+
class Client
|
3
|
+
require 'pocket-ruby'
|
4
|
+
|
5
|
+
def initialize(access_token)
|
6
|
+
@client = Pocket.client(access_token: access_token)
|
7
|
+
end
|
8
|
+
|
9
|
+
def retrieve(options={})
|
10
|
+
info = @client.retrieve(options)
|
11
|
+
hashes = info['list'].values
|
12
|
+
Collection.new(Item, hashes)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module PocketAPI
|
2
|
+
class Collection
|
3
|
+
include Enumerable
|
4
|
+
attr_reader :klass
|
5
|
+
attr_accessor :data
|
6
|
+
|
7
|
+
def initialize(klass, hashes=[])
|
8
|
+
@klass = klass
|
9
|
+
@data = parse_hashes(hashes)
|
10
|
+
end
|
11
|
+
|
12
|
+
def each(&block)
|
13
|
+
@data.each{ |o| block.call(o) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def where(key_value)
|
17
|
+
key, value = key_value.first
|
18
|
+
|
19
|
+
raise InvalidAttributeError, "Invalid attribute: #{key}" unless @klass.method_defined? key.to_sym
|
20
|
+
|
21
|
+
dup_select { |o| o.send(key) == value }
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def dup_select(&block)
|
27
|
+
dup = self.dup
|
28
|
+
dup.data = select(&block)
|
29
|
+
dup
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse_hashes(hashes)
|
33
|
+
hashes.map { |hash| @klass.new(hash) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module PocketAPI
|
2
|
+
class Item
|
3
|
+
INTEGER_ATTRIBUTES = %w(favorite status word_count has_video has_image)
|
4
|
+
BOOLEAN_ATTRIBUTES = %w(is_article is_index)
|
5
|
+
TIME_ATTRIBUTES = %w(time_added time_updated time_read time_favorited)
|
6
|
+
|
7
|
+
def initialize(hash)
|
8
|
+
hash.each do |name, value|
|
9
|
+
self.class.send(:define_method, "#{name}=".to_sym) do |val|
|
10
|
+
instance_variable_set("@" + name.to_s, val)
|
11
|
+
end
|
12
|
+
|
13
|
+
self.class.send(:define_method, name.to_sym) do
|
14
|
+
instance_variable_get("@" + name.to_s)
|
15
|
+
end
|
16
|
+
|
17
|
+
self.send("#{name}=".to_sym, normalize(name, value))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def id
|
22
|
+
item_id
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def normalize(name, value)
|
28
|
+
case
|
29
|
+
when INTEGER_ATTRIBUTES.include?(name)
|
30
|
+
value.to_i
|
31
|
+
when BOOLEAN_ATTRIBUTES.include?(name)
|
32
|
+
value.to_i == 1
|
33
|
+
when TIME_ATTRIBUTES.include?(name)
|
34
|
+
value.to_i == 0 ? nil : Time.at(value.to_i)
|
35
|
+
else
|
36
|
+
value
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PocketAPI
|
2
|
+
# Current major release.
|
3
|
+
# @return [Integer]
|
4
|
+
MAJOR = 0
|
5
|
+
|
6
|
+
# Current minor release.
|
7
|
+
# @return [Integer]
|
8
|
+
MINOR = 0
|
9
|
+
|
10
|
+
# Current patch level.
|
11
|
+
# @return [Integer]
|
12
|
+
PATCH = 0
|
13
|
+
|
14
|
+
# Full release version.
|
15
|
+
# @return [String]
|
16
|
+
VERSION = [MAJOR, MINOR, PATCH].join('.').freeze
|
17
|
+
end
|
data/pocket-api.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'pocket_api/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.add_dependency 'pocket-ruby', '~> 0.0.6'
|
7
|
+
|
8
|
+
spec.name = 'pocket-api'
|
9
|
+
spec.version = PocketAPI::VERSION
|
10
|
+
spec.required_ruby_version = '>= 2.0.0'
|
11
|
+
spec.summary = 'Simple wrapper for the Pocket API'
|
12
|
+
spec.description = 'Simple wrapper for the Pocket API (Non-officially)'
|
13
|
+
spec.authors = ['Wayne Chu']
|
14
|
+
spec.email = 'wayne.5540@gmail.com'
|
15
|
+
spec.homepage = 'https://github.com/wayne5540/pocket_api'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
spec.files = %w(README.md LICENSE.md pocket-api.gemspec)
|
18
|
+
spec.files += Dir.glob("lib/**/*.rb")
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pocket-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wayne Chu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pocket-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.6
|
27
|
+
description: Simple wrapper for the Pocket API (Non-officially)
|
28
|
+
email: wayne.5540@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- LICENSE.md
|
34
|
+
- README.md
|
35
|
+
- lib/pocket_api.rb
|
36
|
+
- lib/pocket_api/client.rb
|
37
|
+
- lib/pocket_api/collection.rb
|
38
|
+
- lib/pocket_api/configurable.rb
|
39
|
+
- lib/pocket_api/item.rb
|
40
|
+
- lib/pocket_api/version.rb
|
41
|
+
- pocket-api.gemspec
|
42
|
+
homepage: https://github.com/wayne5540/pocket_api
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.0
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.6.6
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Simple wrapper for the Pocket API
|
66
|
+
test_files: []
|