mextractr_webapi 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. data/ChangeLog +1 -0
  2. data/lib/mextractr_webapi.rb +54 -13
  3. metadata +10 -9
data/ChangeLog CHANGED
@@ -1,2 +1,3 @@
1
1
  2008-08-27 古川大輔 v0.0.1 release
2
+ 2008-12-09 古川大輔 v0.0.2 非公開バージョン
2
3
 
@@ -16,39 +16,64 @@ require 'uri'
16
16
  require 'net/http'
17
17
  require 'cgi'
18
18
 
19
+ #
20
+ #= Mextractr WEB API(http://api.emetadata.net/)をrubyから使うためのラッパークラス
21
+ #Copyright:: Copyright (C) D.Furukawa 2008. All rights reserved.
22
+ #License:: Ruby ライセンスに準拠
23
+ #
19
24
  class MextractrWebApi
20
25
  Mextractr_webapi_url = 'http://api.emetadata.net/mextractr?text=[[text]]&out=[[out]]&apikey=[[apikey]]'
26
+ @webapi_url = nil
21
27
  @apikey = nil
22
28
  @log = nil
23
29
  @result=nil
24
30
 
25
31
  attr_reader :apikey,:result
26
- #デバッグ用のメソッドたち。new(APIKEY,log)のlog部分にloggerオブジェクトを渡すと出力されます。
27
- def debug_out(text)
28
- if (@log)
29
- @log.debug(text.to_s)
30
- end
31
- end
32
32
 
33
- def debug_obj(obj,msg=nil)
34
- if (@log)
35
- @log.debug(msg.to_s+"\n"+PP.pp(obj,""))
36
- end
33
+ #== 現在利用しているwebAPIのURLを取得
34
+ def api_uri()
35
+ return @webapi_url
37
36
  end
38
37
 
39
- def initialize(myapikey,mylog=nil)
38
+ #== オブジェクトの生成
39
+ #
40
+ #myapikey :: Mextractr Web APIのAPIキーです。http://api.emetadata.net/docから取得したものを設定してください
41
+ #mylog :: loggerを渡すと、Mextractr Web APIとのやりとりの内容が出力されます。デバッグ用です。
42
+ #options :: そのほかのオプションです。
43
+ # - :webapi_url : Mextractr Web APIのURLです。デフォルトと異なるURLに接続したい場合に指定してください。書式は、http://api.emetadata.net/mextractr?text=[[text]]&out=[[out]]&apikey=[[apikey]] という具合です。
44
+ # - :log : loggerを渡すと、Mextractr Web APIとのやりとりの内容が出力されます。デバッグ用です。第二引数のmylogより優先して使用されます。
45
+ # - :myapikey : Mextractr Web APIのAPIキーです。第一引数のmyapikeyより優先して使用されます。
46
+ #
47
+ def initialize(myapikey,mylog=nil,options=nil)
40
48
  @apikey = myapikey
41
49
  @log = mylog
42
50
  if (@log)
43
51
  require 'pp'
44
52
  end
53
+ @webapi_url = Mextractr_webapi_url
54
+ setOptions(options) if (options)
45
55
  end
46
-
56
+
57
+ #== オプションの設定
58
+ #
59
+ # initializeメソッドに渡すoptions引数と同じものを後から設定することが出来ます。通常この関数を直接呼び出す必要はなく、initializeで十分なはずです。
60
+ #
61
+ def setOptions(options)
62
+ @webapi_url = options[:webapi_url] if options[:webapi_url]
63
+ @log = options[:log] if options[:log]
64
+ @apikey = options[:apikey] if options[:apikey]
65
+ end
66
+
67
+ #== 文章解析の実行
68
+ #
69
+ # 引数で渡されたtextをMextractr Web APIに渡して結果を取得します。結果は、この関数の帰り値として取得する事も出来ますし、resultプロパティを参照することも出来ます。
70
+ # いずれにせよ、result["where"],result["when"],といった形で結果が格納されています。
71
+ #
47
72
  def parse(text)
48
73
  text_encoded = CGI.escape( CGI.escapeHTML(text.toutf8) )
49
74
 
50
75
  #Mextractr APIを呼び出す
51
- uri = URI.parse( Mextractr_webapi_url.gsub('[[text]]',text_encoded).gsub('[[out]]','atom').gsub('[[apikey]]',@apikey) )
76
+ uri = URI.parse( @webapi_url.gsub('[[text]]',text_encoded).gsub('[[out]]','atom').gsub('[[apikey]]',@apikey) )
52
77
  debug_out("uri:"+uri.to_s)
53
78
  response = nil
54
79
  Net::HTTP.start(uri.host,uri.port){|http|
@@ -77,6 +102,7 @@ class MextractrWebApi
77
102
  item = {}
78
103
  item['valueString'] = elem.attributes['valueString']
79
104
  item['startTime'] = elem.attributes['startTime']
105
+ item['endTime'] = elem.attributes['endTime']
80
106
  @result['when'] << item
81
107
  }
82
108
  doc.elements.each("feed/entry/gd:where"){|elem|
@@ -102,10 +128,25 @@ class MextractrWebApi
102
128
 
103
129
  return @result
104
130
  end
131
+
132
+ private
133
+ def debug_out(text)
134
+ if (@log)
135
+ @log.debug(text.to_s)
136
+ end
137
+ end
138
+
139
+ def debug_obj(obj,msg=nil)
140
+ if (@log)
141
+ @log.debug(msg.to_s+"\n"+PP.pp(obj,""))
142
+ end
143
+ end
105
144
  end
106
145
 
107
146
  =begin
108
147
  [更新履歴]
109
148
  2008-08-27 D.Furukawa とりあえず作ってみた。帰り値、これでいいかなぁ?
110
149
  2008-09-25 D.Furukawa ファイル名とクラス名をrailsの規約にあわせる
150
+ 2008-12-10 D.Furukawa WebAPIのURLが変わる可能性があるみたいなので、対応できる機能を追加。
151
+ 2008-12-10 D.Furukawa rdocコメントを追加。
111
152
  =end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mextractr_webapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daisuke Furukawa
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-26 00:00:00 +09:00
12
+ date: 2008-12-10 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -19,17 +19,18 @@ executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files: []
23
-
22
+ extra_rdoc_files:
23
+ - README
24
24
  files:
25
25
  - lib/mextractr_webapi.rb
26
26
  - README
27
27
  - ChangeLog
28
- has_rdoc: false
28
+ has_rdoc: true
29
29
  homepage: http://mogya.com
30
30
  post_install_message:
31
- rdoc_options: []
32
-
31
+ rdoc_options:
32
+ - --main
33
+ - README
33
34
  require_paths:
34
35
  - lib
35
36
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -46,10 +47,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
47
  version:
47
48
  requirements: []
48
49
 
49
- rubyforge_project:
50
+ rubyforge_project: mextractr_webapi
50
51
  rubygems_version: 1.0.1
51
52
  signing_key:
52
53
  specification_version: 2
53
- summary: "Mextractr WEB API(http://api.emetadata.net/)\xE3\x82\x92ruby\xE3\x81\x8B\xE3\x82\x89\xE4\xBD\xBF\xE3\x81\x86\xE3\x81\x9F\xE3\x82\x81\xE3\x81\xAE\xE3\x83\xA9\xE3\x83\x83\xE3\x83\x91\xE3\x83\xBC\xE3\x82\xAF\xE3\x83\xA9\xE3\x82\xB9"
54
+ summary: wrapper class for Mextractr WEB API(http://api.emetadata.net/)
54
55
  test_files: []
55
56