Class: Muddyit::Sites::Site::Page

Inherits:
Generic show all
Defined in:
lib/muddyit/page.rb

Defined Under Namespace

Classes: ContentData

Constant Summary

Constants inherited from Base

Base::REST_ENDPOINT

Instance Attribute Summary

Attributes inherited from Generic

#attributes

Attributes inherited from Base

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

Instance Method Summary collapse

Methods inherited from Generic

#method_missing

Methods inherited from Base

#send_request, #sites

Constructor Details

#initialize(muddyit, attributes = {}) ⇒ Page

Create a set of entities from the categorisation results



4
5
6
7
8
# File 'lib/muddyit/page.rb', line 4

def initialize(muddyit, attributes = {})
  super(muddyit, attributes)
  create_entities
  @content_data_cache = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Muddyit::Generic

Instance Method Details

#content_dataObject

get content_data for page



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/muddyit/page.rb', line 30

def content_data
  if @content_data_cache.nil?
    if @attributes[:content_data]
      @content_data_cache = Muddyit::Sites::Site::Page::ContentData.new(@muddyit, @attributes[:content_data])
    else
      r = self.fetch
      @content_data_cache = Muddyit::Sites::Site::Page::ContentData.new(@muddyit, r[:content_data])
    end
  end
  @content_data_cache
end

#destroyObject

delete the page



45
46
47
48
49
50
# File 'lib/muddyit/page.rb', line 45

def destroy
  api_url = "/sites/#{self.site.attributes[:token]}/pages/#{URI.escape(CGI.escape(@attributes[:identifier]),'.')}"
  response = @muddyit.send_request(api_url, :delete, {})
  # Is this the correct thing to return ?
  return true
end

#refresh(options = {}) ⇒ Object

submit a page or text for re-categorisation

Params

  • options (Required)



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

def refresh(options = {})

  # Ensure we get content_data as well
  options[:include_content] = true

  body = { :page => { :uri => self.uri }, :options => options }

  api_url = "/sites/#{self.site.attributes[:token]}/pages/#{URI.escape(CGI.escape(self.identifier),'.')}"
  response = @muddyit.send_request(api_url, :put, {}, body.to_json)
  return Muddyit::Sites::Site::Page.new(@muddyit, response.merge!(:site => self.site))
end

retrieve related pages

Params

  • options (Optional)



57
58
59
60
61
62
63
64
65
66
# File 'lib/muddyit/page.rb', line 57

def related_content(options = {})
  api_url = "/sites/#{self.site.attributes[:token]}/pages/#{URI.escape(CGI.escape(@attributes[:identifier]),'.')}/related/content"
  response = @muddyit.send_request(api_url, :get, options)
  results = []
  response.each { |result|
    # The return format needs sorting out here .......
    results.push :page => @attributes[:site].pages.find(result['identifier']), :count => result['count']
  }
  return results
end