Class: Muddyit::Sites

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

Defined Under Namespace

Classes: Site

Constant Summary

Constants inherited from Base

Base::REST_ENDPOINT

Instance Attribute Summary

Attributes inherited from Base

#access_token, #access_token_secret, #consumer_key, #consumer_secret, #rest_endpoint

Instance Method Summary collapse

Methods inherited from Base

#send_request, #sites

Constructor Details

#initialize(muddyit) ⇒ Sites

create a new sites 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/sites.rb', line 11

def initialize(muddyit)
  @muddyit = muddyit
end

Instance Method Details

#find(type, options = {}) ⇒ Object

find a specific site

Params

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/muddyit/sites.rb', line 21

def find(type, options = {})
  raise 'no type specified' unless type

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

end