update attribute types for bookmark model

the `hash` attribute has been renamed to `instapaper_hash` as the use of
`hash` collides with equalizer's implementation and results in a
StackLevelError
This commit is contained in:
stve 2015-08-30 22:52:30 -04:00
parent 26288c458b
commit 770a722c09
2 changed files with 17 additions and 10 deletions

View file

@ -5,17 +5,17 @@ module Instapaper
include Virtus.value_object include Virtus.value_object
values do values do
attribute :type, String attribute :instapaper_hash, String
attribute :bookmark_id, String
attribute :url, String
attribute :title, String
attribute :description, String attribute :description, String
attribute :time, String attribute :bookmark_id, Integer
attribute :starred, String
attribute :private_source, String attribute :private_source, String
attribute :hash, String attribute :title, String
attribute :url, String
attribute :progress_timestamp, DateTime
attribute :time, DateTime
attribute :progress, String attribute :progress, String
attribute :progress_timestamp, String attribute :starred, String
attribute :type, String
end end
end end
end end

View file

@ -18,7 +18,7 @@ module Instapaper
# @param klass [Class] # @param klass [Class]
def perform_request_with_objects(request_method, path, options, klass) def perform_request_with_objects(request_method, path, options, klass)
perform_request(request_method, path, options).collect do |element| perform_request(request_method, path, options).collect do |element|
klass.new(element) klass.new(coerce_hash(element))
end end
end end
@ -36,7 +36,7 @@ module Instapaper
def perform_request_with_object(request_method, path, options, klass) def perform_request_with_object(request_method, path, options, klass)
response = perform_request(request_method, path, options) response = perform_request(request_method, path, options)
response = response.is_a?(Array) ? response.first : response response = response.is_a?(Array) ? response.first : response
klass.new(response) klass.new(coerce_hash(response))
end end
# @param path [String] # @param path [String]
@ -48,6 +48,13 @@ module Instapaper
def perform_request(method, path, options) def perform_request(method, path, options)
Instapaper::HTTP::Request.new(self, method, path, options).perform Instapaper::HTTP::Request.new(self, method, path, options).perform
end end
def coerce_hash(response)
if response.key?('hash')
response['instapaper_hash'] = response.delete('hash')
end
response
end
end end
end end
end end