Sha256: 6eb265b36d57e977b1a26bad48bdead854e0e1a99058e374661847e7fdccc89a

Contents?: true

Size: 1.12 KB

Versions: 11

Compression:

Stored size: 1.12 KB

Contents

require 'json'

module ARII

  # = JSONSeedReader
  #
  # Load content from JSON seed.
  #
  class JSONSeedReader < SeedReader
    ##
    # == Read
    #
    # => Load the seed data into the @objects array for processing.
    #
    def read
      begin
        url = RestClient.get @seed[:payload][:uri]
        @doc = url.to_str
        JsonPath.on(@doc,@seed[:payload][:query]).each do |element|

          begin
            object = @help.deep_copy @agent[:payload]
            object.each_pair do |key,value|
              variables = @help.identify_variables(object[key])
              variables.each do |v|

                JsonPath.on(element, @seed[:payload][:selectors][v]).each do |el|

                  object[key].gsub!("%{#{v}}", el.to_s)
                end
              end
            end

            JsonPath.on(element,@seed[:payload][:cache]).each do |el|
              object[:seed] = el

            end

            object[:identifier] = @agent.identifier
            @objects.push object
          rescue Exception => e

          end
        end
      rescue Exception => e

      end

      @objects
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
arii-1.2.1 lib/arii/jsonseedreader.rb
arii-1.1 lib/arii/jsonseedreader.rb
arii-1.0.8 lib/arii/jsonseedreader.rb
arii-1.0.7 lib/arii/jsonseedreader.rb
arii-1.0.6 lib/arii/jsonseedreader.rb
arii-1.0.5 lib/arii/jsonseedreader.rb
arii-1.0.4 lib/arii/jsonseedreader.rb
arii-1.0.3 lib/arii/jsonseedreader.rb
arii-1.0.2 lib/arii/jsonseedreader.rb
arii-1.0.1 lib/arii/jsonseedreader.rb
arii-1.0 lib/arii/jsonseedreader.rb