Class: Linkscape::Request
- Inherits:
-
Object
- Object
- Linkscape::Request
- Defined in:
- lib/linkscape/request.rb
Constant Summary collapse
- URL_TEMPLATE =
%Q[http://:apiHost:/:apiRoot:/:api:/:url:?AccessID=:accessID:&Expires=:expiration:&Signature=:signature:]
- MAX_URL_LENGTH =
500
Instance Attribute Summary collapse
-
#requestURL ⇒ Object
require ‘base64’ require ‘rubygems’ require ‘hmac-sha1’.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Request
constructor
A new instance of Request.
- #inspect ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(options) ⇒ Request
Returns a new instance of Request.
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 |
# File 'lib/linkscape/request.rb', line 19 def initialize() new_vals = {} if [:url] case [:url] when String if [:url].length > MAX_URL_LENGTH raise ArgumentError.new("Request URLs must be < #{MAX_URL_LENGTH} long") end new_vals = {:url => CGI::escape([:url].sub(/^https?:\/\//, '')) } when Array @body = [: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(.merge(new_vals))) @requestURL += "&" + [:query].collect{|k,v| "#{CGI::escape(k.to_s)}=#{CGI::escape(v.to_s)}"}.join('&') if [:query] && Hash === [:query] @requestURL += "&" + [:query] if [:query] && String === [:query] [:offset] = 0 if [:offset] && [:offset] < 0 @requestURL += "&Offset=#{[:offset]}" if [:offset] [:limit] = 1000 if [:limit] && [:limit] > 1000 @requestURL += "&Limit=#{[:limit]}" if [:limit] end |
Instance Attribute Details
#requestURL ⇒ Object
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
15 16 17 |
# File 'lib/linkscape/request.rb', line 15 def self.run() self.new().run end |
Instance Method Details
#inspect ⇒ Object
54 55 56 57 |
# File 'lib/linkscape/request.rb', line 54 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 |