Class: Muddyit::Sites::Site::Pages
- Defined in:
- lib/muddyit/sites/pages.rb
Defined Under Namespace
Classes: Page
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Generic
Attributes inherited from Base
#access_token, #access_token_secret, #consumer_key, #consumer_secret, #rest_endpoint
Instance Method Summary collapse
-
#create(doc = {}, options = {}) ⇒ Object
submit a page or text for categorisation.
-
#find(type, options = {}) ⇒ Object
find a specific page from the site.
-
#find_by_entities(uris, options = {}, &block) ⇒ Object
find all pages with specified entities.
-
#find_by_entity(uri, options = {}, &block) ⇒ Object
find all pages with specified entity.
-
#find_by_term(term, options = {}, &block) ⇒ Object
find all pages with specified term.
-
#find_by_terms(terms, options = {}, &block) ⇒ Object
find all pages with specified terms.
Methods inherited from Generic
Methods inherited from Base
#initialize, #send_request, #sites
Constructor Details
This class inherits a constructor from Muddyit::Generic
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Muddyit::Generic
Instance Method Details
#create(doc = {}, options = {}) ⇒ Object
submit a page or text for categorisation
Params
-
options (Required)
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/muddyit/sites/pages.rb', line 52 def create(doc = {}, = {}) # Ensure we get content_data as well [:include_content] = true # Ensure we have encoded the identifier and URI unless doc[:uri] || doc[:text] raise end body = { :page => doc, :options => } api_url = "/sites/#{self.site.attributes[:token]}/pages/" response = @muddyit.send_request(api_url, :post, {}, body.to_json) return Muddyit::Sites::Site::Pages::Page.new(@muddyit, response['page'].merge!(:site => self.site)) end |
#find(type, options = {}) ⇒ Object
find a specific page from the site
Params
-
type (Required)
one of :all or a page identifier
9 10 11 12 13 14 15 16 17 18 19 20 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/pages.rb', line 9 def find(type, = {}) raise 'no type specified' if type.nil? if type.is_a? Symbol case type when :all api_url = "/sites/#{self.site.attributes[:token]}/pages" if block_given? token = nil begin response = @muddyit.send_request(api_url, :get, .merge!(:page => token)) response['pages'].each { |page| yield Muddyit::Sites::Site::Pages::Page.new(@muddyit, page.merge!(:site => self.site)) } token = response['next_page'] # Need to figure out which of the below actually occurs end while !token.nil? || !token == '' else api_url = "/sites/#{self.site.attributes[:token]}/pages" response = @muddyit.send_request(api_url, :get, ) pages = [] response['pages'].each { |page| pages.push Muddyit::Sites::Site::Pages::Page.new(@muddyit, page.merge!(:site => self.site)) } return { :next_page => response['next_page'], :pages => pages } end else raise 'invalid type specified' end elsif type.is_a? String api_url = "/sites/#{self.site.attributes[:token]}/pages/#{type}" response = @muddyit.send_request(api_url, :get, {}) response.has_key?('identifier') ? Muddyit::Sites::Site::Pages::Page.new(@muddyit, response.merge!(:site => self.site)) : nil end end |
#find_by_entities(uris, options = {}, &block) ⇒ Object
find all pages with specified entities
Params
-
uris (Required) an array of dbpedia URIs
-
options (Optional)
89 90 91 |
# File 'lib/muddyit/sites/pages.rb', line 89 def find_by_entities(uris, = {}, &block) queryAllWithURI(uris.join(','), , &block) end |
#find_by_entity(uri, options = {}, &block) ⇒ Object
find all pages with specified entity
Params
-
uri (Required) a dbpedia URI
-
options (Optional)
77 78 79 |
# File 'lib/muddyit/sites/pages.rb', line 77 def find_by_entity(uri, = {}, &block) queryAllWithURI(uri, , &block) end |
#find_by_term(term, options = {}, &block) ⇒ Object
find all pages with specified term
Params
-
term (Required) a string e.g. ‘Gordon Brown’
-
options (Optional)
101 102 103 |
# File 'lib/muddyit/sites/pages.rb', line 101 def find_by_term(term, = {}, &block) queryAllWithTerm(term, , &block) end |
#find_by_terms(terms, options = {}, &block) ⇒ Object
find all pages with specified terms
Params
-
terms (Required) an array of strings e.g. [‘Gordon Brown’, ‘Tony Blair’]
-
options (Optional)
113 114 115 |
# File 'lib/muddyit/sites/pages.rb', line 113 def find_by_terms(terms, = {}, &block) queryAllWithTerm(terms.join(','), , &block) end |