pocket-api 0.0.0 → 0.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a617b75466441efd28d35e75b2b799a7114292b0
4
- data.tar.gz: 0e34bef396c56db192c38d0650009341e41ef525
3
+ metadata.gz: cf50bf32ff0bb64ed5851a1fdc668a060b07641d
4
+ data.tar.gz: fb5b93f2d445697f1f48addfaa06de1eec2a3246
5
5
  SHA512:
6
- metadata.gz: 75dd4d2bc98ab42039abf647f9a8a287bb193a8817f282fba6841941a2af4ed417fed2a01c431d58296fd6a532e22d33e451e996ec6c278e8e4a1cf82d9e7711
7
- data.tar.gz: 8ffb2b62d7b6efb1744db28055eac59108d18cf3c6a3f43c5919ace0582ac1985d03c6a3fe1edf811e5533d47cebcd7f693925a2b87477f5f3de1921e0b99f59
6
+ metadata.gz: 381eee908d0abfc267c1917e8033ae1c7d28ae61587fcf21f4f0b12fa4c0fa1c7c66593c1251d09b806427fab10dd0b5be7af2f826fe1f435a5d3ab032e081d1
7
+ data.tar.gz: 25d2c20a4d3997a405ed38635002cbc6c09f3f307c5a50ef11aebb4093292001cd1c891671f5e5fc0b2373aba34b156cbe283b9865fc8963c79f55ab4a1523e4
data/README.md CHANGED
@@ -19,27 +19,37 @@ PocketAPI.configure do |config|
19
19
  end
20
20
  ```
21
21
 
22
- ### Fetch Items (TODO, priority=1)
22
+ ### Fetch Items
23
23
 
24
- #### Make request
25
24
 
26
25
  ```rb
27
26
  access_token = "UserAccessToken"
28
27
  client = PocketAPI::Client.new(access_token)
29
28
  items = client.retrieve({ detailType: "simple" }) #=> returns Collection of Items
29
+
30
+ article_items = items.where(is_article: true)
31
+ item = article_items.first
32
+ item.is_article #=> true
33
+ item.status #=> 0
30
34
  ```
31
35
 
32
- #### Play with response
36
+ ## TODO Usage
37
+
38
+ ### Fetch Items (TODO, priority=1)
33
39
 
34
40
  ```rb
35
41
  items.unread #=> Returns PocketAPI::Item Collection with only unread items
36
42
  items.archived #=> Returns PocketAPI::Item Collection with only archived items
37
43
  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
44
  item.tags #=> Returns PocketAPI::Tag Collection
40
45
  item.authors #=> Returns PocketAPI::Auther Collection
41
46
  item.images #=> Returns PocketAPI::Image Collection
42
47
  item.videos #=> Returns PocketAPI::Video Collection
48
+
49
+ item.status #=> :unread
50
+ item.unread? #=> boolean
51
+ item.archived? #=> boolean
52
+ item.deleted? #=> boolean
43
53
  ```
44
54
 
45
55
  ### Create Item (TODO, priority=2)
@@ -8,7 +8,12 @@ module PocketAPI
8
8
 
9
9
  def retrieve(options={})
10
10
  info = @client.retrieve(options)
11
- hashes = info['list'].values
11
+ hashes = if info['list'].empty?
12
+ []
13
+ else
14
+ info['list'].values
15
+ end
16
+
12
17
  Collection.new(Item, hashes)
13
18
  end
14
19
  end
@@ -1,20 +1,22 @@
1
1
  module PocketAPI
2
2
  class Item
3
- INTEGER_ATTRIBUTES = %w(favorite status word_count has_video has_image)
3
+ INTEGER_ATTRIBUTES = %w(favorite status word_count has_video has_image sort_id)
4
4
  BOOLEAN_ATTRIBUTES = %w(is_article is_index)
5
5
  TIME_ATTRIBUTES = %w(time_added time_updated time_read time_favorited)
6
+ STRING_ATTRIBUTES = %w(item_id resolved_id given_url given_title resolved_title resolved_url excerpt)
7
+ ALL_ATTRIBUTES = INTEGER_ATTRIBUTES | BOOLEAN_ATTRIBUTES | TIME_ATTRIBUTES | STRING_ATTRIBUTES
6
8
 
7
9
  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)
10
+ ALL_ATTRIBUTES.each do |attr_name|
11
+ self.class.send(:define_method, "#{attr_name}=".to_sym) do |val|
12
+ instance_variable_set("@" + attr_name.to_s, val)
11
13
  end
12
14
 
13
- self.class.send(:define_method, name.to_sym) do
14
- instance_variable_get("@" + name.to_s)
15
+ self.class.send(:define_method, attr_name.to_sym) do
16
+ instance_variable_get("@" + attr_name.to_s)
15
17
  end
16
18
 
17
- self.send("#{name}=".to_sym, normalize(name, value))
19
+ self.send("#{attr_name}=".to_sym, normalize(attr_name, hash[attr_name]))
18
20
  end
19
21
  end
20
22
 
@@ -26,6 +28,8 @@ module PocketAPI
26
28
 
27
29
  def normalize(name, value)
28
30
  case
31
+ when value == nil
32
+ nil
29
33
  when INTEGER_ATTRIBUTES.include?(name)
30
34
  value.to_i
31
35
  when BOOLEAN_ATTRIBUTES.include?(name)
@@ -9,7 +9,7 @@ module PocketAPI
9
9
 
10
10
  # Current patch level.
11
11
  # @return [Integer]
12
- PATCH = 0
12
+ PATCH = 1
13
13
 
14
14
  # Full release version.
15
15
  # @return [String]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pocket-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wayne Chu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-17 00:00:00.000000000 Z
11
+ date: 2016-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pocket-ruby