Method: Hive::Broadcast.custom_json

Defined in:
lib/hive/broadcast.rb

.custom_json(options, &block) ⇒ Object

Serves the same purpose as custom but also supports required posting authorities.

Parameters:

  • options (Hash)

    options

Options Hash (options):

  • :wif (String)

    Posting wif

  • :params (Hash)
    • :required_auths (Array<String>)

    • :required_posting_auths (Arrat<String>)

    • :id (String)

    • :data (Hash) Data of the custom json, becomes ‘json`.

    • :json (String) String version of ‘data` (use one or the other).

  • :pretend (Boolean)

    Just validate, do not broadcast.

See Also:



842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
# File 'lib/hive/broadcast.rb', line 842

def self.custom_json(options, &block)
  required_fields = %i(id)
  params = options[:params]
  
  if !!params[:data] && !!params[:json]
    raise Hive::ArgumentError, 'Assign either data or json, not both.'
  end
  
  data = params.delete(:data) || {}
  data ||= (JSON[params[:json]] || nil) || {}
  params[:json] = data.to_json
  
  check_required_fields(params, *required_fields)
  
  params[:required_auths] ||= []
  params[:required_posting_auths] ||= []
  ops = [[:custom_json, params]]
  
  process(options.merge(ops: ops), &block)
end