muddyit_fu 0.2.6 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -21
- data/VERSION +1 -1
- data/examples/newsindexer.rb +24 -0
- data/examples/oauth.rb +49 -0
- data/lib/muddyit/base.rb +2 -2
- data/lib/muddyit/oauth.rb +49 -0
- data/lib/muddyit/sites/entities/entity.rb +8 -8
- data/lib/muddyit/sites/pages/page.rb +1 -1
- data/lib/muddyit_fu.rb +2 -1
- data/muddyit_fu.gemspec +9 -2
- metadata +8 -4
data/README.rdoc
CHANGED
@@ -8,23 +8,10 @@
|
|
8
8
|
|
9
9
|
== Getting started
|
10
10
|
|
11
|
-
muddy.it uses oauth to manage it's api access.
|
12
|
-
programmatically you will need to register an application. Login and visit :
|
11
|
+
muddy.it uses oauth to manage it's api access.
|
13
12
|
|
14
|
-
http://
|
15
|
-
|
16
|
-
You can register an application here, a callback URI isn't required.
|
17
|
-
|
18
|
-
The 'consumer token' and 'consumer secret' are used to generate a token for
|
19
|
-
accessing muddy.it. For further details and an example of how to programatically
|
20
|
-
generate a new access token for muddy.it see here :
|
21
|
-
|
22
|
-
http://stakeventures.com/articles/2008/02/23/developing-oauth-clients-in-ruby
|
23
|
-
|
24
|
-
See the 'Authorising clients using irb' section for a sample irb session.
|
25
|
-
|
26
|
-
These details are then used to provide access to the service. The credentials
|
27
|
-
can be stored in a yml file, an example of which is provided below.
|
13
|
+
See http://blog.muddy.it/2009/11/getting-started-with-muddy for details on how to
|
14
|
+
use the API.
|
28
15
|
|
29
16
|
== Example muddyit.yml
|
30
17
|
|
@@ -53,7 +40,7 @@ can be stored in a yml file, an example of which is provided below.
|
|
53
40
|
require 'muddyit_fu'
|
54
41
|
muddyit = Muddyit.new('muddyit.yml')
|
55
42
|
site = muddyit.sites.first
|
56
|
-
site.pages.create({:
|
43
|
+
site.pages.create({:uri => 'http://news.bbc.co.uk/1/hi/uk_politics/8011321.stm'}, {:minium_confidence => 0.2})
|
57
44
|
|
58
45
|
== View categorised pages
|
59
46
|
|
@@ -100,10 +87,6 @@ can be stored in a yml file, an example of which is provided below.
|
|
100
87
|
puts "#{results[:page].title} #{results[:count]}"
|
101
88
|
end
|
102
89
|
|
103
|
-
== Obtaining oauth access credentials
|
104
|
-
|
105
|
-
See http://gist.github.com/178993
|
106
|
-
|
107
90
|
== Contact
|
108
91
|
|
109
92
|
Author: Rob Lee
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.8
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'muddyit_fu'
|
4
|
+
require 'rss'
|
5
|
+
require 'open-uri'
|
6
|
+
|
7
|
+
# Connect to Muddy
|
8
|
+
muddyit = Muddyit.new('./config.yml')
|
9
|
+
site = muddyit.sites.find(:all).first
|
10
|
+
# Parse RSS
|
11
|
+
rss_content = ''
|
12
|
+
open('http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/uk_politics/rss.xml') do |f|
|
13
|
+
rss_content = f.read
|
14
|
+
end
|
15
|
+
rss = RSS::Parser.parse(rss_content, false)
|
16
|
+
# Loop through, analyse and display entities
|
17
|
+
rss.items.each do |item|
|
18
|
+
page = site.pages.create({:uri => item.guid.content}, {:realtime => true, :store => false})
|
19
|
+
puts "#{item.guid.content} contains:"
|
20
|
+
page.entities.each do |entity|
|
21
|
+
puts "\t#{entity.term}, #{entity.classification}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/examples/oauth.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# Script to ease muddy oauth application verification
|
4
|
+
# from http://github.com/jnunemaker/twitter/blob/master/examples/oauth.rb
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'muddyit_fu'
|
8
|
+
require 'launchy'
|
9
|
+
|
10
|
+
puts "> enter consumer key"
|
11
|
+
token = gets.chomp
|
12
|
+
puts "> enter consumer secret"
|
13
|
+
secret = gets.chomp
|
14
|
+
|
15
|
+
oauth = Muddyit::OAuth.new(token, secret)
|
16
|
+
rtoken = oauth.request_token.token
|
17
|
+
rsecret = oauth.request_token.secret
|
18
|
+
|
19
|
+
puts "> redirecting you to muddy to authorize"
|
20
|
+
puts "> opening #{oauth.request_token.authorize_url}"
|
21
|
+
Launchy.open(oauth.request_token.authorize_url)
|
22
|
+
|
23
|
+
puts "> authorize in the browser and then press enter"
|
24
|
+
waiting = gets.chomp
|
25
|
+
|
26
|
+
begin
|
27
|
+
stoken,ssecret = oauth.authorize_from_request(rtoken, rsecret)
|
28
|
+
|
29
|
+
puts "Access Details"
|
30
|
+
puts
|
31
|
+
puts "Token : #{stoken}"
|
32
|
+
puts "Secret : #{ssecret}"
|
33
|
+
puts
|
34
|
+
|
35
|
+
puts "Account sites"
|
36
|
+
puts
|
37
|
+
|
38
|
+
muddyit = Muddyit.new(:consumer_key => token,
|
39
|
+
:consumer_secret => secret,
|
40
|
+
:access_token => stoken,
|
41
|
+
:access_token_secret => ssecret)
|
42
|
+
|
43
|
+
muddyit.sites.find(:all).each do |site|
|
44
|
+
puts "#{site.label} has token #{site.token}"
|
45
|
+
end
|
46
|
+
|
47
|
+
rescue OAuth::Unauthorized
|
48
|
+
puts "> FAIL!"
|
49
|
+
end
|
data/lib/muddyit/base.rb
CHANGED
@@ -67,8 +67,8 @@ module Muddyit
|
|
67
67
|
raise 'config file must contain consumer_key and consumer_secret' unless @consumer_key and @consumer_secret
|
68
68
|
end
|
69
69
|
|
70
|
-
@consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret, {:site=>@rest_endpoint})
|
71
|
-
@accesstoken = OAuth::AccessToken.new(@consumer, @access_token, @access_token_secret)
|
70
|
+
@consumer = ::OAuth::Consumer.new(@consumer_key, @consumer_secret, {:site=>@rest_endpoint})
|
71
|
+
@accesstoken = ::OAuth::AccessToken.new(@consumer, @access_token, @access_token_secret)
|
72
72
|
|
73
73
|
end
|
74
74
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Borrowed from http://github.com/jnunemaker/twitter
|
2
|
+
module Muddyit
|
3
|
+
class OAuth
|
4
|
+
extend Forwardable
|
5
|
+
def_delegators :access_token, :get, :post, :put, :delete
|
6
|
+
|
7
|
+
attr_reader :ctoken, :csecret, :consumer_options
|
8
|
+
|
9
|
+
|
10
|
+
def initialize(ctoken, csecret, options={})
|
11
|
+
@ctoken, @csecret, @consumer_options = ctoken, csecret, {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def consumer
|
15
|
+
@consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => 'http://muddy.it'}.merge(consumer_options))
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_callback_url(url)
|
19
|
+
clear_request_token
|
20
|
+
request_token(:oauth_callback => url)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Note: If using oauth with a web app, be sure to provide :oauth_callback.
|
24
|
+
# Options:
|
25
|
+
# :oauth_callback => String, url that twitter should redirect to
|
26
|
+
def request_token(options={})
|
27
|
+
@request_token ||= consumer.get_request_token(options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def authorize_from_request(rtoken, rsecret)
|
31
|
+
request_token = ::OAuth::RequestToken.new(consumer, rtoken, rsecret)
|
32
|
+
access_token = request_token.get_access_token()
|
33
|
+
@atoken, @asecret = access_token.token, access_token.secret
|
34
|
+
end
|
35
|
+
|
36
|
+
def access_token
|
37
|
+
@access_token ||= ::OAuth::AccessToken.new(consumer, @atoken, @asecret)
|
38
|
+
end
|
39
|
+
|
40
|
+
def authorize_from_access(atoken, asecret)
|
41
|
+
@atoken, @asecret = atoken, asecret
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def clear_request_token
|
46
|
+
@request_token = nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
class Muddyit::Sites::Site::Entities::Entity < Muddyit::Generic
|
2
2
|
|
3
|
-
def classification
|
4
|
-
unless @attributes[:type]
|
5
|
-
# We merge here as we don't want to overwrite a entity specific confidence score
|
6
|
-
@attributes.merge!(self.fetch)
|
7
|
-
end
|
8
|
-
@attributes[:type]
|
9
|
-
end
|
3
|
+
# def classification
|
4
|
+
# unless @attributes[:type]
|
5
|
+
# # We merge here as we don't want to overwrite a entity specific confidence score
|
6
|
+
# @attributes.merge!(self.fetch)
|
7
|
+
# end
|
8
|
+
# @attributes[:type]
|
9
|
+
# end
|
10
10
|
|
11
11
|
# retrieve entities related to the specified entity within the site entities collection
|
12
12
|
#
|
@@ -27,7 +27,7 @@ class Muddyit::Sites::Site::Entities::Entity < Muddyit::Generic
|
|
27
27
|
|
28
28
|
protected
|
29
29
|
def fetch
|
30
|
-
api_url = "/sites/#{@attributes[:site]
|
30
|
+
api_url = "/sites/#{@attributes[:site].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
|
@@ -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)
|
82
|
+
results.push Muddyit::Sites::Site::Entities::Entity.new(@muddyit, result.merge!(:site => @attributes[:site]))
|
83
83
|
end
|
84
84
|
@attributes[:entities] = results
|
85
85
|
end
|
data/lib/muddyit_fu.rb
CHANGED
@@ -6,6 +6,7 @@ require 'json'
|
|
6
6
|
#gem 'monkeyhelper-oauth', :lib => 'lib/oauth'
|
7
7
|
require 'oauth/consumer'
|
8
8
|
require 'digest/md5'
|
9
|
+
require 'forwardable'
|
9
10
|
|
10
11
|
require 'pp'
|
11
12
|
|
@@ -46,7 +47,7 @@ class Hash
|
|
46
47
|
end
|
47
48
|
|
48
49
|
# base must load first
|
49
|
-
%w(base 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 sites entities sites/site sites/pages sites/pages/page sites/pages/page/extracted_content sites/entities sites/entities/entity).each do |file|
|
50
51
|
require File.join(File.dirname(__FILE__), 'muddyit', file)
|
51
52
|
end
|
52
53
|
|
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.
|
5
|
+
s.version = "0.2.8"
|
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-
|
9
|
+
s.date = %q{2009-11-10}
|
10
10
|
s.email = %q{support[at]muddy.it}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
@@ -19,10 +19,13 @@ Gem::Specification.new do |s|
|
|
19
19
|
"README.rdoc",
|
20
20
|
"Rakefile",
|
21
21
|
"VERSION",
|
22
|
+
"examples/newsindexer.rb",
|
23
|
+
"examples/oauth.rb",
|
22
24
|
"lib/muddyit/base.rb",
|
23
25
|
"lib/muddyit/entities.rb",
|
24
26
|
"lib/muddyit/errors.rb",
|
25
27
|
"lib/muddyit/generic.rb",
|
28
|
+
"lib/muddyit/oauth.rb",
|
26
29
|
"lib/muddyit/sites.rb",
|
27
30
|
"lib/muddyit/sites/entities.rb",
|
28
31
|
"lib/muddyit/sites/entities/entity.rb",
|
@@ -38,6 +41,10 @@ Gem::Specification.new do |s|
|
|
38
41
|
s.require_paths = ["lib"]
|
39
42
|
s.rubygems_version = %q{1.3.5}
|
40
43
|
s.summary = %q{Provides a ruby interface to muddy.it}
|
44
|
+
s.test_files = [
|
45
|
+
"examples/newsindexer.rb",
|
46
|
+
"examples/oauth.rb"
|
47
|
+
]
|
41
48
|
|
42
49
|
if s.respond_to? :specification_version then
|
43
50
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
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.
|
4
|
+
version: 0.2.8
|
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-
|
12
|
+
date: 2009-11-10 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -48,10 +48,13 @@ files:
|
|
48
48
|
- README.rdoc
|
49
49
|
- Rakefile
|
50
50
|
- VERSION
|
51
|
+
- examples/newsindexer.rb
|
52
|
+
- examples/oauth.rb
|
51
53
|
- lib/muddyit/base.rb
|
52
54
|
- lib/muddyit/entities.rb
|
53
55
|
- lib/muddyit/errors.rb
|
54
56
|
- lib/muddyit/generic.rb
|
57
|
+
- lib/muddyit/oauth.rb
|
55
58
|
- lib/muddyit/sites.rb
|
56
59
|
- lib/muddyit/sites/entities.rb
|
57
60
|
- lib/muddyit/sites/entities/entity.rb
|
@@ -89,5 +92,6 @@ rubygems_version: 1.3.5
|
|
89
92
|
signing_key:
|
90
93
|
specification_version: 3
|
91
94
|
summary: Provides a ruby interface to muddy.it
|
92
|
-
test_files:
|
93
|
-
|
95
|
+
test_files:
|
96
|
+
- examples/newsindexer.rb
|
97
|
+
- examples/oauth.rb
|