Class: Tappy::AgentFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/tappy/filter/agent_filter.rb

Instance Attribute Summary

Attributes inherited from Filter

#options

Instance Method Summary collapse

Methods inherited from Filter

#initialize

Constructor Details

This class inherits a constructor from Tappy::Filter

Instance Method Details

#filter(response) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tappy/filter/agent_filter.rb', line 5

def filter(response)      
  json = JSON.parse(response.body)
  begin
    if json.class == Array
      filtered = []

      json.each do |item|
        source = item["source"]
        if !source.nil? 
          if source.match(options)
            puts "filterer: #{item["source"]}"
          else
            filtered << item
          end
        else
          return response.body
        end
      end
      result = filtered.to_json
      result
    else
      response.body
    end
  rescue
    response.body
  end
end