tpinto-sapo-rb 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +13 -0
- data/README.rdoc +61 -0
- data/Rakefile +17 -0
- data/VERSION.yml +4 -0
- data/lib/sapo.rb +3 -0
- data/lib/sapo/adsl.rb +16 -0
- data/lib/sapo/adwords.rb +28 -0
- data/lib/sapo/auto.rb +41 -0
- data/lib/sapo/blogs.rb +28 -0
- data/lib/sapo/cacert.pem +3154 -0
- data/lib/sapo/id.rb +32 -0
- data/lib/sapo/jobs.rb +29 -0
- data/lib/sapo/photos.rb +47 -0
- data/lib/sapo/shopping.rb +29 -0
- data/lib/sapo/traffic.rb +28 -0
- metadata +69 -0
data/lib/sapo/id.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'sapo.rb')
|
2
|
+
require 'rexml/document'
|
3
|
+
require 'net/https'
|
4
|
+
|
5
|
+
module SAPO
|
6
|
+
class ID
|
7
|
+
attr_accessor :email, :password, :primary, :token
|
8
|
+
|
9
|
+
def initialize(email, password)
|
10
|
+
self.email = email
|
11
|
+
self.password = password
|
12
|
+
|
13
|
+
uri = URI.parse("https://services.sapo.pt/STS/GetPrimaryId?ESBUsername=#{self.email}&ESBPassword=#{self.password}")
|
14
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
15
|
+
http.use_ssl = true
|
16
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
17
|
+
http.ca_file = File.join(File.dirname(__FILE__), "cacert.pem")
|
18
|
+
http.start {
|
19
|
+
http.request_get(uri.path+"?"+uri.query) {|res|
|
20
|
+
output = REXML::Document.new(res.body)
|
21
|
+
begin
|
22
|
+
self.primary = output.root.elements['PrimaryId'].text
|
23
|
+
self.token = output.root.elements['ESBToken'].text
|
24
|
+
rescue
|
25
|
+
raise "Wrong credentials"
|
26
|
+
return nil
|
27
|
+
end
|
28
|
+
}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/sapo/jobs.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'sapo.rb')
|
2
|
+
require 'open-uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module SAPO
|
6
|
+
module Jobs
|
7
|
+
class Offer
|
8
|
+
attr_accessor :title, :link, :region, :published_at, :description
|
9
|
+
|
10
|
+
def initialize(attrs = {})
|
11
|
+
@title = attrs[:title]
|
12
|
+
@link = attrs[:link]
|
13
|
+
@region = attrs[:region]
|
14
|
+
@published_at = attrs[:published_at]
|
15
|
+
@description = attrs[:description]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# FIXME: add sort and pagination options
|
20
|
+
def self.search(query = "")
|
21
|
+
output = open("http://services.sapo.pt/JobOffers/JSON?r=#{query}").read
|
22
|
+
json = JSON.parse(output)
|
23
|
+
|
24
|
+
return json["rss"]["channel"]["item"].map do |p|
|
25
|
+
Offer.new(:title => p["title"], :link => p["link"], :region => p["se:region"], :published_at => p["pubDate"], :description => p["description"])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/sapo/photos.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'sapo.rb')
|
2
|
+
require 'open-uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module SAPO
|
6
|
+
module Photos
|
7
|
+
class Photo
|
8
|
+
attr_accessor :title, :description, :link, :published_at, :src
|
9
|
+
|
10
|
+
def initialize(attrs = {})
|
11
|
+
@title = attrs[:title]
|
12
|
+
@link = attrs[:link]
|
13
|
+
@src = attrs[:src]
|
14
|
+
@published_at = attrs[:published_at]
|
15
|
+
@description = attrs[:description]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# FIXME: add sort and pagination options
|
20
|
+
def self.search(options = {})
|
21
|
+
if options.is_a?(String)
|
22
|
+
output = open("http://services.sapo.pt/Photos/JSON?tag=#{options}").read
|
23
|
+
elsif options.is_a?(Hash)
|
24
|
+
options = {:user => "", :tag => ""}.merge(options)
|
25
|
+
if options[:user] != "" and options[:tag] != ""
|
26
|
+
output = open("http://services.sapo.pt/Photos/JSON?u=#{options[:user]}&tag=#{options[:tag]}").read
|
27
|
+
elsif options[:user] == "" and options[:tag] != ""
|
28
|
+
output = open("http://services.sapo.pt/Photos/JSON?tag=#{options[:tag]}").read
|
29
|
+
elsif options[:user] != "" and options[:tag] == ""
|
30
|
+
output = open("http://services.sapo.pt/Photos/JSON?u=#{options[:user]}").read
|
31
|
+
else
|
32
|
+
return []
|
33
|
+
end
|
34
|
+
else
|
35
|
+
return []
|
36
|
+
end
|
37
|
+
|
38
|
+
json = JSON.parse(output)
|
39
|
+
|
40
|
+
return [] if json["rss"]["channel"]["item"].nil?
|
41
|
+
|
42
|
+
return json["rss"]["channel"]["item"].map do |p|
|
43
|
+
Photo.new(:title => p["title"]["cdata"], :src => p["fotoURL"], :description => p["description"]["cdata"], :published_at => p["pubDate"], :link => p["link"]["value"])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'sapo.rb')
|
2
|
+
require 'open-uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module SAPO
|
6
|
+
module Shopping
|
7
|
+
class Listing
|
8
|
+
attr_accessor :title, :link, :region, :published_at, :description
|
9
|
+
|
10
|
+
def initialize(attrs = {})
|
11
|
+
@title = attrs[:title]
|
12
|
+
@link = attrs[:link]
|
13
|
+
@region = attrs[:region]
|
14
|
+
@published_at = attrs[:published_at]
|
15
|
+
@description = attrs[:description]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# FIXME: add sort and pagination options
|
20
|
+
def self.search(query = "")
|
21
|
+
output = open("http://services.sapo.pt/Shopping/search?q=#{query}").read
|
22
|
+
json = JSON.parse(output)
|
23
|
+
|
24
|
+
return json["rss"]["channel"]["item"].map do |p|
|
25
|
+
Listing.new(:title => p["title"], :link => p["link"], :region => p["se:region"], :published_at => p["pubDate"], :description => p["description"])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/sapo/traffic.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'sapo.rb')
|
2
|
+
require 'open-uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module SAPO
|
6
|
+
module Traffic
|
7
|
+
class Information
|
8
|
+
attr_accessor :title, :description, :image, :link
|
9
|
+
|
10
|
+
def initialize(attrs = {})
|
11
|
+
@title = attrs[:title]
|
12
|
+
@link = attrs[:link]
|
13
|
+
@image = attrs[:image]
|
14
|
+
@description = attrs[:description]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# FIXME: add sort and pagination options
|
19
|
+
def self.get_info
|
20
|
+
output = open("http://services.sapo.pt/Traffic/JSON").read
|
21
|
+
json = JSON.parse(output)
|
22
|
+
|
23
|
+
return json["rss"]["channel"]["item"].map do |p|
|
24
|
+
Information.new(:title => p["title"]["cdata"], :link => p["link"]["cdata"], :description => p["description"]["cdata"], :image => p["enclosure"]["url"])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tpinto-sapo-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tiago Pinto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-21 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Ruby library to access SAPO's web services packaged as a RubyGem
|
17
|
+
email: tpinto@webreakstuff.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- History.txt
|
26
|
+
- Rakefile
|
27
|
+
- README.rdoc
|
28
|
+
- VERSION.yml
|
29
|
+
- lib/sapo.rb
|
30
|
+
- lib/sapo
|
31
|
+
- lib/sapo/adsl.rb
|
32
|
+
- lib/sapo/adwords.rb
|
33
|
+
- lib/sapo/auto.rb
|
34
|
+
- lib/sapo/blogs.rb
|
35
|
+
- lib/sapo/cacert.pem
|
36
|
+
- lib/sapo/id.rb
|
37
|
+
- lib/sapo/jobs.rb
|
38
|
+
- lib/sapo/photos.rb
|
39
|
+
- lib/sapo/shopping.rb
|
40
|
+
- lib/sapo/traffic.rb
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://tpinto.github.com/sapo-rb
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --inline-source
|
46
|
+
- --charset=UTF-8
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project: sapo-rb
|
64
|
+
rubygems_version: 1.2.0
|
65
|
+
signing_key:
|
66
|
+
specification_version: 2
|
67
|
+
summary: Ruby library to access SAPO's web services packaged as a RubyGem
|
68
|
+
test_files: []
|
69
|
+
|