Class: Pocket::Article

Inherits:
Object
  • Object
show all
Defined in:
lib/pocket/article.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#responseObject (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

Returns:



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

#authorsObject



120
121
122
# File 'lib/pocket/article.rb', line 120

def authors
  Hash(response["authors"]).values.map { |value| Pocket::Author.new(value) }
end

#domain_metadataObject



124
125
126
127
# File 'lib/pocket/article.rb', line 124

def 
  return nil unless response["domain_metadata"]
  Pocket::.new(response["domain_metadata"])
end

#excerptObject



43
44
45
46
# File 'lib/pocket/article.rb', line 43

def excerpt
  return nil unless response["excerpt"]
  response.fetch("excerpt")
end

#favorite?Boolean

Returns:



35
36
37
# File 'lib/pocket/article.rb', line 35

def favorite?
  Integer(response.fetch("favorite")) == 1
end

#favorited?Boolean

Returns:



98
99
100
# File 'lib/pocket/article.rb', line 98

def favorited?
  Integer(response["time_favorited"]) > 0
end

#given_titleObject



27
28
29
# File 'lib/pocket/article.rb', line 27

def given_title
  response.fetch("given_title")
end

#given_urlObject



19
20
21
# File 'lib/pocket/article.rb', line 19

def given_url
  response.fetch("given_url")
end

#has_image?Boolean

Returns:



53
54
55
# File 'lib/pocket/article.rb', line 53

def has_image?
  Integer(response.fetch("has_image")) == 1
end

#has_video?Boolean

Returns:



61
62
63
# File 'lib/pocket/article.rb', line 61

def has_video?
  Integer(response.fetch("has_video")) == 1
end

#image?Boolean

Returns:



57
58
59
# File 'lib/pocket/article.rb', line 57

def image?
  Integer(response.fetch("has_image")) == 2
end

#item_idObject



15
16
17
# File 'lib/pocket/article.rb', line 15

def item_id
  Integer(response.fetch("item_id"))
end

#read?Boolean

Returns:



108
109
110
# File 'lib/pocket/article.rb', line 108

def read?
  Integer(response["time_read"]) > 0
end

#read_urlObject



112
113
114
# File 'lib/pocket/article.rb', line 112

def read_url
  "https://getpocket.com/read/#{item_id}"
end

#resolved_idObject



74
75
76
# File 'lib/pocket/article.rb', line 74

def resolved_id
  Integer(response.fetch("resolved_id"))
end

#resolved_titleObject



31
32
33
# File 'lib/pocket/article.rb', line 31

def resolved_title
  response.fetch("resolved_title", nil)
end

#resolved_urlObject



23
24
25
# File 'lib/pocket/article.rb', line 23

def resolved_url
  response.fetch("resolved_url", nil)
end

#statusObject



39
40
41
# File 'lib/pocket/article.rb', line 39

def status
  Integer(response.fetch("status"))
end

#tagsObject



116
117
118
# File 'lib/pocket/article.rb', line 116

def tags
  Hash(response["tags"]).values.map { |tag| tag["tag"] }
end

#thumbnailObject



78
79
80
# File 'lib/pocket/article.rb', line 78

def thumbnail
  response.fetch("top_image_url", "")
end

#time_addedObject



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_favoritedObject



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_readObject



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_readObject



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_categoryObject



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_updatedObject



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

Returns:



65
66
67
# File 'lib/pocket/article.rb', line 65

def video?
  Integer(response.fetch("has_video")) == 2
end

#word_countObject



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