Class: GoApiClient::Api::Feed

Inherits:
AbstractApi show all
Defined in:
lib/go_api_client/api/feed.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Feed

Returns a new instance of Feed.



7
8
9
# File 'lib/go_api_client/api/feed.rb', line 7

def initialize(attributes = {})
  super(attributes)
end

Instance Method Details

#feed(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/go_api_client/api/feed.rb', line 11

def feed(options={})
  options = ({:pipeline_name => nil, :feed_uri => nil, :eager_parser => []}).merge(options)
  if options[:feed_uri]
    uri = options[:feed_uri]
  else
    raise 'Insufficient arguments' unless options[:pipeline_name]
    uri = "#{@base_uri}/api/pipelines/#{options[:pipeline_name]}/stages.xml"
  end
  feed = GoApiClient::Parsers::Feed.parse(Nokogiri::XML(@http_fetcher.get!(uri)).root)

  if options[:eager_parser]
    if options[:eager_parser].include?(:stage)
      stage_api = GoApiClient::Api::Stage.new({:base_uri => @base_uri, :http_fetcher => @http_fetcher})
      feed.parsed_entries.each do |entry|
        entry.parsed_stage = stage_api.stage(options.merge({:stage_uri => entry.stage_uri}))
      end
    end
    if options[:eager_parser].include?(:pipeline)
      pipeline_api = GoApiClient::Api::Pipeline.new({:base_uri => @base_uri, :http_fetcher => @http_fetcher})
      feed.parsed_entries.each do |entry|
        entry.parsed_pipeline = pipeline_api.pipeline(options.merge({:pipeline_uri => entry.pipeline_uri}))
      end
    end
  end
  feed
end