diff --git a/lib/instapaper/bookmark.rb b/lib/instapaper/bookmark.rb index 1e5c432..f9c07f6 100644 --- a/lib/instapaper/bookmark.rb +++ b/lib/instapaper/bookmark.rb @@ -13,8 +13,8 @@ module Instapaper attribute? :description, Types::String attribute? :instapaper_hash, Types::String attribute? :private_source, Types::String - attribute? :progress_timestamp, Types::Integer.optional - attribute? :time, Types::Integer.optional + attribute? :progress_timestamp, Types::UnixTime + attribute? :time, Types::UnixTime attribute? :progress, Types::StringOrInteger attribute? :starred, Types::StringOrInteger end diff --git a/lib/instapaper/highlight.rb b/lib/instapaper/highlight.rb index 2f82762..09bb1a9 100644 --- a/lib/instapaper/highlight.rb +++ b/lib/instapaper/highlight.rb @@ -11,6 +11,6 @@ module Instapaper attribute :bookmark_id, Types::Integer attribute :text, Types::String attribute :position, Types::Integer - attribute :time, Types::Integer.optional + attribute :time, Types::UnixTime end end diff --git a/lib/instapaper/types.rb b/lib/instapaper/types.rb index 2781b5c..ce65c4b 100644 --- a/lib/instapaper/types.rb +++ b/lib/instapaper/types.rb @@ -18,5 +18,17 @@ module Instapaper !!value end end + + # Converts Unix timestamps to Time objects + UnixTime = Types::Time.constructor do |value| + case value + when ::Time + value + when nil + nil + else + ::Time.at(value.to_i) + end + end end end