noahru 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/example/noahru.rb +4 -35
- data/lib/noahru/client.rb +5 -8
- data/lib/noahru/dialogue.rb +10 -29
- data/lib/noahru/version.rb +1 -1
- metadata +2 -5
- data/lib/noahru/command.rb +0 -39
- data/lib/noahru/get_talk.rb +0 -34
- data/lib/noahru/get_user_recent.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02aeef81fe886995679275f4fedfd7f26c1ea2a1
|
4
|
+
data.tar.gz: 05514a259b22e38380ef35c37b217956a67fdb7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65cbcb0f7bf8fb163e1bbe86e6b673accc0fcba753047140eba920cd2df8fbd4d7911b883ce06e93d6bb052d7f532d6a181ac674dea9c81fc0a7c036cefc8aba
|
7
|
+
data.tar.gz: dc5db48928ed87379c3b5903c6b3452f521d6de5a284fdd33e34f944db8d63d44b28e24e7a40fb7133c83633d1bc100dd130e307d44d1b4977f92f00720a8c04
|
data/example/noahru.rb
CHANGED
@@ -16,39 +16,8 @@ api_key = ""
|
|
16
16
|
|
17
17
|
###dialogue
|
18
18
|
dialogue = Noahru::Dialogue.new(api_key)
|
19
|
-
dialogue.
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:mode => "markov",
|
19
|
+
puts dialogue.create_dialogue "おはよう", {
|
20
|
+
sister: :sarasty_noah,
|
21
|
+
mode: :api
|
23
22
|
}
|
24
|
-
|
25
|
-
puts dialogue.get_current_data
|
26
|
-
###ここまで
|
27
|
-
|
28
|
-
###command
|
29
|
-
command = Noahru::Command.new(api_key)
|
30
|
-
command.configure config = {
|
31
|
-
:sister => "sarasty_noah",
|
32
|
-
:user_id => "flum_",
|
33
|
-
}
|
34
|
-
puts command.send_command "learn"
|
35
|
-
puts command.get_current_data
|
36
|
-
###ここまで
|
37
|
-
|
38
|
-
###get_talk
|
39
|
-
get_talk = Noahru::Get_talk.new(api_key)
|
40
|
-
get_talk.configure config = {
|
41
|
-
:context => "ABCDEFGH",
|
42
|
-
}
|
43
|
-
puts get_talk.get_talk
|
44
|
-
puts get_talk.get_current_data
|
45
|
-
###ここまで
|
46
|
-
|
47
|
-
###get_user_recent
|
48
|
-
get_user_recent = Noahru::Get_user_recent.new(api_key)
|
49
|
-
get_user_recent.configure config = {
|
50
|
-
:user_id => "flum_",
|
51
|
-
}
|
52
|
-
puts get_user_recent.get_user_recent
|
53
|
-
puts get_user_recent.get_current_data
|
54
|
-
###ここまで
|
23
|
+
###ここまで
|
data/lib/noahru/client.rb
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
module Noahru
|
2
2
|
class NoahruError < Exception; end
|
3
3
|
|
4
|
+
BaseURL = 'http://api.sarasty.flum.pw'
|
4
5
|
class Client
|
5
|
-
|
6
|
+
attr_reader :api_key, :base_url
|
6
7
|
|
7
|
-
def initialize(api_key)
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def get_api_key
|
13
|
-
return self.api_key
|
8
|
+
def initialize(api_key, base_url = BaseURL)
|
9
|
+
@api_key = api_key
|
10
|
+
@base_url = base_url
|
14
11
|
end
|
15
12
|
end
|
16
13
|
end
|
data/lib/noahru/dialogue.rb
CHANGED
@@ -1,47 +1,28 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
require 'json'
|
3
|
+
require 'uri'
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_support/core_ext'
|
3
6
|
|
4
7
|
module Noahru
|
5
8
|
class Dialogue
|
6
|
-
attr_accessor :
|
9
|
+
attr_accessor :request_params, :response_params
|
7
10
|
|
8
11
|
def initialize(api_key)
|
9
12
|
@client = Client.new(api_key)
|
10
13
|
end
|
11
14
|
|
12
15
|
def configure(options = {})
|
13
|
-
options.
|
14
|
-
instance_variable_set("@#{key}", value)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def get_current_data
|
19
|
-
return data = {
|
20
|
-
:sister => self.sister,
|
21
|
-
:user_id => self.user_id,
|
22
|
-
:mode => self.mode,
|
23
|
-
:context => self.context,
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
def build_url(talk)
|
28
|
-
base_url = "#{@client.base_url}/apis/dialogue?api_key=#{@client.get_api_key}"
|
29
|
-
base_url << "&sister=#{self.sister}" unless self.sister.nil?
|
30
|
-
base_url << "&user_id=#{self.user_id}" unless self.user_id.nil?
|
31
|
-
base_url << "&mode=#{self.mode}" unless self.mode.nil?
|
32
|
-
base_url << "&context=#{self.context}" unless self.context.nil?
|
33
|
-
base_url << "&utt=#{talk}" unless talk.nil?
|
34
|
-
return URI.escape(base_url)
|
16
|
+
@request_params = options.to_param
|
35
17
|
end
|
36
18
|
|
37
|
-
def create_dialogue talk
|
38
|
-
|
19
|
+
def create_dialogue talk, options = {}
|
20
|
+
uri = URI(File.join(@client.base_url, 'apis/dialogue'))
|
21
|
+
uri.query = options.merge(api_key: @client.api_key).to_param
|
22
|
+
response = open(uri)
|
39
23
|
result = JSON.parse(response.read)
|
40
24
|
raise NoahruError, result['error']['message'] unless result['error'].nil?
|
41
|
-
|
42
|
-
self.mode = result['mode']
|
43
|
-
self.user_id = result['user_id']
|
44
|
-
self.sister = result['sister']
|
25
|
+
@response_params = result
|
45
26
|
return result['utt']
|
46
27
|
end
|
47
28
|
end
|
data/lib/noahru/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noahru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- flum1025
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03
|
11
|
+
date: 2016-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,10 +70,7 @@ files:
|
|
70
70
|
- example/noahru.rb
|
71
71
|
- lib/noahru.rb
|
72
72
|
- lib/noahru/client.rb
|
73
|
-
- lib/noahru/command.rb
|
74
73
|
- lib/noahru/dialogue.rb
|
75
|
-
- lib/noahru/get_talk.rb
|
76
|
-
- lib/noahru/get_user_recent.rb
|
77
74
|
- lib/noahru/version.rb
|
78
75
|
- noahru.gemspec
|
79
76
|
homepage: https://github.com/flum1025/Noahru
|
data/lib/noahru/command.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module Noahru
|
2
|
-
class Command
|
3
|
-
attr_accessor :sister, :user_id
|
4
|
-
|
5
|
-
def initialize(api_key)
|
6
|
-
@client = Client.new(api_key)
|
7
|
-
end
|
8
|
-
|
9
|
-
def configure(options = {})
|
10
|
-
options.each do |key, value|
|
11
|
-
instance_variable_set("@#{key}", value)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def get_current_data
|
16
|
-
return data = {
|
17
|
-
:sister => self.sister,
|
18
|
-
:user_id => self.user_id,
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
def build_url(talk)
|
23
|
-
base_url = "#{@client.base_url}/apis/command?api_key=#{@client.get_api_key}"
|
24
|
-
base_url << "&sister=#{self.sister}" unless self.sister.nil?
|
25
|
-
base_url << "&user_id=#{self.user_id}" unless self.user_id.nil?
|
26
|
-
base_url << "&command=#{talk}"
|
27
|
-
return URI.escape(base_url)
|
28
|
-
end
|
29
|
-
|
30
|
-
def send_command talk
|
31
|
-
response = open(build_url(talk))
|
32
|
-
result = JSON.parse(response.read)
|
33
|
-
raise NoahruError, result['error']['message'] unless result['error'].nil?
|
34
|
-
self.user_id = result['user_id']
|
35
|
-
self.sister = result['sister']
|
36
|
-
return result['response']
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/lib/noahru/get_talk.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
module Noahru
|
2
|
-
class Get_talk
|
3
|
-
attr_accessor :context
|
4
|
-
|
5
|
-
def initialize(api_key)
|
6
|
-
@client = Client.new(api_key)
|
7
|
-
end
|
8
|
-
|
9
|
-
def configure(options = {})
|
10
|
-
options.each do |key, value|
|
11
|
-
instance_variable_set("@#{key}", value)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def get_current_data
|
16
|
-
return data = {
|
17
|
-
:context => self.context,
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
def build_url
|
22
|
-
base_url = "#{@client.base_url}/apis/get_talk?api_key=#{@client.get_api_key}"
|
23
|
-
base_url << "&context=#{self.context}" unless self.context.nil?
|
24
|
-
return URI.escape(base_url)
|
25
|
-
end
|
26
|
-
|
27
|
-
def get_talk
|
28
|
-
response = open(build_url)
|
29
|
-
result = JSON.parse(response.read)
|
30
|
-
raise NoahruError, result['error']['message'] unless result['error'].nil?
|
31
|
-
return result
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Noahru
|
2
|
-
class Get_user_recent
|
3
|
-
attr_accessor :user_id
|
4
|
-
|
5
|
-
def initialize(api_key)
|
6
|
-
@client = Client.new(api_key)
|
7
|
-
end
|
8
|
-
|
9
|
-
def configure(options = {})
|
10
|
-
options.each do |key, value|
|
11
|
-
instance_variable_set("@#{key}", value)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def get_current_data
|
16
|
-
return data = {
|
17
|
-
:user_id => self.user_id,
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
def build_url
|
22
|
-
base_url = "#{@client.base_url}/apis/get_user_recent?api_key=#{@client.get_api_key}"
|
23
|
-
base_url << "&user_id=#{self.user_id}" unless self.user_id.nil?
|
24
|
-
return URI.escape(base_url)
|
25
|
-
end
|
26
|
-
|
27
|
-
def get_user_recent
|
28
|
-
response = open(build_url)
|
29
|
-
result = JSON.parse(response.read)
|
30
|
-
raise NoahruError, result['error']['message'] unless result['error'].nil?
|
31
|
-
return result
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|