robads 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +5 -0
- data/CHANGES +8 -0
- data/LICENSE +13 -0
- data/README.rdoc +24 -0
- data/Rakefile +30 -0
- data/lib/robads.rb +1 -0
- data/lib/robads/base.rb +57 -0
- data/lib/robads/version.rb +1 -0
- metadata +138 -0
data/AUTHORS
ADDED
data/CHANGES
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Robads is free software: you can redistribute it and/or modify
|
2
|
+
it under the terms of the GNU General Public License as published by
|
3
|
+
the Free Software Foundation, either version 3 of the License, or
|
4
|
+
(at your option) any later version.
|
5
|
+
|
6
|
+
Robads is distributed in the hope that it will be useful,
|
7
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
8
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
9
|
+
GNU General Public License for more details.
|
10
|
+
|
11
|
+
You should have received a copy of the GNU General Public License
|
12
|
+
along with Devrinim. If not, see <http://www.gnu.org/licenses/>.
|
13
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
= Robads
|
2
|
+
|
3
|
+
Robads is a Ruby gem which offers tools to work
|
4
|
+
with robads metadata and robads.json JSON files from a given web site or URL
|
5
|
+
|
6
|
+
== Installation:
|
7
|
+
|
8
|
+
gem install robads
|
9
|
+
|
10
|
+
== Quick Start
|
11
|
+
|
12
|
+
require 'robads'
|
13
|
+
|
14
|
+
Working with robads meta
|
15
|
+
|
16
|
+
meta1 = Robads.fetch_meta('http://www.robads.org')
|
17
|
+
meta1.destination_url # this will give the destination url
|
18
|
+
|
19
|
+
Working with robads.json files
|
20
|
+
|
21
|
+
json1 = Robads.fetch_json('http://www.robads.org/robads.json')
|
22
|
+
json1["ads"].each do |ad|
|
23
|
+
puts ad["destination_url"]
|
24
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
require 'rake/rdoctask'
|
6
|
+
require 'rake/testtask'
|
7
|
+
require './lib/robads/version'
|
8
|
+
|
9
|
+
|
10
|
+
spec = eval(File.read('robads.gemspec'))
|
11
|
+
|
12
|
+
Rake::GemPackageTask.new(spec) do |p|
|
13
|
+
p.gem_spec = spec
|
14
|
+
p.need_tar = false
|
15
|
+
p.need_zip = false
|
16
|
+
end
|
17
|
+
|
18
|
+
Rake::RDocTask.new do |rdoc|
|
19
|
+
files =['README.rdoc', 'LICENSE','CHANGES', 'AUTHORS', 'lib/**/*.rb', 'test/**/*.rb']
|
20
|
+
rdoc.rdoc_files.add(files)
|
21
|
+
rdoc.main = "README"
|
22
|
+
rdoc.title = "Robads Documentation"
|
23
|
+
rdoc.rdoc_dir = 'doc/rdoc'
|
24
|
+
rdoc.options
|
25
|
+
end
|
26
|
+
|
27
|
+
Rake::TestTask.new do |t|
|
28
|
+
t.test_files = FileList['test/**/*.rb']
|
29
|
+
end
|
30
|
+
|
data/lib/robads.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'robads/base'
|
data/lib/robads/base.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'restclient'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
class Robads
|
7
|
+
# Fetch Robads JSON file from the specified URI. Makes an
|
8
|
+
# HTTP GET request and returns an Robads::Object if there
|
9
|
+
# is data to be found or <tt>false</tt> if there isn't.
|
10
|
+
#
|
11
|
+
# Pass <tt>false</tt> for the second argument if you want to
|
12
|
+
# see invalid (i.e. missing a required attribute) data.
|
13
|
+
def self.fetch_json(uri)
|
14
|
+
JSON.parse RestClient.get(uri).body
|
15
|
+
rescue RestClient::Exception, SocketError
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
# Fetch Robads meta data from the specified URI. Makes an
|
20
|
+
# HTTP GET request and returns an Robads::Object if there
|
21
|
+
# is data to be found or <tt>false</tt> if there isn't.
|
22
|
+
#
|
23
|
+
# Pass <tt>false</tt> for the second argument if you want to
|
24
|
+
# see invalid (i.e. missing a required attribute) data.
|
25
|
+
def self.fetch_meta(uri, strict = true)
|
26
|
+
parse(RestClient.get(uri).body, strict)
|
27
|
+
rescue RestClient::Exception, SocketError
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.parse(html, strict = false)
|
32
|
+
doc = Nokogiri::HTML.parse(html)
|
33
|
+
page = Robads::Object.new
|
34
|
+
doc.css('meta').each do |m|
|
35
|
+
if m.attribute('name') && m.attribute('name').to_s.match(/^robads:(.+)$/i)
|
36
|
+
page[$1.gsub('-','_')] = m.attribute('content').to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
return false if page.keys.empty?
|
40
|
+
return false unless page.valid? if strict
|
41
|
+
page
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
# The Robads::Object is a Hash with method accessors for
|
46
|
+
# all detected robads metadata attributes.
|
47
|
+
class Object < Hashie::Mash
|
48
|
+
REQUIRED_ATTRIBUTES = %w(destination_url)
|
49
|
+
|
50
|
+
# If the Robads information for this object doesn't contain
|
51
|
+
# the required attributes, this will be <tt>false</tt>.
|
52
|
+
def valid?
|
53
|
+
REQUIRED_ATTRIBUTES.each{|a| return false unless self[a]}
|
54
|
+
true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
ROBADS_VERSION = "0.1.2"
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: robads
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Alper Akgun
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-27 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: json
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 1
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 5
|
32
|
+
- 1
|
33
|
+
version: 1.5.1
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rest-client
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 13
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 6
|
48
|
+
- 1
|
49
|
+
version: 1.6.1
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: hashie
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 15
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
- 4
|
64
|
+
- 0
|
65
|
+
version: 0.4.0
|
66
|
+
type: :runtime
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: nokogiri
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 15
|
77
|
+
segments:
|
78
|
+
- 1
|
79
|
+
- 4
|
80
|
+
- 4
|
81
|
+
version: 1.4.4
|
82
|
+
type: :runtime
|
83
|
+
version_requirements: *id004
|
84
|
+
description: Robads offers tools to work with robads metadata and robads.json JSON files from a given web site or URL
|
85
|
+
email: robads@robads.org
|
86
|
+
executables: []
|
87
|
+
|
88
|
+
extensions: []
|
89
|
+
|
90
|
+
extra_rdoc_files:
|
91
|
+
- README.rdoc
|
92
|
+
- LICENSE
|
93
|
+
- CHANGES
|
94
|
+
- AUTHORS
|
95
|
+
files:
|
96
|
+
- LICENSE
|
97
|
+
- README.rdoc
|
98
|
+
- Rakefile
|
99
|
+
- AUTHORS
|
100
|
+
- CHANGES
|
101
|
+
- lib/robads/base.rb
|
102
|
+
- lib/robads/version.rb
|
103
|
+
- lib/robads.rb
|
104
|
+
homepage: https://github.com/robads/robads
|
105
|
+
licenses: []
|
106
|
+
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
hash: 3
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
version: "0"
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
hash: 3
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
version: "0"
|
130
|
+
requirements: []
|
131
|
+
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 1.7.2
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: Robads offers tools to work with robads metadata and robads.json JSON files from a given web site or URL
|
137
|
+
test_files: []
|
138
|
+
|