diff --git a/.gitignore b/.gitignore
index 3ca2670..7af4481 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,3 @@
pkg
-doc
Manifest
-nbproject
-
+nbproject
\ No newline at end of file
diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc
index a5b1d25..66ea87a 100644
--- a/CHANGELOG.rdoc
+++ b/CHANGELOG.rdoc
@@ -1,17 +1,43 @@
+== 0.3.1, release 2008-12-05
+
+* Every search method will no longer return libxml node object. It will return self-defined RSS or Result object.
+* implemented easy access to each element in RSS/XML results by calling instance variables
+* added test file (You can refer this file for understanding usage of this gem.)
+* added documentation files (ri, RDoc)
+* fixed searching for "doc" (The name was overlapped with an instance variable.)
+* revised readme file to remove important note and instruction for installing from github
+* 서치 메소드들이 더 이상 libxml 노드 오브젝트를 반환하지 않습니다. 대신에, 자체 정의된 RSS 또는 Result 오브젝트를 반환합니다.
+* 인스턴스 변수를 쓰는 것으로 RSS/XML 결과들의 각 엘러먼트에 쉽게 접근할 수 있도록 함
+* 테스트 파일 추가 (이 파일을 참조하여 이 젬의 사용법을 이해하실 수 있습니다.)
+* 문서 파일 추가 (ri, RDoc)
+* "doc"에 대해서 검색이 안 되던 것을 고침 (인스턴스 변수와 이름이 중복되어 있었음)
+* Readme 파일을 수정하여 중요 공지를 지우고 github로부터 설치하는 방법을 지움
+
+
== 0.2.1, release 2008-12-04
-* converted class Naver to module Naver ("Naver.new" is no longer available) / 클래스에서 모듈로 구조 변경 ("Naver.new"는 더 이상 사용 불가)
-* implemented method missing to use search target name as method / 메소드 미싱을 구현하여 검색 타겟을 메소드로 호출할 수 있게 함
-* added abbreviation hash for passing arguments / 검색 조건 넘길 때 약어로 넘길 수 있게 함
-* added Korean parts of readme and changelog files / readme와 changelog에 한글 부분 추가
-* distributed on rubyforge.org as well (originally only available on github) / 루비포지에서도 배포 (원래는 github에만 있었음)
+* converted class Naver to module Naver ("Naver.new" is no longer available)
+* implemented method missing to use search target name as method
+* added abbreviation hash for passing arguments
+* added Korean parts of readme and changelog files
+* distributed on rubyforge.org as well (originally only available on github)
+* 클래스에서 모듈로 구조 변경 ("Naver.new"는 더 이상 사용 불가)
+* 메소드 미싱을 구현하여 검색 타겟을 메소드로 호출할 수 있게 함
+* 검색 조건 넘길 때 약어로 넘길 수 있게 함
+* readme와 changelog에 한글 부분 추가
+* 루비포지에서도 배포 (원래는 github에만 있었음)
== 0.1.1, release 2008-11-23
-* primitive 'request' method implemented / 원시 'request' 메소드 구현
-* added init.rb / init.rb 파일 추가
+* primitive 'request' method implemented
+* added init.rb
+* 원시 'request' 메소드 구현
+* init.rb 파일 추가
+
== 0.0.1, release 2008-11-22
-* first commit / 첫 번째 커밋
-* no classes, methods implemented / 아직 아무 것도 안 했음
\ No newline at end of file
+* first commit
+* no classes, methods implemented
+* 첫 번째 커밋
+* 아직 아무 것도 안 했음
\ No newline at end of file
diff --git a/README.rdoc b/README.rdoc
index 490ac3e..c5d1156 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -1,28 +1,15 @@
-= Naver 0.2.1
+= Naver 0.3.1
Ruby gem for using Naver OpenAPI (http://dev.naver.com/openapi/tutorial).
네이버 OpenAPI를 위한 루비젬입니다.
-== IMPORTANT NOTE / 중요 공지
-
-* Since this is still in development stage, every method or usage may be deprecated in future versions without any prior notice. (I will try to keep track of changes in CHANGELOG.rdoc, though.)
-* Although I read the Rational Versioning Policy, I would change the middle number when some old codes might not work well with updates since Naver gem is still in development stage. When this gem considered stable, I will follow the RVP.
-* 현재 초기 작업 단계이기 때문에, 사전 공지 없이 모든 메소드나 사용법이 미래 버전에서는 사용하게 없게 될 수도 있습니다. (물론 CHANGELOG.rdoc에 변화 사항들을 기록하려고 노력은 하겠습니다만)
-* Rational Versioning Policy에 대해서 읽기는 했습니다만, 역시 아직 초기 개발 단계라서 과거 버전과 compatible하지 않은 버전을 릴리즈할 경우에 버전의 첫째 자리가 아닌 중간 자리 숫자를 변경할 생각입니다.
-
-
== Install / 설치법
You can install the gem from rubyforge directly.
루비포지에서 바로 설치하실 수 있습니다.
gem install naver
-Or, you can also install from github. The name is diffrent, which is precedented by my id on github.
-아니면, github에서 설치할 수도 있습니다. 젬의 이름이 다른데, 저의 github 아이디가 앞에 붙습니다.
- gem sources -a http://gems.github.com
- gem install oksure-naver
-
== Usage / 사용법
@@ -32,11 +19,18 @@ Before using this gem, you need to get your own API key. To obtain your API key,
require 'naver'
naver = Naver::Base.new(api_key) ### create a naver client / 네이버 클라이언트를 생성합니다
naver.request("kin", "go", {:display => "5", :start => "1", :sort => "sim"}) ### return root node as libxml node / libxml 형식의 노드로 루트 노드를 반환합니다
- naver.kin("go", {:display => "5", :start => "1", :sort => "sim"}) ### return root node as libxml node / libxml 형식의 노드로 루트 노드를 반환합니다
- naver.kin("go", {:d => "5", :start => "5", :so => "sim"}) ### It's possible to use abbreviation for each option / 검색 옵션을 넘길 때 약어를 사용 가능합니다
+ naver.kin("go", {:display => "5", :start => "1", :sort => "sim"}) ### return RSS object / 자체 정의된 RSS 클래스 오브젝트를 반환합니다
+ naver.kin("go", {:d => "5", :st => "5", :so => "sim"}) ### It's possible to use abbreviation for each option / 검색 옵션을 넘길 때 약어를 사용 가능합니다
+ naver.kin("go").lastBuildDate ### return lastBuildDate content in String / 스트링으로 lastBuildDate 값을 반환합니다
+ naver.kin("go").items.each do |i| ### items returns array of Item object which contains title, link, and so on.
+ puts i.title ### items는 Item 오브젝트의 배열을 반환하고 각 Item 오브젝트 속에 title, link 등이 들어있습니다.
+ end
+
+You may want to take a look at the test file (test/test_naver.rb) to better understand the usage.
+보다 자세한 사용법을 이해하시길 원하시면 테스트 파일 (test/test_naver.rb)을 참고하시면 됩니다.
-== Abbreviation List / 약어 목록
+== Search Option Abbreviation List / 검색 옵션 약어 목록
The full list of abbreviation codes is the following. (You can still use full name of each parameter.)
약어 전체 목록을 아래에 정리하였습니다. (약어를 쓰지 않으셔도 작동합니다.)
diff --git a/Rakefile b/Rakefile
index 7741bfa..2e76e57 100644
--- a/Rakefile
+++ b/Rakefile
@@ -2,13 +2,13 @@ require 'rubygems'
require 'rake'
require 'echoe'
-Echoe.new('naver', '0.2.1') do |p|
+Echoe.new('naver', '0.3.1') do |p|
p.description = "Ruby Gem for Naver OpenAPI"
p.url = "http://oksurerails.com/naver"
p.author = "Hyunwoo Park"
p.email = "hwpark@oksurerails.com"
p.ignore_pattern = ["tmp/*", "script/*"]
- p.development_dependencies = ["libxml-ruby"]
+ p.development_dependencies = ["libxml-ruby >=0.9.2"]
end
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
diff --git a/doc/classes/Naver.html b/doc/classes/Naver.html
new file mode 100644
index 0000000..26a5cd6
--- /dev/null
+++ b/doc/classes/Naver.html
@@ -0,0 +1,188 @@
+
+
+
+
+
+ Module: Naver
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Included Modules
+
+
+ LibXML
+
+
+
+
+
+
+
+
+
Constants
+
+
+
+
+ RSS_LIST
+ =
+ %w[kin video image doc book book_adv local shop encyc krdic endic jpdic blog cafe cafearticle webkr news]
+
+
+Searches that returns results in RSS format
+
+
+
+
+ XML_LIST
+ =
+ %w[rank ranktheme recmd adult errata shortcut]
+
+
+Searches that returns results in Non-RSS but
+XML format
+
+
+
+
+ METHOD_LIST
+ =
+ RSS_LIST.concat(XML_LIST)
+
+
+Whole available search list
+
+
+
+
+ ABBREVIATION
+ =
+ {:d => :display, :st => :start, :so => :sort, :f => :filter, :p => :payment, :dt => :d_titl, :da => :d_auth, :dco => :d_cont, :di => :d_isbn, :dp => :d_publ, :ddaf => :d_dafr, :ddat => :d_dato, :dca => :d_catg}
+
+
+Abbreviation for passing options
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/classes/Naver/Base.html b/doc/classes/Naver/Base.html
new file mode 100644
index 0000000..9dee0ae
--- /dev/null
+++ b/doc/classes/Naver/Base.html
@@ -0,0 +1,309 @@
+
+
+
+
+
+ Class: Naver::Base
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+fundamental class for naver gem
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Attributes
+
+
+
+
+ doc_root
+ [RW]
+
+attributes for accessing retrieved raw xml and parsed libxml root node
+
+
+
+
+ raw_xml
+ [RW]
+
+attributes for accessing retrieved raw xml and parsed libxml root node
+
+
+
+
+
+
+
+
+
+
+
+
Public Class methods
+
+
+
+
+
+
+
+
+Replace this API key with your own (see dev.naver.com/openapi/register )
+
+
[Source]
+
+
+
+10: def initialize (key =nil )
+11: @key = key
+12: @host = 'http://openapi.naver.com'
+13: @api = '/search'
+14: end
+
+
+
+
+
+
Public Instance methods
+
+
+
+
+
+
+
+
+Does an HTTP GET on a given URL and returns the response body
+
+
[Source]
+
+
+
+49: def http_get (url )
+50: Net :: HTTP .get_response (URI .parse (url )).body .to_s
+51: end
+
+
+
+
+
+
+
+
+
+
+
+
[Source]
+
+
+
+16: def method_missing (target , query , params ={})
+17: raise NoQuery if query .empty?
+18: if METHOD_LIST .include? (target .to_s )
+19: request (target , query , params )
+20: if XML_LIST .include? (target .to_s )
+21: return Result .new (@doc_root , target .to_s )
+22: else
+23: return RSS .new (@doc_root )
+24: end
+25: else
+26: raise NoMethod
+27: end
+28: end
+
+
+
+
+
+
+
+
+
+
+
+
+Takes a Naver API method name and set of
+parameters; returns an libxml object with the response
+
+
[Source]
+
+
+
+31: def request (target , query , params ={})
+32: response = http_get (request_url (target , query , params ))
+33: parser , parser .string = LibXML :: XML :: Parser .new , response
+34: @raw_xml = parser .parse
+35: @doc_root = @raw_xml .root
+36: end
+
+
+
+
+
+
+
+
+
+
+
+
+Takes a Naver API method name and set of
+parameters; returns the correct URL for the REST API.
+
+
[Source]
+
+
+
+39: def request_url (target , query , params ={})
+40: url = "#{@host}#{@api}?key=#{@key}&target=#{target}&query=#{query}"
+41: params .each do | key , value |
+42: key = ABBREVIATION [key ] unless ABBREVIATION [key ].nil?
+43: url += "&#{key}=" + CGI :: escape (value )
+44: end unless params .nil?
+45: url
+46: end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/classes/Naver/Item.html b/doc/classes/Naver/Item.html
new file mode 100644
index 0000000..e6ed6a1
--- /dev/null
+++ b/doc/classes/Naver/Item.html
@@ -0,0 +1,161 @@
+
+
+
+
+
+ Class: Naver::Item
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+contains each item‘s information and converts XML format to Ruby
+format
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Public Class methods
+
+
+
+
+
+
+
+
+creates Item class object from libxml node input
+
+
[Source]
+
+
+
+ 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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/classes/Naver/NoMethod.html b/doc/classes/Naver/NoMethod.html
new file mode 100644
index 0000000..250df2a
--- /dev/null
+++ b/doc/classes/Naver/NoMethod.html
@@ -0,0 +1,111 @@
+
+
+
+
+
+ Class: Naver::NoMethod
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/classes/Naver/NoQuery.html b/doc/classes/Naver/NoQuery.html
new file mode 100644
index 0000000..59c5d78
--- /dev/null
+++ b/doc/classes/Naver/NoQuery.html
@@ -0,0 +1,111 @@
+
+
+
+
+
+ Class: Naver::NoQuery
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/classes/Naver/RSS.html b/doc/classes/Naver/RSS.html
new file mode 100644
index 0000000..99a7a52
--- /dev/null
+++ b/doc/classes/Naver/RSS.html
@@ -0,0 +1,181 @@
+
+
+
+
+
+ Class: Naver::RSS
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+contains RSS type return and converts XML format to
+Ruby format
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Attributes
+
+
+
+
+ items
+ [RW]
+
+variable for accessing items
+
+
+
+
+
+
+
+
+
+
+
+
Public Class methods
+
+
+
+
+
+
+
+
+creates RSS class object from libxml node input
+
+
[Source]
+
+
+
+10: def initialize (doc_root )
+11: channel = doc_root .find ("//rss/channel" ).first
+12: %w[lastBuildDate total start display] .each do | f |
+13: RSS .class_eval ("attr_accessor :#{f}" )
+14: self .instance_variable_set ("@#{f}" , channel .find (f ).first .content )
+15: end
+16:
+17: @items = []
+18: channel .find ("item" ).each do | i |
+19: @items << Item .new (i )
+20: end
+21: end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/classes/Naver/Result.html b/doc/classes/Naver/Result.html
new file mode 100644
index 0000000..17a2005
--- /dev/null
+++ b/doc/classes/Naver/Result.html
@@ -0,0 +1,202 @@
+
+
+
+
+
+ Class: Naver::Result
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+contains Result type return and converts XML
+format to Ruby format
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Attributes
+
+
+
+
+ items
+ [RW]
+
+variable for accessing items
+
+
+
+
+
+
+
+
+
+
+
+
Public Class methods
+
+
+
+
+
+
+
+
+creates Result object from libxml node input
+
+
[Source]
+
+
+
+10: def initialize (doc_root , target )
+11: channel = doc_root .find ("//result" ).first
+12:
+13: case target
+14: when "rank" , "ranktheme" :
+15: Result .class_eval ("attr_accessor :ranks" )
+16: @ranks = []
+17: channel .find ("item" ).first .children .each do | c |
+18: @ranks << Item .new (c )
+19: end
+20: when "recmd" :
+21: Result .class_eval ("attr_accessor :recmds" )
+22: @recmds = []
+23: channel .find ("item" ).each do | i |
+24: @recmds << i .content
+25: end
+26: when "adult" , "errata" :
+27: Result .class_eval ("attr_accessor :#{target}" )
+28: self .instance_variable_set ("@#{target}" , channel .find ("item/#{target}" ).first .content )
+29: when "shortcut" :
+30: Result .class_eval ("attr_accessor :shortcuts" )
+31: @shortcuts = []
+32: channel .find ("item/shortcut" ).each do | s |
+33: @shortcuts << Item .new (s )
+34: end
+35: else
+36: Result .class_eval ("attr_accessor :items" )
+37: @items = []
+38: channel .find ("item" ).each do | i |
+39: @items << Item .new (i )
+40: end
+41: end
+42: end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/created.rid b/doc/created.rid
new file mode 100644
index 0000000..98801cb
--- /dev/null
+++ b/doc/created.rid
@@ -0,0 +1 @@
+Thu, 04 Dec 2008 23:09:02 -0800
diff --git a/doc/files/CHANGELOG_rdoc.html b/doc/files/CHANGELOG_rdoc.html
new file mode 100644
index 0000000..57202bc
--- /dev/null
+++ b/doc/files/CHANGELOG_rdoc.html
@@ -0,0 +1,221 @@
+
+
+
+
+
+ File: CHANGELOG.rdoc
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
0.3.1, release 2008-12-05
+
+Every search method will no longer return libxml node object. It will
+return self-defined RSS or Result object.
+
+
+implemented easy access to each element in RSS/XML results by calling
+instance variables
+
+
+added test file (You can refer this file for understanding usage of this
+gem.)
+
+
+added documentation files (ri, RDoc)
+
+
+fixed searching for "doc" (The name was overlapped with an
+instance variable.)
+
+
+revised readme file to remove important note and instruction for installing
+from github
+
+
+서치 메소드들이 더 이상 libxml 노드 오브젝트를
+반환하지 않습니다. 대신에, 자체 정의된 RSS 또는 Result
+오브젝트를 반환합니다.
+
+
+인스턴스 변수를 쓰는 것으로 RSS/XML 결과들의 각
+엘러먼트에 쉽게 접근할 수 있도록 함
+
+
+테스트 파일 추가 (이 파일을 참조하여 이 젬의 사용법을
+이해하실 수 있습니다.)
+
+
+문서 파일 추가 (ri, RDoc)
+
+
+"doc"에 대해서 검색이 안 되던 것을 고침
+(인스턴스 변수와 이름이 중복되어 있었음)
+
+
+Readme 파일을 수정하여 중요 공지를 지우고 github로부터
+설치하는 방법을 지움
+
+
+
+
0.2.1, release 2008-12-04
+
+converted class Naver to module Naver ("Naver.new" is no longer
+available)
+
+
+implemented method missing to use search target name as method
+
+
+added abbreviation hash for passing arguments
+
+
+added Korean parts of readme and changelog files
+
+
+distributed on rubyforge.org as well (originally only available on github)
+
+
+클래스에서 모듈로 구조 변경 ("Naver.new"는 더
+이상 사용 불가)
+
+
+메소드 미싱을 구현하여 검색 타겟을 메소드로 호출할
+수 있게 함
+
+
+검색 조건 넘길 때 약어로 넘길 수 있게 함
+
+
+readme와 changelog에 한글 부분 추가
+
+
+루비포지에서도 배포 (원래는 github에만 있었음)
+
+
+
+
0.1.1, release 2008-11-23
+
+primitive ‘request’ method implemented
+
+
+added init.rb
+
+
+원시 ‘request’ 메소드 구현
+
+
+init.rb 파일 추가
+
+
+
+
0.0.1, release 2008-11-22
+
+first commit
+
+
+no classes, methods implemented
+
+
+첫 번째 커밋
+
+
+아직 아무 것도 안 했음
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/files/README_rdoc.html b/doc/files/README_rdoc.html
new file mode 100644
index 0000000..979aa2c
--- /dev/null
+++ b/doc/files/README_rdoc.html
@@ -0,0 +1,176 @@
+
+
+
+
+
+ File: README.rdoc
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Ruby gem for using Naver OpenAPI (dev.naver.com/openapi/tutorial ).
+네이버 OpenAPI를 위한 루비젬입니다.
+
+
Install / 설치법
+
+You can install the gem from rubyforge directly. 루비포지에서 바로
+설치하실 수 있습니다.
+
+
+ gem install naver
+
+
Usage / 사용법
+
+Before using this gem, you need to get your own API key. To obtain your API
+key, see dev.naver.com/openapi/register .
+이 젬을 사용하기 전에 API 키를 발급 받으셔야 합니다.
+API 키 발급을 위해서는 dev.naver.com/openapi/register
+링크를 참고해 주세요.
+
+
+ require 'naver'
+ naver = Naver::Base.new(api_key) ### create a naver client / 네이버 클라이언트를 생성합니다
+ naver.request("kin", "go", {:display => "5", :start => "1", :sort => "sim"}) ### return root node as libxml node / libxml 형식의 노드로 루트 노드를 반환합니다
+ naver.kin("go", {:display => "5", :start => "1", :sort => "sim"}) ### return RSS object / 자체 정의된 RSS 클래스 오브젝트를 반환합니다
+ naver.kin("go", {:d => "5", :st => "5", :so => "sim"}) ### It's possible to use abbreviation for each option / 검색 옵션을 넘길 때 약어를 사용 가능합니다
+ naver.kin("go").lastBuildDate ### return lastBuildDate content in String / 스트링으로 lastBuildDate 값을 반환합니다
+ naver.kin("go").items.each do |i| ### items returns array of Item object which contains title, link, and so on.
+ puts i.title ### items는 Item 오브젝트의 배열을 반환하고 각 Item 오브젝트 속에 title, link 등이 들어있습니다.
+ end
+
+
+You may want to take a look at the test file (test/test_naver.rb) to better
+understand the usage. 보다 자세한 사용법을 이해하시길
+원하시면 테스트 파일 (test/test_naver.rb)을 참고하시면
+됩니다.
+
+
Search Option Abbreviation List / 검색 옵션 약어 목록
+
+The full list of abbreviation codes is the following. (You can still use
+full name of each parameter.) 약어 전체 목록을 아래에
+정리하였습니다. (약어를 쓰지 않으셔도 작동합니다.)
+
+
+ d = display
+ st = start
+ so = sort
+ f = filter
+ p = payment
+ dt = d_titl
+ da = d_auth
+ dcon = d_cont
+ di = d_isbn
+ dp = d_publ
+ ddaf = d_dafr
+ ddat = d_dato
+ dcat = d_catg
+
+
License
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/files/lib/naver/base_rb.html b/doc/files/lib/naver/base_rb.html
new file mode 100644
index 0000000..bc69b3e
--- /dev/null
+++ b/doc/files/lib/naver/base_rb.html
@@ -0,0 +1,101 @@
+
+
+
+
+
+ File: base.rb
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/files/lib/naver/item_rb.html b/doc/files/lib/naver/item_rb.html
new file mode 100644
index 0000000..5b15589
--- /dev/null
+++ b/doc/files/lib/naver/item_rb.html
@@ -0,0 +1,101 @@
+
+
+
+
+
+ File: item.rb
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/files/lib/naver/result_rb.html b/doc/files/lib/naver/result_rb.html
new file mode 100644
index 0000000..c59dbc0
--- /dev/null
+++ b/doc/files/lib/naver/result_rb.html
@@ -0,0 +1,101 @@
+
+
+
+
+
+ File: result.rb
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/files/lib/naver/rss_rb.html b/doc/files/lib/naver/rss_rb.html
new file mode 100644
index 0000000..f254a91
--- /dev/null
+++ b/doc/files/lib/naver/rss_rb.html
@@ -0,0 +1,101 @@
+
+
+
+
+
+ File: rss.rb
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/files/lib/naver_rb.html b/doc/files/lib/naver_rb.html
new file mode 100644
index 0000000..dc0097b
--- /dev/null
+++ b/doc/files/lib/naver_rb.html
@@ -0,0 +1,138 @@
+
+
+
+
+
+ File: naver.rb
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ An easy interface to the Naver OpenAPI (http://dev.naver.com/openapi/tutorial). By Hyunwoo Park.
+
+
+
+USAGE:
+
+
+ require 'naver'
+ naver = Naver.new(api_key) ### create a naver client
+ naver.request("kin", "go", {:display => "5", :start => "1", :sort => "sim"}) ### return root node as libxml node
+
+
+
+
+
+
Required files
+
+
+ naver/base
+ naver/rss
+ naver/result
+ naver/item
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/fr_class_index.html b/doc/fr_class_index.html
new file mode 100644
index 0000000..3ad2db9
--- /dev/null
+++ b/doc/fr_class_index.html
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+ Classes
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/fr_file_index.html b/doc/fr_file_index.html
new file mode 100644
index 0000000..a85b3f0
--- /dev/null
+++ b/doc/fr_file_index.html
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+ Files
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/fr_method_index.html b/doc/fr_method_index.html
new file mode 100644
index 0000000..8c14ae6
--- /dev/null
+++ b/doc/fr_method_index.html
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/index.html b/doc/index.html
new file mode 100644
index 0000000..4b3122b
--- /dev/null
+++ b/doc/index.html
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+ Naver
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/rdoc-style.css b/doc/rdoc-style.css
new file mode 100644
index 0000000..44c7b3d
--- /dev/null
+++ b/doc/rdoc-style.css
@@ -0,0 +1,208 @@
+
+body {
+ font-family: Verdana,Arial,Helvetica,sans-serif;
+ font-size: 90%;
+ margin: 0;
+ margin-left: 40px;
+ padding: 0;
+ background: white;
+}
+
+h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
+h1 { font-size: 150%; }
+h2,h3,h4 { margin-top: 1em; }
+
+a { background: #eef; color: #039; text-decoration: none; }
+a:hover { background: #039; color: #eef; }
+
+/* Override the base stylesheet's Anchor inside a table cell */
+td > a {
+ background: transparent;
+ color: #039;
+ text-decoration: none;
+}
+
+/* and inside a section title */
+.section-title > a {
+ background: transparent;
+ color: #eee;
+ text-decoration: none;
+}
+
+/* === Structural elements =================================== */
+
+div#index {
+ margin: 0;
+ margin-left: -40px;
+ padding: 0;
+ font-size: 90%;
+}
+
+
+div#index a {
+ margin-left: 0.7em;
+}
+
+div#index .section-bar {
+ margin-left: 0px;
+ padding-left: 0.7em;
+ background: #ccc;
+ font-size: small;
+}
+
+
+div#classHeader, div#fileHeader {
+ width: auto;
+ color: white;
+ padding: 0.5em 1.5em 0.5em 1.5em;
+ margin: 0;
+ margin-left: -40px;
+ border-bottom: 3px solid #006;
+}
+
+div#classHeader a, div#fileHeader a {
+ background: inherit;
+ color: white;
+}
+
+div#classHeader td, div#fileHeader td {
+ background: inherit;
+ color: white;
+}
+
+
+div#fileHeader {
+ background: #057;
+}
+
+div#classHeader {
+ background: #048;
+}
+
+
+.class-name-in-header {
+ font-size: 180%;
+ font-weight: bold;
+}
+
+
+div#bodyContent {
+ padding: 0 1.5em 0 1.5em;
+}
+
+div#description {
+ padding: 0.5em 1.5em;
+ background: #efefef;
+ border: 1px dotted #999;
+}
+
+div#description h1,h2,h3,h4,h5,h6 {
+ color: #125;;
+ background: transparent;
+}
+
+div#validator-badges {
+ text-align: center;
+}
+div#validator-badges img { border: 0; }
+
+div#copyright {
+ color: #333;
+ background: #efefef;
+ font: 0.75em sans-serif;
+ margin-top: 5em;
+ margin-bottom: 0;
+ padding: 0.5em 2em;
+}
+
+
+/* === Classes =================================== */
+
+table.header-table {
+ color: white;
+ font-size: small;
+}
+
+.type-note {
+ font-size: small;
+ color: #DEDEDE;
+}
+
+.xxsection-bar {
+ background: #eee;
+ color: #333;
+ padding: 3px;
+}
+
+.section-bar {
+ color: #333;
+ border-bottom: 1px solid #999;
+ margin-left: -20px;
+}
+
+
+.section-title {
+ background: #79a;
+ color: #eee;
+ padding: 3px;
+ margin-top: 2em;
+ margin-left: -30px;
+ border: 1px solid #999;
+}
+
+.top-aligned-row { vertical-align: top }
+.bottom-aligned-row { vertical-align: bottom }
+
+/* --- Context section classes ----------------------- */
+
+.context-row { }
+.context-item-name { font-family: monospace; font-weight: bold; color: black; }
+.context-item-value { font-size: small; color: #448; }
+.context-item-desc { color: #333; padding-left: 2em; }
+
+/* --- Method classes -------------------------- */
+.method-detail {
+ background: #efefef;
+ padding: 0;
+ margin-top: 0.5em;
+ margin-bottom: 1em;
+ border: 1px dotted #ccc;
+}
+.method-heading {
+ color: black;
+ background: #ccc;
+ border-bottom: 1px solid #666;
+ padding: 0.2em 0.5em 0 0.5em;
+}
+.method-signature { color: black; background: inherit; }
+.method-name { font-weight: bold; }
+.method-args { font-style: italic; }
+.method-description { padding: 0 0.5em 0 0.5em; }
+
+/* --- Source code sections -------------------- */
+
+a.source-toggle { font-size: 90%; }
+div.method-source-code {
+ background: #262626;
+ color: #ffdead;
+ margin: 1em;
+ padding: 0.5em;
+ border: 1px dashed #999;
+ overflow: hidden;
+}
+
+div.method-source-code pre { color: #ffdead; overflow: hidden; }
+
+/* --- Ruby keyword styles --------------------- */
+
+.standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
+
+.ruby-constant { color: #7fffd4; background: transparent; }
+.ruby-keyword { color: #00ffff; background: transparent; }
+.ruby-ivar { color: #eedd82; background: transparent; }
+.ruby-operator { color: #00ffee; background: transparent; }
+.ruby-identifier { color: #ffdead; background: transparent; }
+.ruby-node { color: #ffa07a; background: transparent; }
+.ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
+.ruby-regexp { color: #ffa07a; background: transparent; }
+.ruby-value { color: #7fffd4; background: transparent; }
\ No newline at end of file
diff --git a/lib/naver.rb b/lib/naver.rb
index b7390c7..4b3e9f8 100644
--- a/lib/naver.rb
+++ b/lib/naver.rb
@@ -9,25 +9,27 @@
# require 'naver'
# naver = Naver.new(api_key) ### create a naver client
# naver.request("kin", "go", {:display => "5", :start => "1", :sort => "sim"}) ### return root node as libxml node
-#
-# To Do:
-# local search implementation
-require "cgi"
-require "net/http"
-require "libxml"
+%w[cgi net/http libxml].each {|lib| require lib}
$:.unshift(File.join(File.dirname(__FILE__)))
+
require "naver/base"
+require "naver/rss"
+require "naver/result"
+require "naver/item"
module Naver
+ include LibXML
+
class NoMethod < StandardError; end
+ class NoQuery < StandardError; end
# Searches that returns results in RSS format
RSS_LIST = %w[kin video image doc book book_adv local shop encyc krdic endic jpdic blog cafe cafearticle webkr news]
# Searches that returns results in Non-RSS but XML format
- XML_LIST = %w[rank rankthem recmd adult errata shortcut]
+ XML_LIST = %w[rank ranktheme recmd adult errata shortcut]
# Whole available search list
METHOD_LIST = RSS_LIST.concat(XML_LIST)
@@ -36,7 +38,4 @@ class NoMethod < StandardError; end
ABBREVIATION = {:d => :display, :st => :start, :so => :sort, :f => :filter, :p => :payment,
:dt => :d_titl, :da => :d_auth, :dco => :d_cont, :di => :d_isbn, :dp => :d_publ,
:ddaf => :d_dafr, :ddat => :d_dato, :dca => :d_catg}
-
- SourceName = 'navergem'
-
end
\ No newline at end of file
diff --git a/lib/naver/base.rb b/lib/naver/base.rb
index 43cad7a..230aacb 100644
--- a/lib/naver/base.rb
+++ b/lib/naver/base.rb
@@ -1,9 +1,10 @@
module Naver
- include LibXML
+ # fundamental class for naver gem
class Base
- attr_accessor :doc, :raw_xml
+ # attributes for accessing retrieved raw xml and parsed libxml root node
+ attr_accessor :doc_root, :raw_xml
# Replace this API key with your own (see http://dev.naver.com/openapi/register)
def initialize(key=nil)
@@ -13,8 +14,14 @@ def initialize(key=nil)
end
def method_missing(target, query, params={})
+ raise NoQuery if query.empty?
if METHOD_LIST.include?(target.to_s)
request(target, query, params)
+ if XML_LIST.include?(target.to_s)
+ return Result.new(@doc_root, target.to_s)
+ else
+ return RSS.new(@doc_root)
+ end
else
raise NoMethod
end
@@ -25,7 +32,7 @@ def request(target, query, params={})
response = http_get(request_url(target, query, params))
parser, parser.string = LibXML::XML::Parser.new, response
@raw_xml = parser.parse
- @doc = @raw_xml.root
+ @doc_root = @raw_xml.root
end
# Takes a Naver API method name and set of parameters; returns the correct URL for the REST API.
diff --git a/lib/naver/item.rb b/lib/naver/item.rb
new file mode 100644
index 0000000..bd31b5b
--- /dev/null
+++ b/lib/naver/item.rb
@@ -0,0 +1,16 @@
+module Naver
+
+ # contains each item's information and converts XML format to Ruby format
+ class Item
+
+ # creates Item class object from libxml node input
+ def initialize(doc)
+ if cs = doc.children
+ cs.each do |c|
+ Item.class_eval("attr_accessor :#{c.name}")
+ self.instance_variable_set("@#{c.name}", c.content)
+ end
+ end
+ end
+ end
+end
diff --git a/lib/naver/result.rb b/lib/naver/result.rb
new file mode 100644
index 0000000..2054214
--- /dev/null
+++ b/lib/naver/result.rb
@@ -0,0 +1,44 @@
+module Naver
+
+ # contains Result type return and converts XML format to Ruby format
+ class Result
+
+ # variable for accessing items
+ attr_accessor :items
+
+ # creates Result object from libxml node input
+ def initialize(doc_root, target)
+ channel = doc_root.find("//result").first
+
+ case target
+ when "rank", "ranktheme":
+ Result.class_eval("attr_accessor :ranks")
+ @ranks = []
+ channel.find("item").first.children.each do |c|
+ @ranks << Item.new(c)
+ end
+ when "recmd":
+ Result.class_eval("attr_accessor :recmds")
+ @recmds = []
+ channel.find("item").each do |i|
+ @recmds << i.content
+ end
+ when "adult", "errata":
+ Result.class_eval("attr_accessor :#{target}")
+ self.instance_variable_set("@#{target}", channel.find("item/#{target}").first.content)
+ when "shortcut":
+ Result.class_eval("attr_accessor :shortcuts")
+ @shortcuts = []
+ channel.find("item/shortcut").each do |s|
+ @shortcuts << Item.new(s)
+ end
+ else
+ Result.class_eval("attr_accessor :items")
+ @items = []
+ channel.find("item").each do |i|
+ @items << Item.new(i)
+ end
+ end
+ end
+ end
+end
diff --git a/lib/naver/rss.rb b/lib/naver/rss.rb
new file mode 100644
index 0000000..702e36a
--- /dev/null
+++ b/lib/naver/rss.rb
@@ -0,0 +1,23 @@
+module Naver
+
+ # contains RSS type return and converts XML format to Ruby format
+ class RSS
+
+ # variable for accessing items
+ attr_accessor :items
+
+ # creates RSS class object from libxml node input
+ def initialize(doc_root)
+ channel = doc_root.find("//rss/channel").first
+ %w[lastBuildDate total start display].each do |f|
+ RSS.class_eval("attr_accessor :#{f}")
+ self.instance_variable_set("@#{f}", channel.find(f).first.content)
+ end
+
+ @items = []
+ channel.find("item").each do |i|
+ @items << Item.new(i)
+ end
+ end
+ end
+end
diff --git a/naver.gemspec b/naver.gemspec
index b4ce9ce..84713df 100644
--- a/naver.gemspec
+++ b/naver.gemspec
@@ -2,15 +2,15 @@
Gem::Specification.new do |s|
s.name = %q{naver}
- s.version = "0.2.1"
+ s.version = "0.3.1"
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Hyunwoo Park"]
- s.date = %q{2008-12-04}
+ s.date = %q{2008-12-05}
s.description = %q{Ruby Gem for Naver OpenAPI}
s.email = %q{hwpark@oksurerails.com}
- s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/naver/base.rb", "lib/naver.rb", "README.rdoc"]
- s.files = ["CHANGELOG.rdoc", "init.rb", "lib/naver/base.rb", "lib/naver.rb", "Manifest", "rakefile", "README.rdoc", "Rakefile", "naver.gemspec"]
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/naver/base.rb", "lib/naver/item.rb", "lib/naver/result.rb", "lib/naver/rss.rb", "lib/naver.rb", "README.rdoc"]
+ s.files = ["CHANGELOG.rdoc", "init.rb", "lib/naver/base.rb", "lib/naver/item.rb", "lib/naver/result.rb", "lib/naver/rss.rb", "lib/naver.rb", "Manifest", "rakefile", "README.rdoc", "test/test_naver.rb", "Rakefile", "naver.gemspec"]
s.has_rdoc = true
s.homepage = %q{http://oksurerails.com/naver}
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Naver", "--main", "README.rdoc"]
@@ -18,17 +18,18 @@ Gem::Specification.new do |s|
s.rubyforge_project = %q{naver}
s.rubygems_version = %q{1.3.1}
s.summary = %q{Ruby Gem for Naver OpenAPI}
+ s.test_files = ["test/test_naver.rb"]
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 2
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
- s.add_development_dependency(%q, [">= 0"])
+ s.add_development_dependency(%q, [">= 0.9.2"])
else
- s.add_dependency(%q, [">= 0"])
+ s.add_dependency(%q, [">= 0.9.2"])
end
else
- s.add_dependency(%q, [">= 0"])
+ s.add_dependency(%q, [">= 0.9.2"])
end
end
diff --git a/test/test_naver.rb b/test/test_naver.rb
new file mode 100644
index 0000000..6aad015
--- /dev/null
+++ b/test/test_naver.rb
@@ -0,0 +1,105 @@
+# == IMPORTANT!
+# This test consumes about 75 query quota of your API key.
+# == 중요!
+# 이 테스트 파일은 사용자 API Key에 할당된 분량 중, 약 75회 정도의 쿼리 수량을 소모합니다.
+
+$:.unshift File.join(File.dirname(__FILE__),'..','lib')
+
+require 'test/unit'
+require 'naver'
+
+class TestNaver < Test::Unit::TestCase
+
+ # sets up basic setting for unit testing
+ def setup
+ # insert your own Naver API key
+ @n = Naver::Base.new('your_key')
+ end
+
+ # tests if all methods are working fine
+ def test_allmethod
+ # all methods returning RSS format document
+ r = @n.kin("go"); puts r # This shows you the basic usage clear.
+ %w[kin video image doc book book_adv local shop encyc krdic endic jpdic blog cafe cafearticle webkr news].each do |m|
+ instance_eval("assert_kind_of(Naver::RSS, r = @n.#{m}('go'))"); puts r
+ end
+
+ # all methods returning format XML document
+ %w[nexearch cafe blog dic image kin music video webkr site news].each do |q|
+ assert_kind_of(Naver::Result, r = @n.rank(q)); puts r # Select one from "nexearch, cafe, blog, dic, image, kin, music, video, webkr, site, news"
+ end
+ %w[movie schedulemovie runningmovie people singer foreignsinger talent actor foreignactor entertainer broadcaster comedian sportsstar soccer foreignsoccer drama broadcast game perform book university].each do |q|
+ assert_kind_of(Naver::Result, r = @n.ranktheme(q)); puts r # Select one from "movie, schedulemovie, runningmovie, people, singer, foreignsinger, talent, actor, foreignactor, entertainer, broadcaster, comedian, sportsstar, soccer, foreignsoccer, drama, broadcast, game, perform, book, university"
+ end
+ %w[recmd adult errata shortcut].each do |m|
+ instance_eval("assert_kind_of(Naver::Result, r = @n.#{m}('go'))"); puts r
+ end
+ end
+
+ # tests is abbreviations for search options are working fine
+ def test_abbreviation
+ r1 = @n.kin("go", {:display => "5", :start => "6", :sort => "sim"})
+ r2 = @n.kin("go", {:d => "5", :st => "6", :so => "sim"})
+ assert_equal(5, r1.items.length) # for checking display
+ assert_equal(5, r2.items.length) # for checking display
+ assert_equal(r1.items[0].title, r2.items[0].title) # for checking start, sort
+ puts r1.items.length.to_s + " " + r2.items.length.to_s
+ puts r1.items[0].title + " " + r2.items[0].title
+
+ r1 = @n.video("go", {:filter => "high", :payment => "charge"})
+ r2 = @n.video("go", {:f => "high", :p => "charge"})
+ assert_equal(r1.items.length, r2.items.length) # for checking filter, payment
+ puts r1.items.length.to_s + " " + r2.items.length.to_s
+ end
+
+ # tests if all output fields looks fine
+ def test_alloutput
+ @a_kin = %w[title link description]
+ @a_video = %w[thumbnail]
+ @a_image = %w[sizeheight sizewidth]
+ @a_book = %w[image author price discount publisher pubdate isbn]
+ @a_local = %w[telephone address mapx mapy]
+ @a_shop = %w[lprice hprice]
+ @a_blog = %w[bloggername bloggerlink]
+ @a_cafe = %w[ranking member totalarticles newarticles]
+ @a_cafearticle = %w[cafename cafeurl]
+ @a_news = %w[originallink pubDate]
+
+ r, rr = @n.kin("go"), nil
+ %w[lastBuildDate total start display].each do |f|
+ instance_eval("assert_kind_of(String, rr = r.#{f})"); puts rr
+ end
+
+ %w[kin video image book local shop blog cafe cafearticle news].each do |s|
+ instance_eval("r = @n.#{s}('go')")
+ self.instance_variable_get("@a_#{s}").each do |f|
+ instance_eval("assert_kind_of(String, rr = r.items[0].#{f})"); puts rr
+ end
+ end
+
+ r = @n.rank("nexearch")
+ assert_kind_of(String, rr = r.ranks[0].K); puts rr
+ assert_kind_of(String, rr = r.ranks[0].S); puts rr
+ assert_kind_of(String, rr = r.ranks[0].V); puts rr
+
+ r = @n.ranktheme("movie")
+ assert_kind_of(String, rr = r.ranks[0].K); puts rr
+ assert_kind_of(String, rr = r.ranks[0].S); puts rr
+ assert_kind_of(String, rr = r.ranks[0].V); puts rr
+
+ r = @n.recmd("spdlqj")
+ assert_kind_of(String, rr = r.recmds[0]); puts rr
+
+ r = @n.adult("go")
+ assert_kind_of(String, rr = r.adult); puts rr
+
+ r = @n.errata("go")
+ assert_kind_of(String, rr = r.errata); puts rr
+
+ r = @n.shortcut("naver")
+ assert_kind_of(String, rr = r.shortcuts[0].label); puts rr
+ assert_kind_of(String, rr = r.shortcuts[0].url); puts rr
+
+ end
+
+end