archives 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.
@@ -0,0 +1,4 @@
1
+ == 0.0.1, release 2008-12-12
2
+
3
+ * Initial commit and search function implemented
4
+ * 최초 커밋, 검색 기능 구현
@@ -0,0 +1,11 @@
1
+ CHANGELOG.rdoc
2
+ init.rb
3
+ lib/archives/base.rb
4
+ lib/archives/item.rb
5
+ lib/archives/rss.rb
6
+ lib/archives.rb
7
+ rakefile
8
+ README.rdoc
9
+ test/test_archives.rb
10
+ Rakefile
11
+ Manifest
@@ -0,0 +1,62 @@
1
+ = Archives 0.0.1
2
+
3
+ Ruby gem for using Korea Government Archives Search OpenAPI (http://search.archives.go.kr/ArchivesHelp06.htm).
4
+ 대한민국 국가기록원 나라기록검색 OpenAPI를 위한 루비젬입니다.
5
+
6
+
7
+ == Install / 설치법
8
+
9
+ You can install the gem from rubyforge directly.
10
+ 루비포지에서 바로 설치하실 수 있습니다.
11
+ gem install archives
12
+
13
+
14
+ == Usage / 사용법
15
+
16
+ Before using this gem, you need to get your own API key. To obtain your API key, see http://search.archives.go.kr/ArchivesHelp06.htm.
17
+ 이 젬을 사용하기 전에 API 키를 발급 받으셔야 합니다. API 키 발급을 위해서는 http://search.archives.go.kr/ArchivesHelp06.htm 링크를 참고해 주세요.
18
+
19
+ require 'archives'
20
+ archives = Archives::Base.new(api_key) ### create a Archives client / Archives 클라이언트를 생성합니다
21
+ archives.request("한국전쟁") ### search without any options / 아무 조건 없이 쿼리만으로 검색할 수 있습니다
22
+ archives.request("한국전쟁", {:rc_type => "rfile", :prod_year_start => "2005"}) ### return RSS object defined in this gem / 자체 정의된 RSS 클래스 오브젝트를 반환합니다
23
+ archives.request("한국전쟁", {:rt => "rfile", :pys => "2005"}) ### you can use abbreviation
24
+ archives.request("한국전쟁").title ### return title of RSS object
25
+ archives.request("한국전쟁").items.each do |i| ### iteration over items
26
+ i.title ### title of each item
27
+ end
28
+
29
+ You may want to take a look at the test file (test/test_archives.rb) to better understand the usage.
30
+ 보다 자세한 사용법을 이해하시길 원하시면 테스트 파일 (test/test_archives.rb)을 참고하시면 됩니다.
31
+
32
+
33
+ == Search Option Abbreviation List / 검색 옵션 약어 목록
34
+
35
+ The full list of abbreviation codes is the following. (You can still use full name of each parameter.)
36
+ 약어 전체 목록을 아래에 정리하였습니다. (약어를 쓰지 않으셔도 작동합니다.)
37
+
38
+ rt = rc_type
39
+ pys = prod_year_start
40
+ pye = prod_year_end
41
+ pc = prod_code
42
+ pdc = prod_dir_code
43
+ io = is_open
44
+ or = online_reading
45
+ ret = record_type
46
+ dt = doc_type
47
+ mo = mgt_organ
48
+ s = sort
49
+ o = order
50
+ d = display
51
+ p = pageno
52
+ qp = query_phrase
53
+ qo = query_or
54
+ qe = query_exclude
55
+ qt = query_type
56
+ qf = query_field
57
+
58
+
59
+ == License
60
+
61
+ Copyright:: Copyright (c) 2008 Hyunwoo Park <hwpark@oksurerails.com>
62
+ License:: MIT <http://www.opensource.org/licenses/mit-license.php>
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('archives', '0.0.1') do |p|
6
+ p.description = "Ruby Gem for Korea Government Archives Search OpenAPI"
7
+ p.url = "http://oksurerails.com/ruby/archives"
8
+ p.author = "Hyunwoo Park"
9
+ p.email = "hwpark@oksurerails.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = ["libxml-ruby >=0.9.2"]
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
15
+
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{archives}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Hyunwoo Park"]
9
+ s.date = %q{2008-12-11}
10
+ s.description = %q{Ruby Gem for Korea Government Archives Search OpenAPI}
11
+ s.email = %q{hwpark@oksurerails.com}
12
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/archives/base.rb", "lib/archives/item.rb", "lib/archives/rss.rb", "lib/archives.rb", "README.rdoc"]
13
+ s.files = ["CHANGELOG.rdoc", "init.rb", "lib/archives/base.rb", "lib/archives/item.rb", "lib/archives/rss.rb", "lib/archives.rb", "rakefile", "README.rdoc", "test/test_archives.rb", "Rakefile", "Manifest", "archives.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://oksurerails.com/ruby/archives}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Archives", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{archives}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Ruby Gem for Korea Government Archives Search OpenAPI}
21
+ s.test_files = ["test/test_archives.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 2
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_development_dependency(%q<libxml-ruby>, [">= 0.9.2"])
29
+ else
30
+ s.add_dependency(%q<libxml-ruby>, [">= 0.9.2"])
31
+ end
32
+ else
33
+ s.add_dependency(%q<libxml-ruby>, [">= 0.9.2"])
34
+ end
35
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "archives"
@@ -0,0 +1,35 @@
1
+ # = Archives
2
+ # An easy interface to the Korea Government Archives Search OpenAPI (http://dev.naver.com/openapi/tutorial). 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 'archives'
10
+ # archives = Archives::Base.new('api_key') ### create a archives client
11
+ # archives.request("한국전쟁") ### search without any options
12
+ # archives.request("한국전쟁", {:rc_type => "rfile", :prod_year_start => "2005"}) ### return RSS object defined in this gem
13
+ # archives.request("한국전쟁", {:rt => "rfile", :pys => "2005"}) ### you can use abbreviation
14
+ # archives.request("한국전쟁").title ### return title of RSS object
15
+ # archives.request("한국전쟁").items.each do |i| ### iteration over items
16
+ # i.title ### title of each item
17
+ # end
18
+
19
+ %w[cgi net/http libxml].each {|lib| require lib}
20
+
21
+ $:.unshift(File.join(File.dirname(__FILE__)))
22
+
23
+ require "archives/base"
24
+ require "archives/rss"
25
+ require "archives/item"
26
+
27
+ module Archives
28
+ include LibXML
29
+
30
+ # Abbreviation for passing options
31
+ ABBREVIATION = {:rt => :rc_type, :pys => :prod_year_start, :pye => :prod_year_end, :pc => :prod_code, :pdc => :prod_dir_code,
32
+ :io => :is_open, :or => :online_reading, :ret => :record_type, :dt => :doc_type, :mo => :mgt_organ,
33
+ :s => :sort, :o => :order, :d => :display, :p => :pageno, :qp => :query_phrase, :qo => :query_or,
34
+ :qe => :query_exclude, :qt => :query_type, :qf => :query_field}
35
+ end
@@ -0,0 +1,41 @@
1
+ module Archives
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://dev.naver.com/openapi/register)
10
+ def initialize(key=nil)
11
+ @key = key
12
+ @host = 'http://search.archives.go.kr/openapi'
13
+ @api = '/search.arc'
14
+ end
15
+
16
+ # Takes a Archives API method name and set of parameters; returns an RSS object with the response
17
+ def request(query, params={})
18
+ response = http_get(request_url(query, params))
19
+ parser, parser.string = LibXML::XML::Parser.new, response
20
+ @raw_xml = parser.parse
21
+ @doc_root = @raw_xml.root
22
+ RSS.new(@doc_root)
23
+ end
24
+
25
+ # Takes a Archives API method name and set of parameters; returns the correct URL for the REST API.
26
+ def request_url(query, params={})
27
+ url = "#{@host}#{@api}?key=#{@key}&query=#{query}"
28
+ params.each do |key, value|
29
+ key = ABBREVIATION[key] unless ABBREVIATION[key].nil?
30
+ url += "&#{key}=" + CGI::escape(value)
31
+ end unless params.nil?
32
+ url
33
+ end
34
+
35
+ # Does an HTTP GET on a given URL and returns the response body
36
+ def http_get(url)
37
+ Net::HTTP.get_response(URI.parse(URI.encode(url))).body.to_s
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,16 @@
1
+ module Archives
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
@@ -0,0 +1,23 @@
1
+ module Archives
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)
11
+ channel = doc_root.find("//rss/channel").first
12
+ %w[title total].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
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('archives', '0.0.1') do |p|
6
+ p.description = "Ruby Gem for Korea Government Archives Search OpenAPI"
7
+ p.url = "http://oksurerails.com/ruby/archives"
8
+ p.author = "Hyunwoo Park"
9
+ p.email = "hwpark@oksurerails.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = ["libxml-ruby >=0.9.2"]
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
15
+
@@ -0,0 +1,66 @@
1
+ # == IMPORTANT!
2
+ # This test consumes about 5 query quota of your API key.
3
+ # == 중요!
4
+ # 이 테스트 파일은 사용자 API Key에 할당된 분량 중, 약 5회 정도의 쿼리 수량을 소모합니다.
5
+
6
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
7
+
8
+ require 'test/unit'
9
+ require 'archives'
10
+
11
+ class TestArchives < Test::Unit::TestCase
12
+
13
+ # sets up basic setting for unit testing
14
+ def setup
15
+ # insert your own Archives API key
16
+ @a = Archives::Base.new('your_key')
17
+ end
18
+
19
+ # test printing basic elements
20
+ def test_basic_element
21
+ a = @a.request("한국전쟁")
22
+ puts a.title
23
+ puts a.total
24
+ end
25
+
26
+ # test passing options
27
+ def test_passing_options
28
+ a = @a.request("한국전쟁", {:rc_type => "rfile", :prod_year_start => "2005"})
29
+ puts a.title
30
+ puts a.total
31
+ end
32
+
33
+ # test passing options in abbreviation
34
+ def test_passing_options_abbreviation
35
+ a = @a.request("한국전쟁", {:rt => "rfile", :pys => "2005"})
36
+ puts a.title
37
+ puts a.total
38
+ end
39
+
40
+ # test iteration over items
41
+ def test_iteration_items
42
+ a = @a.request("한국전쟁")
43
+ a.items.each do |i|
44
+ puts i.title
45
+ end
46
+ end
47
+
48
+ # test all output fields
49
+ def test_all_output_fields
50
+ a = @a.request("한국전쟁")
51
+ i = a.items.first
52
+ puts i.rc_type
53
+ puts i.rc_code
54
+ puts i.rc_rfile_no
55
+ puts i.rc_ritem_no
56
+ puts i.title
57
+ puts i.mgt_org_name
58
+ puts i.prod_name
59
+ puts i.prod_year
60
+ puts i.is_open
61
+ puts i.arcave_type
62
+ puts i.doc_type
63
+ puts i.online_reading
64
+ puts i.link
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: archives
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hyunwoo Park
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-11 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: libxml-ruby
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.2
24
+ version:
25
+ description: Ruby Gem for Korea Government Archives Search OpenAPI
26
+ email: hwpark@oksurerails.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - CHANGELOG.rdoc
33
+ - lib/archives/base.rb
34
+ - lib/archives/item.rb
35
+ - lib/archives/rss.rb
36
+ - lib/archives.rb
37
+ - README.rdoc
38
+ files:
39
+ - CHANGELOG.rdoc
40
+ - init.rb
41
+ - lib/archives/base.rb
42
+ - lib/archives/item.rb
43
+ - lib/archives/rss.rb
44
+ - lib/archives.rb
45
+ - rakefile
46
+ - README.rdoc
47
+ - test/test_archives.rb
48
+ - Rakefile
49
+ - Manifest
50
+ - archives.gemspec
51
+ has_rdoc: true
52
+ homepage: http://oksurerails.com/ruby/archives
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --line-numbers
56
+ - --inline-source
57
+ - --title
58
+ - Archives
59
+ - --main
60
+ - README.rdoc
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "1.2"
74
+ version:
75
+ requirements: []
76
+
77
+ rubyforge_project: archives
78
+ rubygems_version: 1.3.1
79
+ signing_key:
80
+ specification_version: 2
81
+ summary: Ruby Gem for Korea Government Archives Search OpenAPI
82
+ test_files:
83
+ - test/test_archives.rb