Class: I2X::JSONSeedReader

Inherits:
SeedReader show all
Defined in:
lib/i2x/jsonseedreader.rb

Overview

JSONSeedReader

Load content from JSON seed.

Instance Attribute Summary

Attributes inherited from SeedReader

#agent, #objects, #seed

Instance Method Summary collapse

Methods inherited from SeedReader

#initialize

Constructor Details

This class inherits a constructor from I2X::SeedReader

Instance Method Details

#readObject

Read

> Load the seed data into the @objects array for processing.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/i2x/jsonseedreader.rb', line 15

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