Class: FeedParser

Inherits:
Object
  • Object
show all
Defined in:
lib/feed_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site_id, vendor_id) ⇒ FeedParser

Returns a new instance of FeedParser.



5
6
7
8
# File 'lib/feed_parser.rb', line 5

def initialize(site_id, vendor_id)
  @vendor_id = vendor_id
  @site_id   = site_id
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



3
4
5
# File 'lib/feed_parser.rb', line 3

def headers
  @headers
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/feed_parser.rb', line 3

def params
  @params
end

#site_idObject (readonly)

Returns the value of attribute site_id.



3
4
5
# File 'lib/feed_parser.rb', line 3

def site_id
  @site_id
end

#uriObject (readonly)

Returns the value of attribute uri.



3
4
5
# File 'lib/feed_parser.rb', line 3

def uri
  @uri
end

#vendor_idObject (readonly)

Returns the value of attribute vendor_id.



3
4
5
# File 'lib/feed_parser.rb', line 3

def vendor_id
  @vendor_id
end

Instance Method Details

#create_coupons_from_xml(xml) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/feed_parser.rb', line 10

def create_coupons_from_xml(xml)
  doc = FeedMapper.massage_feed(xml)

  (doc.xpath("//item")).each do |item|
    advertiser_id = item.xpath("./advertiser-id/text()")
    item_id = item.xpath("./item-id/text()")

    unless(item_id.to_s.empty?)
      coupon = Coupon.find_or_create_by_advertiser_id_and_item_id(advertiser_id.to_s, item_id.to_s)
      coupon = CouponFactory.update_coupon_with_item(coupon,item, @site_id, @vendor_id)
      coupon.save
    end
  end
end