switch from values to virtus objects

This commit is contained in:
stve 2015-02-17 13:23:31 -05:00
parent 1bd5ce1728
commit d57d1883f3
8 changed files with 62 additions and 15 deletions

View file

@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'http', '~> 0.7.1'
spec.add_dependency 'multi_json', '~> 1'
spec.add_dependency 'simple_oauth'
spec.add_dependency 'values'
spec.add_dependency 'virtus'
spec.add_development_dependency 'bundler', '~> 1.0'
spec.author = 'Steve Agalloco'
spec.description = "Ruby Client for Instapaper's Full API"

View file

@ -1,6 +1,21 @@
require 'values'
require 'virtus'
module Instapaper
class Bookmark < Value.new(:type, :bookmark_id, :url, :title, :description, :time, :starred, :private_source, :hash, :progress, :progress_timestamp)
class Bookmark
include Virtus.value_object
values do
attribute :type, String
attribute :bookmark_id, String
attribute :url, String
attribute :title, String
attribute :description, String
attribute :time, String
attribute :starred, String
attribute :private_source, String
attribute :hash, String
attribute :progress, String
attribute :progress_timestamp, String
end
end
end

View file

@ -1,6 +1,15 @@
require 'values'
require 'virtus'
module Instapaper
class Folder < Value.new(:type, :folder_id, :title, :sync_to_mobile, :position)
class Folder
include Virtus.value_object
values do
attribute :type, String
attribute :folder_id, String
attribute :title, String
attribute :sync_to_mobile, String
attribute :position, String
end
end
end

View file

@ -1,6 +1,16 @@
require 'values'
require 'virtus'
module Instapaper
class Highlight < Value.new(:type, :highlight_id, :bookmark_id, :text, :position, :time)
class Highlight
include Virtus.value_object
values do
attribute :type, String
attribute :highlight_id, String
attribute :bookmark_id, String
attribute :text, String
attribute :position, String
attribute :time, String
end
end
end

View file

@ -19,7 +19,7 @@ module Instapaper
# @param klass [Class]
def perform_request_with_objects(request_method, path, options, klass)
perform_request(request_method, path, options).collect do |element|
klass.with(element)
klass.new(element)
end
end
@ -37,7 +37,7 @@ module Instapaper
def perform_request_with_object(request_method, path, options, klass)
response = perform_request(request_method, path, options)
response = response.is_a?(Array) ? response.first : response
klass.with(response)
klass.new(response)
end
# @param path [String]

View file

@ -1,6 +1,11 @@
require 'values'
require 'virtus'
module Instapaper
class Meta < Value.new(:type)
class Meta
include Virtus.value_object
values do
attribute :type, String
end
end
end

View file

@ -2,10 +2,10 @@ require 'instapaper/meta'
module Instapaper
class Object
def self.with(data)
def self.new(data)
type = data[:type]
type[0] = type[0].upcase
Instapaper.const_get(type).with(data)
Instapaper.const_get(type).new(data)
end
end
end

View file

@ -1,6 +1,14 @@
require 'values'
require 'virtus'
module Instapaper
class User < Value.new(:type, :user_id, :username, :subscription_is_active)
class User
include Virtus.value_object
values do
attribute :type, String
attribute :user_id, String
attribute :username, String
attribute :subscription_is_active, String
end
end
end