Class: Muddyit::Collections

Inherits:
Base
  • Object
show all
Defined in:
lib/muddyit/collections.rb

Defined Under Namespace

Classes: Collection

Instance Attribute Summary

Attributes inherited from Base

#access_token, #access_token_secret, #auth_type, #consumer_key, #consumer_secret, #password, #rest_endpoint, #username

Instance Method Summary collapse

Methods inherited from Base

#collections, #extract, #send_request

Constructor Details

#initialize(muddyit) ⇒ Collections

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



11
12
13
# File 'lib/muddyit/collections.rb', line 11

def initialize(muddyit)
  @muddyit = muddyit
end

Instance Method Details

#create(label, uri) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/muddyit/collections.rb', line 15

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(type, options = {}) ⇒ Object

find a specific collection

Params

  • type (Required) one of :all or a token



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/muddyit/collections.rb', line 34

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