./lib/animoto/resources/base.rb in animoto-0.1.1.beta1 vs ./lib/animoto/resources/base.rb in animoto-1.0.0
- old
+ new
@@ -1,9 +1,9 @@
module Animoto
module Resources
- # @abstract Set {#endpoint} and maybe override {Support::StandardEnvelope#unpack_standard_envelope} to subclass.
+ # @abstract Set {#endpoint} and maybe override {Support::StandardEnvelope::ClassMethods#unpack_standard_envelope} to subclass.
class Base
include Support::StandardEnvelope
# @overload endpoint(path)
# Sets the endpoint for this class. This is the URL where all requests related
@@ -32,11 +32,11 @@
# it assumes the hash you're passing is structured correctly and does no format checking
# at all, so if the hash is not in the "standard envelope", this method will most likely
# raise an error.
#
# @private
- # @param [Hash<String,Object>] body the deserialized response body
+ # @param [Hash{String=>Object}] body the deserialized response body
# @return [Resources::Base] an instance of this class
def self.load body
new unpack_standard_envelope(body)
end
@@ -50,11 +50,11 @@
# client = Animoto::Client.new
# storyboard1 = Animoto::Resources::Storyboard.new :url => "https://api.animoto.com/storyboards/1"
# storyboard2 = client.find! Animoto::Resources::Storyboard, "https://api.animoto.com/storyboards/1"
# storyboard1.equal?(storyboard2) # => true
#
- # @param [Hash<String,Object>] attributes a hash of attributes for this resource
+ # @param [Hash{String=>Object}] attributes a hash of attributes for this resource
# @return [Resources::Base] either a new Resource instance, or an existing one with updated
# attributes
alias_method :original_new, :new
def new attributes = {}
if attributes[:url] && instances[attributes[:url]]
@@ -77,42 +77,42 @@
private
# Returns (or vivifies) the identity map for this class.
#
- # @return [Hash<String,Resources::Base>] the identity map
+ # @return [Hash{String=>Resources::Base}] the identity map
def instances
@instances ||= {}
end
end
attr_reader :url, :errors
# Creates a new resource.
#
- # @param [Hash<String,Object>] attributes hash of attributes for this resource
+ # @param [Hash{String=>Object}] attributes hash of attributes for this resource
# @see #instantiate
# @return [Resources::Base] the resource
def initialize attributes = {}
instantiate attributes
end
# Update this instance with new attributes from the response body.
#
# @private
- # @param [Hash<String,Object>] body deserialized from a response body
+ # @param [Hash{String=>Object}] body deserialized from a response body
# @return [self] this instance, updated
def load body = {}
instantiate unpack_standard_envelope(body)
end
# Since resources can be created a number of different ways, this method does
# the actual attribute setting for a resource, acting much like a public version
# of #initialize.
#
# @private
- # @param [Hash<Symbol,Object>] attributes hash of attributes for this resource
+ # @param [Hash{Symbol=>Object}] attributes hash of attributes for this resource
# @return [self] this instance
def instantiate attributes = {}
@errors = (attributes[:errors] || []).collect { |e| wrap_error e }
@url = attributes[:url]
self.class.register(self) if @url
@@ -121,10 +121,10 @@
private
# Turns an error from a response body into a Ruby object.
#
- # @param [Hash<String,Object>] error the error "object" from a response body
+ # @param [Hash{String=>Object}] error the error "object" from a response body
# @return [Animoto::Error] a Ruby error object
def wrap_error error
Animoto::Error.new error['message']
end
end
\ No newline at end of file