Sha256: a12175290294fa6d66e561864ddfdad0447bfda938e646ad33184f2a0b66409c

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 KB

Contents

module SodaXmlTeam

  require 'httparty'
  require 'nokogiri'

  class Client

    def initialize(username, password)
      @auth = {:username => username, :password => password}
      @dir = File.dirname __FILE__
    end

    def content_finder(options={})
      response = HTTParty.get(SodaXmlTeam::Address.build("get_listing", options), :basic_auth => @auth, :ssl_ca_file => "#{@dir}/../ca-certificates.crt", :ssl_version => :SSLv3)
      feed = Nokogiri::XML(response.body)

      documents = []
      feed.css('item').each do |item|
        record = {}

        # Parse for document ID
        link = item.css('link').inner_text
        document_id = link.gsub /(.*)?doc-ids=/i, ''

        record[:title] = item.css('title').inner_text
        record[:link] = link
        record[:document_id] = document_id
        record[:date] = DateTime.parse(item.xpath('./dc:date').inner_text)
        item.xpath('./sportsml:sports-content-codes').each do |sportscontent|
          sportscontent.xpath('./sportsml:sports-content-code').each do |content|
            record[content['code-type'].to_sym] = content['code-key']
          end
        end

        documents << record
      end

      return documents

    end

    # Deprecated: Please use `content_finder` instead
    def get_listing(options={})
      warn "[DEPRECATION] `get_listing` is deprecated.  Please use `content_finder` instead."
      response = HTTParty.get(SodaXmlTeam::Address.build("get_listing", options), :basic_auth => @auth, :ssl_ca_file => "#{@dir}/../ca-certificates.crt", :ssl_version => :SSLv3)
      Nokogiri::XML(response.body)
    end

    def get_document(options={})
      response = HTTParty.get(SodaXmlTeam::Address.build("get_document", options), :basic_auth => @auth, :ssl_ca_file => "#{@dir}/../ca-certificates.crt", :ssl_version => :SSLv3)
      Nokogiri::XML(response.body)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
soda_xml_team-1.3.1 lib/soda_xml_team/client.rb
soda_xml_team-1.3.0 lib/soda_xml_team/client.rb