Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
j_api_agent / lib / j_api_agent / content_parser / flickr_parser.rb
Size: Mime:
require "nokogiri"

module JApiAgent::ContentParser
  class FlickrParser
    FLICKR_FEED_MAPPING = {
      :published_date => :published,
      :content => :title,
      :content_source => :url
    }
    def self.parse(posts)
      parsed_posts = []
      default_options = { :platform => "Flickr" }
      posts.entries.each do |p|
        post_hash = {}
        FLICKR_FEED_MAPPING.each {|k,v| post_hash[k] = p.send(v)}
        post_hash.merge!(default_options)
        pp = Post.new(post_hash)
        a = Nokogiri::HTML(p.content)
        b = a.xpath("//img")
        b.each do |x|
          if x["src"]
            pp.post_image = x["src"]
          end
        end
        pp.author = {:name=>p.author}
        parsed_posts << pp
      end
      parsed_posts
    end
  end
end