Class: Mushikago::Hotaru::Client

Inherits:
Mushikago::Http::Client show all
Defined in:
lib/mushikago/hotaru/client.rb

Overview

Hotaruサービスを利用する

Examples:

client = Mushikago::Hotaru::Client.new(:api_key => '<api_key>', :secret_key => '<secret_key>')

client.capture('http://www.hotaru.ne.jp/', :thumbnail => true, :tags => ['hotaru', 'webservice'])

captures = client.captures
captures['images'].each do |image|
  puts image['image_url']
end

APIキーをファイルから読み込む場合

Mushikago.config.load(YAML.load(File.read('config.yml')))
client = Mushikago::Hotaru::Client.new

Instance Attribute Summary

Attributes inherited from Mushikago::Http::Client

api_key, signer, use_ssl

Instance Method Summary (collapse)

Methods inherited from Mushikago::Http::Client

#initialize, #send_request

Constructor Details

This class inherits a constructor from Mushikago::Http::Client

Instance Method Details

- (Mushikago::Http::Response) classifier_judge(domain_name, text, options = {})

指定されたtextにふさわしいtagを返す

Examples:

client.classifier_judge

Parameters:

  • domain_name (String)

    ドメイン名

  • text (String)

    text

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



166
167
168
169
# File 'lib/mushikago/hotaru/client.rb', line 166

def classifier_judge domain_name, text, options={}
  request = Hotaru::ClassifierJudgeRequest.new(domain_name, text, options)
  send_request(request)
end

- (Mushikago::Http::Response) collocation_create(domain_name, tags, options = {})

共起グラフを作成する

Examples:

client.collocation_create('sample_domain', ['tag1', 'tag2'])
client.collocation_create('sample_domain', 'tag1', :parts_of_speech => Mushikago::Hotaru::CollocationCreateRequest::POS_LARGE)

Parameters:

  • domain_name (String)

    ドメイン名

  • tags (String, Array)

    タグ

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :parts_of_speech (String, Array)

    共起を取る単語の品詞

  • :collocation_name (String)

    共起グラフにつける名前

  • :lower_threshold (String)

    単語の出現数下限

  • :upper_threshold (String)

    単語の出現数上限

  • :description (String)

    共起グラフの説明

Returns:



185
186
187
188
# File 'lib/mushikago/hotaru/client.rb', line 185

def collocation_create domain_name, tags, options={}
  request = Hotaru::CollocationCreateRequest.new(domain_name, tags, options)
  send_request(request)
end

- (Mushikago::Http::Response) collocation_delete(domain_name, collocation_id, options = {})

共起グラフを削除する

Examples:

client.collocation_delete('sample_domain', 'c12345')

Parameters:

  • domain_name (String)

    ドメイン名

  • collocation_id (String)

    共起ID

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



214
215
216
217
# File 'lib/mushikago/hotaru/client.rb', line 214

def collocation_delete domain_name, collocation_id, options={}
  request = Hotaru::CollocationDeleteRequest.new(domain_name, collocation_id, options)
  send_request(request)
end

- (Mushikago::Http::Response) collocation_download(domain_name, collocation_id, options = {})

共起グラフをダウンロードする

Examples:

client.collocation_download('sample_domain', 'c12345')

Parameters:

  • domain_name (String)

    ドメイン名

  • collocation_id (String)

    共起ID

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :with_body (Boolean)

    trueを指定すると、response[‘body’]でファイルの内容にアクセスすることができるようになります。

Returns:



258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/mushikago/hotaru/client.rb', line 258

def collocation_download domain_name, collocation_id, options={}
  request = Hotaru::CollocationDownloadRequest.new(domain_name, collocation_id, options)
  result = send_request(request)
  if options[:with_body]
    begin
      uri = URI.parse(result['url'])
      result['body'] = Net::HTTP.get(uri.host, uri.request_uri)
    rescue
    end
  end
  return result
end

- (Mushikago::Http::Response) collocation_get(domain_name, collocation_id, word, options = {})

共起語を取得する

Examples:

client.collocation_get('sample_domain', 'c12345', '我輩')

Parameters:

  • domain_name (String)

    ドメイン名

  • collocation_id (String)

    共起ID

  • word (String)

    共起語を取得したい単語

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



228
229
230
231
# File 'lib/mushikago/hotaru/client.rb', line 228

def collocation_get domain_name, collocation_id, word, options={}
  request = Hotaru::CollocationGetRequest.new(domain_name, collocation_id, word, options)
  send_request(request)
end

- (Mushikago::Http::Response) collocation_list(domain_name, options = {})

共起グラフ一覧を取得する

Examples:

client.collocation_list('sample_domain')

Parameters:

  • domain_name (String)

    ドメイン名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :limit (Integer)
  • :offset (Integer)
  • :filter (String)
  • :status (String)

Returns:



201
202
203
204
# File 'lib/mushikago/hotaru/client.rb', line 201

def collocation_list domain_name, options={}
  request = Hotaru::CollocationListRequest.new(domain_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) collocation_wordlist(domain_name, collocation_id, options = {})

共起グラフ内の単語一覧を取得する

Examples:

client.collocation_wordlist('sample_domain', 'c12345')

Parameters:

  • domain_name (String)

    ドメイン名

  • collocation_id (String)

    共起ID

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :limit (Integer)
  • :offset (Integer)
  • :filter (String)

Returns:



244
245
246
247
# File 'lib/mushikago/hotaru/client.rb', line 244

def collocation_wordlist domain_name, collocation_id, options={}
  request = Hotaru::CollocationWordlistRequest.new(domain_name, collocation_id, options)
  send_request(request)
end

- (Mushikago::Http::Response) dictionary_delete(dictionary_id, options = {})

辞書を削除する

Examples:

client.dictionary_delete('dicid')

Parameters:

  • dictionary_id (String)

    辞書ID

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



368
369
370
371
# File 'lib/mushikago/hotaru/client.rb', line 368

def dictionary_delete dictionary_id, options={}
  request = Hotaru::DictionaryDeleteRequest.new(dictionary_id, options)
  send_request(request)
end

- (Mushikago::Http::Response) dictionary_list(options = {})

辞書の一覧を取得する

Examples:

client.dictionary_list

Parameters:

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



356
357
358
359
# File 'lib/mushikago/hotaru/client.rb', line 356

def dictionary_list options={}
  request = Hotaru::DictionaryListRequest.new(options)
  send_request(request)
end

- (Mushikago::Http::Response) dictionary_put(dictionary_file, options = {})

辞書を登録する

Examples:

client.dictionary_put 'custom.csv', :dictionary_name => 'mushikago用語'

Parameters:

  • dictionary_file (String, File)

    辞書ファイル

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



345
346
347
348
# File 'lib/mushikago/hotaru/client.rb', line 345

def dictionary_put dictionary_file, options={}
  request = Hotaru::DictionaryPutRequest.new(dictionary_file, options)
  send_request(request)
end

- (Mushikago::Http::Response) domain_create(domain_name, splitter, options = {})

ドメインを作成する

Examples:

client.domain_create('sample_domain', '2gram')

Parameters:

  • domain_name (String)

    ドメイン名

  • splitter (String)

    スプリッター

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :description (String)

    ドメインの説明

  • :dictionary_ids (String, Array)

    ユーザ辞書のID

  • :tags (String, Array)

    ドメイン内で使用するタグ

Returns:



31
32
33
34
# File 'lib/mushikago/hotaru/client.rb', line 31

def domain_create domain_name, splitter, options={}
  request = Hotaru::DomainCreateRequest.new(domain_name, splitter, options)
  send_request(request)
end

- (Mushikago::Http::Response) domain_delete(domain_name, options = {})

ドメインを削除する

Examples:

client.domain_delete 'sample_domain'

Parameters:

  • domain_name (String)

    ドメイン名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



70
71
72
73
# File 'lib/mushikago/hotaru/client.rb', line 70

def domain_delete domain_name, options={}
  request = Hotaru::DomainDeleteRequest.new(domain_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) domain_info(domain_name, options = {})

ドメインの情報を参照する

Examples:

client.domain_info('sample_domain')

Parameters:

  • domain_name (String)

    ドメイン名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :time (Integer)

Returns:



44
45
46
47
# File 'lib/mushikago/hotaru/client.rb', line 44

def domain_info domain_name, options={}
  request = Hotaru::DomainInfoRequest.new(domain_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) domain_list(options = {})

ドメインの一覧を取得する

Examples:

client.domain_list

Parameters:

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :limit (Integer)
  • :offset (Integer)
  • :filter (String)

Returns:



58
59
60
61
# File 'lib/mushikago/hotaru/client.rb', line 58

def domain_list options={}
  request = Hotaru::DomainListRequest.new(options)
  send_request(request)
end

- (Mushikago::Http::Response) tag_delete(domain_name, tag, options = {})

ドメインに登録されているタグを削除する

Examples:

client.tag_delete('sample_domain', 'tag1')

Parameters:

  • domain_name (String)

    ドメイン名

  • tag (String)

    タグ

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



292
293
294
295
# File 'lib/mushikago/hotaru/client.rb', line 292

def tag_delete domain_name, tag, options={}
  request = Hotaru::TagDeleteRequest.new(domain_name, tag, options)
  send_request(request)
end

- (Mushikago::Http::Response) tag_list(domain_name, options = {})

ドメイン内のタグ一覧を取得する

Examples:

client.tag_list('sample_domain')

Parameters:

  • domain_name (String)

    ドメイン名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :filter (String)

Returns:



305
306
307
308
# File 'lib/mushikago/hotaru/client.rb', line 305

def tag_list domain_name, options={}
  request = Hotaru::TagListRequest.new(domain_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) tag_put(domain_name, tag, options = {})

ドメインにタグを登録する

Examples:

client.tag_put('sample_domain', 'tag1')

Parameters:

  • domain_name (String)

    ドメイン名

  • tag (String)

    タグ

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



279
280
281
282
# File 'lib/mushikago/hotaru/client.rb', line 279

def tag_put domain_name, tag, options={}
  request = Hotaru::TagPutRequest.new(domain_name, tag, options)
  send_request(request)
end

- (Mushikago::Http::Response) text_delete(domain_name, text_id, options = {})

テキストを削除する

Examples:

client.text_delete 'sample_domain', 'text_id'

Parameters:

  • domain_name (String)

    ドメイン名

  • text_id (String)

    テキストID

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :forcedelete (String)

    textを強制的に削除する場合true

Returns:



99
100
101
102
# File 'lib/mushikago/hotaru/client.rb', line 99

def text_delete domain_name, text_id, options={}
  request = Hotaru::TextDeleteRequest.new(domain_name, text_id, options)
  send_request(request)
end

- (Mushikago::Http::Response) text_get(domain_name, text_id, options = {})

テキストを取得する

Examples:

client.text_get 'sample_domain', 'text_id'

Parameters:

  • domain_name (String)

    ドメイン名

  • text_id (String)

    テキストID

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :with_body (Boolean)

    trueを指定すると、response[‘body’]でファイルの内容にアクセスすることができるようになります。

Returns:



128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/mushikago/hotaru/client.rb', line 128

def text_get domain_name, text_id, options={}
  request = Hotaru::TextGetRequest.new(domain_name, text_id, options)
  result = send_request(request)
  if options[:with_body]
    begin
      uri = URI.parse(result['url'])
      result['body'] = Net::HTTP.get(uri.host, uri.request_uri)
    rescue
    end
  end
  return result
end

- (Mushikago::Http::Response) text_list(domain_name, options = {})

テキスト一覧を取得する

Examples:

client.text_list('sample_domain')

Parameters:

  • domain_name (String)

    ドメイン名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :limit (Integer)
  • :offset (Integer)
  • :filter (String)
  • :tags (String, Array)
  • :status (String)

Returns:



153
154
155
156
# File 'lib/mushikago/hotaru/client.rb', line 153

def text_list domain_name, options={}
  request = Hotaru::TextListRequest.new(domain_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) text_put(domain_name, text, tags, options = {})

テキストを登録する

Examples:

client.text_put 'sample_domain', '吾輩は猫である。名前はまだない。....', ['夏目漱石'], :text_name => '吾輩は猫である'

Parameters:

  • domain_name (String)

    ドメイン名

  • text (String)

    テキスト

  • tags (String)

    タグ

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :text_name (String)

    テキストにつける名前

Returns:



85
86
87
88
# File 'lib/mushikago/hotaru/client.rb', line 85

def text_put domain_name, text, tags, options={}
  request = Hotaru::TextPutRequest.new(domain_name, text, tags, options)
  send_request(request)
end

- (Mushikago::Http::Response) text_tagset(domain_name, text_id, tags, options = {})

テキストにヒモ付たタグの追加更新

Examples:

client.text_tagset 'sample_domain', 'text_id', ['hoge']

Parameters:

  • domain_name (String)

    ドメイン名

  • text_id (String)

    テキストID

  • tags (String, Array)

    タグ

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :replace (String)

    tagを追加する場合false, 入れ替える場合true

Returns:



114
115
116
117
# File 'lib/mushikago/hotaru/client.rb', line 114

def text_tagset domain_name, text_id, tags, options={}
  request = Hotaru::TextTagsetRequest.new(domain_name, text_id, tags, options)
  send_request(request)
end

- (Mushikago::Http::Response) word_get(domain_name, word, options = {})

指定した単語の詳細な情報を返す

Examples:

client.word_get('sample_domain', '我輩')

Parameters:

  • domain_name (String)

    ドメイン名

  • word (String)
  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



333
334
335
336
# File 'lib/mushikago/hotaru/client.rb', line 333

def word_get domain_name, word, options={}
  request = Hotaru::WordGetRequest.new(domain_name, word, options)
  send_request(request)
end

- (Mushikago::Http::Response) word_list(domain_name, options = {})

単語の一覧を取得する

Examples:

client.word_list 'sample_domain'

Parameters:

  • options (Hash) (defaults to: {})

    リクエストのオプション

  • domain_name (String)

    ドメイン名

Options Hash (options):

  • :limit (Integer)
  • :offset (Integer)
  • :filter (String)

Returns:



320
321
322
323
# File 'lib/mushikago/hotaru/client.rb', line 320

def word_list domain_name, options={}
  request = Hotaru::WordListRequest.new(domain_name, options)
  send_request(request)
end