docomo-api 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e4cfe99e0173b1e1722fa1a5d3d18ee421b722b9
4
+ data.tar.gz: 3af9b076eedba4846269ae840774771b0d74344c
5
+ SHA512:
6
+ metadata.gz: ef20336bc8d1d24496df526473461dbac00ab2b751feda9a125c004c948c4390543f3bd0d40d027b4bd845adbed2e45d7b8bf96d1a88cf2ec6e94975a0954c5d
7
+ data.tar.gz: 53f111e66aea8d8380a487ab423d7d3b68057027b40094e154861e04f583203af7a4c26ef4ecd4a345436eed94c25bf8cfad0c0b019a70d99d29169a255d2e54
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/bundle
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.*
4
+ before_install: CODECLIMATE_REPO_TOKEN=e8fbc5d14be5ba100ae22c6bcfcc87caada77f23e0e462f4bf615fa1576e850d COVERALLS_REPO_TOKEN=WTsbiG2zuXloeywC1XEP9oZzsgGnO4jZi gem install bundler -v 1.11.2
5
+ script: bundle exec rake test
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in docomo-api-ruby.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'coveralls', require: false
8
+ gem 'codeclimate-test-reporter', require: false
9
+
10
+ gem 'webmock'
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ippei Kato
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # DocomoApi
2
+
3
+ [![Build Status](https://travis-ci.org/beco-ippei/docomo-api-ruby.svg?branch=master)](https://travis-ci.org/beco-ippei/docomo-api-ruby)
4
+ [![Coverage Status](https://coveralls.io/repos/github/beco-ippei/docomo-api-ruby/badge.svg?branch=master)](https://coveralls.io/github/beco-ippei/docomo-api-ruby?branch=master)
5
+ [![Code Climate](https://codeclimate.com/github/beco-ippei/docomo-api-ruby/badges/gpa.svg)](https://codeclimate.com/github/beco-ippei/docomo-api-ruby)
6
+
7
+ Simple api wrapper for Docomo-API.
8
+ (Dialogue service only)
9
+
10
+ シンプルなドコモAPIのラッパー
11
+ (雑談APIのみ対応。他のAPIは対応未定)
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'docomo-api'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install docomo-api
28
+
29
+ ## Usage
30
+
31
+ ### in irb
32
+ ```
33
+ $ bundle exec irb
34
+ irb(main):001:0> require 'docomo-api'
35
+ => true
36
+ irb(main):001:0> d = DocomoAPI::Dialogue.new "XXXXXXXXXXXXXXXX"
37
+ => #<DocomoAPI::Dialogue:0xAAAAAAAAAAAA @uri=#<URI::HTTPS https://api.apigw.smt.docomo.ne.jp/dialogue/v1/dialogue?APIKEY=XXXXXXXXXXXXXXXXXXXXXXx>, @http=#<Net::HTTP api.apigw.smt.docomo.ne.jp:443 open=false>>
38
+ irb(main):002:0> d.talk '大寒波来てる'
39
+ => "大寒波はくるんですね?テレビは見やすいですね"
40
+ ```
41
+
42
+ ### use Dialogue console
43
+ test for api
44
+ ```
45
+ $ DOCOMO_API_KEY=XXXXXXXXXXXXXXXXXXX bundle exec bin/dialogue
46
+ start dialogue (if you need help type 'help' and enter)
47
+ bot: 2016年になりましたね。
48
+ you: 申年やね
49
+ bot: つら
50
+ you: ぽよ
51
+ bot: ぽよ
52
+ you: exit
53
+ ```
54
+
55
+
56
+ ## Development
57
+
58
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
59
+
60
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/docomo-api-ruby.
65
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
data/bin/dialogue ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "docomo_api"
4
+
5
+ APIKEY = ENV['DOCOMO_API_KEY']
6
+ unless APIKEY
7
+ puts "environment variable 'DOCOMO_API_KEY' is mising'"
8
+ exit 1
9
+ end
10
+
11
+ dlg = DocomoAPI::Dialogue.new APIKEY
12
+ msg = ''
13
+ puts "start dialogue (if you need help type 'help' and enter)"
14
+ loop do
15
+ if /^reset$/i =~ msg
16
+ dlg.reset
17
+ elsif /^help$/i =~ msg
18
+ puts <<-HELP
19
+ reset ... reset dialogue context
20
+ exit ... exit dialogue session
21
+ help ... this messages
22
+ HELP
23
+ else
24
+ res = dlg.talk msg
25
+ puts "bot: #{res}"
26
+ end
27
+
28
+ print 'you: '
29
+ msg = gets.chomp
30
+
31
+ break if /^exit$/i =~ msg
32
+ end
33
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'docomo_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "docomo-api"
8
+ spec.version = DocomoAPI::VERSION
9
+ spec.authors = ["beco-ippei"]
10
+ spec.email = ["beco.ippei@gmail.com"]
11
+
12
+ spec.summary = %q{Simple API wrapper for Docomo talk API(s).}
13
+ spec.description = %q{}
14
+ spec.homepage = "http://github.com/beco-ippei/docomo-api-ruby"
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ end
data/lib/docomo-api.rb ADDED
@@ -0,0 +1 @@
1
+ require "docomo_api"
data/lib/docomo_api.rb ADDED
@@ -0,0 +1,5 @@
1
+ module DocomoAPI
2
+ ROOT_URL = "https://api.apigw.smt.docomo.ne.jp"
3
+ end
4
+
5
+ require "docomo_api/dialogue"
@@ -0,0 +1,51 @@
1
+ require 'uri'
2
+ require 'json'
3
+ require 'openssl'
4
+ require 'net/http'
5
+
6
+ module DocomoAPI
7
+ class Dialogue
8
+ API_URL = "#{DocomoAPI::ROOT_URL}/dialogue/v1/dialogue"
9
+ def initialize(key)
10
+ @uri = URI.parse("#{API_URL}?APIKEY=#{key}")
11
+ @http = Net::HTTP.new(@uri.host, @uri.port)
12
+ @http.use_ssl = true
13
+ end
14
+
15
+ #TODO: set 't' option
16
+
17
+ def reset
18
+ @context = nil
19
+ end
20
+
21
+ # call api
22
+ def talk(msg)
23
+ response = @http.start do |h|
24
+ res = h.request(request(msg))
25
+ JSON.parse(res.body)
26
+ end
27
+
28
+ if err = response['requestError']
29
+ raise err.inspect
30
+ end
31
+
32
+ @context = response['context']
33
+ response['utt']
34
+ end
35
+
36
+ private
37
+
38
+ def request(msg)
39
+ body = {
40
+ 'utt' => msg,
41
+ }
42
+ body['context'] = @context if @context
43
+ request = Net::HTTP::Post.new(
44
+ @uri.request_uri,
45
+ 'Content-Type' => 'application/json'
46
+ )
47
+ request.body = body.to_json
48
+ request
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module DocomoAPI
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: docomo-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - beco-ippei
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-26 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: ''
56
+ email:
57
+ - beco.ippei@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - bin/dialogue
69
+ - docomo-api.gemspec
70
+ - lib/docomo-api.rb
71
+ - lib/docomo_api.rb
72
+ - lib/docomo_api/dialogue.rb
73
+ - lib/docomo_api/version.rb
74
+ homepage: http://github.com/beco-ippei/docomo-api-ruby
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.5.1
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Simple API wrapper for Docomo talk API(s).
98
+ test_files: []