pocket-ruby 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23523be975e32aab67f1eb9eae5bd8a9a23032e7b9e32dd16c7ebd54829dcfd5
4
- data.tar.gz: f340f0180bffcee80c64321392205ad43439434a12171b670baab1b7c30eb56f
3
+ metadata.gz: 4d7b6ddfe9a36ea0ec8e2f9cf289882025e83f1a864edc99df3bc1deaf2aef0e
4
+ data.tar.gz: 7b7e5197505e43aaf60d59187a0c453ace474e317aa135b197d4ec1883c159bc
5
5
  SHA512:
6
- metadata.gz: 9c639bdd2f2637e55642da60be20d03e3e8e4ea7bc87b2da4ebf5951d8f99d7717e3d7608e3ec66c79a1e7b0bdf49f4c673a95590ffa34bd54baf4f0b5293b8a
7
- data.tar.gz: 03f454e5471e90266dce757748b7a3fefad8adcfefd954bae3e2bd52f687dc922c7d0d7911ef02e85b94344f733803b6aea2c5dbfb50dfe45c2a0f8679ed81e0
6
+ metadata.gz: 1e39623af247edd6aaf4e7d6a3ea932ec81b770cf9807b63991af63b764be306934e3a50bbdfb3ff8dfda555e8ccc5e14d8fb97edefb118749e2fe02818a0239
7
+ data.tar.gz: ac0a9a2fba76645632bc045f785ac21ed1cf4687a8a873320ab73debce00a95d79415986e9a267855e34662afd4aacf6f9614648cd7ceb2b7e608efea6c71067
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2021-04-11
4
+
5
+ - Hand article with missing `excerpt`. ([#63](https://github.com/turadg/pocket-ruby/pull/63))
6
+ - Add support for `domain_metadata` in Article response. ([#57](https://github.com/turadg/pocket-ruby/pull/57))
7
+ - Add `time_to_read` field to `Pocket::Article`.
8
+ - Return nil for `word_count` if not present ([#48](https://github.com/turadg/pocket-ruby/pull/48))
9
+
3
10
  ## [0.2.1] - 2021-04-10
4
11
 
5
12
  - Return nil if `time_read` or `time_favorited` is '0' in the API response. Otherwise, this may be interpreted the Unix epoch (1970-01-01). ([#46](https://github.com/turadg/pocket-ruby/pull/46))
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pocket-ruby (0.2.1)
4
+ pocket-ruby (0.3.0)
5
5
  faraday (>= 0.7)
6
6
  faraday_middleware
7
7
  multi_json (~> 1.0, >= 1.0.3)
data/README.md CHANGED
@@ -3,11 +3,11 @@ pocket-ruby
3
3
 
4
4
  [![Code Climate](https://codeclimate.com/github/turadg/pocket-ruby.png)](https://codeclimate.com/github/turadg/pocket-ruby) [![Gem Version](https://badge.fury.io/rb/pocket-ruby.png)](http://badge.fury.io/rb/pocket-ruby)
5
5
 
6
- Ruby API for v3 of the [Pocket API](http://getpocket.com/developer/docs/overview) (formerly Read It Later)
6
+ Ruby API for v3 of the [Pocket API](http://getpocket.com/developer/docs/overview) (formerly Read It Later)
7
7
 
8
8
  # Usage
9
9
 
10
- Just clone the repo here and refer to the demo-server.rb file for examples on how to interact with the Pocket API.
10
+ Just clone the repo here and refer to the demo-server.rb file for examples on how to interact with the Pocket API.
11
11
 
12
12
  ```sh
13
13
  git clone
@@ -16,6 +16,24 @@ Just clone the repo here and refer to the demo-server.rb file for examples on ho
16
16
  ruby demo-server.rb
17
17
  ```
18
18
 
19
+ *Note:* Changes to the `demo-server.rb` will require a restart to take effect (or you can use [rerun](https://github.com/alexch/rerun)).
20
+
19
21
  Pocket-Ruby can be installed via the gem, ```gem install pocket-ruby```
20
22
 
21
23
  Or via bundler, ```gem 'pocket-ruby'```
24
+
25
+ ## Pocket API Notes
26
+
27
+ Below are some aspects of the Pocket API that aren't covered in the official documentation, or that have been observed:
28
+
29
+ * For very long articles, the maximum reported `word_count` is 65535, even if the article is longer.
30
+ * If a `count` isn't specified, the `Retreive` call will return maximum of 5000 items.
31
+ * The API response may contain a number of undocumented fields, including:
32
+ * `domain_metadata`
33
+ * `amp_url`
34
+ * `listen_duration_estimate`
35
+ * `time_to_read`
36
+ * `sort_id`
37
+ * `lang` ([ISO_639-1](https://en.wikipedia.org/wiki/ISO_639-1)?)
38
+ * Every integer value is returned as a string, *except* for `time_to_read`, `listen_duration_estimate` and `sort_id`.
39
+ * The `time_to_read` is in minutes, but `listen_duration_estimate` is in seconds.
data/lib/pocket-ruby.rb CHANGED
@@ -4,6 +4,7 @@ require File.expand_path("../pocket/api", __FILE__)
4
4
  require File.expand_path("../pocket/client", __FILE__)
5
5
  require File.expand_path("../pocket/article", __FILE__)
6
6
  require File.expand_path("../pocket/author", __FILE__)
7
+ require File.expand_path("../pocket/domain_metadata", __FILE__)
7
8
 
8
9
  module Pocket
9
10
  extend Configuration
@@ -41,6 +41,7 @@ module Pocket
41
41
  end
42
42
 
43
43
  def excerpt
44
+ return nil unless response["excerpt"]
44
45
  response.fetch("excerpt")
45
46
  end
46
47
 
@@ -65,6 +66,7 @@ module Pocket
65
66
  end
66
67
 
67
68
  def word_count
69
+ return nil unless response["word_count"]
68
70
  Integer(response.fetch("word_count"))
69
71
  end
70
72
 
@@ -117,5 +119,30 @@ module Pocket
117
119
  def authors
118
120
  Hash(response["authors"]).values.map { |value| Pocket::Author.new(value) }
119
121
  end
122
+
123
+ def domain_metadata
124
+ return nil unless response["domain_metadata"]
125
+ Pocket::DomainMetadata.new(response["domain_metadata"])
126
+ end
127
+
128
+ def time_to_read
129
+ return nil unless response["time_to_read"]
130
+ return nil if response["time_to_read"] == 0
131
+ response.fetch("time_to_read")
132
+ end
133
+
134
+ def time_to_read_category
135
+ return nil if time_to_read.nil?
136
+
137
+ if time_to_read >= 21
138
+ "very_long"
139
+ elsif time_to_read >= 11
140
+ "long"
141
+ elsif time_to_read >= 6
142
+ "medium"
143
+ else
144
+ "quick"
145
+ end
146
+ end
120
147
  end
121
148
  end
@@ -0,0 +1,23 @@
1
+ module Pocket
2
+ class DomainMetadata
3
+ def initialize(response)
4
+ @response = response
5
+ end
6
+
7
+ def name
8
+ response.fetch("name")
9
+ end
10
+
11
+ def logo
12
+ response.fetch("logo")
13
+ end
14
+
15
+ def greyscale_logo
16
+ response.fetch("greyscale_logo")
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :response
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Pocket
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -17,6 +17,7 @@
17
17
  "time_updated": "1617412993",
18
18
  "time_read": "1617412994",
19
19
  "time_favorited": "1617412995",
20
+ "time_to_read": 14,
20
21
  "images": {
21
22
  "1": {
22
23
  "item_id": "229279689",
@@ -56,5 +57,10 @@
56
57
  "name":"Stephen King",
57
58
  "url":"https://example.com/author"
58
59
  }
59
- }
60
+ },
61
+ "domain_metadata":{
62
+ "name": "The Verge",
63
+ "logo": "https://logo.clearbit.com/theverge.com?size=800",
64
+ "greyscale_logo": "https://logo.clearbit.com/theverge.com?size=800&greyscale=true"
65
+ }
60
66
  }
@@ -40,6 +40,11 @@ module Pocket
40
40
  assert_include article.excerpt, "list of things"
41
41
  end
42
42
 
43
+ test "excerpt is nil if field not present" do
44
+ parsed_response.delete("excerpt")
45
+ assert_nil article.excerpt
46
+ end
47
+
43
48
  test "article?" do
44
49
  assert article.article?
45
50
  end
@@ -64,6 +69,11 @@ module Pocket
64
69
  assert_equal 3197, article.word_count
65
70
  end
66
71
 
72
+ test "word_count is nil is field not present" do
73
+ parsed_response.delete("word_count")
74
+ assert_nil article.word_count
75
+ end
76
+
67
77
  test "resolved_id" do
68
78
  assert_equal 229279689, article.resolved_id
69
79
  end
@@ -152,6 +162,44 @@ module Pocket
152
162
  assert_equal [], article.authors
153
163
  end
154
164
 
165
+ test "time_to_read" do
166
+ assert_equal 14, article.time_to_read
167
+ end
168
+
169
+ test "time_to_read returns nil if field not present" do
170
+ parsed_response.delete("time_to_read")
171
+ assert_nil article.time_to_read
172
+ end
173
+
174
+ test "time_to_read returns nil if value is 0" do
175
+ parsed_response["time_to_read"] = 0
176
+ assert_nil article.time_to_read
177
+ end
178
+
179
+ test "time_to_read_category" do
180
+ parsed_response.delete("time_to_read")
181
+ assert_nil article.time_to_read_category
182
+
183
+ parsed_response["time_to_read"] = 0
184
+ assert_nil article.time_to_read_category
185
+
186
+ parsed_response["time_to_read"] = 25
187
+ assert_equal "very_long", article.time_to_read_category
188
+
189
+ parsed_response["time_to_read"] = 15
190
+ assert_equal "long", article.time_to_read_category
191
+
192
+ parsed_response["time_to_read"] = 8
193
+ assert_equal "medium", article.time_to_read_category
194
+
195
+ parsed_response["time_to_read"] = 3
196
+ assert_equal "quick", article.time_to_read_category
197
+ end
198
+
199
+ test "domain_metadata" do
200
+ assert_equal "The Verge", article.domain_metadata.name
201
+ end
202
+
155
203
  private
156
204
 
157
205
  def article
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pocket-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Turadg Aleahmad
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-04-10 00:00:00.000000000 Z
13
+ date: 2021-04-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sinatra
@@ -175,6 +175,7 @@ files:
175
175
  - lib/pocket/client/retrieve.rb
176
176
  - lib/pocket/configuration.rb
177
177
  - lib/pocket/connection.rb
178
+ - lib/pocket/domain_metadata.rb
178
179
  - lib/pocket/error.rb
179
180
  - lib/pocket/oauth.rb
180
181
  - lib/pocket/version.rb