Sha256: 5482e4b97dc3fca44e65c48543b31ec661cd34982099aab3e52e54246031c3dc

Contents?: true

Size: 1.48 KB

Versions: 6

Compression:

Stored size: 1.48 KB

Contents

class Muddyit::Collections < Muddyit::Base

  # create a new collections object
  # not a muddyit:generic as it doesn't need the method missing loader
  #
  # Params :
  #
  # * muddyit (Required)
  # a muddyit::base instance
  #
  def initialize(muddyit)
    @muddyit = muddyit
  end

  def create(label, uri)

    raise unless label

    body = {:collection => {}}
    body[:collection].merge!(:label => label) if label
    body[:collection].merge!(:uri => uri) if uri

    api_url = "/collections/"
    response = @muddyit.send_request(api_url, :post, {}, body.to_json)
    return Muddyit::Collections::Collection.new(@muddyit, response['collection'])
  end

  # find a specific collection
  #
  # Params
  # * type (Required)
  #   one of :all or a token
  #
  def find(type, options = {})
    raise 'no type specified' unless type

    if type.is_a? Symbol
      case type
      when :all
        api_url = "/collections/"
        response = @muddyit.send_request(api_url, :get, options)
        collections = []
        response.each { |collection| collections.push Muddyit::Collections::Collection.new(@muddyit, collection['collection']) }
        return collections
      else
        raise 'invalid type specified'
      end
    elsif type.is_a? String
      api_url = "/collections/#{type}"
      response = @muddyit.send_request(api_url, :get, options)
      return Muddyit::Collections::Collection.new(@muddyit, response['collection'])
    else
      raise 'invalid type specified'
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
muddyit_fu-0.2.14 lib/muddyit/collections.rb
muddyit_fu-0.2.13 lib/muddyit/collections.rb
muddyit_fu-0.2.12 lib/muddyit/collections.rb
muddyit_fu-0.2.11 lib/muddyit/collections.rb
muddyit_fu-0.2.10 lib/muddyit/collections.rb
muddyit_fu-0.2.9 lib/muddyit/collections.rb