Sha256: c9d867265fe628628148d35d7cf95fa3ca84f8a9deff4504fd2b3ebc0c7fedee

Contents?: true

Size: 1.41 KB

Versions: 5

Compression:

Stored size: 1.41 KB

Contents

module EasyPost
  class Report < Resource
    REPORT_TYPES = { shprep: 'shipment', plrep: 'payment_log', trkrep: 'tracker' }

    def self.create(params={}, api_key=nil)
      url = self.url
      wrapped_params = {}
      wrapped_params[class_name.to_sym] = params

      if REPORT_TYPES.values.include?(params[:type].to_s)
        url += "/#{params[:type]}"
      else
        raise Error.new("Undetermined Report Type")
      end

      response, api_key = EasyPost.request(:post, url, api_key, params)
      return Util.convert_to_easypost_object(response, api_key)
    end

    def self.retrieve(params, api_key=nil)
      url = self.url
      obj_id = params[:id].split("_")[0]

      if REPORT_TYPES.has_key?(obj_id.to_sym)
        url += "/#{REPORT_TYPES[obj_id.to_sym]}/#{params[:id]}"
      else
        raise Error.new("Undetermined Report Type")
      end

      response, api_key = EasyPost.request(:get, url, api_key, params)
      return EasyPost::Util::convert_to_easypost_object(response, api_key) if response
    end

    def self.all(filters={}, api_key=nil)
      url = self.url

      if REPORT_TYPES.values.include?(filters[:type].to_s)
        url += "/#{filters[:type]}"
      else
        raise Error.new("Undetermined Report Type")
      end

      response, api_key = EasyPost.request(:get, url, api_key, filters)
      return EasyPost::Util::convert_to_easypost_object(response, api_key) if response
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
easypost-2.6.2 lib/easypost/report.rb
easypost-2.6.1 lib/easypost/report.rb
easypost-2.6.0 lib/easypost/report.rb
easypost-2.5.0 lib/easypost/report.rb
easypost-2.4.0 lib/easypost/report.rb