mushikago-sdk 0.4.3 → 2.0.0

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 (134) hide show
  1. data/README.md +3 -1
  2. data/Rakefile +1 -0
  3. data/lib/mushikago/hanamgri/client.rb +264 -0
  4. data/lib/mushikago/hanamgri/create_domain_request.rb +25 -0
  5. data/lib/mushikago/hanamgri/delete_dictionary_request.rb +14 -0
  6. data/lib/mushikago/hanamgri/delete_domain_request.rb +16 -0
  7. data/lib/mushikago/hanamgri/delete_knowledge_request.rb +15 -0
  8. data/lib/mushikago/hanamgri/field.rb +20 -0
  9. data/lib/mushikago/hanamgri/get_analysis_request.rb +16 -0
  10. data/lib/mushikago/hanamgri/get_information_request.rb +14 -0
  11. data/lib/mushikago/hanamgri/get_queue_size_request.rb +14 -0
  12. data/lib/mushikago/hanamgri/list_analyses_request.rb +24 -0
  13. data/lib/mushikago/hanamgri/list_dictionaries_request.rb +17 -0
  14. data/lib/mushikago/hanamgri/list_domains_request.rb +20 -0
  15. data/lib/mushikago/hanamgri/list_knowledges_request.rb +20 -0
  16. data/lib/mushikago/hanamgri/request_analysis_request.rb +21 -0
  17. data/lib/mushikago/hanamgri/save_dictionary_request.rb +18 -0
  18. data/lib/mushikago/hanamgri/save_knowledge_request.rb +19 -0
  19. data/lib/mushikago/hanamgri/schema.rb +28 -0
  20. data/lib/mushikago/hanamgri/search_schema_request.rb +19 -0
  21. data/lib/mushikago/hanamgri/train_request.rb +21 -0
  22. data/lib/mushikago/hanamgri/training_data.rb +27 -0
  23. data/lib/mushikago/hanamgri/update_domain_request.rb +18 -0
  24. data/lib/mushikago/hanamgri.rb +30 -0
  25. data/lib/mushikago/version.rb +1 -1
  26. data/lib/mushikago.rb +1 -0
  27. data/spec/mushikago/hanamgri/client_spec.rb +61 -0
  28. data/spec/mushikago/hanamgri/create_domain_spec.rb +34 -0
  29. data/spec/mushikago/hanamgri/delete_dictionary_spec.rb +11 -0
  30. data/spec/mushikago/hanamgri/delete_domain_spec.rb +12 -0
  31. data/spec/mushikago/hanamgri/delete_knowledge_request_spec.rb +11 -0
  32. data/spec/mushikago/hanamgri/field_spec.rb +44 -0
  33. data/spec/mushikago/hanamgri/get_analysis_request_spec.rb +12 -0
  34. data/spec/mushikago/hanamgri/get_information_request_spec.rb +14 -0
  35. data/spec/mushikago/hanamgri/get_queue_size_request_spec.rb +10 -0
  36. data/spec/mushikago/hanamgri/list_analyses_spec.rb +25 -0
  37. data/spec/mushikago/hanamgri/list_dictionaries_spec.rb +19 -0
  38. data/spec/mushikago/hanamgri/list_domains_spec.rb +19 -0
  39. data/spec/mushikago/hanamgri/list_knowledges_request_spec.rb +20 -0
  40. data/spec/mushikago/hanamgri/request_analysis_request_spec.rb +21 -0
  41. data/spec/mushikago/hanamgri/save_dictionary_request_spec.rb +22 -0
  42. data/spec/mushikago/hanamgri/save_knowledge_request_spec.rb +22 -0
  43. data/spec/mushikago/hanamgri/schema_spec.rb +53 -0
  44. data/spec/mushikago/hanamgri/search_schema_request_spec.rb +22 -0
  45. data/spec/mushikago/hanamgri/train_spec.rb +31 -0
  46. data/spec/mushikago/hanamgri/update_domain_spec.rb +22 -0
  47. metadata +95 -109
  48. data/doc/Mushikago/Auth/Signature.html +0 -312
  49. data/doc/Mushikago/Auth/Signer.html +0 -465
  50. data/doc/Mushikago/Auth.html +0 -122
  51. data/doc/Mushikago/Config.html +0 -285
  52. data/doc/Mushikago/Hotaru/ClassifierJudgeRequest.html +0 -307
  53. data/doc/Mushikago/Hotaru/Client.html +0 -4174
  54. data/doc/Mushikago/Hotaru/CollocationCreateRequest.html +0 -375
  55. data/doc/Mushikago/Hotaru/CollocationDeleteRequest.html +0 -307
  56. data/doc/Mushikago/Hotaru/CollocationDownloadRequest.html +0 -307
  57. data/doc/Mushikago/Hotaru/CollocationGetRequest.html +0 -309
  58. data/doc/Mushikago/Hotaru/CollocationListRequest.html +0 -313
  59. data/doc/Mushikago/Hotaru/CollocationWordlistRequest.html +0 -313
  60. data/doc/Mushikago/Hotaru/DictionaryDeleteRequest.html +0 -305
  61. data/doc/Mushikago/Hotaru/DictionaryListRequest.html +0 -309
  62. data/doc/Mushikago/Hotaru/DictionaryPutRequest.html +0 -342
  63. data/doc/Mushikago/Hotaru/DomainCreateRequest.html +0 -313
  64. data/doc/Mushikago/Hotaru/DomainDeleteRequest.html +0 -305
  65. data/doc/Mushikago/Hotaru/DomainInfoRequest.html +0 -307
  66. data/doc/Mushikago/Hotaru/DomainListRequest.html +0 -311
  67. data/doc/Mushikago/Hotaru/TagDeleteRequest.html +0 -307
  68. data/doc/Mushikago/Hotaru/TagListRequest.html +0 -307
  69. data/doc/Mushikago/Hotaru/TagPutRequest.html +0 -307
  70. data/doc/Mushikago/Hotaru/TextDeleteRequest.html +0 -309
  71. data/doc/Mushikago/Hotaru/TextGetRequest.html +0 -307
  72. data/doc/Mushikago/Hotaru/TextListRequest.html +0 -315
  73. data/doc/Mushikago/Hotaru/TextPutRequest.html +0 -311
  74. data/doc/Mushikago/Hotaru/TextTagsetRequest.html +0 -311
  75. data/doc/Mushikago/Hotaru/WordGetRequest.html +0 -307
  76. data/doc/Mushikago/Hotaru/WordListRequest.html +0 -311
  77. data/doc/Mushikago/Hotaru.html +0 -120
  78. data/doc/Mushikago/Http/Client.html +0 -673
  79. data/doc/Mushikago/Http/DeleteRequest.html +0 -240
  80. data/doc/Mushikago/Http/GetRequest.html +0 -240
  81. data/doc/Mushikago/Http/MultipartPostRequest.html +0 -265
  82. data/doc/Mushikago/Http/MultipartPutRequest.html +0 -265
  83. data/doc/Mushikago/Http/MultipartRequest.html +0 -362
  84. data/doc/Mushikago/Http/PostRequest.html +0 -240
  85. data/doc/Mushikago/Http/PutRequest.html +0 -240
  86. data/doc/Mushikago/Http/Request.html +0 -1223
  87. data/doc/Mushikago/Http/Response.html +0 -840
  88. data/doc/Mushikago/Http.html +0 -120
  89. data/doc/Mushikago/Mitsubachi/Client.html +0 -3232
  90. data/doc/Mushikago/Mitsubachi/HttpFetchRequest.html +0 -319
  91. data/doc/Mushikago/Mitsubachi/HttpPushRequest.html +0 -321
  92. data/doc/Mushikago/Mitsubachi/Project.html +0 -742
  93. data/doc/Mushikago/Mitsubachi/ProjectCreateRequest.html +0 -317
  94. data/doc/Mushikago/Mitsubachi/ProjectDeleteRequest.html +0 -307
  95. data/doc/Mushikago/Mitsubachi/ProjectDiscontinueRequest.html +0 -305
  96. data/doc/Mushikago/Mitsubachi/ProjectInfoRequest.html +0 -307
  97. data/doc/Mushikago/Mitsubachi/ProjectListRequest.html +0 -309
  98. data/doc/Mushikago/Mitsubachi/ProjectQueuesRequest.html +0 -305
  99. data/doc/Mushikago/Mitsubachi/ProjectUpdateRequest.html +0 -315
  100. data/doc/Mushikago/Mitsubachi/Projects.html +0 -474
  101. data/doc/Mushikago/Mitsubachi/Resource.html +0 -569
  102. data/doc/Mushikago/Mitsubachi/ResourceDeleteRequest.html +0 -307
  103. data/doc/Mushikago/Mitsubachi/ResourceGetRequest.html +0 -307
  104. data/doc/Mushikago/Mitsubachi/ResourceListRequest.html +0 -311
  105. data/doc/Mushikago/Mitsubachi/ResourceStoreRequest.html +0 -346
  106. data/doc/Mushikago/Mitsubachi/Resources.html +0 -546
  107. data/doc/Mushikago/Mitsubachi/Script.html +0 -569
  108. data/doc/Mushikago/Mitsubachi/ScriptDeleteRequest.html +0 -307
  109. data/doc/Mushikago/Mitsubachi/ScriptDeployRequest.html +0 -342
  110. data/doc/Mushikago/Mitsubachi/ScriptGetRequest.html +0 -307
  111. data/doc/Mushikago/Mitsubachi/ScriptListRequest.html +0 -311
  112. data/doc/Mushikago/Mitsubachi/Scripts.html +0 -546
  113. data/doc/Mushikago/Mitsubachi.html +0 -120
  114. data/doc/Mushikago/Tombo/CaptureRequest.html +0 -454
  115. data/doc/Mushikago/Tombo/CapturesRequest.html +0 -417
  116. data/doc/Mushikago/Tombo/Client.html +0 -830
  117. data/doc/Mushikago/Tombo/DeleteRequest.html +0 -357
  118. data/doc/Mushikago/Tombo/InfoRequest.html +0 -338
  119. data/doc/Mushikago/Tombo.html +0 -120
  120. data/doc/Mushikago.html +0 -246
  121. data/doc/_index.html +0 -701
  122. data/doc/class_list.html +0 -47
  123. data/doc/css/common.css +0 -1
  124. data/doc/css/full_list.css +0 -55
  125. data/doc/css/style.css +0 -322
  126. data/doc/file.README.html +0 -250
  127. data/doc/file_list.html +0 -49
  128. data/doc/frames.html +0 -13
  129. data/doc/index.html +0 -250
  130. data/doc/js/app.js +0 -205
  131. data/doc/js/full_list.js +0 -167
  132. data/doc/js/jquery.js +0 -16
  133. data/doc/method_list.html +0 -1806
  134. data/doc/top-level-namespace.html +0 -103
@@ -0,0 +1,27 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'json'
3
+ module Mushikago
4
+ module Hanamgri
5
+ class TrainingData
6
+ attr_reader :training_data
7
+
8
+ def initialize(&block)
9
+ @training_data = {}
10
+ instance_eval(&block) if block_given?
11
+ end
12
+
13
+ def []= key, value
14
+ @training_data[key] = value
15
+ end
16
+
17
+ def put key, value
18
+ @training_data[key] = value
19
+ end
20
+
21
+ def to_json *args
22
+ @training_data.to_json(args)
23
+ end
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,18 @@
1
+ # -*- coding : utf-8 -*-
2
+ module Mushikago
3
+ module Hanamgri
4
+ class UpdateDomainRequest < Mushikago::Http::PostRequest
5
+ def path; "/1/hanamgri/domains/#{domain_name}" end
6
+ attr_accessor :domain_name
7
+ request_parameter :description
8
+
9
+ def initialize domain_name, description, options={}
10
+ super(options)
11
+ self.domain_name = domain_name
12
+ self.description = description
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+
@@ -0,0 +1,30 @@
1
+ # -*- coding : utf-8 -*-
2
+ module Mushikago
3
+ module Hanamgri
4
+ autoload :Client, 'mushikago/hanamgri/client'
5
+
6
+ autoload :CreateDomainRequest, 'mushikago/hanamgri/create_domain_request'
7
+ autoload :DeleteDomainRequest, 'mushikago/hanamgri/delete_domain_request'
8
+ autoload :RequestAnalysisRequest, 'mushikago/hanamgri/request_analysis_request'
9
+ autoload :GetAnalysisRequest, 'mushikago/hanamgri/get_analysis_request'
10
+ autoload :GetQueueSizeRequest, 'mushikago/hanamgri/get_queue_size_request'
11
+ autoload :GetInformationRequest, 'mushikago/hanamgri/get_information_request'
12
+ autoload :GetListDomainsRequest, 'mushikago/hanamgri/list_domains_request'
13
+ autoload :UpdateDomainRequest, 'mushikago/hanamgri/update_domain_request'
14
+ autoload :GetListAnalysesRequest, 'mushikago/hanamgri/list_analyses_request'
15
+ autoload :SearchSchemaRequest, 'mushikago/hanamgri/search_schema_request'
16
+ autoload :TrainRequest, 'mushikago/hanamgri/train_request'
17
+ autoload :SaveDictionaryRequest, 'mushikago/hanamgri/save_dictionary_request'
18
+ autoload :ListDictionariesRequest, 'mushikago/hanamgri/list_dictionaries_request'
19
+ autoload :DeleteDictionaryRequest, 'mushikago/hanamgri/delete_dictionary_request'
20
+ autoload :SaveKnowledgeRequest, 'mushikago/hanamgri/save_knowledge_request'
21
+ autoload :ListKnowledgesRequest, 'mushikago/hanamgri/list_knowledges_request'
22
+ autoload :DeleteKnowledgeRequest, 'mushikago/hanamgri/delete_knowledge_request'
23
+
24
+ autoload :Schema, 'mushikago/hanamgri/schema'
25
+ autoload :Field, 'mushikago/hanamgri/field'
26
+
27
+ autoload :TrainingData, 'mushikago/hanamgri/training_data'
28
+ end
29
+ end
30
+
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module Mushikago
3
3
  # Mushikago SDK for Ruby のバージョン
4
- VERSION = '0.4.3'
4
+ VERSION = '2.0.0'
5
5
  end
data/lib/mushikago.rb CHANGED
@@ -10,6 +10,7 @@ module Mushikago
10
10
  autoload :Tombo, 'mushikago/tombo'
11
11
  autoload :Hotaru, 'mushikago/hotaru'
12
12
  autoload :Mitsubachi, 'mushikago/mitsubachi'
13
+ autoload :Hanamgri, 'mushikago/hanamgri'
13
14
 
14
15
  # @return [Mushikago::Config] config コンフィグのインスタンスへのアクセスを提供する
15
16
  def self.config
@@ -0,0 +1,61 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::Client do
5
+ subject{ Mushikago::Hanamgri::Client.new }
6
+ it{ should be_respond_to(:create_domain) }
7
+ it{ should be_respond_to(:delete_domain) }
8
+ it{ should be_respond_to(:request_analysis) }
9
+ it{ should be_respond_to(:get_analysis) }
10
+ it{ should be_respond_to(:get_queue_size) }
11
+ it{ should be_respond_to(:get_information) }
12
+ it{ should be_respond_to(:list_domains) }
13
+ it{ should be_respond_to(:update_domain) }
14
+ it{ should be_respond_to(:list_analyses) }
15
+ it{ should be_respond_to(:search_schema) }
16
+ it{ should be_respond_to(:train) }
17
+ it{ should be_respond_to(:save_dictionary) }
18
+ it{ should be_respond_to(:list_dictionaries) }
19
+ it{ should be_respond_to(:delete_dictionary) }
20
+ it{ should be_respond_to(:save_knowledge) }
21
+ it{ should be_respond_to(:list_knowledges) }
22
+ it{ should be_respond_to(:delete_knowledge) }
23
+
24
+ [
25
+ [:create_domain, Mushikago::Hanamgri::CreateDomainRequest, ['domain_name', 'seeds', Mushikago::Hanamgri::Schema.new, {}]],
26
+ [:delete_domain, Mushikago::Hanamgri::DeleteDomainRequest, ['domain_name', {}]],
27
+ [:request_analysis, Mushikago::Hanamgri::RequestAnalysisRequest, ['domain_name', 'url', {}]],
28
+ [:get_analysis, Mushikago::Hanamgri::GetAnalysisRequest, ['domain_name', 'request_id', {}]],
29
+ [:get_queue_size, Mushikago::Hanamgri::GetQueueSizeRequest, ['domain_name', {}]],
30
+ [:get_information, Mushikago::Hanamgri::GetInformationRequest, ['domain_name', {}]],
31
+ [:list_domains, Mushikago::Hanamgri::GetListDomainsRequest, [{}]],
32
+ [:update_domain, Mushikago::Hanamgri::UpdateDomainRequest, ['domain_name', 'description', {}]],
33
+ [:list_analyses, Mushikago::Hanamgri::GetListAnalysesRequest, ['domain_name', {:limit => 20, :offset => 5, :status => 'complete'}]],
34
+ [:search_schema, Mushikago::Hanamgri::SearchSchemaRequest, ['domain_name', 'query_key', 'query_value', {:limit => 20, :offset => 5}]],
35
+ [:train, Mushikago::Hanamgri::TrainRequest, ['domain_name', 'http://www.mushikago.org/', Mushikago::Hanamgri::TrainingData.new, {}]],
36
+ [:save_dictionary, Mushikago::Hanamgri::SaveDictionaryRequest, ['domain_name', {:description => '辞書の説明'}]],
37
+ [:list_dictionaries, Mushikago::Hanamgri::ListDictionariesRequest, [{:limit => 3, :offset => 2}]],
38
+ [:delete_dictionary, Mushikago::Hanamgri::DeleteDictionaryRequest, ['dictionary_name', {}]],
39
+ [:save_knowledge, Mushikago::Hanamgri::SaveKnowledgeRequest, ['domain_name', {:description => '学習データの説明'}]],
40
+ [:list_knowledges, Mushikago::Hanamgri::ListKnowledgesRequest, [{:limit => 3, :offset => 2, :status => 'complete'}]],
41
+ [:delete_knowledge, Mushikago::Hanamgri::DeleteKnowledgeRequest, ['knowledge_name', {}]],
42
+ ].each do |method_name, clazz, args|
43
+ context method_name do
44
+ it "が呼ばれたとき、#{clazz}のインスタンスが生成され、send_requestに渡される" do
45
+ client, mock = create_client_and_request_mock
46
+ clazz.should_receive(:new).with(*args).and_return(mock)
47
+ client.send(method_name, *args)
48
+ end
49
+ end
50
+ end
51
+
52
+ # ====================================
53
+ # define helpers
54
+ def create_client_and_request_mock
55
+ request_mock = Object.new
56
+ client = Mushikago::Hanamgri::Client.new
57
+ client.should_receive(:send_request).with(request_mock)
58
+ return [client, request_mock]
59
+ end
60
+ end
61
+
@@ -0,0 +1,34 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::CreateDomainRequest do
5
+ before :all do
6
+ @schema = Mushikago::Hanamgri::Schema.new do
7
+ add Mushikago::Hanamgri::Field.new('name', true, :string)
8
+ add Mushikago::Hanamgri::Field.new('price', true, :number, 'mushikago/ec/price')
9
+ add Mushikago::Hanamgri::Field.new('shipping', false, :string)
10
+ add Mushikago::Hanamgri::Field.new('description', false, :string)
11
+ end
12
+ end
13
+
14
+ shared_examples_for 'a valid request instance' do |n, s, o|
15
+ subject{ Mushikago::Hanamgri::CreateDomainRequest.new(n, s, @schema, o) }
16
+ it{ should be_kind_of(Mushikago::Http::PutRequest) }
17
+ its(:path){ should == "/1/hanamgri/domains/#{n}" }
18
+ its(:domain_name){ should == n }
19
+ its(:seeds){ should == s }
20
+ its(:schema){ should == @schema.to_json }
21
+ its(:description){ should == o[:description] }
22
+ its(:dictionary_name){ should == o[:dictionary_name] }
23
+ end
24
+
25
+ test_parameters = [
26
+ ['domain_name', 'seeds', {}],
27
+ ['name', 'seeds', {:description => 'description', :dictionary_name => 'dictionary'}],
28
+ ].each do |n, s, o|
29
+ context ".new(#{n}, #{s}, #{o})" do
30
+ it_should_behave_like 'a valid request instance', n, s, o
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::DeleteDictionaryRequest do
5
+ context '.new("domain_name")' do
6
+ subject{ Mushikago::Hanamgri::DeleteDictionaryRequest.new('dictionary_name')}
7
+ it{ should be_kind_of(Mushikago::Http::DeleteRequest)}
8
+ its(:dictionary_name){ should == 'dictionary_name'}
9
+ its(:path){ should == '/1/hanamgri/dictionary'}
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::DeleteDomainRequest do
5
+ context '.new("domain_name")' do
6
+ subject{ Mushikago::Hanamgri::DeleteDomainRequest.new('domain_name') }
7
+ it{ should be_kind_of(Mushikago::Http::DeleteRequest) }
8
+ its(:domain_name){ should == 'domain_name' }
9
+ its(:path){ should == '/1/hanamgri/domains/domain_name' }
10
+ end
11
+ end
12
+
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::DeleteKnowledgeRequest do
5
+ context '.new("domain_name")' do
6
+ subject{ Mushikago::Hanamgri::DeleteKnowledgeRequest.new('knowledge_name')}
7
+ it{ should be_kind_of(Mushikago::Http::DeleteRequest)}
8
+ its(:knowledge_name){ should == 'knowledge_name'}
9
+ its(:path){ should == '/1/hanamgri/knowledge'}
10
+ end
11
+ end
@@ -0,0 +1,44 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::Field do
5
+ shared_examples_for 'a json serializable struct' do |n, r, t, k|
6
+ its(:name){ should == n }
7
+ its(:required){ should == r }
8
+ its(:type){ should == t }
9
+ its(:to_json){ should == {:name => n, :required => r, :type => t, :knowledge_name => k}.to_json }
10
+ end
11
+
12
+ context 'construct with' do
13
+ [
14
+ ['name', true, :string],
15
+ ['価格', true, :number],
16
+ ['shipping', false, :number],
17
+ ['説明', false, :string],
18
+ ['name', true, :string, 'mushikago/ec/title'],
19
+ ].each do |n, r, t, k|
20
+ context "(name:#{n} required:#{r} type:#{t} knowledge_name:#{k})" do
21
+ subject{ Mushikago::Hanamgri::Field.new(n, r, t, k) }
22
+ it_should_behave_like 'a json serializable struct', n, r, t, k
23
+ it('should validate') do
24
+ proc{ subject.validate! }.should_not raise_error
25
+ end
26
+ end
27
+ end
28
+
29
+ [
30
+ ['name', true, :double],
31
+ ['価格', true, :float],
32
+ ['shipping', false, :object],
33
+ ['説明', false, :null],
34
+ ].each do |n, r, t, k|
35
+ context "(name:#{n} required:#{r} type:#{t}) knowledge_name#{k}" do
36
+ subject{ Mushikago::Hanamgri::Field.new(n, r, t, k) }
37
+ it_should_behave_like 'a json serializable struct', n, r, t, k
38
+ it('should not validate') do
39
+ proc{ subject.validate! }.should raise_error
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,12 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::GetAnalysisRequest do
5
+ context '.new("domain_name", "request_id")' do
6
+ subject{ Mushikago::Hanamgri::GetAnalysisRequest.new('domain_name', 'request_id')}
7
+ it{ should be_kind_of(Mushikago::Http::GetRequest)}
8
+ its(:domain_name){ should == 'domain_name'}
9
+ its(:request_id){ should == 'request_id'}
10
+ its(:path){ should == '/1/hanamgri/domains/domain_name/analyses/request_id'}
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+ describe Mushikago::Hanamgri::GetInformationRequest do
4
+ domain_name = 'domain_name'
5
+ path = "/1/hanamgri/domains/#{domain_name}"
6
+
7
+ context 'のインスタンス' do
8
+ subject{ Mushikago::Hanamgri::GetInformationRequest.new(domain_name)}
9
+ it{ should be_kind_of(Mushikago::Http::GetRequest)}
10
+ its(:path){ should == path }
11
+ its(:domain_name){ should == domain_name }
12
+ end
13
+
14
+ end
@@ -0,0 +1,10 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+ describe Mushikago::Hanamgri::GetQueueSizeRequest do
4
+ context 'のインスタンス' do
5
+ subject{ Mushikago::Hanamgri::GetQueueSizeRequest.new('domain_name')}
6
+ it{ should be_kind_of(Mushikago::Http::GetRequest)}
7
+ its(:path){ should == '/1/hanamgri/domains/domain_name/queues'}
8
+ its(:domain_name){ should == 'domain_name'}
9
+ end
10
+ end
@@ -0,0 +1,25 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::GetListAnalysesRequest do
5
+ shared_examples_for 'a valid request instance for list_analyses' do |n, o|
6
+ subject{ Mushikago::Hanamgri::GetListAnalysesRequest.new(n, o) }
7
+ it{ should be_kind_of(Mushikago::Http::GetRequest) }
8
+ its(:path){ should == "/1/hanamgri/domains/#{n}/analyses" }
9
+ its(:domain_name){ should == n }
10
+ its(:limit){ should == o[:limit] }
11
+ its(:offset){ should == o[:offset] }
12
+ its(:filter){ should == o[:filter] }
13
+ its(:status){ should == o[:status] }
14
+ end
15
+
16
+ test_parameters = [
17
+ ['domain_name', {}],
18
+ ['name', {:limit => 20, :offset => 5, :status => 'complete'}],
19
+ ].each do |n, o|
20
+ context ".new(#{n}, #{o})" do
21
+ it_should_behave_like 'a valid request instance for list_analyses', n, o
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,19 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::ListDictionariesRequest do
5
+ context '.new()' do
6
+ subject{ Mushikago::Hanamgri::ListDictionariesRequest.new() }
7
+ it{ should be_kind_of(Mushikago::Http::GetRequest) }
8
+ its(:path){ should == '/1/hanamgri/dictionaries' }
9
+ end
10
+
11
+ context '.new(:limit => 20, :offset => 10)' do
12
+ subject{ Mushikago::Hanamgri::ListDictionariesRequest.new(:limit => 20, :offset => 10) }
13
+ it{ should be_kind_of(Mushikago::Http::GetRequest) }
14
+ its(:limit){ should == 20 }
15
+ its(:offset){ should == 10 }
16
+ end
17
+ end
18
+
19
+
@@ -0,0 +1,19 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::GetListDomainsRequest do
5
+ context '.new()' do
6
+ subject{ Mushikago::Hanamgri::GetListDomainsRequest.new() }
7
+ it{ should be_kind_of(Mushikago::Http::GetRequest) }
8
+ its(:path){ should == '/1/hanamgri/domains' }
9
+ end
10
+
11
+ context '.new(:limit => 20, :offset => 10,:filter => "domain")' do
12
+ subject{ Mushikago::Hanamgri::GetListDomainsRequest.new(:limit => 20, :offset => 10,:filter => 'domain') }
13
+ it{ should be_kind_of(Mushikago::Http::GetRequest) }
14
+ its(:limit){ should == 20 }
15
+ its(:offset){ should == 10 }
16
+ its(:filter){ should == 'domain' }
17
+ end
18
+ end
19
+
@@ -0,0 +1,20 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::ListKnowledgesRequest do
5
+ context '.new()' do
6
+ subject{ Mushikago::Hanamgri::ListKnowledgesRequest.new() }
7
+ it{ should be_kind_of(Mushikago::Http::GetRequest) }
8
+ its(:path){ should == '/1/hanamgri/knowledges' }
9
+ end
10
+
11
+ context '.new(:limit => 20, :offset => 10, :status => "complete")' do
12
+ subject{ Mushikago::Hanamgri::ListKnowledgesRequest.new(:limit => 20, :offset => 10, :status => "complete") }
13
+ it{ should be_kind_of(Mushikago::Http::GetRequest) }
14
+ its(:limit){ should == 20 }
15
+ its(:offset){ should == 10 }
16
+ its(:status){ should == "complete" }
17
+ end
18
+ end
19
+
20
+
@@ -0,0 +1,21 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::RequestAnalysisRequest do
5
+ context '.new("domain_name", "url")' do
6
+ subject{ Mushikago::Hanamgri::RequestAnalysisRequest.new('domain_name', 'url') }
7
+ it{ should be_kind_of(Mushikago::Http::PutRequest) }
8
+ its(:domain_name){ should == 'domain_name' }
9
+ its(:url){ should == 'url' }
10
+ its(:path){ should == '/1/hanamgri/domains/domain_name/analysis' }
11
+ end
12
+
13
+ context '.new("domain_name", "url", :charset => "utf-8", :tag => "tag")' do
14
+ subject{ Mushikago::Hanamgri::RequestAnalysisRequest.new('domain_name', 'url', :charset => 'utf-8', :tag => 'tag') }
15
+ it{ should be_kind_of(Mushikago::Http::PutRequest) }
16
+ its(:domain_name){ should == 'domain_name' }
17
+ its(:url){ should == 'url' }
18
+ its(:charset){ should == 'utf-8' }
19
+ its(:tag){ should == 'tag' }
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::SaveDictionaryRequest do
5
+ shared_examples_for 'a valid request instance for save_dictionary' do |n, o|
6
+ subject{ Mushikago::Hanamgri::SaveDictionaryRequest.new(n, o) }
7
+ it{ should be_kind_of(Mushikago::Http::PutRequest) }
8
+ its(:path){ should == "/1/hanamgri/dictionary" }
9
+ its(:domain_name){ should == n }
10
+ its(:description){ should == o[:description] }
11
+ end
12
+
13
+ test_parameters = [
14
+ ['domain_name', {}],
15
+ ['name', {:description => '辞書の説明'}],
16
+ ].each do |n, o|
17
+ context ".new(#{n}, #{o})" do
18
+ it_should_behave_like 'a valid request instance for save_dictionary', n, o
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,22 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::SaveKnowledgeRequest do
5
+ shared_examples_for 'a valid request instance for save_knowledge' do |n, o|
6
+ subject{ Mushikago::Hanamgri::SaveKnowledgeRequest.new(n, o) }
7
+ it{ should be_kind_of(Mushikago::Http::PutRequest) }
8
+ its(:path){ should == "/1/hanamgri/knowledge" }
9
+ its(:domain_name){ should == n }
10
+ its(:description){ should == o[:description] }
11
+ end
12
+
13
+ test_parameters = [
14
+ ['domain_name', {}],
15
+ ['name', {:description => '学習データの説明'}],
16
+ ].each do |n, o|
17
+ context ".new(#{n}, #{o})" do
18
+ it_should_behave_like 'a valid request instance for save_knowledge', n, o
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,53 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::Schema do
5
+ valid_examples = [
6
+ Mushikago::Hanamgri::Field.new('name', true, :string),
7
+ Mushikago::Hanamgri::Field.new('price', true, :number),
8
+ Mushikago::Hanamgri::Field.new('price', true, :number, 'mushikago/ec/price'),
9
+ {:name => 'name', :required => true, :type => :string},
10
+ {:name => 'price', :required => true, :type => :number},
11
+ {:name => 'price', :required => true, :type => :number, :knowledge_name => 'mushikago/ec/price'},
12
+ ]
13
+
14
+ valid_examples.each do |field|
15
+ context "adding valid field of #{field.class} #{field.to_json}" do
16
+ it 'should success adding field' do
17
+ proc{ Mushikago::Hanamgri::Schema.new.add field }.should_not raise_error
18
+ end
19
+ end
20
+ end
21
+
22
+ it '.new can take a block' do
23
+ proc do
24
+ Mushikago::Hanamgri::Schema.new do
25
+ valid_examples.each do |field|
26
+ add field
27
+ end
28
+ end
29
+ end.should_not raise_error
30
+ end
31
+
32
+ it '.to_json format is valid' do
33
+ instance = Mushikago::Hanamgri::Schema.new do
34
+ add valid_examples[0]
35
+ add valid_examples[1]
36
+ end
37
+ instance.to_json.should == {:fields => valid_examples[0,2]}.to_json
38
+ end
39
+
40
+ invalid_examples = [
41
+ Mushikago::Hanamgri::Field.new('name', true, :double),
42
+ Mushikago::Hanamgri::Field.new('price', true, :boolean),
43
+ {:name => 'name', :required => true, :type => :object},
44
+ {:name => 'price', :required => true, :type => :hogehoge},
45
+ ]
46
+ invalid_examples.each do |field|
47
+ context "adding invalid field of #{field.class} #{field.to_json}" do
48
+ it 'should not success adding field' do
49
+ proc{ Mushikago::Hanamgri::Schema.new.add field }.should raise_error
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,22 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::SearchSchemaRequest do
5
+ shared_examples_for 'a valid request instance for search_schema' do |n, k, v, o|
6
+ subject{ Mushikago::Hanamgri::SearchSchemaRequest.new(n, k, v, o)}
7
+ it{ should be_kind_of(Mushikago::Http::GetRequest)}
8
+ its(:path){ should == "/1/hanamgri/domains/#{n}/schema/search"}
9
+ its(:domain_name){ should == n }
10
+ its(:query_key){ should == k }
11
+ its(:query_value){ should == v }
12
+ end
13
+
14
+ test_parameters = [
15
+ ['domain_name', 'query_key', 'query_value', {}],
16
+ ['name', 'key', 'value', {}],
17
+ ].each do |n, k, v, o|
18
+ context ".new(#{n}, #{k}, #{v}, #{o})" do
19
+ it_should_behave_like 'a valid request instance for search_schema', n, k, v, o
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::TrainRequest do
5
+ before :all do
6
+ @training_data = Mushikago::Hanamgri::TrainingData.new do
7
+ put("name", "株式会社マイニングブラウニー")
8
+ put("address", "東京都中央区日本橋浜町1−2−3")
9
+ put("tel", "03-6206-2812")
10
+ end
11
+ end
12
+
13
+ shared_examples_for 'a valid train instance' do |domain_name, url_or_html|
14
+ subject{ Mushikago::Hanamgri::TrainRequest.new(domain_name, url_or_html, @training_data) }
15
+ it{ should be_kind_of(Mushikago::Http::PostRequest) }
16
+ its(:path){ should == "/1/hanamgri/domains/#{domain_name}/train" }
17
+ its(:domain_name){ should == domain_name }
18
+ its(:url_or_html){ should == url_or_html }
19
+ its(:training_data){ should == @training_data.to_json }
20
+ end
21
+
22
+ test_parameters = [
23
+ ['domain_name', 'http://www.mushikago.org'],
24
+ ['domain_name', '<div>hello mushikago</div>'],
25
+ ].each do |domain_name, url|
26
+ context ".new(#{domain_name}, #{url})" do
27
+ it_should_behave_like 'a valid train instance', domain_name, url
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,22 @@
1
+ # -*- coding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Mushikago::Hanamgri::UpdateDomainRequest do
5
+ shared_examples_for ' a valid request instance for update_domain' do |n, d, o|
6
+ subject{ Mushikago::Hanamgri::UpdateDomainRequest.new(n, d, o) }
7
+ it{ should be_kind_of(Mushikago::Http::PostRequest) }
8
+ its(:path){ should == "/1/hanamgri/domains/#{n}" }
9
+ its(:domain_name){ should == n }
10
+ its(:description){ should == d }
11
+ end
12
+
13
+ test_parameters = [
14
+ ['domain_name', 'description', {}],
15
+ ['name', 'description', {}],
16
+ ].each do |n, d, o|
17
+ context ".new(#{n}, #{d}, #{o})" do
18
+ it_should_behave_like ' a valid request instance for update_domain', n, d, o
19
+ end
20
+ end
21
+ end
22
+