Class: FatZebra::Batch

Inherits:
APIResource show all
Includes:
APIOperation::Delete, APIOperation::Find, APIOperation::Save, APIOperation::Search
Defined in:
lib/fat_zebra/batch.rb

Overview

FatZebra Batch

Manage Batch for the API

  • create

  • search

  • find

  • result

Constant Summary

Constants included from APIOperation::Search

APIOperation::Search::DEFAULT_PARAMS

Instance Attribute Summary

Attributes inherited from FatZebraObject

#accepted

Attributes included from ObjectHelper

#data, #errors, #raw

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperation::Delete

#destroy, included

Methods included from APIOperation::Save

included, #save

Methods included from APIOperation::Find

included

Methods included from APIOperation::Search

included

Methods inherited from APIResource

base_path, request

Methods included from APIHelper

included, #request, #resource_name, #resource_path

Methods inherited from FatZebraObject

initialize_from, #load_response_api, #update_from

Methods included from Validation

#errors, #valid!, #valid?, #validates

Methods included from ObjectHelper

#[], #[]=, #add_accessor, #add_accessors, #add_data, #initialize, #inspect, #keys, #method_missing, #remove_accessor, #to_hash, #to_json, #update_attributes

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class FatZebra::ObjectHelper

Class Method Details

.create(params, options = {}) ⇒ FatZebra::Batch

Upload a batch file

Parameters:

  • params (Hash)

    for the request

  • Additional (Hash)

    options for the request

Returns:



35
36
37
38
39
40
41
42
43
# File 'lib/fat_zebra/batch.rb', line 35

def create(params, options = {})
  params[:multipart] = true
  params[:content_type] = 'text/csv'
  params[:file] = File.new(params.delete(:path)) if params.key?(:path)
  @resource_name = "batches/#{params[:filename]}"
  super(params, options)
ensure
  @resource_name = 'batches'
end

Instance Method Details

#result(params = {}, options = {}) ⇒ String

Return result from the batch

Parameters:

  • params (Hash) (defaults to: {})

    for capture API (Optional)

  • options (Hash) (defaults to: {})

    for the request, and configurations (Optional)

Returns:

  • (String)

    formated as CSV



54
55
56
57
58
59
60
# File 'lib/fat_zebra/batch.rb', line 54

def result(params = {}, options = {})
  request(:get, "#{resource_path}/#{id}/result.csv", params, options)
rescue FatZebra::RequestError => e
  return e.http_body if e.http_status == 422

  raise
end