Sha256: 810a44060267ea2feb8a6f6cbc626b772722b5f26b4e10c495fa75e7c31b44e3

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

module Smartfm::PublicContent

  def self.included(base)
    base.extend(ClassMethods)
    base.send(:include, InstanceMethods)
  end

  module ClassMethods
    def recent(params = {})
      hash = self.rest_client.recent(params)
      self.deserialize(hash) || []
    end

    def find(list_id, params = {})
      params[:id] = list_id
      hash = self.rest_client.find(params)
      self.deserialize(hash)
    end

    def matching(keyword, params = {})
      params[:keyword] = keyword
      hash = self.rest_client.matching(params)
      self.deserialize(hash) || []
    end

    def create(auth, params = {})
      self.new(params).save(auth)
    end

    def delete(obj_id)
      self.find(obj_id).delete
    end
  end

  module InstanceMethods
    def save(auth)
      result = self.rest_client.create(auth, self.to_post_data)
      case result
      when Hash
        self.deserialize(result)
      when String
        self.find(result)
      else
        true
      end
    end

    def delete(auth)
      self.rest_client.delete(auth, {:id => self.id})
    end
    alias_method :destroy, :delete
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smartfm-1.0.1 lib/smartfm/modules/public_content.rb