<commit_before>require 'ruby_fps/api/base'
require 'ruby_fps/api/error_response'

require 'ruby_fps/api/get_recipient_verification_status'
require 'ruby_fps/api/get_token_by_caller'
require 'ruby_fps/api/get_transaction_status'
require 'ruby_fps/api/verify_signature'

module RubyFPS
  class << self
    def get_transaction_status(id)
      submit(:get_transaction_status, :transaction_id => id)
    end

    def get_token_by_caller_reference(ref)
      submit(:get_token_by_caller, :caller_reference => ref)
    end

    def get_token_by_id(id)
      submit(:get_token_by_caller, :token_id => id)
    end

    def get_recipient_verification_status(recipient_token_id)
      submit(:get_recipient_verification_status, :recipient_token_id => recipient_token_id)
    end

    # This is how you verify IPNs and pipeline responses.
    # Returns true if the url and params have been signed by Amazon, false otherwise.
    #
    # +url+ is the full request path up to the query string, as from request.url in the controller
    # +params+ is the full params hash from the controller
    def verify_signature(url, params)
      submit(:verify_signature, :url_end_point => url, :http_parameters => RubyFPS.query_string(params))
    end
    
    def cancel(transaction_id, options = {})
      submit(:cancel, options.merge(:transaction_id => transaction_id))
    end
    
    def cancel_token(token_id, options = {})
      submit(:cancel_token, options.merge(:token_id => token_id))
    end
    
    def settle(transaction_id, options = {})
      submit(:settle, options.merge(:reserve_transaction_id => transaction_id))
    end

    protected

    def submit(action, args)
      RubyFPS::API.const_get(action.to_s.camelcase).new(args).submit
    end
  end
end<commit_msg>helper method to verify a request object entirely<commit_after>require 'ruby_fps/api/base'
require 'ruby_fps/api/error_response'

require 'ruby_fps/api/get_recipient_verification_status'
require 'ruby_fps/api/get_token_by_caller'
require 'ruby_fps/api/get_transaction_status'
require 'ruby_fps/api/verify_signature'

module RubyFPS
  class << self
    def get_transaction_status(id)
      submit(:get_transaction_status, :transaction_id => id)
    end

    def get_token_by_caller_reference(ref)
      submit(:get_token_by_caller, :caller_reference => ref)
    end

    def get_token_by_id(id)
      submit(:get_token_by_caller, :token_id => id)
    end

    def get_recipient_verification_status(recipient_token_id)
      submit(:get_recipient_verification_status, :recipient_token_id => recipient_token_id)
    end
    
    # This is how you verify IPNs and pipeline responses.
    # Pass the entire request object.
    def verify_request(request)
      verify_signature(
        # url without query string
        request.protocol + request.host_with_port + request.path,
        # raw parameters
        request.get? ? request.query_string : request.raw_post
      )
    end

    def verify_signature(url, params)
      submit(:verify_signature, :url_end_point => url, :http_parameters => params)
    end
    
    def cancel(transaction_id, options = {})
      submit(:cancel, options.merge(:transaction_id => transaction_id))
    end
    
    def cancel_token(token_id, options = {})
      submit(:cancel_token, options.merge(:token_id => token_id))
    end
    
    def settle(transaction_id, options = {})
      submit(:settle, options.merge(:reserve_transaction_id => transaction_id))
    end

    protected

    def submit(action, args)
      RubyFPS::API.const_get(action.to_s.camelcase).new(args).submit
    end
  end
end
{'fraction_non_alphanumeric': 0.089265850945495, 'fraction_numerical': 0.0, 'mean_word_length': 3.8739837398373984, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5282526', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1130, 'n_words': 241}