Sha256: a59e1dba3c033049a5e45291e17bff5d842cb12a7451a37d96a07ab5a52191cd
Contents?: true
Size: 1.58 KB
Versions: 7
Compression:
Stored size: 1.58 KB
Contents
# frozen_string_literal: true class EasyPost::Services::Report < EasyPost::Services::Service MODEL_CLASS = EasyPost::Models::Report # Create a Report def create(params = {}) unless params[:type] raise ArgumentError, "Missing 'type' parameter in params" # TODO: replace the error in the error-handling overhaul PR end type = params.delete(:type) url = "reports/#{type}" response = @client.make_request(:post, url, params) EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) end # Retrieve a Report def retrieve(id) response = @client.make_request(:get, "reports/#{id}") EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) end # Retrieve all Report objects def all(params = {}) unless params[:type] raise ArgumentError, "Missing 'type' parameter in params" # TODO: replace the error in the error-handling overhaul PR end type = params.delete(:type) filters = { key: 'reports', type: type, } url = "reports/#{type}" response = get_all_helper(url, MODEL_CLASS, params, filters) response.define_singleton_method(:type) { type } response end # Get next page of Report objects def get_next_page(collection, page_size = nil) raise EasyPost::Errors::EndOfPaginationError.new unless more_pages?(collection) params = { before_id: collection.reports.last.id } params[:page_size] = page_size unless page_size.nil? params.merge!(collection[EasyPost::InternalUtilities::Constants::FILTERS_KEY]).delete(:key) all(params) end end
Version data entries
7 entries across 7 versions & 1 rubygems