Class: ChartMogul::JsonImport

Inherits:
APIResource show all
Defined in:
lib/chartmogul/json_import.rb

Overview

JsonImport resource for bulk importing data via JSON. Use this to efficiently upload large datasets to a data source.

Constant Summary

Constants inherited from APIResource

APIResource::BACKOFF_FACTOR, APIResource::INTERVAL, APIResource::INTERVAL_RANDOMNESS, APIResource::MAX_INTERVAL, APIResource::RETRY_EXCEPTIONS, APIResource::RETRY_STATUSES, APIResource::THREAD_CONNECTION_KEY

Class Method Summary collapse

Methods inherited from APIResource

build_connection, build_query_path, connection, #custom_with_query_params!, custom_with_query_params!, extract_query_params, #extract_query_params, handle_other_error, handle_request_error, handling_errors, immutable_keys, json_patch, json_post, json_put, #path_with_query_params, query_params, set_immutable_keys, set_resource_name, set_resource_path, set_resource_root_key, writeable_query_param

Methods inherited from Object

#allowed_for_write?, #assign_all_attributes, #assign_writeable_attributes, attributes, define_private_writer, define_reader, define_writer, #initialize, #instance_attributes, new_from_json, readonly_attr, #serialize_for_write, #serialized_value_for_attr, writeable_attr, writeable_attributes

Constructor Details

This class inherits a constructor from ChartMogul::Object

Class Method Details

.create!(data_source_uuid:, **data) ⇒ Object

Create a new JSON import batch for a data source

Parameters:

  • data_source_uuid (String)

    The UUID of the data source

  • data (Hash)

    The import data (customers, plans, invoices, etc.)



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/chartmogul/json_import.rb', line 21

def self.create!(data_source_uuid:, **data)
  path = "/v1/data_sources/#{data_source_uuid}/json_imports"
  resp = handling_errors do
    connection.post(path) do |req|
      req.headers['Content-Type'] = 'application/json'
      req.body = JSON.dump(data)
    end
  end
  json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys:)
  new_from_json(json)
end

.retrieve(data_source_uuid:, id:) ⇒ Object

Retrieve the status of a JSON import

Parameters:

  • data_source_uuid (String)

    The UUID of the data source

  • id (String, Integer)

    The ID of the import



36
37
38
39
40
41
42
43
# File 'lib/chartmogul/json_import.rb', line 36

def self.retrieve(data_source_uuid:, id:)
  path = "/v1/data_sources/#{data_source_uuid}/json_imports/#{id}"
  resp = handling_errors do
    connection.get(path)
  end
  json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys:)
  new_from_json(json)
end