golem 0.0.1
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/.gitignore +1 -0
- data/LICENSE +20 -0
- data/README.rdoc +6 -0
- data/Rakefile +9 -0
- data/VERSION +1 -0
- data/golem.gemspec +41 -0
- data/lib/golem.rb +4 -0
- data/lib/golem/golem.rb +62 -0
- data/test/test_golem.rb +71 -0
- metadata +73 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
test/key
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Bernhard Essl
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/golem.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{golem}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Bernhard Essl"]
|
12
|
+
s.date = %q{2010-01-01}
|
13
|
+
s.description = %q{Simple library to look up articles, related videos and related images on http://golem.de}
|
14
|
+
s.email = %q{bee@daigoro.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"golem.gemspec",
|
22
|
+
"LICENSE",
|
23
|
+
"Rakefile",
|
24
|
+
"README.rdoc",
|
25
|
+
"VERSION",
|
26
|
+
"lib/golem.rb",
|
27
|
+
"lib/golem/golem.rb",
|
28
|
+
"test/test_golem.rb"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/daigoro/golem}
|
31
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.5}
|
34
|
+
s.summary = %q{Simple library to look up articles, related videos and related images on http://golem.de}
|
35
|
+
s.test_files = [
|
36
|
+
"test/test_golem.rb"
|
37
|
+
]
|
38
|
+
|
39
|
+
s.add_development_dependency(%q<json_pure>, [">= 0"])
|
40
|
+
end
|
41
|
+
|
data/lib/golem.rb
ADDED
data/lib/golem/golem.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
class Golem
|
2
|
+
|
3
|
+
APIBASEURL = "http://api.golem.de/api/"
|
4
|
+
|
5
|
+
def initialize(key)
|
6
|
+
@action = "article/latest"
|
7
|
+
@key = key
|
8
|
+
end
|
9
|
+
|
10
|
+
def latest_articles(limit=10)
|
11
|
+
request "article/latest/#{limit}/"
|
12
|
+
end
|
13
|
+
|
14
|
+
def list_of_article_images(article_id)
|
15
|
+
request "article/images/#{article_id}/"
|
16
|
+
end
|
17
|
+
|
18
|
+
def top_articles(limit=10)
|
19
|
+
request "article/top/#{limit}/"
|
20
|
+
end
|
21
|
+
|
22
|
+
def article_meta_data(article_id)
|
23
|
+
request "article/meta/#{article_id}/"
|
24
|
+
end
|
25
|
+
|
26
|
+
def search_articles(query, page=1, item_per_page=10)
|
27
|
+
request "article/search/#{page}/#{item_per_page}/#{CGI::escape(query)}/"
|
28
|
+
end
|
29
|
+
|
30
|
+
def articles_by_theme(theme, limit=5)
|
31
|
+
request "theme/article/#{theme}/#{limit}/"
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_themes
|
35
|
+
request "theme/list/"
|
36
|
+
end
|
37
|
+
|
38
|
+
def latest_videos(limit=10)
|
39
|
+
request "video/latest/#{limit}/"
|
40
|
+
end
|
41
|
+
|
42
|
+
def video_meta_data(video_id)
|
43
|
+
request "video/meta/#{video_id}/"
|
44
|
+
end
|
45
|
+
|
46
|
+
def top_videos(limit=10)
|
47
|
+
request "video/top/#{limit}/"
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def request(params)
|
53
|
+
url = "#{APIBASEURL}#{params}?key=#{@key}&format=json"
|
54
|
+
js = open(url).read
|
55
|
+
json_to_hash(js)
|
56
|
+
end
|
57
|
+
|
58
|
+
def json_to_hash(js)
|
59
|
+
JSON.parse(js)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
data/test/test_golem.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) + "/../lib"
|
2
|
+
require 'golem'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TestRequest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@devkey = open(File.dirname(__FILE__) + "/key").read.strip
|
9
|
+
@g = Golem.new(@devkey)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_default
|
13
|
+
assert true
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_latest_articles
|
17
|
+
assert(@g.latest_articles["success"])
|
18
|
+
assert_equal(@g.latest_articles(4)["data"].size, 4)
|
19
|
+
assert_match(/http:\/\/www.golem.de\/+/, @g.latest_articles["data"][0]["url"])
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_list_of_article_images_
|
23
|
+
assert(@g.list_of_article_images(123)["success"])
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_top_articles
|
27
|
+
assert(@g.top_articles["success"])
|
28
|
+
assert(@g.top_articles["data"][0]["headline"])
|
29
|
+
assert_equal(@g.top_articles(3)["data"].size, 3)
|
30
|
+
assert_match(/\d+/, @g.top_articles["data"][2]["articleid"])
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_article_meta_data
|
34
|
+
assert(@g.article_meta_data(71996)["success"])
|
35
|
+
assert_equal(@g.article_meta_data(71996)["data"]["url"], "http://www.golem.de/0912/71996.html")
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_search_articles
|
39
|
+
assert(@g.search_articles("google")["success"])
|
40
|
+
assert_match(/http:\/\/www.golem.de\/+/, @g.search_articles("google")["data"]["records"][0]["url"])
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_articles_by_theme
|
44
|
+
assert(@g.articles_by_theme("Games")["success"])
|
45
|
+
assert_match(/\d/, @g.articles_by_theme("Games")["data"][0]["headline"])
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_get_themes
|
49
|
+
assert(@g.get_themes["success"])
|
50
|
+
assert_match(/\w+/, @g.get_themes["data"][0]["shortname"])
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_latest_videos
|
54
|
+
assert(@g.latest_videos["success"])
|
55
|
+
assert_equal(@g.latest_videos(4)["data"].size, 4)
|
56
|
+
assert_match(/http:\/\/video.golem.de\/+/, @g.latest_videos["data"][0]["url"])
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_video_meta_data
|
60
|
+
assert(@g.video_meta_data(2235)["success"])
|
61
|
+
assert_equal(@g.video_meta_data(2235)["data"]["title"], "KDE 4.3 - Test")
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_top_videos
|
65
|
+
assert(@g.top_videos["success"])
|
66
|
+
assert(@g.top_videos(2)["success"])
|
67
|
+
assert_equal(@g.top_videos(2)["data"].size, 2)
|
68
|
+
assert(@g.top_videos["data"][0]["title"])
|
69
|
+
assert_match(/\d+/, @g.top_videos["data"][2]["videoid"])
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: golem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bernhard Essl
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-01 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json_pure
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Simple library to look up articles, related videos and related images on http://golem.de
|
26
|
+
email: bee@daigoro.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- golem.gemspec
|
37
|
+
- LICENSE
|
38
|
+
- Rakefile
|
39
|
+
- README.rdoc
|
40
|
+
- VERSION
|
41
|
+
- lib/golem.rb
|
42
|
+
- lib/golem/golem.rb
|
43
|
+
- test/test_golem.rb
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://github.com/daigoro/golem
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options:
|
50
|
+
- --charset=UTF-8
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.3.5
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Simple library to look up articles, related videos and related images on http://golem.de
|
72
|
+
test_files:
|
73
|
+
- test/test_golem.rb
|