Sha256: ea9946040ff01ef804fd50550395f9e443177a54317b04119074864dbec63df8

Contents?: true

Size: 841 Bytes

Versions: 1

Compression:

Stored size: 841 Bytes

Contents

require "hypernova/batch_renderer"
require "hypernova/parsed_response"
require "hypernova/plugin_helper"

class Hypernova::RequestService
  include Hypernova::PluginHelper

  def render_batch(jobs)
    return render_batch_blank(jobs) if jobs.empty?
    response_body = Hypernova::ParsedResponse.new(jobs).body
    response_body.each do |index_string, resp|
      error(resp["error"], jobs[index_string.to_i]) if resp["error"]
    end
    build_renderer(jobs).render(response_body)
  end

  def render_batch_blank(jobs)
    build_renderer(jobs).render_blank
  end

  private

  def build_error(name, message)
    Module.const_get(name).new(message)
  end

  def build_renderer(jobs)
    Hypernova::BatchRenderer.new(jobs)
  end

  def error(error_data, job)
    on_error(build_error(error_data["name"], error_data["message"]), job)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hypernova-1.0.0 lib/hypernova/request_service.rb