docomoru 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6273cdb24469ec6c11c0e7a5c9b2964e52916c74
4
+ data.tar.gz: e7a37a7ea0f8e6991089bdcadce03827857dc81e
5
+ SHA512:
6
+ metadata.gz: 93fe2610a237ddd0d45327c1c5cdeb69e0ca8660310a5e80576a4c36d0d6866ca64395c3209bbf056d95614842d5aed8a3b018a0aa7959d41f0b5fd6bcecefbf
7
+ data.tar.gz: e52ec53b50e00f8d224069e9ed3bf69c6cb0f9bb5e43c87fd5ee3a2335befc15c44a8a317fb2d91d9649588eba2adbd1ecb9588d0de8378588f795848e5a1f27
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in docomoru.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryo Nakamura
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Docomoru
2
+ Client library for DoCoMo API written in Ruby.
3
+
4
+ ## Usage
5
+ Currenty docomoru is supporting [Dialogue API](https://dev.smt.docomo.ne.jp/?p=docs.api.page&api_docs_id=3).
6
+
7
+ ```rb
8
+ client = Docomoru::Client.new(api_key: ENV["DOCOMO_API_KEY"])
9
+ response = client.create_dialogue("Gemつくりました")
10
+ response.status #=> 200
11
+ response.headers #=> {
12
+ "Asyncserviceinvoke" => "false",
13
+ "Content-Type" => "application/json;charset=UTF-8",
14
+ "Date" => "Fri, 05 Dec 2014 15:10:11 GMT",
15
+ "Content-Length" => "165",
16
+ "Connection" => "Close"
17
+ }
18
+ response.body #=> {
19
+ "utt" => "gemに登録されるのでしょうかね",
20
+ "yomi" => "gemに登録されるのでしょうかね",
21
+ "mode" => "dialog",
22
+ "da" => "12",
23
+ "context" => "dXIgT9u1_XKfO1QbaVkAGQ"
24
+ }
25
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/docomoru.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "docomoru/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "docomoru"
7
+ spec.version = Docomoru::VERSION
8
+ spec.authors = ["Ryo Nakamura"]
9
+ spec.email = ["r7kamura@gmail.com"]
10
+ spec.summary = "Client library for DoCoMo API written in Ruby."
11
+ spec.homepage = "https://github.com/r7kamura/docomoru"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "activesupport"
20
+ spec.add_dependency "faraday"
21
+ spec.add_dependency "faraday_middleware"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
@@ -0,0 +1,62 @@
1
+ require "docomoru/dialogue_methods"
2
+ require "docomoru/response"
3
+ require "active_support/core_ext/object/to_query"
4
+ require "faraday"
5
+ require "faraday_middleware"
6
+ require "uri"
7
+
8
+ module Docomoru
9
+ class Client
10
+ DEFAULT_HOST = "api.apigw.smt.docomo.ne.jp"
11
+
12
+ DEFAULT_USER_AGENT = "#{self} #{VERSION}"
13
+
14
+ DEFAULT_HEADERS = {
15
+ "User-Agent" => DEFAULT_USER_AGENT,
16
+ }
17
+
18
+ include DialogueMethods
19
+
20
+ # @param [String] api_key APIKEY issued from DoCoMo.
21
+ def initialize(api_key:)
22
+ @api_key = api_key
23
+ end
24
+
25
+ def post(path, params = nil, headers = nil)
26
+ process(:post, path, params, headers)
27
+ end
28
+
29
+ private
30
+
31
+ def connection
32
+ @connection ||= Faraday.new(headers: DEFAULT_HEADERS, url: url_prefix) do |connection|
33
+ connection.request :json
34
+ connection.response :json
35
+ connection.adapter Faraday.default_adapter
36
+ end
37
+ end
38
+
39
+ def default_queries
40
+ { APIKEY: @api_key }
41
+ end
42
+
43
+ def default_query_string
44
+ default_queries.to_query
45
+ end
46
+
47
+ def process(request_method, path, params, headers)
48
+ Response.new(
49
+ connection.send(
50
+ request_method,
51
+ URI.escape(path),
52
+ params,
53
+ headers,
54
+ )
55
+ )
56
+ end
57
+
58
+ def url_prefix
59
+ "https://#{DEFAULT_HOST}"
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,13 @@
1
+ module Docomoru
2
+ module DialogueMethods
3
+ PATH = "/dialogue/v1/dialogue"
4
+
5
+ def create_dialogue(utt, params = {}, headers = {})
6
+ post(
7
+ "#{PATH}?#{default_query_string}",
8
+ params.merge(utt: utt),
9
+ headers,
10
+ )
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ require "active_support/core_ext/string/inflections"
2
+
3
+ module Docomoru
4
+ class Response
5
+ def initialize(faraday_response)
6
+ @raw_body = faraday_response.body
7
+ @raw_headers = faraday_response.headers
8
+ @raw_status = faraday_response.status
9
+ end
10
+
11
+ def body
12
+ @raw_body
13
+ end
14
+
15
+ def headers
16
+ @headers ||= @raw_headers.inject({}) do |result, (key, value)|
17
+ result.merge(key.split("-").map(&:capitalize).join("-") => value)
18
+ end
19
+ end
20
+
21
+ def status
22
+ @raw_status
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Docomoru
2
+ VERSION = "0.0.1"
3
+ end
data/lib/docomoru.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "docomoru/client"
2
+ require "docomoru/version"
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: docomoru
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
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
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ description:
98
+ email:
99
+ - r7kamura@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - docomoru.gemspec
110
+ - lib/docomoru.rb
111
+ - lib/docomoru/client.rb
112
+ - lib/docomoru/dialogue_methods.rb
113
+ - lib/docomoru/response.rb
114
+ - lib/docomoru/version.rb
115
+ homepage: https://github.com/r7kamura/docomoru
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.2.2
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Client library for DoCoMo API written in Ruby.
139
+ test_files: []
140
+ has_rdoc: