lib/pas/resource.rb in pas-0.0.1 vs lib/pas/resource.rb in pas-0.0.2

- old
+ new

@@ -1,27 +1,19 @@ -class PAS +module PAS class Resource < ActiveResource::Base - self.site = "http://publisher.pas.local" + self.site = PAS.config[:domain_name] class << self - # Find a single resource from the default URL - def find_single(scope, options) - prefix_options, query_options = split_options(options[:params]) - - # Generate the API authentication signature and merge parameters to the query_options - path_without_query_options = element_path(scope, prefix_options) - timestamp = Time.now.to_i.to_s - signature = generate_signature("GET", path_without_query_options, timestamp) - query_options.merge!({ :api_token => PAS.api_token.to_s, :timestamp => timestamp, :signature => signature }) - - path = element_path(scope, prefix_options, query_options) - instantiate_record(connection.get(path, headers), prefix_options) - end - - def generate_signature(request_method, request_path, timestamp) - data = PAS.api_token.to_s + request_method + request_path + timestamp - signature = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, PAS.api_access_key.to_s, data) - Base64.encode64(signature).chomp + def connection(refresh = false) + if defined?(@connection) || superclass == Object + @connection = PAS::Connection.new(site, format) if refresh || @connection.nil? + @connection.user = user if user + @connection.password = password if password + @connection.timeout = timeout if timeout + @connection + else + superclass.connection + end end end end end \ No newline at end of file