Module: Evri::URLs

Defined in:
lib/evri/urls.rb

Class Method Summary collapse

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 options = {} #:nodoc:
  query = ""
  case options[:type]
  when :uri
    path = options[:query]
  when :relations
    path = options[:query] + "/relations"
    if options[:from_domains]
      query = "includeDomain=#{options[:from_domains]}"
    end
  when :related_by
    if options[:uri]
      path = options[:query] + "/related/entities"
      query = "uri=#{escape(options[:uri])}"
    else
      path = options[:query] + "/relations"
      if options[:verb]
        path += "/#{options[:verb]}/#{escape(options[:value])}"
        if options[:entity]
          path += options[:entity].href
        end
      end
      if options[:media]
        query += "media=#{options[:media]}"
      end
    end
  when :zeitgeist
    path = "/zeitgeist/entities/" + options[:query]
  when :related_medias
    path = options[:query] + "/media/related"
    if options[:entities]
      query = options[:entities].map do |e|
      "entityURI=#{e}&"
      end
      query = query.join
    end
    query += "type=#{options[:media]}" if options[:media]
  when :from_media
    path = "/media/entities"
    query = "uri=#{escape(options[:uri])}&text=#{escape(options[:text])}"
  when :search
    path  = "/entities/find"
    query = "name=#{escape(options[:query])}"
  when :prefix
    path  = "/entities/find"
    query = "prefix=#{escape(options[:query])}"
  else
    raise ArgumentError, "unexpected type #{ options[:type] }"
  end
  
  query = nil if query.empty?

  return [path, query]
end