muddyit_fu 0.2.8 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  *.gem
2
2
  nbproject
3
+ test/config.yml
data/README.rdoc CHANGED
@@ -21,26 +21,26 @@ use the API.
21
21
  access_token: "YOUR_ACCESS_TOKEN"
22
22
  access_token_secret: "YOUR_ACCESS_TOKEN_SECRET"
23
23
 
24
- == Retrieving all sites
24
+ == Retrieving all collections
25
25
 
26
26
  require 'muddyit_fu'
27
27
  muddyit = Muddyit.new('muddyit.yml')
28
- muddyit.sites.find(:all).each do |site|
29
- puts "#{site.label} : #{site.token}"
28
+ muddyit.collections.find(:all).each do |collection|
29
+ puts "#{collection.label} : #{collection.token}"
30
30
  end
31
31
 
32
- == Retrieving a single site
32
+ == Retrieving a single collection
33
33
 
34
34
  require 'muddyit_fu'
35
35
  muddyit = Muddyit.new('muddyit.yml')
36
- puts muddyit.sites.find('a0ret4').label
36
+ puts muddyit.collections.find('a0ret4').label
37
37
 
38
38
  == Categorisation request
39
39
 
40
40
  require 'muddyit_fu'
41
41
  muddyit = Muddyit.new('muddyit.yml')
42
- site = muddyit.sites.first
43
- site.pages.create({:uri => 'http://news.bbc.co.uk/1/hi/uk_politics/8011321.stm'}, {:minium_confidence => 0.2})
42
+ collection = muddyit.collections.first
43
+ collection.pages.create({:uri => 'http://news.bbc.co.uk/1/hi/uk_politics/8011321.stm'}, {:minium_confidence => 0.2})
44
44
 
45
45
  == View categorised pages
46
46
 
@@ -49,8 +49,8 @@ use the API.
49
49
  :consumer_secret => 'bbb',
50
50
  :access_token => 'ccc',
51
51
  :access_token_secret => 'ddd')
52
- site = muddyit.sites.first
53
- site.pages.find(:all) do |page|
52
+ collection = muddyit.collections.first
53
+ collection.pages.find(:all) do |page|
54
54
  puts page.title
55
55
  page.entities.each do |entity|
56
56
  puts entity.uri
@@ -61,8 +61,8 @@ use the API.
61
61
 
62
62
  require 'muddyit_fu'
63
63
  muddyit = Muddyit.new('muddyit.yml')
64
- site = muddyit.sites.find(:all).first
65
- site.pages.find_by_entity('http://dbpedia.org/resource/Gordon_Brown') do |page|
64
+ collection = muddyit.collections.find(:all).first
65
+ collection.pages.find_by_entity('http://dbpedia.org/resource/Gordon_Brown') do |page|
66
66
  puts page.identifier
67
67
  end
68
68
 
@@ -70,9 +70,9 @@ use the API.
70
70
 
71
71
  require 'muddyit_fu'
72
72
  muddyit = Muddyit.new('muddyit.yml')
73
- site = muddyit.sites.find(:all).first
73
+ collection = muddyit.collcetions.find(:all).first
74
74
  puts "Related entity\tOccurance
75
- site.entities.find_related('http://dbpedia.org/resource/Gordon_Brown').each do |entry|
75
+ collection.entities.find_related('http://dbpedia.org/resource/Gordon_Brown').each do |entry|
76
76
  puts "#{entry[:enity].uri}\t#{entry[:count]}"
77
77
  end
78
78
 
@@ -80,8 +80,8 @@ use the API.
80
80
 
81
81
  require 'muddyit_fu'
82
82
  muddyit = Muddyit.new('muddyit.yml')
83
- site = muddyit.sites.find(:all).first
84
- page = site.pages.find(:all, :uri => 'http://news.bbc.co.uk/1/hi/uk_politics/7878418.stm').first
83
+ collection = muddyit.collections.find(:all).first
84
+ page = collection.pages.find(:all, :uri => 'http://news.bbc.co.uk/1/hi/uk_politics/7878418.stm').first
85
85
  puts "Our page : #{page.title}\n\n"
86
86
  page.related_content.each do |results|
87
87
  puts "#{results[:page].title} #{results[:count]}"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.8
1
+ 0.2.9
@@ -6,7 +6,7 @@ require 'open-uri'
6
6
 
7
7
  # Connect to Muddy
8
8
  muddyit = Muddyit.new('./config.yml')
9
- site = muddyit.sites.find(:all).first
9
+ collection= muddyit.collections.find(:all).first
10
10
  # Parse RSS
11
11
  rss_content = ''
12
12
  open('http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/uk_politics/rss.xml') do |f|
@@ -15,7 +15,7 @@ end
15
15
  rss = RSS::Parser.parse(rss_content, false)
16
16
  # Loop through, analyse and display entities
17
17
  rss.items.each do |item|
18
- page = site.pages.create({:uri => item.guid.content}, {:realtime => true, :store => false})
18
+ page = collection.pages.create({:uri => item.guid.content}, {:realtime => true, :store => false})
19
19
  puts "#{item.guid.content} contains:"
20
20
  page.entities.each do |entity|
21
21
  puts "\t#{entity.term}, #{entity.classification}"
data/examples/oauth.rb CHANGED
@@ -32,7 +32,7 @@ begin
32
32
  puts "Secret : #{ssecret}"
33
33
  puts
34
34
 
35
- puts "Account sites"
35
+ puts "Account collections"
36
36
  puts
37
37
 
38
38
  muddyit = Muddyit.new(:consumer_key => token,
@@ -40,8 +40,8 @@ begin
40
40
  :access_token => stoken,
41
41
  :access_token_secret => ssecret)
42
42
 
43
- muddyit.sites.find(:all).each do |site|
44
- puts "#{site.label} has token #{site.token}"
43
+ muddyit.collections.find(:all).each do |collection|
44
+ puts "#{collection.label} has token #{collection.token}"
45
45
  end
46
46
 
47
47
  rescue OAuth::Unauthorized
data/lib/muddyit/base.rb CHANGED
@@ -88,18 +88,25 @@ module Muddyit
88
88
  res = request_over_http(api_url, http_method, opts, body)
89
89
  # Strip any js wrapping methods
90
90
 
91
- if res.body =~ /^.+\((.+)\)$/
92
- r = JSON.parse($1)
91
+ case res
92
+ when Net::HTTPSuccess, Net::HTTPRedirection
93
+ case res.body
94
+ when " "
95
+ return res
96
+ when /^.+\((.+)\)$/
97
+ return JSON.parse($1)
98
+ else
99
+ return JSON.parse(res.body)
100
+ end
101
+ when Net::HTTPNotFound
102
+ return res
93
103
  else
94
- r = JSON.parse(res.body)
104
+ return res.error!
95
105
  end
96
-
97
- return r
98
106
  end
99
107
 
100
-
101
- # creates and/or returns the Muddyit::Sites object
102
- def sites() @sites ||= Muddyit::Sites.new(self) end
108
+ # creates and/or returns the Muddyit::Collections object
109
+ def collections() @collections ||= Muddyit::Collections.new(self) end
103
110
 
104
111
  protected
105
112
 
@@ -0,0 +1,20 @@
1
+ class Muddyit::Collections::Collection < Muddyit::Generic
2
+
3
+ # get pages object for collection
4
+ #
5
+ def pages() @pages ||= Muddyit::Collections::Collection::Pages.new(@muddyit, :collection => self) end
6
+ def entities() @entities ||= Muddyit::Collections::Collection::Entities.new(@muddyit, :collection => self) end
7
+
8
+ def destroy
9
+ api_url = "/collections/#{@attributes[:token]}"
10
+ @muddyit.send_request(api_url, :delete, {})
11
+ end
12
+
13
+ protected
14
+ def fetch
15
+ api_url = "/collections/#{@attributes[:token]}"
16
+ response = @muddyit.send_request(api_url, :get, {})
17
+ response['collections'].nested_symbolize_keys!
18
+ end
19
+
20
+ end
@@ -1,4 +1,4 @@
1
- class Muddyit::Sites::Site::Entities::Entity < Muddyit::Generic
1
+ class Muddyit::Collections::Collection::Entities::Entity < Muddyit::Generic
2
2
 
3
3
  # def classification
4
4
  # unless @attributes[:type]
@@ -8,26 +8,26 @@ class Muddyit::Sites::Site::Entities::Entity < Muddyit::Generic
8
8
  # @attributes[:type]
9
9
  # end
10
10
 
11
- # retrieve entities related to the specified entity within the site entities collection
11
+ # retrieve entities related to the specified entity within the collection entities collection
12
12
  #
13
13
  # Params
14
14
  # * options (Optional)
15
15
  #
16
16
  def related(options = {})
17
- api_url = "/sites/#{self.site.attributes[:token]}/entities/#{Digest::MD5.hexdigest(@attributes[:uri])}/related"
17
+ api_url = "/collections/#{self.collection.attributes[:token]}/entities/#{Digest::MD5.hexdigest(@attributes[:uri])}/related"
18
18
  response = @muddyit.send_request(api_url, :get, options)
19
19
 
20
20
  results = []
21
21
  response.each { |result|
22
22
  # The return format needs sorting out here .......
23
- results.push Muddyit::Sites::Site::Entities::Entity.new(@muddyit, result)
23
+ results.push Muddyit::Collections::Collection::Entities::Entity.new(@muddyit, result)
24
24
  }
25
25
  return results
26
26
  end
27
27
 
28
28
  protected
29
29
  def fetch
30
- api_url = "/sites/#{@attributes[:site].token}/entities/#{Digest::MD5.hexdigest(@attributes[:uri])}"
30
+ api_url = "/collections/#{@attributes[:collection].token}/entities/#{Digest::MD5.hexdigest(@attributes[:uri])}"
31
31
  response = @muddyit.send_request(api_url, :get)
32
32
  response.nested_symbolize_keys!
33
33
  end
@@ -1,7 +1,7 @@
1
- class Muddyit::Sites::Site::Entities < Muddyit::Generic
1
+ class Muddyit::Collections::Collection::Entities < Muddyit::Generic
2
2
  # Placeholder
3
3
 
4
- # retrieve entities related to the specified entity within the site entities collection
4
+ # retrieve entities related to the specified entity within the collection entities collection
5
5
  #
6
6
  # Params
7
7
  # * options (Optional)
@@ -9,12 +9,12 @@ class Muddyit::Sites::Site::Entities < Muddyit::Generic
9
9
  def find_related(uri, options = {})
10
10
 
11
11
  raise if uri.nil?
12
- api_url = "/sites/#{self.site.attributes[:token]}/entities/#{Digest::MD5.hexdigest(uri)}/related"
12
+ api_url = "/collections/#{self.collection.attributes[:token]}/entities/#{Digest::MD5.hexdigest(uri)}/related"
13
13
  response = @muddyit.send_request(api_url, :get, options)
14
14
 
15
15
  results = []
16
16
  response.each { |result|
17
- results.push :count => result.delete('count'), :entity => Muddyit::Sites::Site::Entities::Entity.new(@muddyit, result)
17
+ results.push :count => result.delete('count'), :entity => Muddyit::Collections::Collection::Entities::Entity.new(@muddyit, result)
18
18
  }
19
19
  return results
20
20
  end
@@ -1,11 +1,10 @@
1
- class Muddyit::Sites::Site::Pages::Page::ExtractedContent < Muddyit::Generic
1
+ class Muddyit::Collections::Collection::Pages::Page::ExtractedContent < Muddyit::Generic
2
2
 
3
3
  def initialize(muddyit, attributes)
4
4
  super(muddyit, attributes)
5
5
  populate_terms
6
6
  end
7
7
 
8
-
9
8
  protected
10
9
 
11
10
  def populate_terms
@@ -1,4 +1,4 @@
1
- class Muddyit::Sites::Site::Pages::Page < Muddyit::Generic
1
+ class Muddyit::Collections::Collection::Pages::Page < Muddyit::Generic
2
2
 
3
3
  # Create a set of entities from the categorisation results
4
4
  def initialize(muddyit, attributes = {})
@@ -19,9 +19,9 @@ class Muddyit::Sites::Site::Pages::Page < Muddyit::Generic
19
19
 
20
20
  body = { :page => { :uri => self.uri, :options => options } }
21
21
 
22
- api_url = "/sites/#{self.site.attributes[:token]}/pages/#{self.identifier}"
22
+ api_url = "/collections/#{self.collection.attributes[:token]}/pages/#{self.identifier}"
23
23
  response = @muddyit.send_request(api_url, :put, {}, body.to_json)
24
- return Muddyit::Sites::Site::Pages::Page.new(@muddyit, response['page'].merge!(:site => self.site))
24
+ return Muddyit::Collections::Collection::Pages::Page.new(@muddyit, response['page'].merge!(:collection => self.collection))
25
25
  end
26
26
 
27
27
 
@@ -30,10 +30,10 @@ class Muddyit::Sites::Site::Pages::Page < Muddyit::Generic
30
30
  def extracted_content
31
31
  if @extracted_content_cache.nil?
32
32
  if @attributes[:extracted_content]
33
- @extracted_content_cache = Muddyit::Sites::Site::Pages::Page::ExtractedContent.new(@muddyit, @attributes[:extracted_content])
33
+ @extracted_content_cache = Muddyit::Collections::Collection::Pages::Page::ExtractedContent.new(@muddyit, @attributes[:extracted_content])
34
34
  else
35
35
  r = self.fetch
36
- @extracted_content_cache = Muddyit::Sites::Site::Pages::Page::ExtractedContent.new(@muddyit, r[:extracted_content])
36
+ @extracted_content_cache = Muddyit::Collections::Collection::Pages::Page::ExtractedContent.new(@muddyit, r[:extracted_content])
37
37
  end
38
38
  end
39
39
  @extracted_content_cache
@@ -43,7 +43,7 @@ class Muddyit::Sites::Site::Pages::Page < Muddyit::Generic
43
43
  # delete the page
44
44
  #
45
45
  def destroy
46
- api_url = "/sites/#{self.site.attributes[:token]}/pages/#{@attributes[:identifier]}"
46
+ api_url = "/colletions/#{self.collection.attributes[:token]}/pages/#{@attributes[:identifier]}"
47
47
  response = @muddyit.send_request(api_url, :delete, {})
48
48
  # Is this the correct thing to return ?
49
49
  return true
@@ -55,19 +55,19 @@ class Muddyit::Sites::Site::Pages::Page < Muddyit::Generic
55
55
  # * options (Optional)
56
56
  #
57
57
  def related_content(options = {})
58
- api_url = "/sites/#{self.site.attributes[:token]}/pages/#{@attributes[:identifier]}/related"
58
+ api_url = "/collections/#{self.collection.attributes[:token]}/pages/#{@attributes[:identifier]}/related"
59
59
  response = @muddyit.send_request(api_url, :get, options, nil)
60
60
  results = []
61
61
  response.each { |result|
62
62
  # The return format needs sorting out here .......
63
- results.push :page => @attributes[:site].pages.find(result['identifier']), :count => result['count']
63
+ results.push :page => @attributes[:collection].pages.find(result['identifier']), :count => result['count']
64
64
  }
65
65
  return results
66
66
  end
67
67
 
68
68
  protected
69
69
  def fetch
70
- api_url = "/sites/#{self.site.attributes[:token]}/pages/#{@attributes[:identifier]}"
70
+ api_url = "/collections/#{self.collection.attributes[:token]}/pages/#{@attributes[:identifier]}"
71
71
 
72
72
  response = @muddyit.send_request(api_url, :get, {:include_content => true}, nil)
73
73
 
@@ -79,7 +79,7 @@ class Muddyit::Sites::Site::Pages::Page < Muddyit::Generic
79
79
  results = []
80
80
  if @attributes.has_key?(:entities)
81
81
  @attributes[:entities].each do |result|
82
- results.push Muddyit::Sites::Site::Entities::Entity.new(@muddyit, result.merge!(:site => @attributes[:site]))
82
+ results.push Muddyit::Collections::Collection::Entities::Entity.new(@muddyit, result.merge!(:collection => @attributes[:collection]))
83
83
  end
84
84
  @attributes[:entities] = results
85
85
  end
@@ -1,6 +1,6 @@
1
- class Muddyit::Sites::Site::Pages < Muddyit::Generic
1
+ class Muddyit::Collections::Collection::Pages < Muddyit::Generic
2
2
 
3
- # find a specific page from the site
3
+ # find a specific page from the collection
4
4
  #
5
5
  # Params
6
6
  # * type (Required)
@@ -12,23 +12,23 @@ class Muddyit::Sites::Site::Pages < Muddyit::Generic
12
12
  if type.is_a? Symbol
13
13
  case type
14
14
  when :all
15
- api_url = "/sites/#{self.site.attributes[:token]}/pages"
15
+ api_url = "/collections/#{self.collection.attributes[:token]}/pages"
16
16
  if block_given?
17
17
  token = nil
18
18
  begin
19
19
  response = @muddyit.send_request(api_url, :get, options.merge!(:page => token))
20
20
  response['pages'].each { |page|
21
- yield Muddyit::Sites::Site::Pages::Page.new(@muddyit, page.merge!(:site => self.site))
21
+ yield Muddyit::Collections::Collection::Pages::Page.new(@muddyit, page.merge!(:collection => self.collection))
22
22
  }
23
23
  token = response['next_page']
24
24
  # Need to figure out which of the below actually occurs
25
25
  end while !token.nil? || !token == ''
26
26
  else
27
- api_url = "/sites/#{self.site.attributes[:token]}/pages"
27
+ api_url = "/collections/#{self.collection.attributes[:token]}/pages"
28
28
  response = @muddyit.send_request(api_url, :get, options)
29
29
 
30
30
  pages = []
31
- response['pages'].each { |page| pages.push Muddyit::Sites::Site::Pages::Page.new(@muddyit, page.merge!(:site => self.site)) }
31
+ response['pages'].each { |page| pages.push Muddyit::Collections::Collection::Pages::Page.new(@muddyit, page.merge!(:collection => self.collection)) }
32
32
  return { :next_page => response['next_page'], :pages => pages }
33
33
  end
34
34
  else
@@ -36,9 +36,9 @@ class Muddyit::Sites::Site::Pages < Muddyit::Generic
36
36
  end
37
37
 
38
38
  elsif type.is_a? String
39
- api_url = "/sites/#{self.site.attributes[:token]}/pages/#{type}"
39
+ api_url = "/collections/#{self.collection.attributes[:token]}/pages/#{type}"
40
40
  response = @muddyit.send_request(api_url, :get, {})
41
- response.has_key?('identifier') ? Muddyit::Sites::Site::Pages::Page.new(@muddyit, response.merge!(:site => self.site)) : nil
41
+ response.has_key?('identifier') ? Muddyit::Collections::Collection::Pages::Page.new(@muddyit, response.merge!(:collection => self.collection)) : nil
42
42
  end
43
43
  end
44
44
 
@@ -61,9 +61,9 @@ class Muddyit::Sites::Site::Pages < Muddyit::Generic
61
61
 
62
62
  body = { :page => doc.merge!(:options => options) }
63
63
 
64
- api_url = "/sites/#{self.site.attributes[:token]}/pages/"
64
+ api_url = "/collections/#{self.collection.attributes[:token]}/pages/"
65
65
  response = @muddyit.send_request(api_url, :post, {}, body.to_json)
66
- return Muddyit::Sites::Site::Pages::Page.new(@muddyit, response['page'].merge!(:site => self.site))
66
+ return Muddyit::Collections::Collection::Pages::Page.new(@muddyit, response['page'].merge!(:collection => self.collection))
67
67
  end
68
68
 
69
69
  # find all pages with specified entity
@@ -125,7 +125,7 @@ class Muddyit::Sites::Site::Pages < Muddyit::Generic
125
125
  # must contain uri parameter which corresponds to dbpedia uri
126
126
  #
127
127
  def queryAllWithURI(uri, options, &block)
128
- api_url = "/sites/#{self.site.attributes[:token]}/entities/#{Digest::MD5.hexdigest(uri)}"
128
+ api_url = "/collections/#{self.collection.attributes[:token]}/entities/#{Digest::MD5.hexdigest(uri)}"
129
129
  query_page(api_url, options, &block)
130
130
  end
131
131
 
@@ -138,7 +138,7 @@ class Muddyit::Sites::Site::Pages < Muddyit::Generic
138
138
  #
139
139
  #
140
140
  def queryAllWithTerm(term, options, &block)
141
- api_url = "/sites/#{self.site.attributes[:token]}/terms/#{term}"
141
+ api_url = "/collections/#{self.collection.attributes[:token]}/terms/#{term}"
142
142
  query_page(api_url, options, &block)
143
143
  end
144
144
 
@@ -155,7 +155,7 @@ class Muddyit::Sites::Site::Pages < Muddyit::Generic
155
155
  options.merge!(:page => token) unless token.nil?
156
156
  response = @muddyit.send_request(api_url, :get, options.merge!(:page => token))
157
157
  response['pages'].each { |page|
158
- yield Muddyit::Sites::Site::Pages::Page.new(@muddyit, page.merge!(:site => self.site))
158
+ yield Muddyit::Collections::Collection::Pages::Page.new(@muddyit, page.merge!(:collection => self.collection))
159
159
  }
160
160
  token = response['next_page']
161
161
  # Need to figure out which of the below actually occurs
@@ -164,7 +164,7 @@ class Muddyit::Sites::Site::Pages < Muddyit::Generic
164
164
  response = @muddyit.send_request(api_url, :get, {})
165
165
 
166
166
  pages = []
167
- response['pages'].each { |page| pages.push Muddyit::Sites::Site::Pages::Page.new(@muddyit, page.merge!(:site => self.site)) }
167
+ response['pages'].each { |page| pages.push Muddyit::Collections::Collection::Pages::Page.new(@muddyit, page.merge!(:collection => self.collection)) }
168
168
  return { :next_page => response[:next_page], :pages => pages }
169
169
  end
170
170
  end
@@ -0,0 +1,58 @@
1
+ class Muddyit::Collections < Muddyit::Base
2
+
3
+ # create a new collections object
4
+ # not a muddyit:generic as it doesn't need the method missing loader
5
+ #
6
+ # Params :
7
+ #
8
+ # * muddyit (Required)
9
+ # a muddyit::base instance
10
+ #
11
+ def initialize(muddyit)
12
+ @muddyit = muddyit
13
+ end
14
+
15
+ def create(label, uri)
16
+
17
+ raise unless label
18
+
19
+ body = {:collection => {}}
20
+ body[:collection].merge!(:label => label) if label
21
+ body[:collection].merge!(:uri => uri) if uri
22
+
23
+ api_url = "/collections/"
24
+ response = @muddyit.send_request(api_url, :post, {}, body.to_json)
25
+ return Muddyit::Collections::Collection.new(@muddyit, response['collection'])
26
+ end
27
+
28
+ # find a specific collection
29
+ #
30
+ # Params
31
+ # * type (Required)
32
+ # one of :all or a token
33
+ #
34
+ def find(type, options = {})
35
+ raise 'no type specified' unless type
36
+
37
+ if type.is_a? Symbol
38
+ case type
39
+ when :all
40
+ api_url = "/collections/"
41
+ response = @muddyit.send_request(api_url, :get, options)
42
+ collections = []
43
+ response.each { |collection| collections.push Muddyit::Collections::Collection.new(@muddyit, collection['collection']) }
44
+ return collections
45
+ else
46
+ raise 'invalid type specified'
47
+ end
48
+ elsif type.is_a? String
49
+ api_url = "/collections/#{type}"
50
+ response = @muddyit.send_request(api_url, :get, options)
51
+ return Muddyit::Collections::Collection.new(@muddyit, response['collection'])
52
+ else
53
+ raise 'invalid type specified'
54
+ end
55
+
56
+ end
57
+
58
+ end
@@ -38,7 +38,8 @@ class Muddyit::Generic < Muddyit::Base
38
38
  @info_added = true
39
39
  end
40
40
  unless @attributes.has_key?(method.to_sym)
41
- raise "No method named #{method.to_s}"
41
+ puts "Failed to find missing method #{method.to_s}"
42
+ raise
42
43
  end
43
44
  if args.nil?
44
45
  @attributes[method.to_sym]
data/lib/muddyit_fu.rb CHANGED
@@ -47,8 +47,6 @@ class Hash
47
47
  end
48
48
 
49
49
  # base must load first
50
- %w(base oauth errors generic sites entities sites/site sites/pages sites/pages/page sites/pages/page/extracted_content sites/entities sites/entities/entity).each do |file|
50
+ %w(base oauth errors generic collections entities collections/collection collections/pages collections/pages/page collections/pages/page/extracted_content collections/entities collections/entities/entity).each do |file|
51
51
  require File.join(File.dirname(__FILE__), 'muddyit', file)
52
52
  end
53
-
54
-
data/muddyit_fu.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{muddyit_fu}
5
- s.version = "0.2.8"
5
+ s.version = "0.2.9"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["rattle"]
9
- s.date = %q{2009-11-10}
9
+ s.date = %q{2010-01-09}
10
10
  s.email = %q{support[at]muddy.it}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -22,19 +22,22 @@ Gem::Specification.new do |s|
22
22
  "examples/newsindexer.rb",
23
23
  "examples/oauth.rb",
24
24
  "lib/muddyit/base.rb",
25
+ "lib/muddyit/collections.rb",
26
+ "lib/muddyit/collections/collection.rb",
27
+ "lib/muddyit/collections/entities.rb",
28
+ "lib/muddyit/collections/entities/entity.rb",
29
+ "lib/muddyit/collections/pages.rb",
30
+ "lib/muddyit/collections/pages/page.rb",
31
+ "lib/muddyit/collections/pages/page/extracted_content.rb",
25
32
  "lib/muddyit/entities.rb",
26
33
  "lib/muddyit/errors.rb",
27
34
  "lib/muddyit/generic.rb",
28
35
  "lib/muddyit/oauth.rb",
29
- "lib/muddyit/sites.rb",
30
- "lib/muddyit/sites/entities.rb",
31
- "lib/muddyit/sites/entities/entity.rb",
32
- "lib/muddyit/sites/pages.rb",
33
- "lib/muddyit/sites/pages/page.rb",
34
- "lib/muddyit/sites/pages/page/extracted_content.rb",
35
- "lib/muddyit/sites/site.rb",
36
36
  "lib/muddyit_fu.rb",
37
- "muddyit_fu.gemspec"
37
+ "muddyit_fu.gemspec",
38
+ "test/config.yml.example",
39
+ "test/test_helper.rb",
40
+ "test/test_muddyit_fu.rb"
38
41
  ]
39
42
  s.homepage = %q{http://github.com/rattle/muddyit_fu}
40
43
  s.rdoc_options = ["--charset=UTF-8"]
@@ -42,7 +45,9 @@ Gem::Specification.new do |s|
42
45
  s.rubygems_version = %q{1.3.5}
43
46
  s.summary = %q{Provides a ruby interface to muddy.it}
44
47
  s.test_files = [
45
- "examples/newsindexer.rb",
48
+ "test/test_muddyit_fu.rb",
49
+ "test/test_helper.rb",
50
+ "examples/newsindexer.rb",
46
51
  "examples/oauth.rb"
47
52
  ]
48
53
 
@@ -0,0 +1,6 @@
1
+ consumer_key: Ni2rDBLHWym3BZxDwEm0d
2
+ consumer_secret: X5zHwQrtGUV8M7LnOfaQtbH8r6Ka3nkONyS3gbklqM
3
+ access_token: KzS6wjiCdKBIyeZtIq9v7A
4
+ access_token_secret: zCd625JS6hZ3vhRVvNu8qNKx65eRdkLpHfKsXRPFy0
5
+ rest_endpoint: http://muddy.it
6
+
@@ -0,0 +1,21 @@
1
+
2
+ require 'rubygems'
3
+ require 'shoulda'
4
+ require 'yaml'
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
7
+ require 'muddyit_fu'
8
+
9
+ class Test::Unit::TestCase
10
+ # Add more helper methods to be used by all tests here...
11
+
12
+ def load_config(file = 'config.yml')
13
+ f = File.dirname(__FILE__) + '/../test/' + file
14
+ unless File.exist?(f)
15
+ puts "Unable to find configuration file #{f}"
16
+ exit 1
17
+ end
18
+ open(f) {|file| YAML.load(file) }
19
+ end
20
+
21
+ end
@@ -0,0 +1,141 @@
1
+ require 'test_helper'
2
+ require 'pp'
3
+
4
+ class TestMuddyitFu < Test::Unit::TestCase
5
+
6
+ @@COLLECTION_LABEL = Time.now.to_s
7
+ @@STORY = 'http://news.bbc.co.uk/1/hi/business/8186840.stm'
8
+
9
+ context 'A muddy account' do
10
+
11
+ setup do
12
+ c = load_config
13
+ begin
14
+ @muddyit = Muddyit.new(:consumer_key => c['consumer_key'],
15
+ :consumer_secret => c['consumer_secret'],
16
+ :access_token => c['access_token'],
17
+ :access_token_secret => c['access_token_secret'],
18
+ :rest_endpoint => c['rest_endpoint'])
19
+ rescue
20
+ puts "Failed to connect to muddy, are the details correct ?"
21
+ end
22
+ end
23
+
24
+ should 'be able to create a collection' do
25
+ collection = @muddyit.collections.create(@@COLLECTION_LABEL, 'http://www.test.com')
26
+ assert !collection.token.nil?
27
+ end
28
+
29
+ should 'be able to find a collection' do
30
+ # This is a bit rubbish
31
+ @muddyit.collections.find(:all).each do |collection|
32
+ if collection.label == @@COLLECTION_LABEL
33
+ assert true
34
+ end
35
+ end
36
+ end
37
+
38
+ should 'be able to destroy a collection' do
39
+ # This is also a bit rubbish
40
+ collections = @muddyit.collections.find(:all)
41
+ collections.each do |collection|
42
+ if collection.label == @@COLLECTION_LABEL
43
+ res = collection.destroy
44
+ assert_equal res.code, "200"
45
+ end
46
+ end
47
+ end
48
+
49
+ context "with a collection" do
50
+
51
+ setup do
52
+ @collection = @muddyit.collections.create(@@COLLECTION_LABEL, 'http://www.test.com')
53
+ end
54
+
55
+ should "categorise a page in realtime and not store it" do
56
+ page = @collection.pages.create({:uri => @@STORY}, :realtime => true, :store => false)
57
+ assert page.entities.length > 0
58
+ pages = @collection.pages.find(:all)
59
+ assert pages[:pages].length == 0
60
+ end
61
+
62
+ should "categorise a page in realtime and store it" do
63
+ page = @collection.pages.create({:uri => @@STORY}, :realtime => true, :store => true)
64
+ assert page.entities.length > 0
65
+ pages = @collection.pages.find(:all)
66
+ assert_equal pages[:pages].length, 1
67
+ end
68
+
69
+ context "with a page" do
70
+
71
+ setup do
72
+ @page = @collection.pages.create({:uri => @@STORY}, :realtime => true)
73
+ end
74
+
75
+ should "find a page" do
76
+ assert_equal @collection.pages.find(@page.identifier).identifier, @page.identifier
77
+ end
78
+
79
+ should "have page attributes" do
80
+ assert !@page.identifier.nil?
81
+ assert !@page.title.nil?
82
+ assert !@page.created_at.nil?
83
+ assert !@page.content.nil?
84
+ assert !@page.uri.nil?
85
+ #assert !@page.token.nil?
86
+ # More attributes here ?
87
+ end
88
+
89
+ should "have many entities" do
90
+ assert @page.entities.length > 0
91
+ end
92
+
93
+ should "have an entity with a term and label" do
94
+ entity = @page.entities.first
95
+ assert !entity.term.nil?
96
+ assert !entity.uri.nil?
97
+ end
98
+
99
+ should "have extracted content" do
100
+ assert !@page.extracted_content.content.nil?
101
+ assert @page.extracted_content.terms.length > 0
102
+ assert @page.extracted_content.start_position > 0
103
+ assert @page.extracted_content.end_position > 0
104
+ end
105
+
106
+ should "delete a page" do
107
+ assert @page.destroy, "200"
108
+ end
109
+
110
+ end
111
+
112
+ context "with two pages" do
113
+
114
+ setup do
115
+ @page1 = @collection.pages.create({:uri => @@STORY}, :realtime => true)
116
+ @page2 = @collection.pages.create({:uri => @@STORY}, :realtime => true)
117
+ end
118
+
119
+ should "find all pages" do
120
+ assert_equal @collection.pages.find(:all).length, 2
121
+ end
122
+
123
+ should "find related pages" do
124
+ assert_equal @page1.related_content.length, 1
125
+ end
126
+
127
+ end
128
+
129
+ teardown do
130
+ #token = @collection.token
131
+ @collection.destroy
132
+ #res = @muddyit.collections.find(token)
133
+ # This should be a 404 (!)
134
+ #assert_equal res.code, "404"
135
+ end
136
+
137
+ end
138
+
139
+ end
140
+ end
141
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muddyit_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - rattle
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-10 00:00:00 +00:00
12
+ date: 2010-01-09 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -51,19 +51,22 @@ files:
51
51
  - examples/newsindexer.rb
52
52
  - examples/oauth.rb
53
53
  - lib/muddyit/base.rb
54
+ - lib/muddyit/collections.rb
55
+ - lib/muddyit/collections/collection.rb
56
+ - lib/muddyit/collections/entities.rb
57
+ - lib/muddyit/collections/entities/entity.rb
58
+ - lib/muddyit/collections/pages.rb
59
+ - lib/muddyit/collections/pages/page.rb
60
+ - lib/muddyit/collections/pages/page/extracted_content.rb
54
61
  - lib/muddyit/entities.rb
55
62
  - lib/muddyit/errors.rb
56
63
  - lib/muddyit/generic.rb
57
64
  - lib/muddyit/oauth.rb
58
- - lib/muddyit/sites.rb
59
- - lib/muddyit/sites/entities.rb
60
- - lib/muddyit/sites/entities/entity.rb
61
- - lib/muddyit/sites/pages.rb
62
- - lib/muddyit/sites/pages/page.rb
63
- - lib/muddyit/sites/pages/page/extracted_content.rb
64
- - lib/muddyit/sites/site.rb
65
65
  - lib/muddyit_fu.rb
66
66
  - muddyit_fu.gemspec
67
+ - test/config.yml.example
68
+ - test/test_helper.rb
69
+ - test/test_muddyit_fu.rb
67
70
  has_rdoc: true
68
71
  homepage: http://github.com/rattle/muddyit_fu
69
72
  licenses: []
@@ -93,5 +96,7 @@ signing_key:
93
96
  specification_version: 3
94
97
  summary: Provides a ruby interface to muddy.it
95
98
  test_files:
99
+ - test/test_muddyit_fu.rb
100
+ - test/test_helper.rb
96
101
  - examples/newsindexer.rb
97
102
  - examples/oauth.rb
@@ -1,15 +0,0 @@
1
- class Muddyit::Sites::Site < Muddyit::Generic
2
-
3
- # get pages object for site
4
- #
5
- def pages() @pages ||= Muddyit::Sites::Site::Pages.new(@muddyit, :site => self) end
6
- def entities() @entities ||= Muddyit::Sites::Site::Entities.new(@muddyit, :site => self) end
7
-
8
- protected
9
- def fetch
10
- api_url = "/sites/#{@attributes[:token]}"
11
- response = @muddyit.send_request(api_url, :get, {})
12
- response['site'].nested_symbolize_keys!
13
- end
14
-
15
- end
data/lib/muddyit/sites.rb DELETED
@@ -1,45 +0,0 @@
1
- class Muddyit::Sites < Muddyit::Base
2
-
3
- # create a new sites object
4
- # not a muddyit:generic as it doesn't need the method missing loader
5
- #
6
- # Params :
7
- #
8
- # * muddyit (Required)
9
- # a muddyit::base instance
10
- #
11
- def initialize(muddyit)
12
- @muddyit = muddyit
13
- end
14
-
15
- # find a specific site
16
- #
17
- # Params
18
- # * type (Required)
19
- # one of :all or a site token
20
- #
21
- def find(type, options = {})
22
- raise 'no type specified' unless type
23
-
24
- if type.is_a? Symbol
25
- case type
26
- when :all
27
- api_url = "/sites/"
28
- response = @muddyit.send_request(api_url, :get, options)
29
- sites = []
30
- response.each { |site| sites.push Muddyit::Sites::Site.new(@muddyit, site['site']) }
31
- return sites
32
- else
33
- raise 'invalid type specified'
34
- end
35
- elsif type.is_a? String
36
- api_url = "/sites/#{type}"
37
- response = @muddyit.send_request(api_url, :get, options)
38
- return Muddyit::Sites::Site.new(@muddyit, response['site'])
39
- else
40
- raise 'invalid type specified'
41
- end
42
-
43
- end
44
-
45
- end