docomoru 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8938cee1dc86c5fcbb4b03212e03bc8796edf776
4
- data.tar.gz: 219bb80f68c6ab072efaeac56d9413c0b8da7bed
3
+ metadata.gz: 980fdc8d5e4becacc3c352f09ba54c4911427e60
4
+ data.tar.gz: 2d9dd4b4ec00780c292db47287a898590b64568f
5
5
  SHA512:
6
- metadata.gz: 9f3e7b75bc937acb886709466ce14a1c7a34f4672d06320da05f524dd9b943abc446c1b9ebe5c4d4858dd25788f55e2e6decb67a3326ba950b7a2dac6fdb4e85
7
- data.tar.gz: fd3af2dd9e9f676e44d039307010875c80502c6a27ec12f27cefd211ba098b72f5e8d8a4aafc0d971cdf4ab682511801bcb65e5ef0c3c69f7738865ad2e4c1f4
6
+ metadata.gz: 5a91c3147ae3ff54bb5b9e1fbe55567ed0394a1d58263be05a3e252c691db429797dae9f2ed2265968d6e2ccbc17f34d63ce5e694f234d1f07b9de3a21ed3896
7
+ data.tar.gz: 1cade03851a761b7122a6f0e04532870b17ccea87e8e2d46315c3e761566b8495bf4c94b6434b71356026884c7e5fa4ea6ba0e5b93958fcaa557f0d9540c3ddb
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,56 @@
1
+ Lint/UnusedBlockArgument:
2
+ Enabled: false
3
+
4
+ Lint/UnusedMethodArgument:
5
+ Enabled: false
6
+
7
+ Metrics/AbcSize:
8
+ Enabled: false
9
+
10
+ Metrics/ClassLength:
11
+ Enabled: false
12
+
13
+ Metrics/CyclomaticComplexity:
14
+ Enabled: false
15
+
16
+ Metrics/LineLength:
17
+ Max: 120
18
+
19
+ Metrics/MethodLength:
20
+ Enabled: false
21
+
22
+ Metrics/PerceivedComplexity:
23
+ Enabled: false
24
+
25
+ Style/Documentation:
26
+ Enabled: false
27
+
28
+ Style/DoubleNegation:
29
+ Enabled: false
30
+
31
+ Style/FormatString:
32
+ Enabled: false
33
+
34
+ Style/MultilineBlockChain:
35
+ Enabled: false
36
+
37
+ Style/PercentLiteralDelimiters:
38
+ Enabled: false
39
+
40
+ Style/PredicateName:
41
+ Enabled: false
42
+
43
+ Style/RegexpLiteral:
44
+ MaxSlashes: 0
45
+
46
+ Style/SignalException:
47
+ Enabled: false
48
+
49
+ Style/StringLiterals:
50
+ EnforcedStyle: double_quotes
51
+
52
+ Style/TrailingComma:
53
+ Enabled: false
54
+
55
+ Style/TrivialAccessors:
56
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ env:
5
+ global:
6
+ secure: MqBEEAkWJkzm/hrmI+BTH1cL00jiswMWOl3QAiRfyGwG+Qj3cogYUz1jEKW7olhgAFTXc8SIooSjfp53yXWRlN1bXkkfPPNoyiyeFa7n62wCgaaQ435NpXBuf3YJwZTkbcCGYogOLSdOkuTtYJJ5IBp0naMm/CGHttvP8H6gj8A=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.1.2
2
+ - Support slop version 4
3
+
1
4
  ## 0.1.1
2
5
  - Support Knowledge Q&A API (Thx @kkosuge)
3
6
 
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in docomoru.gemspec
4
3
  gemspec
data/README.md CHANGED
@@ -1,15 +1,37 @@
1
- # Docomoru
1
+ # Docomoru [![Build Status](https://travis-ci.org/r7kamura/docomoru.svg)](https://travis-ci.org/r7kamura/docomoru) [![Code Climate](https://codeclimate.com/github/r7kamura/docomoru/badges/gpa.svg)](https://codeclimate.com/github/r7kamura/docomoru) [![Test Coverage](https://codeclimate.com/github/r7kamura/docomoru/badges/coverage.svg)](https://codeclimate.com/github/r7kamura/docomoru)
2
2
  Client library for docomo API written in Ruby.
3
3
 
4
4
  ## Install
5
- Note: requires Ruby 2.0.0 or higher.
5
+ docomoru can be installed from [rubygems.org](https://rubygems.org/gems/docomoru) as a gem.
6
6
 
7
7
  ```sh
8
8
  gem install docomoru
9
9
  ```
10
10
 
11
- ## Library
12
- Currenty Docomoru is supporting [Dialogue API](https://dev.smt.docomo.ne.jp/?p=docs.api.page&api_docs_id=3) & [Knowledge Q&A API](https://dev.smt.docomo.ne.jp/?p=docs.api.page&api_docs_id=6).
11
+ ## Authentication
12
+ To use docomo API via docomoru, you need to get docomo API Key.
13
+
14
+ 1. Sign-in to https://dev.smt.docomo.ne.jp/
15
+ 2. Register new application
16
+ 3. Generate API Key
17
+
18
+ ## Supported APIs
19
+ Currently docomoru is supporting the following APIs.
20
+
21
+ - [Dialogue API](https://dev.smt.docomo.ne.jp/?p=docs.api.page&api_docs_id=3)
22
+ - [Knowledge Q&A API](https://dev.smt.docomo.ne.jp/?p=docs.api.page&api_docs_id=6).
23
+
24
+ ## Usage
25
+ You can use docomoru as a library on Ruby code or an executable on CLI.
26
+
27
+ ### Library
28
+ Create an instance of `Docomoru::Client`,
29
+ then call a method to send an HTTP request to docomo API.
30
+ Each method returns `Docomoru::Response` that has status code, headers, and body values.
31
+
32
+ Here is an example code to use Dialogue API via docomoru.
33
+ As you can see, `Docomoru::Client` provides low-level interface of HTTP,
34
+ so you may need some wrapper class to use it from your application.
13
35
 
14
36
  ```rb
15
37
  client = Docomoru::Client.new(api_key: ENV["DOCOMO_API_KEY"])
@@ -32,7 +54,9 @@ response.body #=> {
32
54
  ```
33
55
 
34
56
  ## CLI
35
- `docomoru` executable is bundled to call use Docomoru from CLI.
57
+ `docomoru` executable is bundled to call docomo API from CLI.
58
+ This executable handily creates an instance of `Docomoru::Client` with given API Key,
59
+ then call the specified method, and returns its response.
36
60
 
37
61
  ```
38
62
  $ docomoru <method> <arguments> [options]
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "rubocop/rake_task"
2
4
 
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new(:style)
7
+ task default: [:style, :spec]
data/docomoru.gemspec CHANGED
@@ -23,6 +23,9 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency "rack"
24
24
  spec.add_dependency "slop"
25
25
  spec.add_development_dependency "bundler", "~> 1.7"
26
- spec.add_development_dependency "pry"
27
- spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "codeclimate-test-reporter", "0.4.4"
27
+ spec.add_development_dependency "rake", "10.4.2"
28
+ spec.add_development_dependency "rspec", "3.2.0"
29
+ spec.add_development_dependency "rubocop", "0.29.1"
30
+ spec.add_development_dependency "webmock", "1.20.4"
28
31
  end
@@ -24,7 +24,7 @@ module Docomoru
24
24
  end
25
25
 
26
26
  def method_name
27
- ARGV[0]
27
+ slop_options.arguments[0]
28
28
  end
29
29
 
30
30
  def params
@@ -70,7 +70,7 @@ module Docomoru
70
70
  end
71
71
 
72
72
  def has_valid_arguments?
73
- -(Client.instance_method(method_name).arity) - 1 == arguments.length
73
+ -(Client.instance_method(method_name).arity) == arguments.length
74
74
  end
75
75
 
76
76
  def has_valid_method_name?
@@ -98,7 +98,7 @@ module Docomoru
98
98
  params = {}
99
99
  headers = {}
100
100
  arguments = []
101
- ARGV[1..-1].each do |section|
101
+ slop_options.arguments[1..-1].each do |section|
102
102
  case
103
103
  when /(?<key>.+):(?<value>[^=]+)/ =~ section
104
104
  headers[key] = value
@@ -119,12 +119,16 @@ module Docomoru
119
119
  end
120
120
 
121
121
  def slop_options
122
- @slop_options ||= Slop.parse!(@argv) do
123
- banner "Usage: docomoru <method> [arguments] [headers|params] [options]"
124
- on "a", "api-key=", "Pass API Key or use DOCOMO_API_KEY instead"
125
- on "h", "help", "Display help message"
126
- on "header", "Show response header"
127
- on "no-body", "Hide response body"
122
+ @slop_options ||= Slop.parse(@argv, suppress_errors: true) do |options|
123
+ options.banner = "Usage: docomoru <method> [arguments] [headers|params] [options]"
124
+ if Slop::VERSION >= "4.0.0"
125
+ options.string("-a", "--api-key", "Pass API Key or use DOCOMO_API_KEY instead")
126
+ else
127
+ options.on("-a", "--api-key=", "Pass API Key or use DOCOMO_API_KEY instead")
128
+ end
129
+ options.on("-h", "--help", "Display help message")
130
+ options.on("--header", "Show response header")
131
+ options.on("--no-body", "Hide response body")
128
132
  end
129
133
  end
130
134
  end
@@ -5,7 +5,6 @@ require "docomoru/version"
5
5
  require "active_support/core_ext/object/to_query"
6
6
  require "faraday"
7
7
  require "faraday_middleware"
8
- require "uri"
9
8
 
10
9
  module Docomoru
11
10
  class Client
@@ -20,7 +19,7 @@ module Docomoru
20
19
  include DialogueMethods
21
20
  include KnowledgeMethods
22
21
 
23
- # @param [String] api_key APIKEY issued from DoCoMo.
22
+ # @param [String] api_key API Key issued from docomo.
24
23
  def initialize(api_key: nil)
25
24
  @api_key = api_key
26
25
  end
@@ -55,7 +54,7 @@ module Docomoru
55
54
  Response.new(
56
55
  connection.send(
57
56
  request_method,
58
- URI.escape(path),
57
+ path,
59
58
  params,
60
59
  headers,
61
60
  )
@@ -2,10 +2,10 @@ module Docomoru
2
2
  module DialogueMethods
3
3
  PATH = "/dialogue/v1/dialogue"
4
4
 
5
- def create_dialogue(utt, params = {}, headers = {})
5
+ def create_dialogue(message, params = {}, headers = {})
6
6
  post(
7
7
  "#{PATH}?#{default_query_string}",
8
- params.merge(utt: utt),
8
+ params.merge(utt: message),
9
9
  headers,
10
10
  )
11
11
  end
@@ -2,9 +2,9 @@ module Docomoru
2
2
  module KnowledgeMethods
3
3
  PATH = "/knowledgeQA/v1/ask"
4
4
 
5
- def create_knowledge(q, params = {}, headers = {})
5
+ def create_knowledge(message, params = {}, headers = {})
6
6
  get(
7
- "#{PATH}?#{default_query_string}&q=#{q}",
7
+ "#{PATH}?#{default_query_string}&q=#{message}",
8
8
  params,
9
9
  headers,
10
10
  )
@@ -1,3 +1,3 @@
1
1
  module Docomoru
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,64 @@
1
+ require "active_support/core_ext/object/to_query"
2
+
3
+ RSpec.describe Docomoru::Client do
4
+ let(:client) do
5
+ described_class.new(api_key: api_key)
6
+ end
7
+
8
+ let(:api_key) do
9
+ "dummy"
10
+ end
11
+
12
+ describe "#create_dialogue" do
13
+ subject do
14
+ client.create_dialogue(message)
15
+ end
16
+
17
+ let(:message) do
18
+ "test"
19
+ end
20
+
21
+ let!(:stubbed_request) do
22
+ stub_request(
23
+ :post,
24
+ "https://api.apigw.smt.docomo.ne.jp/dialogue/v1/dialogue?" + {
25
+ APIKEY: api_key,
26
+ }.to_query,
27
+ ).with(
28
+ body: {
29
+ utt: message,
30
+ },
31
+ )
32
+ end
33
+
34
+ it "sends HTTP request with given message and API key to Dialogue API" do
35
+ is_expected.to be_a Docomoru::Response
36
+ expect(stubbed_request).to have_been_requested
37
+ end
38
+ end
39
+
40
+ describe "#create_knowledge" do
41
+ subject do
42
+ client.create_knowledge(message)
43
+ end
44
+
45
+ let(:message) do
46
+ "test"
47
+ end
48
+
49
+ let!(:stubbed_request) do
50
+ stub_request(
51
+ :get,
52
+ "https://api.apigw.smt.docomo.ne.jp/knowledgeQA/v1/ask?" + {
53
+ APIKEY: api_key,
54
+ q: message,
55
+ }.to_query,
56
+ )
57
+ end
58
+
59
+ it "sends HTTP request with given message and API key to Knowledge API" do
60
+ is_expected.to be_a Docomoru::Response
61
+ expect(stubbed_request).to have_been_requested
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,59 @@
1
+ RSpec.describe Docomoru::CommandBuilder do
2
+ let(:argv) do
3
+ []
4
+ end
5
+
6
+ let(:command_builder) do
7
+ described_class.new(argv)
8
+ end
9
+
10
+ describe "#build" do
11
+ subject do
12
+ command_builder.call.call
13
+ end
14
+
15
+ let(:dummy_response) do
16
+ double(
17
+ body: {},
18
+ headers: {},
19
+ status: 200,
20
+ status_message: "OK",
21
+ )
22
+ end
23
+
24
+ context "with unknown command line option" do
25
+ let(:argv) do
26
+ super() << "--unknown"
27
+ end
28
+
29
+ it "aborts with help message" do
30
+ expect_any_instance_of(Docomoru::Commands::Error).to receive(:abort)
31
+ subject
32
+ end
33
+ end
34
+
35
+ context "with create_dialogue" do
36
+ let(:argv) do
37
+ super() + %w[create_dialogue message --api-key dummy]
38
+ end
39
+
40
+ it "calls create_dialogue method" do
41
+ expect_any_instance_of(Docomoru::Commands::Request).to receive(:print)
42
+ expect_any_instance_of(Docomoru::Client).to receive(:create_dialogue).and_return(dummy_response)
43
+ subject
44
+ end
45
+ end
46
+
47
+ context "with create_knowledge" do
48
+ let(:argv) do
49
+ super() + %w[create_knowledge message --api-key dummy]
50
+ end
51
+
52
+ it "calls create_knowledge method" do
53
+ expect_any_instance_of(Docomoru::Commands::Request).to receive(:print)
54
+ expect_any_instance_of(Docomoru::Client).to receive(:create_knowledge).and_return(dummy_response)
55
+ subject
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,26 @@
1
+ if ENV["CI"]
2
+ require "codeclimate-test-reporter"
3
+ CodeClimate::TestReporter.start
4
+ end
5
+
6
+ require "docomoru"
7
+ require "webmock/rspec"
8
+
9
+ RSpec.configure do |config|
10
+ config.expect_with :rspec do |expectations|
11
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
12
+ end
13
+
14
+ config.mock_with :rspec do |mocks|
15
+ mocks.verify_partial_doubles = true
16
+ end
17
+
18
+ config.disable_monkey_patching!
19
+ config.filter_run :focus
20
+ config.run_all_when_everything_filtered = true
21
+ config.warnings = true
22
+
23
+ config.after(:suite) do
24
+ WebMock.disable_net_connect!(allow: "codeclimate.com")
25
+ end
26
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docomoru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-28 00:00:00.000000000 Z
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -109,33 +109,75 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.7'
111
111
  - !ruby/object:Gem::Dependency
112
- name: pry
112
+ name: codeclimate-test-reporter
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: 0.4.4
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: 0.4.4
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rake
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: '10.0'
131
+ version: 10.4.2
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 10.4.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 3.2.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 3.2.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 0.29.1
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 0.29.1
167
+ - !ruby/object:Gem::Dependency
168
+ name: webmock
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '='
172
+ - !ruby/object:Gem::Version
173
+ version: 1.20.4
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '='
137
179
  - !ruby/object:Gem::Version
138
- version: '10.0'
180
+ version: 1.20.4
139
181
  description:
140
182
  email:
141
183
  - r7kamura@gmail.com
@@ -145,6 +187,9 @@ extensions: []
145
187
  extra_rdoc_files: []
146
188
  files:
147
189
  - ".gitignore"
190
+ - ".rspec"
191
+ - ".rubocop.yml"
192
+ - ".travis.yml"
148
193
  - CHANGELOG.md
149
194
  - Gemfile
150
195
  - LICENSE.txt
@@ -165,6 +210,9 @@ files:
165
210
  - lib/docomoru/response.rb
166
211
  - lib/docomoru/response_renderer.rb
167
212
  - lib/docomoru/version.rb
213
+ - spec/docomoru/client_spec.rb
214
+ - spec/docomoru/command_builder_spec.rb
215
+ - spec/spec_helper.rb
168
216
  homepage: https://github.com/r7kamura/docomoru
169
217
  licenses:
170
218
  - MIT
@@ -185,9 +233,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
233
  version: '0'
186
234
  requirements: []
187
235
  rubyforge_project:
188
- rubygems_version: 2.2.2
236
+ rubygems_version: 2.4.5
189
237
  signing_key:
190
238
  specification_version: 4
191
239
  summary: Client library for docomo API written in Ruby.
192
- test_files: []
240
+ test_files:
241
+ - spec/docomoru/client_spec.rb
242
+ - spec/docomoru/command_builder_spec.rb
243
+ - spec/spec_helper.rb
193
244
  has_rdoc: