joevandyk-evri 0.01 → 0.03
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/Manifest.txt +1 -0
- data/Rakefile +10 -0
- data/evri-api.gemspec +39 -0
- data/lib/evri/entity.rb +19 -1
- data/lib/evri/media.rb +3 -0
- data/lib/evri/relation.rb +2 -0
- data/lib/evri/zeitgeist.rb +16 -4
- data/lib/evri.rb +8 -1
- metadata +20 -1
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -6,6 +6,16 @@ require './lib/evri.rb'
|
|
6
6
|
|
7
7
|
Hoe.new('evri', Evri::VERSION) do |p|
|
8
8
|
p.developer('Joe Van Dyk', 'joe@@fixieconsulting.com')
|
9
|
+
p.extra_deps = [:json]
|
10
|
+
p.extra_dev_deps = [:mocha]
|
11
|
+
end
|
12
|
+
|
13
|
+
task :github do
|
14
|
+
data = `rake check_manifest | sed 1d`
|
15
|
+
IO.popen("patch -p0 Manifest.txt", "w") do |p|
|
16
|
+
p << data
|
17
|
+
end
|
18
|
+
`rake debug_gem | sed 1d > evri-api.gemspec`
|
9
19
|
end
|
10
20
|
|
11
21
|
# vim: syntax=Ruby
|
data/evri-api.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{evri}
|
3
|
+
s.version = "0.03"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Joe Van Dyk"]
|
7
|
+
s.date = %q{2008-10-27}
|
8
|
+
s.description = %q{A beautiful API that wraps the RESTful services provided by evri.com.}
|
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"]
|
12
|
+
s.has_rdoc = true
|
13
|
+
s.homepage = %q{http://github.com/joevandyk/evri-api}
|
14
|
+
s.rdoc_options = ["--main", "README.txt"]
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
s.rubyforge_project = %q{evri}
|
17
|
+
s.rubygems_version = %q{1.2.0}
|
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"]
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 2
|
24
|
+
|
25
|
+
if current_version >= 3 then
|
26
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
27
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
28
|
+
s.add_development_dependency(%q<hoe>, [">= 1.7.0"])
|
29
|
+
else
|
30
|
+
s.add_dependency(%q<json>, [">= 0"])
|
31
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
32
|
+
s.add_dependency(%q<hoe>, [">= 1.7.0"])
|
33
|
+
end
|
34
|
+
else
|
35
|
+
s.add_dependency(%q<json>, [">= 0"])
|
36
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
37
|
+
s.add_dependency(%q<hoe>, [">= 1.7.0"])
|
38
|
+
end
|
39
|
+
end
|
data/lib/evri/entity.rb
CHANGED
@@ -3,6 +3,7 @@ module Evri
|
|
3
3
|
class Entity
|
4
4
|
attr_reader :properties
|
5
5
|
|
6
|
+
# Finds a specific entity, given an ID.
|
6
7
|
def self.find id
|
7
8
|
@entended_properties = true
|
8
9
|
@results ||= {}
|
@@ -13,18 +14,21 @@ module Evri
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
17
|
+
# Searches for an exact match.
|
16
18
|
def self.search name
|
17
19
|
create_from_jsons do
|
18
20
|
Evri.query(:type => :search, :query => name)
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
24
|
+
# Searches for a partial match. i.e. 'ob' will return 'Obama'.
|
22
25
|
def self.search_by_prefix prefix
|
23
26
|
create_from_jsons do
|
24
27
|
Evri.query(:type => :prefix, :query => prefix)
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
31
|
+
# Given a :uri and :text options, return the related entities.
|
28
32
|
def self.from_media options={}
|
29
33
|
uri, text = options[:uri], options[:text]
|
30
34
|
raise ArgumentError, "Must specify URI via the :uri option" unless uri
|
@@ -36,10 +40,13 @@ module Evri
|
|
36
40
|
end
|
37
41
|
end
|
38
42
|
|
43
|
+
# Returns where the information for this entity came from.
|
39
44
|
def source_url
|
40
45
|
@source_url
|
41
46
|
end
|
42
47
|
|
48
|
+
# Returns information about an entity.
|
49
|
+
# i.e obama.info(:birth_date)
|
43
50
|
def info option=nil
|
44
51
|
@properties ||= {}
|
45
52
|
if defined?(@extended_properties)
|
@@ -56,9 +63,14 @@ module Evri
|
|
56
63
|
end
|
57
64
|
|
58
65
|
def to_s
|
59
|
-
"#{name}
|
66
|
+
"#{name} (#{ id })"
|
60
67
|
end
|
61
68
|
|
69
|
+
def inspect
|
70
|
+
"#<Evri::Entity:#{to_s}>"
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns the name of the entity
|
62
74
|
def name
|
63
75
|
@parsed_json["name"]["$"] || @parsed_json["name"]
|
64
76
|
end
|
@@ -76,6 +88,7 @@ module Evri
|
|
76
88
|
self.id == b.id
|
77
89
|
end
|
78
90
|
|
91
|
+
# Returns the Evri URI of the entity
|
79
92
|
def href
|
80
93
|
@parsed_json["@href"]
|
81
94
|
end
|
@@ -83,10 +96,12 @@ module Evri
|
|
83
96
|
alias id href
|
84
97
|
alias uri href
|
85
98
|
|
99
|
+
# TODO
|
86
100
|
def target_href
|
87
101
|
@parsed_json["@targetHref"]
|
88
102
|
end
|
89
103
|
|
104
|
+
# Returns relationships for the entity
|
90
105
|
def relations options={}
|
91
106
|
from_domains = nil
|
92
107
|
if options[:from]
|
@@ -106,6 +121,7 @@ module Evri
|
|
106
121
|
@relations
|
107
122
|
end
|
108
123
|
|
124
|
+
# Returns which entities are related to the current entity
|
109
125
|
def related_by options={}
|
110
126
|
media, verb, verb_value, entity, uri = nil, nil, nil, nil, nil
|
111
127
|
options.each do |key, value|
|
@@ -137,6 +153,7 @@ module Evri
|
|
137
153
|
@entities
|
138
154
|
end
|
139
155
|
|
156
|
+
# Returns images relating to the current entity
|
140
157
|
def images options={}
|
141
158
|
medias = []
|
142
159
|
if options[:entities]
|
@@ -159,6 +176,7 @@ module Evri
|
|
159
176
|
medias
|
160
177
|
end
|
161
178
|
|
179
|
+
# Returns articles relating to the current entity
|
162
180
|
def articles options={}
|
163
181
|
medias = []
|
164
182
|
if options[:entities]
|
data/lib/evri/media.rb
CHANGED
@@ -2,6 +2,7 @@ module Evri
|
|
2
2
|
class Media
|
3
3
|
end
|
4
4
|
|
5
|
+
# Represents an Article.
|
5
6
|
class Article < Media
|
6
7
|
attr_accessor :title, :href, :uri, :author, :published_at, :content
|
7
8
|
def initialize json
|
@@ -14,6 +15,7 @@ module Evri
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
18
|
+
# Represents an Image.
|
17
19
|
class Image < Media
|
18
20
|
attr_accessor :size, :title, :article_href, :mime_type, :thumbnail, :date, :content, :width, :url, :click_url, :height
|
19
21
|
def initialize json
|
@@ -31,6 +33,7 @@ module Evri
|
|
31
33
|
@thumbnail = Thumbnail.new(json["thumbnail"])
|
32
34
|
end
|
33
35
|
|
36
|
+
# Represents an Thumbnail for an Image.
|
34
37
|
class Thumbnail
|
35
38
|
attr_accessor :size, :width, :height, :url
|
36
39
|
def initialize json
|
data/lib/evri/relation.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
module Evri
|
2
|
+
# Represents a relation.
|
2
3
|
class Relation
|
3
4
|
attr_accessor :name, :href, :type
|
4
5
|
def initialize json
|
@@ -8,6 +9,7 @@ module Evri
|
|
8
9
|
@entities = []
|
9
10
|
end
|
10
11
|
|
12
|
+
# Returns the entities in this relation.
|
11
13
|
def entities
|
12
14
|
return @entities unless @entities.empty?
|
13
15
|
json = JSON.parse(Evri.query(:type => :uri, :query => @href))
|
data/lib/evri/zeitgeist.rb
CHANGED
@@ -1,10 +1,22 @@
|
|
1
1
|
module Evri
|
2
|
+
# Returns information about a specific trend.
|
3
|
+
#
|
4
|
+
# To access the information, combine a TREND with a TYPE to form a class method.
|
5
|
+
#
|
6
|
+
# i.e.
|
7
|
+
#
|
8
|
+
# * Zeitgeist.all_chemical
|
9
|
+
# * Zeitgeist.falling_person
|
10
|
+
# * Zeitgeist.popular_organization
|
11
|
+
#
|
12
|
+
# etc
|
2
13
|
class Zeitgeist
|
3
|
-
ENTITY_TYPES = %w( animal backterium checmical concept disorder event location organization person plant product virus )
|
4
|
-
TYPES = %w( all popular rising falling )
|
5
14
|
|
6
|
-
TYPES
|
7
|
-
|
15
|
+
TYPES = %w( animal backterium chemical concept disorder event location organization person plant product virus )
|
16
|
+
TRENDS = %w( all popular rising falling )
|
17
|
+
|
18
|
+
TRENDS.each do |t|
|
19
|
+
TYPES.each do |et|
|
8
20
|
eval %(
|
9
21
|
def self.#{t}_#{et}
|
10
22
|
json = Evri.parse_json(Evri.query :type => :zeitgeist, :query => "#{et}/#{t}")
|
data/lib/evri.rb
CHANGED
@@ -24,31 +24,37 @@ module Evri
|
|
24
24
|
# Raised whenever the entity you are searching for cannot be found.
|
25
25
|
class EntityNotFound < Error; end
|
26
26
|
|
27
|
-
VERSION = "0.
|
27
|
+
VERSION = "0.03"
|
28
28
|
@@api_host = "api.evri.com"
|
29
29
|
@@source_host = @@api_host
|
30
30
|
@@source_url = nil
|
31
31
|
|
32
|
+
# Sets the hostname for the Evri API.
|
32
33
|
def self.api_host= host
|
33
34
|
@@api_host = validate_host(host)
|
34
35
|
end
|
35
36
|
|
37
|
+
# Returns the hostname for the Evri API.
|
36
38
|
def self.api_host
|
37
39
|
@@api_host
|
38
40
|
end
|
39
41
|
|
42
|
+
# Returns the source host for the Evri API
|
40
43
|
def self.source_host
|
41
44
|
@@source_host
|
42
45
|
end
|
43
46
|
|
47
|
+
# Returns the source host for the Evri API
|
44
48
|
def self.source_host= host
|
45
49
|
@@source_host = validate_host(host)
|
46
50
|
end
|
47
51
|
|
52
|
+
# Returns the source url for the Evri API
|
48
53
|
def self.source_url
|
49
54
|
@@source_url
|
50
55
|
end
|
51
56
|
|
57
|
+
# Parses JSON data
|
52
58
|
def self.parse_json json
|
53
59
|
begin
|
54
60
|
JSON.parse(json)
|
@@ -119,6 +125,7 @@ module Evri
|
|
119
125
|
response.body
|
120
126
|
end
|
121
127
|
|
128
|
+
# Escapes CGI text
|
122
129
|
def self.escape text
|
123
130
|
text ? CGI.escape(text.to_s) : ''
|
124
131
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joevandyk-evri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.03"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Van Dyk
|
@@ -12,6 +12,24 @@ cert_chain: []
|
|
12
12
|
date: 2008-10-27 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: mocha
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "0"
|
32
|
+
version:
|
15
33
|
- !ruby/object:Gem::Dependency
|
16
34
|
name: hoe
|
17
35
|
version_requirement:
|
@@ -38,6 +56,7 @@ files:
|
|
38
56
|
- README.txt
|
39
57
|
- Rakefile
|
40
58
|
- TODO
|
59
|
+
- evri-api.gemspec
|
41
60
|
- lib/evri.rb
|
42
61
|
- lib/evri/entity.rb
|
43
62
|
- lib/evri/media.rb
|