Module: Evri
- Defined in:
- lib/evri.rb,
lib/evri/urls.rb,
lib/evri/media.rb,
lib/evri/entity.rb,
lib/evri/relation.rb,
lib/evri/zeitgeist.rb
Defined Under Namespace
Modules: URLs Classes: Article, Entity, EntityNotFound, Error, Image, Media, Relation, Zeitgeist
Constant Summary collapse
- VERSION =
"0.07"
- @@api_host =
"api.evri.com"
- @@source_host =
@@api_host
- @@source_url =
nil
Class Method Summary collapse
-
.api_host ⇒ Object
Returns the hostname for the Evri API.
-
.api_host=(host) ⇒ Object
Sets the hostname for the Evri API.
-
.parse_json(json) ⇒ Object
Parses JSON data.
-
.query(options = {}) ⇒ Object
TODO Rewrite Build the path and query string, get a response from the api server, and parse the data.
-
.source_host ⇒ Object
Returns the source host for the Evri API.
-
.source_host=(host) ⇒ Object
Returns the source host for the Evri API.
-
.source_url ⇒ Object
Returns the source url for the Evri API.
Class Method Details
.api_host ⇒ Object
Returns the hostname for the Evri API.
39 40 41 |
# File 'lib/evri.rb', line 39 def self.api_host @@api_host end |
.api_host=(host) ⇒ Object
Sets the hostname for the Evri API.
34 35 36 |
# File 'lib/evri.rb', line 34 def self.api_host= host @@api_host = validate_host(host) end |
.parse_json(json) ⇒ Object
Parses JSON data
59 60 61 62 63 64 65 |
# File 'lib/evri.rb', line 59 def self.parse_json json begin Traverse.new JSON.parse(json) rescue JSON::ParserError => e raise Error.new(e) end end |
.query(options = {}) ⇒ Object
TODO Rewrite Build the path and query string, get a response from the api server, and parse the data. Not used by clients. Maybe use :nodoc: here.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/evri.rb', line 70 def self.query ={} path, query = Evri::URLs.generate uri = URI::HTTP.build :host => self.api_host, :path => path + '.json', :query => query response = Net::HTTP.get_response(uri) raise Error.new("unexpected http response: #{ response.code }") unless response.code == "200" # Remember the source URL for this request. @@source_url = @@source_host + uri.request_uri # Return the parsed JSON parse_json(response.body) end |
.source_host ⇒ Object
Returns the source host for the Evri API
44 45 46 |
# File 'lib/evri.rb', line 44 def self.source_host @@source_host end |
.source_host=(host) ⇒ Object
Returns the source host for the Evri API
49 50 51 |
# File 'lib/evri.rb', line 49 def self.source_host= host @@source_host = validate_host(host) end |
.source_url ⇒ Object
Returns the source url for the Evri API
54 55 56 |
# File 'lib/evri.rb', line 54 def self.source_url @@source_url end |