monkeyhelper-muddyit_fu 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/README.rdoc +84 -17
- data/Rakefile +3 -0
- data/VERSION +1 -1
- data/lib/muddyit/base.rb +41 -96
- data/lib/muddyit/entity.rb +1 -1
- data/lib/muddyit/page.rb +11 -20
- data/lib/muddyit/pages.rb +19 -24
- data/lib/muddyit/site.rb +1 -1
- data/lib/muddyit/sites.rb +2 -2
- data/lib/muddyit_fu.rb +1 -2
- data/muddyit_fu.gemspec +10 -5
- metadata +25 -6
data/CHANGELOG
CHANGED
data/README.rdoc
CHANGED
@@ -1,20 +1,38 @@
|
|
1
|
-
=
|
1
|
+
= muddyit_fu
|
2
|
+
|
3
|
+
== Installation
|
4
|
+
|
5
|
+
sudo gem install muddyit-fu
|
2
6
|
|
3
7
|
== Getting started
|
4
8
|
|
5
|
-
|
9
|
+
muddy.it uses oauth to manage it's api access. To access the muddy.it data
|
10
|
+
programmatically you will need to register an application. Login and visit :
|
6
11
|
|
7
|
-
|
12
|
+
http://www.muddy.it/oauth_clients/
|
13
|
+
|
14
|
+
You can register an application here, a callback URI isn't required.
|
15
|
+
|
16
|
+
The 'consumer token' and 'consumer secret' are used to generate a token for
|
17
|
+
accessing muddy.it. For further details and an example of how to programatically
|
18
|
+
generate a new access token for muddy.it see here :
|
8
19
|
|
9
|
-
|
20
|
+
http://stakeventures.com/articles/2008/02/23/developing-oauth-clients-in-ruby
|
21
|
+
|
22
|
+
See the 'Authorising clients using irb' section for a sample irb session.
|
23
|
+
|
24
|
+
These details are then used to provide access to the service. The credentials
|
25
|
+
can be stored in a yml file, an example of which is provided below.
|
10
26
|
|
11
27
|
== Example muddyit.yml
|
12
28
|
|
13
|
-
---
|
14
|
-
|
15
|
-
|
29
|
+
---
|
30
|
+
consumer_key: "YOUR_CONSUMER_KEY"
|
31
|
+
consumer_secret: "YOUR_CONSUMER_SECRET"
|
32
|
+
access_token: "YOUR_ACCESS_TOKEN"
|
33
|
+
access_token_secret: "YOUR_ACCESS_TOKEN_SECRET"
|
16
34
|
|
17
|
-
==
|
35
|
+
== Retrieving a site
|
18
36
|
|
19
37
|
require 'muddyit_fu'
|
20
38
|
muddyit = Muddyit.new('muddyit.yml')
|
@@ -27,13 +45,15 @@ secret_access_key: "YOUR SECRET"
|
|
27
45
|
require 'muddyit_fu'
|
28
46
|
muddyit = Muddyit.new('muddyit.yml')
|
29
47
|
site = muddyit.sites.first
|
30
|
-
site.pages.categorise(:identifier => 'http://news.bbc.co.uk/1/hi/uk_politics/8011321.stm')
|
48
|
+
site.pages.categorise({:identifier => 'http://news.bbc.co.uk/1/hi/uk_politics/8011321.stm'}, {:minium_confidence => 0.2})
|
31
49
|
|
32
50
|
== View categorised pages
|
33
51
|
|
34
52
|
require 'muddyit_fu'
|
35
|
-
muddyit = Muddyit.new(:
|
36
|
-
:
|
53
|
+
muddyit = Muddyit.new(:consumer_key => 'aaa',
|
54
|
+
:consumer_secret => 'bbb',
|
55
|
+
:access_token => 'ccc',
|
56
|
+
:access_token_secret => 'ddd')
|
37
57
|
site = muddyit.sites.first
|
38
58
|
site.pages.index do |page|
|
39
59
|
puts page.content_data.title
|
@@ -45,8 +65,7 @@ secret_access_key: "YOUR SECRET"
|
|
45
65
|
== View all pages containing 'Gordon Brown'
|
46
66
|
|
47
67
|
require 'muddyit_fu'
|
48
|
-
muddyit =
|
49
|
-
:secret_access_key => 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')
|
68
|
+
muddyit = Muddyit.new('muddyit.yml')
|
50
69
|
site = muddyit.sites.first
|
51
70
|
site.pages.find_by_entity('http://dbpedia.org/resource/Gordon_Brown') do |page|
|
52
71
|
puts page.identifier
|
@@ -55,8 +74,7 @@ secret_access_key: "YOUR SECRET"
|
|
55
74
|
== Find related entities for 'Gordon Brown'
|
56
75
|
|
57
76
|
require 'muddyit_fu'
|
58
|
-
muddyit =
|
59
|
-
:secret_access_key => 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')
|
77
|
+
muddyit = Muddyit.new('muddyit.yml')
|
60
78
|
site = muddyit.sites.first
|
61
79
|
site.pages.related_entities('http://dbpedia.org/resource/Gordon_Brown').each do |entity|
|
62
80
|
puts "#{entity.uri} : #{entity.confidence}"
|
@@ -65,8 +83,7 @@ secret_access_key: "YOUR SECRET"
|
|
65
83
|
== Find related content for : http://news.bbc.co.uk/1/hi/uk_politics/7878418.stm
|
66
84
|
|
67
85
|
require 'muddyit_fu'
|
68
|
-
muddyit =
|
69
|
-
:secret_access_key => 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')
|
86
|
+
muddyit = Muddyit.new('muddyit.yml')
|
70
87
|
site = muddyit.sites.first
|
71
88
|
page = site.pages.find('http://news.bbc.co.uk/1/hi/uk_politics/7878418.stm')
|
72
89
|
puts "Our page : #{page.content_data.title}\n\n"
|
@@ -74,6 +91,56 @@ secret_access_key: "YOUR SECRET"
|
|
74
91
|
puts "#{results[:page].content_data.title} #{results[:count]}"
|
75
92
|
end
|
76
93
|
|
94
|
+
== Authorising clients using irb
|
95
|
+
|
96
|
+
robl@fry:~/$ irb
|
97
|
+
irb(main):002:0> require 'rubygems'
|
98
|
+
=> true
|
99
|
+
irb(main):003:0> require 'oauth'
|
100
|
+
=> true
|
101
|
+
irb(main):004:0> require 'oauth/consumer'
|
102
|
+
=> false
|
103
|
+
irb(main):005:0> @consumer=OAuth::Consumer.new "yourtoken", "yoursecret", {:site => 'http://www.muddy.it' }
|
104
|
+
=> #<OAuth::Consumer:0xb7683b7c @key="yourtoken", @secret="yoursecret", @options={:oauth_version=>"1.0",
|
105
|
+
:signature_method=>"HMAC-SHA1", :request_token_path=>"/oauth/request_token",
|
106
|
+
:site=>"http://www.muddy.it", :scheme=>:header,
|
107
|
+
:authorize_path=>"/oauth/authorize", :access_token_path=>"/oauth/access_token",
|
108
|
+
:http_method=>:post}>
|
109
|
+
irb(main):006:0> @request_token=@consumer.get_request_token
|
110
|
+
=> #<OAuth::RequestToken:0xb76778e0 @consumer=#<OAuth::Consumer:0xb7683b7c @key="tokenkey",
|
111
|
+
@http=#<Net::HTTP www.muddy.it:80 open=false>, @http_method=:post,
|
112
|
+
@secret="tokensecret", @options={:oauth_version=>"1.0", :signature_method=>"HMAC-SHA1",
|
113
|
+
:request_token_path=>"/oauth/request_token", :site=>"http://www.muddy.it",
|
114
|
+
:scheme=>:header, :authorize_path=>"/oauth/authorize", :access_token_path=>"/oauth/access_token",
|
115
|
+
:http_method=>:post}>, @token="tokenkey", @secret="tokensecret">
|
116
|
+
irb(main):007:0> @request_token.authorize_url
|
117
|
+
=> "http://www.muddy.it/oauth/authorize?oauth_token=tokenkey"
|
118
|
+
|
119
|
+
To authorise the application, visit the URL, check the 'authorize access' box and
|
120
|
+
save. The request token can now be exchanged for an access token :
|
121
|
+
|
122
|
+
irb(main):008:0> @access_token=@request_token.get_access_token
|
123
|
+
=> #<OAuth::AccessToken:0xb7667c10 @consumer=#<OAuth::Consumer:0xb7683b7c @key="accesstoken_key",
|
124
|
+
@http=#<Net::HTTP www.muddy.it:80 open=false>, @http_method=:post,
|
125
|
+
@secret="accesstoken_secret", @options={:oauth_version=>"1.0",
|
126
|
+
:signature_method=>"HMAC-SHA1", :request_token_path=>"/oauth/request_token",
|
127
|
+
:site=>"http://www.muddy.it", :scheme=>:header, :authorize_path=>"/oauth/authorize",
|
128
|
+
:access_token_path=>"/oauth/access_token", :http_method=>:post}>, @token="accesstoken",
|
129
|
+
@secret="accesstoken_secret">
|
130
|
+
|
131
|
+
This token can also be used to access the service :
|
132
|
+
|
133
|
+
irb(main):016:0> res = @access_token.get "/sites.json"
|
134
|
+
=> #<Net::HTTPOK 200 OK readbody=true>
|
135
|
+
irb(main):017:0> res.body
|
136
|
+
....
|
137
|
+
|
138
|
+
The access token credentials to be used with muddyit_fu are :
|
139
|
+
|
140
|
+
irb(main):011:0> @access_token.token
|
141
|
+
=> "sometoken"
|
142
|
+
irb(main):012:0> @access_token.secret
|
143
|
+
=> "somesecret"
|
77
144
|
|
78
145
|
== Contact
|
79
146
|
|
data/Rakefile
CHANGED
@@ -9,6 +9,9 @@ begin
|
|
9
9
|
gem.email = "robl[at]monkeyhelper.com"
|
10
10
|
gem.homepage = "http://github.com/monkeyhelper/muddyit_fu"
|
11
11
|
gem.authors = ["robl"]
|
12
|
+
gem.add_dependency('json', '>= 0.0.0')
|
13
|
+
gem.add_dependency('oauth', '>= 0.0.0')
|
14
|
+
|
12
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
16
|
end
|
14
17
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/muddyit/base.rb
CHANGED
@@ -8,12 +8,12 @@ module Muddyit
|
|
8
8
|
class_attr_accessor :http_open_timeout
|
9
9
|
class_attr_accessor :http_read_timeout
|
10
10
|
attr_accessor :rest_endpoint
|
11
|
-
attr_reader :
|
11
|
+
attr_reader :consumer_key, :consumer_secret, :access_token, :access_token_secret
|
12
12
|
|
13
|
-
@@http_open_timeout =
|
14
|
-
@@http_read_timeout =
|
13
|
+
@@http_open_timeout = 120
|
14
|
+
@@http_read_timeout = 120
|
15
15
|
|
16
|
-
REST_ENDPOINT = 'http://www.muddy.it
|
16
|
+
REST_ENDPOINT = 'http://www.muddy.it'
|
17
17
|
|
18
18
|
# Set the request signing method
|
19
19
|
@@digest1 = OpenSSL::Digest::Digest.new("sha1")
|
@@ -26,10 +26,14 @@ module Muddyit
|
|
26
26
|
#
|
27
27
|
# You can either pass a hash with the following attributes:
|
28
28
|
#
|
29
|
-
# * :
|
30
|
-
# the
|
31
|
-
# * :
|
32
|
-
# the secret
|
29
|
+
# * :consumer_key (Required)
|
30
|
+
# the consumer key
|
31
|
+
# * :consumer_secret (Required)
|
32
|
+
# the consumer secret
|
33
|
+
# * :access_token (Required)
|
34
|
+
# the token
|
35
|
+
# * :access_token_secret (Required)
|
36
|
+
# the token secret
|
33
37
|
# * :rest_endpoint (Optional)
|
34
38
|
# the muddy.it rest service endpoint
|
35
39
|
# or:
|
@@ -38,24 +42,34 @@ module Muddyit
|
|
38
42
|
#
|
39
43
|
# Config Example (yaml file)
|
40
44
|
# ---
|
41
|
-
#
|
42
|
-
#
|
45
|
+
# consumer_key: AAA
|
46
|
+
# consumer_secret: BBB
|
47
|
+
# access_token: CCC
|
48
|
+
# access_token_secret: DDD
|
43
49
|
#
|
44
50
|
def initialize(config_hash_or_file)
|
45
51
|
if config_hash_or_file.is_a? Hash
|
46
52
|
config_hash_or_file.nested_symbolize_keys!
|
47
|
-
@
|
48
|
-
@
|
53
|
+
@consumer_key = config_hash_or_file[:consumer_key]
|
54
|
+
@consumer_secret = config_hash_or_file[:consumer_secret]
|
55
|
+
@access_token = config_hash_or_file[:access_token]
|
56
|
+
@access_token_secret = config_hash_or_file[:access_token_secret]
|
49
57
|
@rest_endpoint = config_hash_or_file.has_key?(:rest_endpoint) ? config_hash_or_file[:rest_endpoint] : REST_ENDPOINT
|
50
|
-
raise 'config_hash must contain
|
58
|
+
raise 'config_hash must contain consumer_key and consumer_secret' unless @consumer_key and @consumer_secret
|
51
59
|
else
|
52
60
|
config = YAML.load_file(config_hash_or_file)
|
53
61
|
config.nested_symbolize_keys!
|
54
|
-
@
|
55
|
-
@
|
62
|
+
@consumer_key = config[:consumer_key]
|
63
|
+
@consumer_secret = config[:consumer_secret]
|
64
|
+
@access_token = config[:access_token]
|
65
|
+
@access_token_secret = config[:access_token_secret]
|
56
66
|
@rest_endpoint = config.has_key?(:rest_endpoint) ? config[:rest_endpoint] : REST_ENDPOINT
|
57
|
-
raise 'config file must contain
|
67
|
+
raise 'config file must contain consumer_key and consumer_secret' unless @consumer_key and @consumer_secret
|
58
68
|
end
|
69
|
+
|
70
|
+
@consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret, {:site=>@rest_endpoint})
|
71
|
+
@accesstoken = OAuth::AccessToken.new(@consumer, @access_token, @access_token_secret)
|
72
|
+
|
59
73
|
end
|
60
74
|
|
61
75
|
# sends a request to the muddyit REST api
|
@@ -68,13 +82,12 @@ module Muddyit
|
|
68
82
|
# * options (Optional)
|
69
83
|
# hash of query parameters, you do not need to include access_key_id, secret_access_key because these are added automatically
|
70
84
|
#
|
71
|
-
def send_request(api_url, http_method = :get,
|
85
|
+
def send_request(api_url, http_method = :get, opts = {}, body = nil)
|
72
86
|
|
73
87
|
raise 'no api_url supplied' unless api_url
|
74
|
-
|
75
|
-
res = request_over_http(api_url, http_method, options)
|
88
|
+
res = request_over_http(api_url, http_method, opts, body)
|
76
89
|
# Strip any js wrapping methods
|
77
|
-
|
90
|
+
|
78
91
|
if res.body =~ /^.+\((.+)\)$/
|
79
92
|
r = JSON.parse($1)
|
80
93
|
else
|
@@ -91,94 +104,26 @@ module Muddyit
|
|
91
104
|
protected
|
92
105
|
|
93
106
|
# For easier testing. You can mock this method with a XML file you re expecting to receive
|
94
|
-
def request_over_http(api_url, http_method,
|
107
|
+
def request_over_http(api_url, http_method, opts, body)
|
95
108
|
|
96
|
-
|
97
|
-
|
98
|
-
url = URI.parse(api_url)
|
109
|
+
http_opts = { "Accept" => "application/json", "Content-Type" => "application/json", "User-Agent" => "muddyit_fu" }
|
110
|
+
query_string = opts.to_a.map {|x| x.join("=")}.join("&")
|
99
111
|
|
100
112
|
case http_method
|
101
113
|
when :get
|
102
|
-
|
103
|
-
|
114
|
+
url = opts.empty? ? api_url : "#{api_url}?#{query_string}"
|
115
|
+
@accesstoken.get(url, http_opts)
|
104
116
|
when :post
|
105
|
-
|
117
|
+
@accesstoken.post(api_url, body, http_opts)
|
106
118
|
when :put
|
107
|
-
|
119
|
+
@accesstoken.put(api_url, body, http_opts)
|
108
120
|
when :delete
|
109
|
-
|
121
|
+
@accesstoken.delete(api_url, http_opts)
|
110
122
|
else
|
111
123
|
raise 'invalid http method specified'
|
112
124
|
end
|
113
|
-
|
114
|
-
options = calculate_signature(http_method, url.path, options)
|
115
|
-
req.set_form_data(options) unless options.keys.empty?
|
116
|
-
#req.basic_auth @username, @password
|
117
|
-
|
118
|
-
http = Net::HTTP.new(url.host, url.port)
|
119
|
-
http.open_timeout = @@http_open_timeout
|
120
|
-
http.read_timeout = @@http_read_timeout
|
121
|
-
http.start do |http|
|
122
|
-
res = http.request(req)
|
123
|
-
case res
|
124
|
-
when Net::HTTPSuccess
|
125
|
-
return res
|
126
|
-
else
|
127
|
-
raise Muddyit::Errors.error_for(res.code, 'HTTP Error')
|
128
|
-
end
|
129
|
-
end
|
130
125
|
|
131
126
|
end
|
132
127
|
|
133
|
-
# aws request signature methods, taken from http://rightscale.rubyforge.org/right_aws_gem_doc
|
134
|
-
|
135
|
-
def calculate_signature(http_verb, url, options)
|
136
|
-
endpoint = URI.parse(@rest_endpoint)
|
137
|
-
options.nested_stringify_keys!
|
138
|
-
options.delete('Signature')
|
139
|
-
options['AccessKeyId'] = @access_key_id
|
140
|
-
options['Signature'] = sign_request_v2(@secret_access_key, options, http_verb.to_s, endpoint.host, url)
|
141
|
-
|
142
|
-
return options
|
143
|
-
end
|
144
|
-
|
145
|
-
def signed_service_params(aws_secret_access_key, service_hash, http_verb, host, uri)
|
146
|
-
sign_request_v2(aws_secret_access_key, service_hash, http_verb, host, uri)
|
147
|
-
end
|
148
|
-
|
149
|
-
def sign_request_v2(aws_secret_access_key, service_hash, http_verb, host, uri)
|
150
|
-
fix_service_params(service_hash, '2')
|
151
|
-
# select a signing method (make an old openssl working with sha1)
|
152
|
-
# make 'HmacSHA256' to be a default one
|
153
|
-
service_hash['SignatureMethod'] = 'HmacSHA256' unless ['HmacSHA256', 'HmacSHA1'].include?(service_hash['SignatureMethod'])
|
154
|
-
service_hash['SignatureMethod'] = 'HmacSHA1' unless @@digest256
|
155
|
-
# select a digest
|
156
|
-
digest = (service_hash['SignatureMethod'] == 'HmacSHA256' ? @@digest256 : @@digest1)
|
157
|
-
# form string to sign
|
158
|
-
canonical_string = service_hash.keys.sort.map do |key|
|
159
|
-
"#{amz_escape(key)}=#{amz_escape(service_hash[key])}"
|
160
|
-
end.join('&')
|
161
|
-
string_to_sign = "#{http_verb.to_s.upcase}\n#{host.downcase}\n#{uri}\n#{canonical_string}"
|
162
|
-
|
163
|
-
# sign the string
|
164
|
-
amz_escape(Base64.encode64(OpenSSL::HMAC.digest(digest, aws_secret_access_key, string_to_sign)).strip)
|
165
|
-
end
|
166
|
-
|
167
|
-
# Set a timestamp and a signature version
|
168
|
-
def fix_service_params(service_hash, signature)
|
169
|
-
service_hash["Timestamp"] ||= Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.000Z") unless service_hash["Expires"]
|
170
|
-
service_hash["SignatureVersion"] = signature
|
171
|
-
service_hash
|
172
|
-
end
|
173
|
-
|
174
|
-
# Escape a string accordingly Amazon rulles
|
175
|
-
# http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/index.html?REST_RESTAuth.html
|
176
|
-
def amz_escape(param)
|
177
|
-
param.to_s.gsub(/([^a-zA-Z0-9._~-]+)/n) do
|
178
|
-
'%' + $1.unpack('H2' * $1.size).join('%').upcase
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
|
183
128
|
end
|
184
129
|
end
|
data/lib/muddyit/entity.rb
CHANGED
@@ -10,7 +10,7 @@ class Muddyit::Entity < Muddyit::Generic
|
|
10
10
|
|
11
11
|
protected
|
12
12
|
def fetch
|
13
|
-
api_url = "
|
13
|
+
api_url = "/entities/#{URI.escape(CGI.escape(@attributes[:uri]),'.')}"
|
14
14
|
response = @muddyit.send_request(api_url, :get)
|
15
15
|
response.nested_symbolize_keys!
|
16
16
|
end
|
data/lib/muddyit/page.rb
CHANGED
@@ -12,23 +12,15 @@ class Muddyit::Sites::Site::Page < Muddyit::Generic
|
|
12
12
|
# Params
|
13
13
|
# * options (Required)
|
14
14
|
#
|
15
|
-
def refresh(options)
|
15
|
+
def refresh(options = {})
|
16
16
|
|
17
17
|
# Ensure we get content_data as well
|
18
|
-
options[:include_content] = true
|
18
|
+
options[:include_content] = true
|
19
19
|
|
20
|
-
|
21
|
-
options[:uri] = options[:identifier] if options.has_key?(:identifier) && !options.has_key?(:uri) && !options.has_key?(:text)
|
20
|
+
body = { :page => { :uri => self.uri }, :options => options }
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
options[:uri] = URI.escape(CGI.escape(options[:uri]),'.')
|
26
|
-
elsif options.has_key?(:identifier)
|
27
|
-
options[:identifier] = URI.escape(CGI.escape(options[:identifier]),'.')
|
28
|
-
end
|
29
|
-
|
30
|
-
api_url = "#{@muddyit.rest_endpoint}/sites/#{self.site.attributes[:token]}/pages/#{URI.escape(CGI.escape(@attributes[:identifier]),'.')}/refresh"
|
31
|
-
response = @muddyit.send_request(api_url, :post, options)
|
22
|
+
api_url = "/sites/#{self.site.attributes[:token]}/pages/#{URI.escape(CGI.escape(self.identifier),'.')}"
|
23
|
+
response = @muddyit.send_request(api_url, :put, {}, body.to_json)
|
32
24
|
return Muddyit::Sites::Site::Page.new(@muddyit, response.merge!(:site => self.site))
|
33
25
|
end
|
34
26
|
|
@@ -51,7 +43,7 @@ class Muddyit::Sites::Site::Page < Muddyit::Generic
|
|
51
43
|
# delete the page
|
52
44
|
#
|
53
45
|
def destroy
|
54
|
-
api_url = "
|
46
|
+
api_url = "/sites/#{self.site.attributes[:token]}/pages/#{URI.escape(CGI.escape(@attributes[:identifier]),'.')}"
|
55
47
|
response = @muddyit.send_request(api_url, :delete, {})
|
56
48
|
# Is this the correct thing to return ?
|
57
49
|
return true
|
@@ -63,9 +55,8 @@ class Muddyit::Sites::Site::Page < Muddyit::Generic
|
|
63
55
|
# * options (Optional)
|
64
56
|
#
|
65
57
|
def related_content(options = {})
|
66
|
-
api_url = "
|
58
|
+
api_url = "/sites/#{self.site.attributes[:token]}/pages/#{URI.escape(CGI.escape(@attributes[:identifier]),'.')}/related/content"
|
67
59
|
response = @muddyit.send_request(api_url, :get, options)
|
68
|
-
|
69
60
|
results = []
|
70
61
|
response.each { |result|
|
71
62
|
# The return format needs sorting out here .......
|
@@ -76,7 +67,7 @@ class Muddyit::Sites::Site::Page < Muddyit::Generic
|
|
76
67
|
|
77
68
|
protected
|
78
69
|
def fetch
|
79
|
-
api_url = "
|
70
|
+
api_url = "/sites/#{self.site.attributes[:token]}/pages/#{URI.escape(CGI.escape(@attributes[:identifier]),'.')}"
|
80
71
|
response = @muddyit.send_request(api_url, :get, {:include_content => true })
|
81
72
|
response.nested_symbolize_keys!
|
82
73
|
end
|
@@ -84,11 +75,11 @@ class Muddyit::Sites::Site::Page < Muddyit::Generic
|
|
84
75
|
# Convert results to entities
|
85
76
|
def create_entities
|
86
77
|
results = []
|
87
|
-
if @attributes.has_key?(:
|
88
|
-
@attributes[:
|
78
|
+
if @attributes.has_key?(:entities)
|
79
|
+
@attributes[:entities].each do |result|
|
89
80
|
results.push Muddyit::Entity.new(@muddyit, result)
|
90
81
|
end
|
91
|
-
@attributes[:
|
82
|
+
@attributes[:entities] = results
|
92
83
|
end
|
93
84
|
end
|
94
85
|
|
data/lib/muddyit/pages.rb
CHANGED
@@ -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 = "
|
15
|
+
api_url = "/sites/#{self.site.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
|
-
response['
|
20
|
+
response['pages'].each { |page|
|
21
21
|
yield Muddyit::Sites::Site::Page.new(@muddyit, page.merge!(:site => self.site))
|
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 = "
|
27
|
+
api_url = "/sites/#{self.site.attributes[:token]}/pages"
|
28
28
|
response = @muddyit.send_request(api_url, :get, options)
|
29
29
|
|
30
30
|
pages = []
|
31
|
-
response['
|
31
|
+
response['pages'].each { |page| pages.push Muddyit::Sites::Site::Page.new(@muddyit, page.merge!(:site => self.site)) }
|
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 = "
|
39
|
+
api_url = "/sites/#{self.site.attributes[:token]}/pages/#{URI.escape(CGI.escape(type),'.')}"
|
40
40
|
response = @muddyit.send_request(api_url, :get, {})
|
41
|
-
response.has_key?('
|
41
|
+
response.has_key?('identifier') ? Muddyit::Sites::Site::Page.new(@muddyit, response.merge!(:site => self.site)) : nil
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -49,7 +49,7 @@ class Muddyit::Sites::Site::Pages < Muddyit::Generic
|
|
49
49
|
#
|
50
50
|
def related_entities(uri, options = {})
|
51
51
|
raise "no uri supplied" if uri.nil?
|
52
|
-
api_url = "
|
52
|
+
api_url = "/sites/#{self.site.attributes[:token]}/related/entities/#{URI.escape(CGI.escape(uri),'.')}"
|
53
53
|
response = @muddyit.send_request(api_url, :get, options)
|
54
54
|
|
55
55
|
results = []
|
@@ -65,25 +65,20 @@ class Muddyit::Sites::Site::Pages < Muddyit::Generic
|
|
65
65
|
# Params
|
66
66
|
# * options (Required)
|
67
67
|
#
|
68
|
-
def categorise(options)
|
68
|
+
def categorise(doc = {}, options = {})
|
69
69
|
|
70
70
|
# Ensure we get content_data as well
|
71
71
|
options[:include_content] = true
|
72
72
|
|
73
|
-
# Set the URI if not set
|
74
|
-
options[:uri] = options[:identifier] if options.has_key?(:identifier) && !options.has_key?(:uri) && !options.has_key?(:text)
|
75
|
-
|
76
73
|
# Ensure we have encoded the identifier and URI
|
77
|
-
|
78
|
-
raise
|
79
|
-
options[:uri] = URI.escape(CGI.escape(options[:uri]),'.')
|
80
|
-
elsif options.has_key?(:identifier)
|
81
|
-
raise if options[:identifier].nil?
|
82
|
-
options[:identifier] = URI.escape(CGI.escape(options[:identifier]),'.')
|
74
|
+
unless doc[:uri] || doc[:text]
|
75
|
+
raise
|
83
76
|
end
|
84
77
|
|
85
|
-
|
86
|
-
|
78
|
+
body = { :page => doc, :options => options }
|
79
|
+
|
80
|
+
api_url = "/sites/#{self.site.attributes[:token]}/pages/"
|
81
|
+
response = @muddyit.send_request(api_url, :post, {}, body.to_json)
|
87
82
|
return Muddyit::Sites::Site::Page.new(@muddyit, response.merge!(:site => self.site))
|
88
83
|
end
|
89
84
|
|
@@ -146,7 +141,7 @@ class Muddyit::Sites::Site::Pages < Muddyit::Generic
|
|
146
141
|
# must contain uri parameter which corresponds to dbpedia uri
|
147
142
|
#
|
148
143
|
def queryAllWithURI(uri, options, &block)
|
149
|
-
api_url = "
|
144
|
+
api_url = "/sites/#{self.site.attributes[:token]}/entities/#{URI.escape(CGI.escape(uri),'.')}"
|
150
145
|
query_page(api_url, options, &block)
|
151
146
|
end
|
152
147
|
|
@@ -159,7 +154,7 @@ class Muddyit::Sites::Site::Pages < Muddyit::Generic
|
|
159
154
|
#
|
160
155
|
#
|
161
156
|
def queryAllWithTerm(term, options, &block)
|
162
|
-
api_url = "
|
157
|
+
api_url = "/sites/#{self.site.attributes[:token]}/terms/#{URI.escape(CGI.escape(term),'.')}"
|
163
158
|
query_page(api_url, options, &block)
|
164
159
|
end
|
165
160
|
|
@@ -174,8 +169,8 @@ class Muddyit::Sites::Site::Pages < Muddyit::Generic
|
|
174
169
|
token = nil
|
175
170
|
begin
|
176
171
|
options.merge!(:page => token) unless token.nil?
|
177
|
-
response = @muddyit.send_request(api_url, :get, options)
|
178
|
-
response['
|
172
|
+
response = @muddyit.send_request(api_url, :get, options.merge!(:page => token))
|
173
|
+
response['pages'].each { |page|
|
179
174
|
yield Muddyit::Sites::Site::Page.new(@muddyit, page.merge!(:site => self.site))
|
180
175
|
}
|
181
176
|
token = response['next_page']
|
@@ -185,7 +180,7 @@ class Muddyit::Sites::Site::Pages < Muddyit::Generic
|
|
185
180
|
response = @muddyit.send_request(api_url, :get, {})
|
186
181
|
|
187
182
|
pages = []
|
188
|
-
response['
|
183
|
+
response['pages'].each { |page| pages.push Muddyit::Sites::Site::Page.new(@muddyit, page.merge!(:site => self.site)) }
|
189
184
|
return { :next_page => response[:next_page], :pages => pages }
|
190
185
|
end
|
191
186
|
end
|
data/lib/muddyit/site.rb
CHANGED
@@ -6,7 +6,7 @@ class Muddyit::Sites::Site < Muddyit::Generic
|
|
6
6
|
|
7
7
|
protected
|
8
8
|
def fetch
|
9
|
-
api_url = "
|
9
|
+
api_url = "/sites/#{@attributes[:token]}"
|
10
10
|
response = @muddyit.send_request(api_url, :get, {})
|
11
11
|
response['site'].nested_symbolize_keys!
|
12
12
|
end
|
data/lib/muddyit/sites.rb
CHANGED
@@ -24,7 +24,7 @@ class Muddyit::Sites < Muddyit::Base
|
|
24
24
|
if type.is_a? Symbol
|
25
25
|
case type
|
26
26
|
when :all
|
27
|
-
api_url = "
|
27
|
+
api_url = "/sites/"
|
28
28
|
response = @muddyit.send_request(api_url, :get, options)
|
29
29
|
sites = []
|
30
30
|
response.each { |site| sites.push Muddyit::Sites::Site.new(@muddyit, site['site']) }
|
@@ -33,7 +33,7 @@ class Muddyit::Sites < Muddyit::Base
|
|
33
33
|
raise 'invalid type specified'
|
34
34
|
end
|
35
35
|
elsif type.is_a? String
|
36
|
-
api_url = "
|
36
|
+
api_url = "/sites/#{type}"
|
37
37
|
response = @muddyit.send_request(api_url, :get, options)
|
38
38
|
return Muddyit::Sites::Site.new(@muddyit, response['site'])
|
39
39
|
else
|
data/lib/muddyit_fu.rb
CHANGED
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.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["robl"]
|
9
|
-
s.date = %q{2009-06-
|
9
|
+
s.date = %q{2009-06-23}
|
10
10
|
s.email = %q{robl[at]monkeyhelper.com}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
@@ -31,20 +31,25 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/muddyit_fu.rb",
|
32
32
|
"muddyit_fu.gemspec"
|
33
33
|
]
|
34
|
-
s.has_rdoc = true
|
35
34
|
s.homepage = %q{http://github.com/monkeyhelper/muddyit_fu}
|
36
35
|
s.rdoc_options = ["--charset=UTF-8"]
|
37
36
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = %q{1.3.
|
37
|
+
s.rubygems_version = %q{1.3.4}
|
39
38
|
s.summary = %q{Provides a ruby interface to muddy.it}
|
40
39
|
|
41
40
|
if s.respond_to? :specification_version then
|
42
41
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
-
s.specification_version =
|
42
|
+
s.specification_version = 3
|
44
43
|
|
45
44
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<json>, [">= 0.0.0"])
|
46
|
+
s.add_runtime_dependency(%q<oauth>, [">= 0.0.0"])
|
46
47
|
else
|
48
|
+
s.add_dependency(%q<json>, [">= 0.0.0"])
|
49
|
+
s.add_dependency(%q<oauth>, [">= 0.0.0"])
|
47
50
|
end
|
48
51
|
else
|
52
|
+
s.add_dependency(%q<json>, [">= 0.0.0"])
|
53
|
+
s.add_dependency(%q<oauth>, [">= 0.0.0"])
|
49
54
|
end
|
50
55
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monkeyhelper-muddyit_fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- robl
|
@@ -9,10 +9,29 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-23 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: oauth
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.0
|
34
|
+
version:
|
16
35
|
description:
|
17
36
|
email: robl[at]monkeyhelper.com
|
18
37
|
executables: []
|
@@ -40,7 +59,7 @@ files:
|
|
40
59
|
- lib/muddyit/sites.rb
|
41
60
|
- lib/muddyit_fu.rb
|
42
61
|
- muddyit_fu.gemspec
|
43
|
-
has_rdoc:
|
62
|
+
has_rdoc: false
|
44
63
|
homepage: http://github.com/monkeyhelper/muddyit_fu
|
45
64
|
post_install_message:
|
46
65
|
rdoc_options:
|
@@ -64,7 +83,7 @@ requirements: []
|
|
64
83
|
rubyforge_project:
|
65
84
|
rubygems_version: 1.2.0
|
66
85
|
signing_key:
|
67
|
-
specification_version:
|
86
|
+
specification_version: 3
|
68
87
|
summary: Provides a ruby interface to muddy.it
|
69
88
|
test_files: []
|
70
89
|
|