oksure-daum 0.0.1 → 0.1.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/CHANGELOG.rdoc +14 -0
- data/README.rdoc +58 -8
- data/Rakefile +4 -4
- data/daum.gemspec +11 -7
- data/init.rb +1 -0
- data/lib/daum.rb +48 -1
- data/lib/daum/base.rb +65 -0
- data/lib/daum/item.rb +16 -0
- data/lib/daum/rss.rb +31 -0
- data/test/test_daum.rb +23 -0
- metadata +32 -11
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
== 0.1.1, release 2008-12-17
|
2
|
+
|
3
|
+
* added init.rb, CHANGELOG.rdoc, Unit Test
|
4
|
+
* implemented search api wrapper
|
5
|
+
* init.rb, CHANGELOG.rdoc, Unit Test 추가
|
6
|
+
* 검색 API wrapper 구현
|
7
|
+
|
8
|
+
|
9
|
+
== 0.0.1, release 2008-11-22
|
10
|
+
|
11
|
+
* first commit
|
12
|
+
* no classes, methods implemented
|
13
|
+
* 첫 번째 커밋
|
14
|
+
* 아직 아무 것도 안 했음
|
data/README.rdoc
CHANGED
@@ -1,19 +1,69 @@
|
|
1
|
-
= Daum
|
1
|
+
= Daum 0.2.1
|
2
2
|
|
3
|
-
Ruby gem for using Daum
|
3
|
+
Ruby gem for using Daum OpenAPI (http://dna.daum.net/apis).
|
4
|
+
다음 OpenAPI를 위한 루비젬입니다.
|
4
5
|
|
5
6
|
|
6
|
-
==
|
7
|
+
== Notice / 유의점
|
7
8
|
|
8
|
-
|
9
|
+
Keyword suggestion api is not supported by this gem.
|
10
|
+
문맥 키워드 추천 API는 이 젬에서 지원하지 않습니다.
|
9
11
|
|
12
|
+
Output file formats other than RSS will cause an error.
|
13
|
+
RSS 포맷으로만 아웃풋을 출력하셔야 합니다. 그렇지 않으면 에러가 발생할 수 있습니다.
|
10
14
|
|
11
|
-
|
15
|
+
For using shopping detail api, you have to enter DocID instead of Query string.
|
16
|
+
쇼핑 상품 API를 사용하실 때는 쿼리문 대신에 DocID 문자열을 넘겨주셔야 합니다.
|
12
17
|
|
13
|
-
Let's say something.
|
14
18
|
|
19
|
+
== Install / 설치법
|
15
20
|
|
16
|
-
|
21
|
+
You can install the gem from rubyforge directly.
|
22
|
+
루비포지에서 바로 설치하실 수 있습니다.
|
23
|
+
gem install daum
|
24
|
+
|
25
|
+
|
26
|
+
== Usage / 사용법
|
27
|
+
|
28
|
+
Before using this gem, you need to get your own API key. To obtain your API key, see https://apis.daum.net/register/apikey.daum.
|
29
|
+
이 젬을 사용하기 전에 API 키를 발급 받으셔야 합니다. API 키 발급을 위해서는 https://apis.daum.net/register/apikey.daum 링크를 참고해 주세요.
|
30
|
+
|
31
|
+
require 'daum'
|
32
|
+
daum = Daum::Base.new(api_key) ### create a daum client / 다음 클라이언트를 생성합니다
|
33
|
+
daum.request("삼국지", "go", {:result => "10", :pageno => "1", :sort => "date"}) ### return root node as libxml node / libxml 형식의 노드로 루트 노드를 반환합니다
|
34
|
+
daum.knowledge("삼국지", {:result => "10", :pageno => "1", :sort => "date"}) ### return RSS object / 자체 정의된 RSS 클래스 오브젝트를 반환합니다
|
35
|
+
daum.knowledge("삼국지", {:re => "10", :p => "1", :so => "date"}) ### It's possible to use abbreviation for each option / 검색 옵션을 넘길 때 약어를 사용 가능합니다
|
36
|
+
daum.knowledge("삼국지").lastBuildDate ### return lastBuildDate content in String / 스트링으로 lastBuildDate 값을 반환합니다
|
37
|
+
daum.knowledge("삼국지").items.each do |i| ### items returns array of Item object which contains title, link, and so on.
|
38
|
+
puts i.title ### items는 Item 오브젝트의 배열을 반환하고 각 Item 오브젝트 속에 title, link 등이 들어있습니다.
|
39
|
+
end
|
40
|
+
|
41
|
+
You may want to take a look at the test file (test/test_daum.rb) to better understand the usage.
|
42
|
+
보다 자세한 사용법을 이해하시길 원하시면 테스트 파일 (test/test_daum.rb)을 참고하시면 됩니다.
|
17
43
|
|
18
|
-
Copyright (c) 2008 Hyunwoo Park
|
19
44
|
|
45
|
+
== Search Option Abbreviation List / 검색 옵션 약어 목록
|
46
|
+
|
47
|
+
The full list of abbreviation codes is the following. (You can still use full name of each parameter.)
|
48
|
+
약어 전체 목록을 아래에 정리하였습니다. (약어를 쓰지 않으셔도 작동합니다.)
|
49
|
+
|
50
|
+
re = result
|
51
|
+
ra = range
|
52
|
+
p = pageno
|
53
|
+
o = output
|
54
|
+
s = sort
|
55
|
+
ta = target
|
56
|
+
c = condition
|
57
|
+
ci = cate_id
|
58
|
+
st = searchType
|
59
|
+
ts = tagsearch
|
60
|
+
di = docid
|
61
|
+
g = group
|
62
|
+
req = requestor
|
63
|
+
ti = title
|
64
|
+
|
65
|
+
|
66
|
+
== License
|
67
|
+
|
68
|
+
Copyright:: Copyright (c) 2008 Hyunwoo Park <hwpark@oksurerails.com>
|
69
|
+
License:: MIT <http://www.opensource.org/licenses/mit-license.php>
|
data/Rakefile
CHANGED
@@ -2,13 +2,13 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('daum', '0.
|
6
|
-
p.description = "Ruby Gem for Daum
|
7
|
-
p.url = "http://oksurerails.com/daum"
|
5
|
+
Echoe.new('daum', '0.1.1') do |p|
|
6
|
+
p.description = "Ruby Gem for Daum OpenAPI"
|
7
|
+
p.url = "http://oksurerails.com/ruby/daum"
|
8
8
|
p.author = "Hyunwoo Park"
|
9
9
|
p.email = "hwpark@oksurerails.com"
|
10
10
|
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
-
p.development_dependencies = []
|
11
|
+
p.development_dependencies = ["libxml >= 0.9.2"]
|
12
12
|
end
|
13
13
|
|
14
14
|
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/daum.gemspec
CHANGED
@@ -2,30 +2,34 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{daum}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Hyunwoo Park"]
|
9
|
-
s.date = %q{2008-
|
10
|
-
s.description = %q{Ruby Gem for Daum
|
9
|
+
s.date = %q{2008-12-17}
|
10
|
+
s.description = %q{Ruby Gem for Daum OpenAPI}
|
11
11
|
s.email = %q{hwpark@oksurerails.com}
|
12
|
-
s.extra_rdoc_files = ["lib/daum.rb", "README.rdoc"]
|
13
|
-
s.files = ["lib/daum.rb", "
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/daum/base.rb", "lib/daum/item.rb", "lib/daum/rss.rb", "lib/daum.rb", "README.rdoc"]
|
13
|
+
s.files = ["CHANGELOG.rdoc", "daum.gemspec", "init.rb", "lib/daum/base.rb", "lib/daum/item.rb", "lib/daum/rss.rb", "lib/daum.rb", "Manifest", "Rakefile", "README.rdoc", "test/test_daum.rb"]
|
14
14
|
s.has_rdoc = true
|
15
|
-
s.homepage = %q{http://oksurerails.com/daum}
|
15
|
+
s.homepage = %q{http://oksurerails.com/ruby/daum}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Daum", "--main", "README.rdoc"]
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.rubyforge_project = %q{daum}
|
19
19
|
s.rubygems_version = %q{1.3.1}
|
20
|
-
s.summary = %q{Ruby Gem for Daum
|
20
|
+
s.summary = %q{Ruby Gem for Daum OpenAPI}
|
21
|
+
s.test_files = ["test/test_daum.rb"]
|
21
22
|
|
22
23
|
if s.respond_to? :specification_version then
|
23
24
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
25
|
s.specification_version = 2
|
25
26
|
|
26
27
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_development_dependency(%q<libxml>, [">= 0", "= 0.9.2"])
|
27
29
|
else
|
30
|
+
s.add_dependency(%q<libxml>, [">= 0", "= 0.9.2"])
|
28
31
|
end
|
29
32
|
else
|
33
|
+
s.add_dependency(%q<libxml>, [">= 0", "= 0.9.2"])
|
30
34
|
end
|
31
35
|
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "daum"
|
data/lib/daum.rb
CHANGED
@@ -1,5 +1,52 @@
|
|
1
|
-
|
1
|
+
# = Daum
|
2
|
+
# An easy interface to the Daum OpenAPI (http://dna.daum.net/apis). By Hyunwoo Park.
|
3
|
+
#
|
4
|
+
# Author:: Hyunwoo Park <hwpark@oksurerails.com>
|
5
|
+
# Copyright:: Copyright (c) 2008 Hyunwoo Park <hwpark@oksurerails.com>
|
6
|
+
# License:: MIT <http://www.opensource.org/licenses/mit-license.php>
|
7
|
+
#
|
8
|
+
# USAGE:
|
9
|
+
# require 'daum'
|
10
|
+
# daum = Daum::Base.new(api_key) ### create a naver client
|
11
|
+
# daum.request("삼국지", "go", {:display => "5", :start => "1", :sort => "sim"}) ### return root node as libxml node
|
12
|
+
# daum.knowledge("삼국지", {:display => "5", :start => "1", :sort => "sim"}) ### return RSS object / 자체 정의된 RSS 클래스 오브젝트를 반환합니다
|
13
|
+
# daum.knowledge("삼국지", {:d => "5", :st => "5", :so => "sim"}) ### It's possible to use abbreviation for each option / 검색 옵션을 넘길 때 약어를 사용 가능합니다
|
14
|
+
# daum.knowledge("삼국지").lastBuildDate ### return lastBuildDate content in String / 스트링으로 lastBuildDate 값을 반환합니다
|
15
|
+
# daum.knowledge("삼국지").items.each do |i| ### items returns array of Item object which contains title, link, and so on.
|
16
|
+
# puts i.title ### items는 Item 오브젝트의 배열을 반환하고 각 Item 오브젝트 속에 title, link 등이 들어있습니다.
|
17
|
+
# end
|
18
|
+
|
19
|
+
%w[cgi net/http libxml].each {|lib| require lib}
|
20
|
+
|
21
|
+
$:.unshift(File.join(File.dirname(__FILE__)))
|
22
|
+
|
23
|
+
require "daum/base"
|
24
|
+
require "daum/rss"
|
25
|
+
require "daum/item"
|
2
26
|
|
3
27
|
module Daum
|
28
|
+
include LibXML
|
29
|
+
|
30
|
+
class NoMethod < StandardError; end
|
31
|
+
class NoQuery < StandardError; end
|
32
|
+
|
33
|
+
# "/search" api list
|
34
|
+
SEARCH_LIST = %w[knowledge board cafe blog news book vclip image]
|
35
|
+
|
36
|
+
# "/search/dic" api list
|
37
|
+
DIC_LIST = %w[jpdic]
|
38
|
+
|
39
|
+
# "/shopping" api list
|
40
|
+
SHOPPING_LIST = %w[search detail]
|
41
|
+
|
42
|
+
# Method list
|
43
|
+
METHOD_LIST = SEARCH_LIST + DIC_LIST + SHOPPING_LIST
|
44
|
+
|
45
|
+
# Methods returning "channel" element as a document root
|
46
|
+
DIFF_DOC_ROOT_LIST = %w[book jpdic]
|
4
47
|
|
48
|
+
# Abbreviation for passing options
|
49
|
+
ABBREVIATION = {:re => :result, :p => :pageno, :ra => :range, :o => :output, :s => :sort,
|
50
|
+
:ta => :target, :c => :condition, :ci => :cate_id, :st => :searchType, :ts => :tagsearch,
|
51
|
+
:di => :docid, :g => :group, :req => :requestor, :ti => :title}
|
5
52
|
end
|
data/lib/daum/base.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module Daum
|
2
|
+
|
3
|
+
# fundamental class for naver gem
|
4
|
+
class Base
|
5
|
+
|
6
|
+
# attributes for accessing retrieved raw xml and parsed libxml root node
|
7
|
+
attr_accessor :doc_root, :raw_xml
|
8
|
+
|
9
|
+
# Replace this API key with your own (see http://dna.daum.net/apis)
|
10
|
+
def initialize(key=nil)
|
11
|
+
@key = key
|
12
|
+
@host = 'http://apis.daum.net'
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(target, query, params={})
|
16
|
+
raise NoQuery if query.empty?
|
17
|
+
if METHOD_LIST.include?(target.to_s)
|
18
|
+
request(target, query, params)
|
19
|
+
return RSS.new(@doc_root, target)
|
20
|
+
else
|
21
|
+
raise NoMethod
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Takes a Daum API method name and set of parameters; returns an libxml object with the response
|
26
|
+
def request(target, query, params={})
|
27
|
+
response = http_get(request_url(target, query, params))
|
28
|
+
parser, parser.string = LibXML::XML::Parser.new, response
|
29
|
+
@raw_xml = parser.parse
|
30
|
+
@doc_root = @raw_xml.root
|
31
|
+
end
|
32
|
+
|
33
|
+
# Takes a Daum API method name and set of parameters; returns the correct URL for the REST API.
|
34
|
+
def request_url(target, query, params={})
|
35
|
+
url = @host
|
36
|
+
if SEARCH_LIST.include?(target.to_s)
|
37
|
+
url += "/search/#{target}"
|
38
|
+
elsif DIC_LIST.include?(target.to_s)
|
39
|
+
url += "/search/dic/#{target}"
|
40
|
+
elsif SHOPPING_LIST.include?(target.to_s)
|
41
|
+
url += "/shopping/#{target}"
|
42
|
+
elsif SUGGEST_LIST.include?(target.to_s)
|
43
|
+
url += "/suggest/#{target}"
|
44
|
+
end
|
45
|
+
|
46
|
+
unless target.to_s == "detail"
|
47
|
+
url += "?apikey=#{@key}&q=#{query}"
|
48
|
+
else
|
49
|
+
url += "?apikey=#{@key}&docid=#{query}"
|
50
|
+
end
|
51
|
+
|
52
|
+
params.each do |key, value|
|
53
|
+
key = ABBREVIATION[key] unless ABBREVIATION[key].nil?
|
54
|
+
url += "&#{key}=" + CGI::escape(value)
|
55
|
+
end unless params.nil?
|
56
|
+
url
|
57
|
+
end
|
58
|
+
|
59
|
+
# Does an HTTP GET on a given URL and returns the response body
|
60
|
+
def http_get(url)
|
61
|
+
Net::HTTP.get_response(URI.parse(URI.encode(url))).body.to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
data/lib/daum/item.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Daum
|
2
|
+
|
3
|
+
# contains each item's information and converts XML format to Ruby format
|
4
|
+
class Item
|
5
|
+
|
6
|
+
# creates Item class object from libxml node input
|
7
|
+
def initialize(doc)
|
8
|
+
if cs = doc.children
|
9
|
+
cs.each do |c|
|
10
|
+
Item.class_eval("attr_accessor :#{c.name}")
|
11
|
+
self.instance_variable_set("@#{c.name}", c.content)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/daum/rss.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Daum
|
2
|
+
|
3
|
+
# contains RSS type return and converts XML format to Ruby format
|
4
|
+
class RSS
|
5
|
+
|
6
|
+
# variable for accessing items
|
7
|
+
attr_accessor :items
|
8
|
+
|
9
|
+
# creates RSS class object from libxml node input
|
10
|
+
def initialize(doc_root, target)
|
11
|
+
if DIFF_DOC_ROOT_LIST.include?(target.to_s)
|
12
|
+
channel = doc_root
|
13
|
+
else
|
14
|
+
channel = doc_root.find("channel").first
|
15
|
+
end
|
16
|
+
|
17
|
+
if cs = channel.children
|
18
|
+
cs.each do |c|
|
19
|
+
next if c.name == "item"
|
20
|
+
RSS.class_eval("attr_accessor :#{c.name}")
|
21
|
+
self.instance_variable_set("@#{c.name}", c.content)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
@items = []
|
26
|
+
channel.find("item").each do |i|
|
27
|
+
@items << Item.new(i)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/test/test_daum.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require 'daum'
|
8
|
+
|
9
|
+
class TestDaum < Test::Unit::TestCase
|
10
|
+
|
11
|
+
# sets up basic setting for unit testing
|
12
|
+
def setup
|
13
|
+
# insert your own Naver API key
|
14
|
+
@d = Daum::Base.new('your_key')
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_allmethod
|
18
|
+
@d.knowledge("삼국지").items.each do |i|
|
19
|
+
puts i.title
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oksure-daum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hyunwoo Park
|
@@ -9,27 +9,48 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-17 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: libxml
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
- - "="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 0.9.2
|
26
|
+
version:
|
27
|
+
description: Ruby Gem for Daum OpenAPI
|
17
28
|
email: hwpark@oksurerails.com
|
18
29
|
executables: []
|
19
30
|
|
20
31
|
extensions: []
|
21
32
|
|
22
33
|
extra_rdoc_files:
|
34
|
+
- CHANGELOG.rdoc
|
35
|
+
- lib/daum/base.rb
|
36
|
+
- lib/daum/item.rb
|
37
|
+
- lib/daum/rss.rb
|
23
38
|
- lib/daum.rb
|
24
39
|
- README.rdoc
|
25
40
|
files:
|
41
|
+
- CHANGELOG.rdoc
|
42
|
+
- daum.gemspec
|
43
|
+
- init.rb
|
44
|
+
- lib/daum/base.rb
|
45
|
+
- lib/daum/item.rb
|
46
|
+
- lib/daum/rss.rb
|
26
47
|
- lib/daum.rb
|
48
|
+
- Manifest
|
27
49
|
- Rakefile
|
28
50
|
- README.rdoc
|
29
|
-
-
|
30
|
-
- daum.gemspec
|
51
|
+
- test/test_daum.rb
|
31
52
|
has_rdoc: true
|
32
|
-
homepage: http://oksurerails.com/daum
|
53
|
+
homepage: http://oksurerails.com/ruby/daum
|
33
54
|
post_install_message:
|
34
55
|
rdoc_options:
|
35
56
|
- --line-numbers
|
@@ -58,6 +79,6 @@ rubyforge_project: daum
|
|
58
79
|
rubygems_version: 1.2.0
|
59
80
|
signing_key:
|
60
81
|
specification_version: 2
|
61
|
-
summary: Ruby Gem for Daum
|
62
|
-
test_files:
|
63
|
-
|
82
|
+
summary: Ruby Gem for Daum OpenAPI
|
83
|
+
test_files:
|
84
|
+
- test/test_daum.rb
|