Class: Pocket::Article
- Inherits:
-
Object
- Object
- Pocket::Article
- Defined in:
- lib/pocket/article.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #article? ⇒ Boolean
- #authors ⇒ Object
- #domain_metadata ⇒ Object
- #excerpt ⇒ Object
- #favorite? ⇒ Boolean
- #favorited? ⇒ Boolean
- #given_title ⇒ Object
- #given_url ⇒ Object
- #has_image? ⇒ Boolean
- #has_video? ⇒ Boolean
- #image? ⇒ Boolean
-
#initialize(response) ⇒ Article
constructor
A new instance of Article.
- #item_id ⇒ Object
- #read? ⇒ Boolean
- #read_url ⇒ Object
- #resolved_id ⇒ Object
- #resolved_title ⇒ Object
- #resolved_url ⇒ Object
- #status ⇒ Object
- #tags ⇒ Object
- #thumbnail ⇒ Object
- #time_added ⇒ Object
- #time_favorited ⇒ Object
- #time_read ⇒ Object
- #time_to_read ⇒ Object
- #time_to_read_category ⇒ Object
- #time_updated ⇒ Object
- #video? ⇒ Boolean
- #word_count ⇒ Object
Constructor Details
#initialize(response) ⇒ Article
Returns a new instance of Article.
7 8 9 |
# File 'lib/pocket/article.rb', line 7 def initialize(response) @response = response end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/pocket/article.rb', line 5 def response @response end |
Class Method Details
.from_json(json_string) ⇒ Object
11 12 13 |
# File 'lib/pocket/article.rb', line 11 def self.from_json(json_string) new(JSON.parse(json_string)) end |
Instance Method Details
#article? ⇒ Boolean
48 49 50 51 |
# File 'lib/pocket/article.rb', line 48 def article? return false unless response["is_article"] Integer(response.fetch("is_article")) == 1 end |
#authors ⇒ Object
120 121 122 |
# File 'lib/pocket/article.rb', line 120 def Hash(response["authors"]).values.map { |value| Pocket::Author.new(value) } end |
#domain_metadata ⇒ Object
124 125 126 127 |
# File 'lib/pocket/article.rb', line 124 def return nil unless response["domain_metadata"] Pocket::DomainMetadata.new(response["domain_metadata"]) end |
#excerpt ⇒ Object
43 44 45 46 |
# File 'lib/pocket/article.rb', line 43 def excerpt return nil unless response["excerpt"] response.fetch("excerpt") end |
#favorite? ⇒ Boolean
35 36 37 |
# File 'lib/pocket/article.rb', line 35 def favorite? Integer(response.fetch("favorite")) == 1 end |
#favorited? ⇒ Boolean
98 99 100 |
# File 'lib/pocket/article.rb', line 98 def favorited? Integer(response["time_favorited"]) > 0 end |
#given_title ⇒ Object
27 28 29 |
# File 'lib/pocket/article.rb', line 27 def given_title response.fetch("given_title") end |
#given_url ⇒ Object
19 20 21 |
# File 'lib/pocket/article.rb', line 19 def given_url response.fetch("given_url") end |
#has_image? ⇒ Boolean
53 54 55 |
# File 'lib/pocket/article.rb', line 53 def has_image? Integer(response.fetch("has_image")) == 1 end |
#has_video? ⇒ Boolean
61 62 63 |
# File 'lib/pocket/article.rb', line 61 def has_video? Integer(response.fetch("has_video")) == 1 end |
#image? ⇒ Boolean
57 58 59 |
# File 'lib/pocket/article.rb', line 57 def image? Integer(response.fetch("has_image")) == 2 end |
#item_id ⇒ Object
15 16 17 |
# File 'lib/pocket/article.rb', line 15 def item_id Integer(response.fetch("item_id")) end |
#read? ⇒ Boolean
108 109 110 |
# File 'lib/pocket/article.rb', line 108 def read? Integer(response["time_read"]) > 0 end |
#read_url ⇒ Object
112 113 114 |
# File 'lib/pocket/article.rb', line 112 def read_url "https://getpocket.com/read/#{item_id}" end |
#resolved_id ⇒ Object
74 75 76 |
# File 'lib/pocket/article.rb', line 74 def resolved_id Integer(response.fetch("resolved_id")) end |
#resolved_title ⇒ Object
31 32 33 |
# File 'lib/pocket/article.rb', line 31 def resolved_title response.fetch("resolved_title", nil) end |
#resolved_url ⇒ Object
23 24 25 |
# File 'lib/pocket/article.rb', line 23 def resolved_url response.fetch("resolved_url", nil) end |
#status ⇒ Object
39 40 41 |
# File 'lib/pocket/article.rb', line 39 def status Integer(response.fetch("status")) end |
#tags ⇒ Object
116 117 118 |
# File 'lib/pocket/article.rb', line 116 def Hash(response["tags"]).values.map { |tag| tag["tag"] } end |
#thumbnail ⇒ Object
78 79 80 |
# File 'lib/pocket/article.rb', line 78 def thumbnail response.fetch("top_image_url", "") end |
#time_added ⇒ Object
82 83 84 85 |
# File 'lib/pocket/article.rb', line 82 def time_added return nil unless response["time_added"] Time.at(Integer(response["time_added"])).utc end |
#time_favorited ⇒ Object
102 103 104 105 106 |
# File 'lib/pocket/article.rb', line 102 def time_favorited return nil unless response["time_favorited"] return nil if response["time_favorited"] == "0" Time.at(Integer(response["time_favorited"])).utc end |
#time_read ⇒ Object
92 93 94 95 96 |
# File 'lib/pocket/article.rb', line 92 def time_read return nil unless response["time_read"] return nil if response["time_read"] == "0" Time.at(Integer(response["time_read"])).utc end |
#time_to_read ⇒ Object
129 130 131 132 133 |
# File 'lib/pocket/article.rb', line 129 def time_to_read return nil unless response["time_to_read"] return nil if response["time_to_read"] == 0 response.fetch("time_to_read") end |
#time_to_read_category ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/pocket/article.rb', line 135 def time_to_read_category return nil if time_to_read.nil? if time_to_read >= 21 "very_long" elsif time_to_read >= 11 "long" elsif time_to_read >= 6 "medium" else "quick" end end |
#time_updated ⇒ Object
87 88 89 90 |
# File 'lib/pocket/article.rb', line 87 def time_updated return nil unless response["time_updated"] Time.at(Integer(response["time_updated"])).utc end |
#video? ⇒ Boolean
65 66 67 |
# File 'lib/pocket/article.rb', line 65 def video? Integer(response.fetch("has_video")) == 2 end |
#word_count ⇒ Object
69 70 71 72 |
# File 'lib/pocket/article.rb', line 69 def word_count return nil unless response["word_count"] Integer(response.fetch("word_count")) end |