Class: Request Abstract Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class is abstract.

The base abstract Request class. Universal request logic is captured here.

Class Method Summary collapse

Class Method Details

.generate_signature(call_class, access_key, secret_key) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Generates a signature for the API call per the Refworks API signature specification.

Parameters:

  • call_class (String)

    The name of the class being called.

  • access_key (String)

    The user’s access key.

  • secret_key (String)

    The user’s secret key.

Returns:

  • (String)

    A Refworks signature.



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

def self.generate_signature(call_class, access_key, secret_key)

  # Construct the RW-required signature using the algorithm from their docs
  # expires should be the current time represented in microseconds since the epoch
  expires = Time.now.to_i * 1000

  # RW formula for signature message
  signature = call_class + access_key + expires.to_s.chomp

  # Run it through HMAC SHA1 using secret key
  hmacsig = OpenSSL::HMAC.digest('sha1', secret_key, signature)

  # Base64 encode it
  # Ruby 1.8 way
  #encodedsig = Base64.encode64(hmacsig)
  # Ruby 1.9.2 way
  encodedsig = Base64.strict_encode64(hmacsig)

  # Base64.encode64 adds a newline at end of string if not present.  This strips it.
  # Otherwise, you get an Invalid Signature error from RW
  # Do this if you are using Ruby 1.8 and don't have access to strict_encode64 as used above
  #encodedsig.gsub!(/%0A/,'')

  # Return hash
  {:signature => encodedsig, :accesskeyid => access_key, :expires => expires}
end

.http_request_verbString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the verb which should be used to request a particular API method. Since most of the API is based on GET requests, we define that as the default behavior here and override in subclasses where necessary.

Returns:

  • (String)

    The string ‘GET’



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

def self.http_request_verb
  'GET'
end