evri 0.06 → 0.07

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -4,12 +4,18 @@ README.txt
4
4
  Rakefile
5
5
  TODO
6
6
  evri-api.gemspec
7
+ index.html
7
8
  lib/evri.rb
8
9
  lib/evri/entity.rb
9
10
  lib/evri/media.rb
10
11
  lib/evri/relation.rb
12
+ lib/evri/urls.rb
11
13
  lib/evri/zeitgeist.rb
14
+ lib/traverse.rb
15
+ t.rb
16
+ test/barack.txt
12
17
  test/test_entity.rb
13
18
  test/test_evri.rb
14
19
  test/test_media.rb
20
+ test/test_traverse.rb
15
21
  test/test_zeitgeist.rb
data/evri-api.gemspec CHANGED
@@ -1,22 +1,22 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{evri}
3
- s.version = "0.03"
3
+ s.version = "0.07"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["Joe Van Dyk"]
7
- s.date = %q{2008-10-27}
7
+ s.date = %q{2008-11-06}
8
8
  s.description = %q{A beautiful API that wraps the RESTful services provided by evri.com.}
9
9
  s.email = ["joe@@fixieconsulting.com"]
10
- s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
11
- s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "TODO", "evri-api.gemspec", "lib/evri.rb", "lib/evri/entity.rb", "lib/evri/media.rb", "lib/evri/relation.rb", "lib/evri/zeitgeist.rb", "test/test_entity.rb", "test/test_evri.rb", "test/test_media.rb", "test/test_zeitgeist.rb"]
10
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt", "test/barack.txt"]
11
+ s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "TODO", "evri-api.gemspec", "index.html", "lib/evri.rb", "lib/evri/entity.rb", "lib/evri/media.rb", "lib/evri/relation.rb", "lib/evri/urls.rb", "lib/evri/zeitgeist.rb", "lib/traverse.rb", "t.rb", "test/barack.txt", "test/test_entity.rb", "test/test_evri.rb", "test/test_media.rb", "test/test_traverse.rb", "test/test_zeitgeist.rb"]
12
12
  s.has_rdoc = true
13
13
  s.homepage = %q{http://github.com/joevandyk/evri-api}
14
14
  s.rdoc_options = ["--main", "README.txt"]
15
15
  s.require_paths = ["lib"]
16
- s.rubyforge_project = %q{evri}
16
+ s.rubyforge_project = %q{evri-api}
17
17
  s.rubygems_version = %q{1.2.0}
18
18
  s.summary = %q{A beautiful API that wraps the RESTful services provided by evri.com.}
19
- s.test_files = ["test/test_media.rb", "test/test_zeitgeist.rb", "test/test_entity.rb", "test/test_evri.rb"]
19
+ s.test_files = ["test/test_entity.rb", "test/test_evri.rb", "test/test_zeitgeist.rb", "test/test_media.rb", "test/test_traverse.rb"]
20
20
 
21
21
  if s.respond_to? :specification_version then
22
22
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -25,15 +25,15 @@ Gem::Specification.new do |s|
25
25
  if current_version >= 3 then
26
26
  s.add_runtime_dependency(%q<json>, [">= 0"])
27
27
  s.add_development_dependency(%q<mocha>, [">= 0"])
28
- s.add_development_dependency(%q<hoe>, [">= 1.7.0"])
28
+ s.add_development_dependency(%q<hoe>, [">= 1.8.2"])
29
29
  else
30
30
  s.add_dependency(%q<json>, [">= 0"])
31
31
  s.add_dependency(%q<mocha>, [">= 0"])
32
- s.add_dependency(%q<hoe>, [">= 1.7.0"])
32
+ s.add_dependency(%q<hoe>, [">= 1.8.2"])
33
33
  end
34
34
  else
35
35
  s.add_dependency(%q<json>, [">= 0"])
36
36
  s.add_dependency(%q<mocha>, [">= 0"])
37
- s.add_dependency(%q<hoe>, [">= 1.7.0"])
37
+ s.add_dependency(%q<hoe>, [">= 1.8.2"])
38
38
  end
39
39
  end
data/index.html ADDED
@@ -0,0 +1,6 @@
1
+ <html>
2
+ <body>
3
+ <h1> Evri Page </h1>
4
+ <p> Welcome, Dude. <a href="/evri">Here is the API</a>.</p>
5
+ </body>
6
+ </html>
data/lib/evri.rb CHANGED
@@ -25,7 +25,7 @@ module Evri
25
25
  # Raised whenever the entity you are searching for cannot be found.
26
26
  class EntityNotFound < Error; end
27
27
 
28
- VERSION = "0.06"
28
+ VERSION = "0.07"
29
29
  @@api_host = "api.evri.com"
30
30
  @@source_host = @@api_host
31
31
  @@source_url = nil
data/lib/evri/urls.rb ADDED
@@ -0,0 +1,67 @@
1
+ module Evri
2
+ module URLs
3
+ # FIXME This is ugly and should be changed.
4
+ # Given a set of options, builds a path and query string that we will be requesting.
5
+ # :type is the name of the type of query you are done.
6
+ # :query (should be renamed) is the thing you are looking for
7
+ # :entity is an entity that ..
8
+ def self.generate options = {} #:nodoc:
9
+ query = ""
10
+ case options[:type]
11
+ when :uri
12
+ path = options[:query]
13
+ when :relations
14
+ path = options[:query] + "/relations"
15
+ if options[:from_domains]
16
+ query = "includeDomain=#{options[:from_domains]}"
17
+ end
18
+ when :related_by
19
+ if options[:uri]
20
+ path = options[:query] + "/related/entities"
21
+ query = "uri=#{escape(options[:uri])}"
22
+ else
23
+ path = options[:query] + "/relations"
24
+ if options[:verb]
25
+ path += "/#{options[:verb]}/#{escape(options[:value])}"
26
+ if options[:entity]
27
+ path += options[:entity].href
28
+ end
29
+ end
30
+ if options[:media]
31
+ query += "media=#{options[:media]}"
32
+ end
33
+ end
34
+ when :zeitgeist
35
+ path = "/zeitgeist/entities/" + options[:query]
36
+ when :related_medias
37
+ path = options[:query] + "/media/related"
38
+ if options[:entities]
39
+ query = options[:entities].map do |e|
40
+ "entityURI=#{e}&"
41
+ end
42
+ query = query.join
43
+ end
44
+ query += "type=#{options[:media]}" if options[:media]
45
+ when :from_media
46
+ path = "/media/entities"
47
+ query = "uri=#{escape(options[:uri])}&text=#{escape(options[:text])}"
48
+ when :search
49
+ path = "/entities/find"
50
+ query = "name=#{escape(options[:query])}"
51
+ when :prefix
52
+ path = "/entities/find"
53
+ query = "prefix=#{escape(options[:query])}"
54
+ else
55
+ raise ArgumentError, "unexpected type #{ options[:type] }"
56
+ end
57
+
58
+ query = nil if query.empty?
59
+
60
+ return [path, query]
61
+ end
62
+
63
+ def self.escape text
64
+ text ? CGI.escape(text.to_s) : ''
65
+ end
66
+ end
67
+ end
data/lib/traverse.rb ADDED
@@ -0,0 +1,65 @@
1
+
2
+ class Traverse
3
+ include Enumerable
4
+ attr_reader :json
5
+
6
+ def each
7
+ @json.each { |j| yield Traverse.new(j) }
8
+ end
9
+
10
+ def multiple?
11
+ @json.class == Array
12
+ end
13
+
14
+ def initialize json
15
+ @json = json
16
+ end
17
+
18
+ def size
19
+ @json.size
20
+ end
21
+
22
+ def blank?
23
+ size == 0
24
+ end
25
+
26
+ alias empty? blank?
27
+
28
+ # TODO clean this crap up
29
+ def [] value
30
+ value = value.to_s
31
+ if values = value.split("/") and values.size > 1
32
+ str = values.map { |v| "['#{v}']" }.join
33
+ code = "self#{str}"
34
+ return eval(code)
35
+ end
36
+ result =
37
+ if @json.class == Array
38
+ @json.find do |key|
39
+ if key.class == Array
40
+ if key.first.class == Array
41
+ if key.first.first == "$"
42
+ key.first.last == value
43
+ end
44
+ elsif key.first.class == String
45
+ key.first == value
46
+ end
47
+ end
48
+ end
49
+ else
50
+ @json[value] || @json["@#{value}"]
51
+ end
52
+ if result
53
+ if result.class == Hash
54
+ result = result["$"] || result
55
+ end
56
+ end
57
+ if result.class == Hash || result.class == Array
58
+ result = Traverse.new(result)
59
+ else
60
+ result
61
+ end
62
+ return result if result
63
+ return Traverse.new([])
64
+ end
65
+ end
data/t.rb ADDED
@@ -0,0 +1,8 @@
1
+
2
+ require 'lib/evri'
3
+ require 'pp'
4
+
5
+ text = %(He starred in "Forgetting Sarah Marshall" and was picked as one of Variety's 10 comics to watch, but Russell Brand's latest performance is no laughing matter for the BBC.)
6
+ uri = "http://www.variety.com/article/VR1117994787.html?categoryid=14&cs=1&nid=2565"
7
+
8
+ pp Evri::Entity.from_media(:text => text, :uri => uri).first
data/test/barack.txt ADDED
@@ -0,0 +1,307 @@
1
+ {
2
+ "entity": {
3
+ "name": {
4
+ "$": "Barack Obama"
5
+ },
6
+ "@href": "\/person\/barack-obama-0x16f69",
7
+ "@inOntology": "true",
8
+ "@id": "94057",
9
+ "type": {
10
+ "$": "PERSON"
11
+ },
12
+ "links": {
13
+
14
+ },
15
+ "@score": "0.0",
16
+ "properties": {
17
+ "property": [
18
+ {
19
+ "name": {
20
+ "$": "birthplace"
21
+ },
22
+ "@provenance": "8",
23
+ "value": {
24
+ "$": "Honolulu, Hawaii"
25
+ }
26
+ },
27
+ {
28
+ "name": {
29
+ "$": "occupation"
30
+ },
31
+ "@provenance": "8",
32
+ "value": {
33
+ "$": "Attorney"
34
+ }
35
+ },
36
+ {
37
+ "name": {
38
+ "$": "source_url"
39
+ },
40
+ "@provenance": "8",
41
+ "value": {
42
+ "$": "http:\/\/en.wikipedia.org\/wiki\/Barack_Obama"
43
+ }
44
+ },
45
+ {
46
+ "name": {
47
+ "$": "residence"
48
+ },
49
+ "@provenance": "8",
50
+ "value": {
51
+ "$": "Kenwood, Chicago, Illinois"
52
+ }
53
+ },
54
+ {
55
+ "name": {
56
+ "$": "full_title"
57
+ },
58
+ "@provenance": "8",
59
+ "value": {
60
+ "$": "President-elect of the United States"
61
+ }
62
+ },
63
+ {
64
+ "name": {
65
+ "$": "name"
66
+ },
67
+ "@provenance": "8",
68
+ "value": {
69
+ "$": "Obama, Barack Hussein"
70
+ }
71
+ },
72
+ {
73
+ "name": {
74
+ "$": "birth_name"
75
+ },
76
+ "@provenance": "8",
77
+ "value": {
78
+ "$": "Barack Hussein Obama II"
79
+ }
80
+ },
81
+ {
82
+ "name": {
83
+ "$": "birth_date"
84
+ },
85
+ "@provenance": "8",
86
+ "value": {
87
+ "$": "1961-08-04 00:00:00.0"
88
+ }
89
+ },
90
+ {
91
+ "name": {
92
+ "$": "birthplace"
93
+ },
94
+ "@provenance": "8",
95
+ "value": {
96
+ "$": "Honolulu, Hawaii, U.S.A."
97
+ }
98
+ },
99
+ {
100
+ "name": {
101
+ "$": "name"
102
+ },
103
+ "@provenance": "8",
104
+ "value": {
105
+ "$": "Obama, Barack, Jr."
106
+ }
107
+ },
108
+ {
109
+ "name": {
110
+ "$": "university_attended"
111
+ },
112
+ "@provenance": "8",
113
+ "value": {
114
+ "$": "Columbia University"
115
+ }
116
+ },
117
+ {
118
+ "name": {
119
+ "$": "vice_president"
120
+ },
121
+ "@provenance": "8",
122
+ "@linkObjectName": "Joe Biden",
123
+ "value": {
124
+ "$": "Joe Biden (elect)"
125
+ },
126
+ "@linkHref": "\/person\/joe-biden-0x2d99a",
127
+ "@linkInOntology": "true"
128
+ },
129
+ {
130
+ "name": {
131
+ "$": "name"
132
+ },
133
+ "@provenance": "8",
134
+ "value": {
135
+ "$": "Barack Obama"
136
+ }
137
+ },
138
+ {
139
+ "name": {
140
+ "$": "wikipedia_paragraph"
141
+ },
142
+ "@provenance": "8",
143
+ "value": {
144
+ "$": "Barack Hussein Obama II (pronounced: \/b\u0259\u02c8r\u0251\u02d0k h\u028a\u02c8se\u026an o\u028a\u02c8b\u0251\u02d0m\u0259\/; born August 4, 1961) is the President-elect of the United States of America and the junior United States Senator from Illinois. His inauguration into office as the forty-fourth President of the United States is scheduled for January 20, 2009. Obama is the first African American to be elected President of the United States, and was the first to be nominated for President by a major political party. Obama is also the first candidate born in Hawaii to have been nominated and subsequently elected president.\n\nA graduate of Columbia University and Harvard Law School, he became the first African American to serve as president of the Harvard Law Review. Obama worked as a community organizer and practiced as a civil rights attorney before serving three terms in the Illinois Senate from 1997 to 2004. He taught constitutional law at the University of Chicago Law School from 1992 to 2004. Following an unsuccessful bid for a seat in the U.S. House of Representatives in 2000, he announced his campaign for the U.S. Senate in January 2003. After a primary victory in March 2004, Obama delivered the keynote address at the Democratic National Convention in July 2004. He was elected to the Senate in November 2004 with 70 percent of the vote."
145
+ }
146
+ },
147
+ {
148
+ "name": {
149
+ "$": "children"
150
+ },
151
+ "@provenance": "8",
152
+ "value": {
153
+ "$": "Malia Ann, Sasha"
154
+ }
155
+ },
156
+ {
157
+ "name": {
158
+ "$": "university_attended"
159
+ },
160
+ "@provenance": "8",
161
+ "@linkObjectName": "Occidental College",
162
+ "value": {
163
+ "$": "Occidental College"
164
+ },
165
+ "@linkHref": "\/organization\/occidental-college-0xbd22f",
166
+ "@linkInOntology": "true"
167
+ },
168
+ {
169
+ "name": {
170
+ "$": "university_attended"
171
+ },
172
+ "@provenance": "8",
173
+ "@linkObjectName": "Harvard Law School",
174
+ "value": {
175
+ "$": "Harvard Law School"
176
+ },
177
+ "@linkHref": "\/organization\/harvard-law-school-0xd826a",
178
+ "@linkInOntology": "true"
179
+ },
180
+ {
181
+ "name": {
182
+ "$": "religion"
183
+ },
184
+ "@provenance": "8",
185
+ "@linkObjectName": "United Church of Christ",
186
+ "value": {
187
+ "$": "United Church of Christ"
188
+ },
189
+ "@linkHref": "\/organization\/united-church-of-christ-0x12af2d",
190
+ "@linkInOntology": "true"
191
+ },
192
+ {
193
+ "name": {
194
+ "$": "political_party"
195
+ },
196
+ "@provenance": "8",
197
+ "@linkObjectName": "Democratic Party",
198
+ "value": {
199
+ "$": "Democratic Party"
200
+ },
201
+ "@linkHref": "\/organization\/democratic-party-0x3e58b",
202
+ "@linkInOntology": "true"
203
+ },
204
+ {
205
+ "name": {
206
+ "$": "occupation"
207
+ },
208
+ "@provenance": "8",
209
+ "value": {
210
+ "$": "Politician"
211
+ }
212
+ },
213
+ {
214
+ "name": {
215
+ "$": "spouse"
216
+ },
217
+ "@provenance": "8",
218
+ "@linkObjectName": "Michelle Obama",
219
+ "value": {
220
+ "$": "Michelle Obama"
221
+ },
222
+ "@linkHref": "\/person\/michelle-obama-0x4c6e8",
223
+ "@linkInOntology": "true"
224
+ },
225
+ {
226
+ "name": {
227
+ "$": "represent_political"
228
+ },
229
+ "@groupNum": "2",
230
+ "@provenance": "8",
231
+ "@linkObjectName": "Illinois",
232
+ "value": {
233
+ "$": "Illinois"
234
+ },
235
+ "@linkHref": "\/location\/illinois-0x319c2",
236
+ "@linkInOntology": "true"
237
+ },
238
+ {
239
+ "name": {
240
+ "$": "official_website"
241
+ },
242
+ "@provenance": "8",
243
+ "value": {
244
+ "$": "Office of the President-Elect"
245
+ }
246
+ },
247
+ {
248
+ "name": {
249
+ "$": "birth_date"
250
+ },
251
+ "@provenance": "8",
252
+ "value": {
253
+ "$": "1961-08-04 00:00:00.0"
254
+ }
255
+ }
256
+ ]
257
+ },
258
+ "facets": {
259
+ "facet": [
260
+ {
261
+ "name": {
262
+ "$": "Author"
263
+ },
264
+ "relations": {
265
+
266
+ },
267
+ "properties": {
268
+
269
+ }
270
+ },
271
+ {
272
+ "name": {
273
+ "$": "Lawyer"
274
+ },
275
+ "relations": {
276
+
277
+ },
278
+ "properties": {
279
+
280
+ }
281
+ },
282
+ {
283
+ "name": {
284
+ "$": "U.S. Politician"
285
+ },
286
+ "relations": {
287
+
288
+ },
289
+ "properties": {
290
+
291
+ }
292
+ },
293
+ {
294
+ "name": {
295
+ "$": "Academic"
296
+ },
297
+ "relations": {
298
+
299
+ },
300
+ "properties": {
301
+
302
+ }
303
+ }
304
+ ]
305
+ }
306
+ }
307
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evri
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.06"
4
+ version: "0.07"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Van Dyk
@@ -53,6 +53,7 @@ extra_rdoc_files:
53
53
  - History.txt
54
54
  - Manifest.txt
55
55
  - README.txt
56
+ - test/barack.txt
56
57
  files:
57
58
  - History.txt
58
59
  - Manifest.txt
@@ -60,14 +61,20 @@ files:
60
61
  - Rakefile
61
62
  - TODO
62
63
  - evri-api.gemspec
64
+ - index.html
63
65
  - lib/evri.rb
64
66
  - lib/evri/entity.rb
65
67
  - lib/evri/media.rb
66
68
  - lib/evri/relation.rb
69
+ - lib/evri/urls.rb
67
70
  - lib/evri/zeitgeist.rb
71
+ - lib/traverse.rb
72
+ - t.rb
73
+ - test/barack.txt
68
74
  - test/test_entity.rb
69
75
  - test/test_evri.rb
70
76
  - test/test_media.rb
77
+ - test/test_traverse.rb
71
78
  - test/test_zeitgeist.rb
72
79
  has_rdoc: true
73
80
  homepage: http://github.com/joevandyk/evri-api