From d57d1883f35662655dc9cf51ebb2cb11168c99df Mon Sep 17 00:00:00 2001 From: stve Date: Tue, 17 Feb 2015 13:23:31 -0500 Subject: [PATCH] switch from values to virtus objects --- instapaper.gemspec | 2 +- lib/instapaper/bookmark.rb | 19 +++++++++++++++++-- lib/instapaper/folder.rb | 13 +++++++++++-- lib/instapaper/highlight.rb | 14 ++++++++++++-- lib/instapaper/http/utils.rb | 4 ++-- lib/instapaper/meta.rb | 9 +++++++-- lib/instapaper/object.rb | 4 ++-- lib/instapaper/user.rb | 12 ++++++++++-- 8 files changed, 62 insertions(+), 15 deletions(-) diff --git a/instapaper.gemspec b/instapaper.gemspec index 0bb4f74..f241cb3 100644 --- a/instapaper.gemspec +++ b/instapaper.gemspec @@ -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" diff --git a/lib/instapaper/bookmark.rb b/lib/instapaper/bookmark.rb index 2a56b7e..4d15e6b 100644 --- a/lib/instapaper/bookmark.rb +++ b/lib/instapaper/bookmark.rb @@ -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 diff --git a/lib/instapaper/folder.rb b/lib/instapaper/folder.rb index c554375..99a61f2 100644 --- a/lib/instapaper/folder.rb +++ b/lib/instapaper/folder.rb @@ -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 diff --git a/lib/instapaper/highlight.rb b/lib/instapaper/highlight.rb index 3290c86..4f363af 100644 --- a/lib/instapaper/highlight.rb +++ b/lib/instapaper/highlight.rb @@ -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 diff --git a/lib/instapaper/http/utils.rb b/lib/instapaper/http/utils.rb index 90cb68f..a9b9af0 100644 --- a/lib/instapaper/http/utils.rb +++ b/lib/instapaper/http/utils.rb @@ -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] diff --git a/lib/instapaper/meta.rb b/lib/instapaper/meta.rb index 898219c..eee144e 100644 --- a/lib/instapaper/meta.rb +++ b/lib/instapaper/meta.rb @@ -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 diff --git a/lib/instapaper/object.rb b/lib/instapaper/object.rb index 0a4fc82..dbccfd1 100644 --- a/lib/instapaper/object.rb +++ b/lib/instapaper/object.rb @@ -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 diff --git a/lib/instapaper/user.rb b/lib/instapaper/user.rb index 51c45fb..3fb9be3 100644 --- a/lib/instapaper/user.rb +++ b/lib/instapaper/user.rb @@ -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