Class: Muddyit::Collections::Collection::Pages::Page

Inherits:
Generic
  • Object
show all
Defined in:
lib/muddyit/collections/pages/page.rb

Defined Under Namespace

Classes: ExtractedContent

Instance Attribute Summary

Attributes inherited from Generic

#attributes

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 Generic

#method_missing

Methods inherited from Base

#collections, #extract, #send_request

Constructor Details

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

Create a set of entities from the categorisation results



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

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

Dynamic Method Handling

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

Instance Method Details

#destroyObject

delete the page



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

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

#extracted_contentObject

get extracted_content for page



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

def extracted_content
  if @extracted_content_cache.nil?
    if @attributes[:extracted_content]
      @extracted_content_cache = Muddyit::Collections::Collection::Pages::Page::ExtractedContent.new(@muddyit, @attributes[:extracted_content])
    else
      r = self.fetch
      @extracted_content_cache = Muddyit::Collections::Collection::Pages::Page::ExtractedContent.new(@muddyit, r[:extracted_content])
    end
  end
  @extracted_content_cache
end

retrieve related pages

Params

  • options (Optional)



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

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

#update(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/collections/pages/page.rb', line 15

def update(options = {})

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

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

  api_url = "/collections/#{self.collection.attributes[:token]}/pages/#{self.identifier}"
  response = @muddyit.send_request(api_url, :put, {}, body.to_json)
  return Muddyit::Collections::Collection::Pages::Page.new(@muddyit, response['page'].merge!(:collection => self.collection))
end