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:



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

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



52
53
54
55
56
57
# File 'lib/fat_zebra/batch.rb', line 52

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