Sha256: 531d337c6b7f4972a7100e7c21dc529cdfd6e65a21c495fe5f84d6e50b016dfb
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
module SlidePay class Report < Hash attr_accessor :sfa attr_accessor :url attr_accessor :report_type attr_accessor :token, :api_key, :endpoint def initialize(search_params={}) # Initialize search_filter_arrays if search_params.is_a? Hash @sfa = [search_params] elsif search_params.is_a? Array @sfa = search_params else @sfa = [] end end def retrieve(options={}) token = @token || options[:token] api_key = @api_key || options[:api_key] endpoint = @endpoint || options[:endpoint] if @report_type == :put response = SlidePay.put(path: @url, data: data_from_sfa, token: token, api_key: api_key, endpoint: endpoint) elsif @report_type == :post response = SlidePay.post(path: @url, data: data_from_sfa, token: token, api_key: api_key, endpoint: endpoint) end if response.was_successful? populate_from_response(response) end end private # Override this for specialty reports def data_from_sfa return @sfa.to_json end def populate_from_response(response) if response.data.instance_of? Array self.merge! response.data.first elsif response.data.instance_of? Hash self.merge! response.data else raise Exception.new("Report was unsuccessful.") end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
slidepay-0.0.13 | lib/slidepay/reports/report.rb |
slidepay-0.0.12 | lib/slidepay/reports/report.rb |