Module: Evri::URLs
- Defined in:
- lib/evri/urls.rb
Class Method Summary collapse
- .escape(text) ⇒ Object
-
.generate(options = {}) ⇒ Object
FIXME This is ugly and should be changed.
Class Method Details
.escape(text) ⇒ Object
63 64 65 |
# File 'lib/evri/urls.rb', line 63 def self.escape text text ? CGI.escape(text.to_s) : '' end |
.generate(options = {}) ⇒ Object
FIXME This is ugly and should be changed. Given a set of options, builds a path and query string that we will be requesting. :type is the name of the type of query you are done. :query (should be renamed) is the thing you are looking for :entity is an entity that ..
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/evri/urls.rb', line 8 def self.generate = {} #:nodoc: query = "" case [:type] when :uri path = [:query] when :relations path = [:query] + "/relations" if [:from_domains] query = "includeDomain=#{[:from_domains]}" end when :related_by if [:uri] path = [:query] + "/related/entities" query = "uri=#{escape([:uri])}" else path = [:query] + "/relations" if [:verb] path += "/#{[:verb]}/#{escape([:value])}" if [:entity] path += [:entity].href end end if [:media] query += "media=#{[:media]}" end end when :zeitgeist path = "/zeitgeist/entities/" + [:query] when :related_medias path = [:query] + "/media/related" if [:entities] query = [:entities].map do |e| "entityURI=#{e}&" end query = query.join end query += "type=#{[:media]}" if [:media] when :from_media path = "/media/entities" query = "uri=#{escape([:uri])}&text=#{escape([:text])}" when :search path = "/entities/find" query = "name=#{escape([:query])}" when :prefix path = "/entities/find" query = "prefix=#{escape([:query])}" else raise ArgumentError, "unexpected type #{ [:type] }" end query = nil if query.empty? return [path, query] end |