Class: Linkscape::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/linkscape/request.rb

Constant Summary collapse

URL_TEMPLATE =
%Q[http://:apiHost:/:apiRoot:/:api:/:url:?AccessID=:accessID:&Expires=:expiration:&Signature=:signature:]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Request

Returns a new instance of Request.



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
# File 'lib/linkscape/request.rb', line 18

def initialize(options)
 
  new_vals = {}
  if options[:url] 
    case options[:url]
    when String
      new_vals = {:url => CGI::escape(options[:url].sub(/^https?:\/\//, '')) }
    when Array
      @body = options[:url].collect{ |u| u.sub(/^https?:\/\//, '') }
      new_vals = {:url => ""}
    else
      raise "URL most be a String or an Array"
    end
  end
 
  @requestURL = URL_TEMPLATE.template(signRequest(options.merge(new_vals)))
  @requestURL += "&" + options[:query].collect{|k,v| "#{CGI::escape(k.to_s)}=#{CGI::escape(v.to_s)}"}.join('&') if options[:query] && Hash === options[:query]
  @requestURL += "&" + options[:query] if options[:query] && String === options[:query]

  options[:offset] = 0 if options[:offset] && options[:offset] < 0
  @requestURL += "&Offset=#{options[:offset]}" if options[:offset]

  options[:limit] = 1000 if options[:limit] && options[:limit] > 1000
  @requestURL += "&Limit=#{options[:limit]}" if options[:limit]
end

Instance Attribute Details

#requestURLObject

require ‘base64’ require ‘rubygems’ require ‘hmac-sha1’



10
11
12
# File 'lib/linkscape/request.rb', line 10

def requestURL
  @requestURL
end

Class Method Details

.run(options) ⇒ Object



14
15
16
# File 'lib/linkscape/request.rb', line 14

def self.run(options)
  self.new(options).run
end

Instance Method Details

#inspectObject



50
51
52
53
# File 'lib/linkscape/request.rb', line 50

def inspect
  #<Linkscape::Request:0x1016228a0 @requestURL="http://lsapi.seomoz.com/linkscape/mozrank/www.martian.at%2F?AccessID=ose&Expires=1258772331&Signature=Hfwssn0ZbWMe9MEf6%2FWoHOGFHzQ%3D">
  %Q[#<#{self.class}="#{@requestURL}">]
end

#runObject



44
45
46
47
48
# File 'lib/linkscape/request.rb', line 44

def run
  res = fetch(URI.parse(@requestURL))
  # res = fetch(URI.parse('http://martian.at/other/ose.json'))
  return Response.new(self, res)
end