noahru 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.project +17 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +67 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/example/noahru.rb +54 -0
- data/lib/noahru/client.rb +16 -0
- data/lib/noahru/command.rb +39 -0
- data/lib/noahru/dialogue.rb +48 -0
- data/lib/noahru/get_talk.rb +34 -0
- data/lib/noahru/get_user_recent.rb +35 -0
- data/lib/noahru/version.rb +3 -0
- data/lib/noahru.rb +6 -0
- data/noahru.gemspec +24 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 34a1c26941d0a97a9ba767f69b1989d4af0bd5ab
|
4
|
+
data.tar.gz: 1e94543b91d29318982331c184a10114f6e689ba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8be361f0d13e007ddc191e7c7715cba0aaca88df287f9d2e4713a7a366342785b58dd9c38539a90f2085d70945b964d8efa49b4eb2c243e0fda673795b2e8a7d
|
7
|
+
data.tar.gz: ce73fa387eb3417c9bd68777f9331d65c4e1a8c0d9be754af628def7b140d5f692777cd6486b079d95e9a7f12a3ad8830f4f7934d819885f246f8e51c69d5073
|
data/.gitignore
ADDED
data/.project
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>noahru</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>org.eclipse.dltk.core.scriptbuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>org.eclipse.dltk.ruby.core.nature</nature>
|
16
|
+
</natures>
|
17
|
+
</projectDescription>
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Noahru
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/noahru`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
さらすてぃAPIのクライアントライブラリです。
|
6
|
+
たった2行で姉妹と会話することができます。
|
7
|
+
apiについての説明は[さらすてぃ姉妹のAPI](http://flum.pw/sarasty/api.php)
|
8
|
+
公式サイトは[さらすてぃ姉妹のサイト](http://flum.pw/sarasty/)
|
9
|
+
|
10
|
+
質問等ありましたらTwitter:[@flum_](https://twitter.com/flum_)までお願いします。
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'noahru'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install noahru
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
requireしてから
|
32
|
+
|
33
|
+
```
|
34
|
+
dialogue = Noahru::Dialogue.new(api_key)
|
35
|
+
puts dialogue.create_dialogue "たおの事どう思う?" #=>その内ヤバイ罪犯しそう
|
36
|
+
```
|
37
|
+
|
38
|
+
たったこれだけで会話することができます。
|
39
|
+
詳しいパラメータ等は、さらすてぃ姉妹のサイトを参照して
|
40
|
+
```
|
41
|
+
dialogue.configure config = {
|
42
|
+
:sister => "noah",
|
43
|
+
:user_id => "flum_",
|
44
|
+
:mode => "markov",
|
45
|
+
}
|
46
|
+
```
|
47
|
+
の様な感じでセットしてください。
|
48
|
+
|
49
|
+
##Supported APIs
|
50
|
+
###/apis/dialogue
|
51
|
+
###/apis/command
|
52
|
+
###/apis/get_talk
|
53
|
+
###/apis/get_user_recent
|
54
|
+
|
55
|
+
## Development
|
56
|
+
|
57
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
58
|
+
|
59
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
1. Fork it ( https://github.com/[my-github-username]/noahru/fork )
|
64
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
65
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
66
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
67
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "noahru"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/example/noahru.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Coding: UTF-8
|
2
|
+
lib = File.expand_path('../../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'noahru'
|
5
|
+
|
6
|
+
api_key = ""
|
7
|
+
|
8
|
+
###Noahruの使用例
|
9
|
+
####詳しい説明は https://github.com/flum1025/noahru
|
10
|
+
####apiについての説明は http://flum.pw/sarasty/api.php
|
11
|
+
####公式サイトは http://flum.pw/sarasty/
|
12
|
+
|
13
|
+
###Copyright c @flum_ 2015
|
14
|
+
###Twitter:@flum https://twitter.com/flum_
|
15
|
+
###WEBサイト http://flum.pw/
|
16
|
+
|
17
|
+
###dialogue
|
18
|
+
dialogue = Noahru::Dialogue.new(api_key)
|
19
|
+
dialogue.configure config = {
|
20
|
+
:sister => "sarasty_noah",
|
21
|
+
:user_id => "flum_",
|
22
|
+
:mode => "markov",
|
23
|
+
}
|
24
|
+
puts dialogue.create_dialogue "たおの事どう思う?" #=>その内ヤバイ罪犯しそう
|
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
|
+
###ここまで
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Noahru
|
2
|
+
class NoahruError < Exception; end
|
3
|
+
|
4
|
+
class Client
|
5
|
+
attr_accessor :api_key, :base_url
|
6
|
+
|
7
|
+
def initialize(api_key)
|
8
|
+
self.api_key = api_key
|
9
|
+
self.base_url = 'http://api.sarasty.flum.pw'
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_api_key
|
13
|
+
return self.api_key
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Noahru
|
5
|
+
class Dialogue
|
6
|
+
attr_accessor :sister, :user_id, :mode, :context
|
7
|
+
|
8
|
+
def initialize(api_key)
|
9
|
+
@client = Client.new(api_key)
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure(options = {})
|
13
|
+
options.each do |key, value|
|
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)
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_dialogue talk
|
38
|
+
response = open(build_url(talk))
|
39
|
+
result = JSON.parse(response.read)
|
40
|
+
raise NoahruError, result['error']['message'] unless result['error'].nil?
|
41
|
+
self.context = result['context']
|
42
|
+
self.mode = result['mode']
|
43
|
+
self.user_id = result['user_id']
|
44
|
+
self.sister = result['sister']
|
45
|
+
return result['utt']
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
@@ -0,0 +1,35 @@
|
|
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
|
data/lib/noahru.rb
ADDED
data/noahru.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'noahru/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "noahru"
|
8
|
+
spec.version = Noahru::VERSION
|
9
|
+
spec.authors = ["flum1025"]
|
10
|
+
spec.email = ["flum.1025@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Sarasty sister API Library}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/flum1025/Noahru"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_dependency 'json'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: noahru
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- flum1025
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Sarasty sister API Library
|
56
|
+
email:
|
57
|
+
- flum.1025@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .project
|
64
|
+
- .travis.yml
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- example/noahru.rb
|
71
|
+
- lib/noahru.rb
|
72
|
+
- lib/noahru/client.rb
|
73
|
+
- lib/noahru/command.rb
|
74
|
+
- lib/noahru/dialogue.rb
|
75
|
+
- lib/noahru/get_talk.rb
|
76
|
+
- lib/noahru/get_user_recent.rb
|
77
|
+
- lib/noahru/version.rb
|
78
|
+
- noahru.gemspec
|
79
|
+
homepage: https://github.com/flum1025/Noahru
|
80
|
+
licenses: []
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.5.2
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Sarasty sister API Library
|
102
|
+
test_files: []
|