Sha256: 75408ef79da285833306db2e45a502ba028ad0f8a3a8023c2e0c816f103c5a68

Contents?: true

Size: 902 Bytes

Versions: 1

Compression:

Stored size: 902 Bytes

Contents

require File.join(File.dirname(__FILE__), '..', 'sapo.rb')
require 'open-uri'
require 'json'

module SAPO
  module Jobs
    class Offer
      attr_accessor :title, :link, :region, :published_at, :description
      
      def initialize(attrs = {})
        @title        = attrs[:title]
        @link         = attrs[:link]
        @region       = attrs[:region]
        @published_at = attrs[:published_at]
        @description  = attrs[:description]
      end
    end
    
    # FIXME: add sort and pagination options
    def self.search(query = "")
      output = open("http://services.sapo.pt/JobOffers/JSON?r=#{query}").read
      json = JSON.parse(output)
      
      return json["rss"]["channel"]["item"].map do |p|
        Offer.new(:title => p["title"], :link => p["link"], :region => p["se:region"], :published_at => p["pubDate"], :description => p["description"])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tpinto-sapo-rb-0.0.3 lib/sapo/jobs.rb