mirror of
https://github.com/samsonjs/instapaper.git
synced 2026-04-27 14:57:44 +00:00
switch from values to virtus objects
This commit is contained in:
parent
1bd5ce1728
commit
d57d1883f3
8 changed files with 62 additions and 15 deletions
|
|
@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
||||||
spec.add_dependency 'http', '~> 0.7.1'
|
spec.add_dependency 'http', '~> 0.7.1'
|
||||||
spec.add_dependency 'multi_json', '~> 1'
|
spec.add_dependency 'multi_json', '~> 1'
|
||||||
spec.add_dependency 'simple_oauth'
|
spec.add_dependency 'simple_oauth'
|
||||||
spec.add_dependency 'values'
|
spec.add_dependency 'virtus'
|
||||||
spec.add_development_dependency 'bundler', '~> 1.0'
|
spec.add_development_dependency 'bundler', '~> 1.0'
|
||||||
spec.author = 'Steve Agalloco'
|
spec.author = 'Steve Agalloco'
|
||||||
spec.description = "Ruby Client for Instapaper's Full API"
|
spec.description = "Ruby Client for Instapaper's Full API"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,21 @@
|
||||||
require 'values'
|
require 'virtus'
|
||||||
|
|
||||||
module Instapaper
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,15 @@
|
||||||
require 'values'
|
require 'virtus'
|
||||||
|
|
||||||
module Instapaper
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,16 @@
|
||||||
require 'values'
|
require 'virtus'
|
||||||
|
|
||||||
module Instapaper
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,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.with(element)
|
klass.new(element)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -37,7 +37,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.with(response)
|
klass.new(response)
|
||||||
end
|
end
|
||||||
|
|
||||||
# @param path [String]
|
# @param path [String]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
require 'values'
|
require 'virtus'
|
||||||
|
|
||||||
module Instapaper
|
module Instapaper
|
||||||
class Meta < Value.new(:type)
|
class Meta
|
||||||
|
include Virtus.value_object
|
||||||
|
|
||||||
|
values do
|
||||||
|
attribute :type, String
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ require 'instapaper/meta'
|
||||||
|
|
||||||
module Instapaper
|
module Instapaper
|
||||||
class Object
|
class Object
|
||||||
def self.with(data)
|
def self.new(data)
|
||||||
type = data[:type]
|
type = data[:type]
|
||||||
type[0] = type[0].upcase
|
type[0] = type[0].upcase
|
||||||
Instapaper.const_get(type).with(data)
|
Instapaper.const_get(type).new(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
require 'values'
|
require 'virtus'
|
||||||
|
|
||||||
module Instapaper
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue