kokkai 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aa6a9f32a839a3b3c52c7f3084a40845912b4fe1e57d3f877363e84004b75761
4
+ data.tar.gz: 912c6e5eee3f26ab5e8596c705f7f1ab051c377a28ffe40cf14a1d96d2d4fdcb
5
+ SHA512:
6
+ metadata.gz: 3f972b3aa5fcf13368ddc9eadf37c045b2979af427ded8494fcc5dbdbefbc9f004834130cc0401b64ef618624c7b67bc45faf0d0d779c47ff80a1d10cc7113cf
7
+ data.tar.gz: 39afb09d5eb26a0752d366b805f575f078668eed081d109efe39091e7d1ceeb7d31e42f1a524c60af310678dedb0e4e08bf1fce3746a6f241af8b3078dd987e5
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/cassettes/
10
+ /tmp/
11
+ /vendor/
12
+ *.bundle
13
+ *.so
14
+ *.o
15
+ *.a
16
+ mkmf.log
17
+ .solargraph.yml
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in kokkai.gemspec
6
+ gemspec
@@ -0,0 +1,17 @@
1
+ # More info at https://github.com/guard/guard#readme
2
+ guard :rspec, cmd: "bundle exec rspec" do
3
+ require "guard/rspec/dsl"
4
+ dsl = Guard::RSpec::Dsl.new(self)
5
+
6
+ # RSpec files
7
+ rspec = dsl.rspec
8
+ watch(rspec.spec_helper) { rspec.spec_dir }
9
+ watch(rspec.spec_support) { rspec.spec_dir }
10
+ watch(rspec.spec_files)
11
+
12
+ # Ruby files
13
+ ruby = dsl.ruby
14
+ dsl.watch_spec_files_for(ruby.lib_files)
15
+
16
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
17
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 kimihito
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # Kokkai
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/kokkai`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'kokkai'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install kokkai
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kokkai.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kokkai"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "kokkai/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kokkai"
8
+ spec.version = Kokkai::VERSION
9
+ spec.authors = ["kimihito"]
10
+ spec.email = ["tatsurotamashiro@gmail.com"]
11
+
12
+ spec.summary = %q{http://kokkai.ndl.go.jp/api.html client library, written in Ruby}
13
+ spec.description = %q{http://kokkai.ndl.go.jp/api.html client library, written in Ruby}
14
+ spec.homepage = "https://github.com/kimihito/kokkai"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "faraday"
25
+ spec.add_dependency "faraday_middleware"
26
+ spec.add_dependency "multi_xml"
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "pry"
30
+ spec.add_development_dependency "rspec"
31
+ spec.add_development_dependency "webmock"
32
+ spec.add_development_dependency "vcr"
33
+ spec.add_development_dependency "guard"
34
+ spec.add_development_dependency "guard-rspec"
35
+ spec.add_development_dependency "rspec-nc"
36
+ end
@@ -0,0 +1,5 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+
4
+ require "kokkai/version"
5
+ require "kokkai/client"
@@ -0,0 +1,7 @@
1
+ module Kokkai
2
+ module ApiMethods
3
+ def speech(params = nil)
4
+ send_get("/api/1.0/speech", params)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,66 @@
1
+ require 'kokkai/errors'
2
+ require 'kokkai/api_methods'
3
+ require 'kokkai/response'
4
+
5
+ module Kokkai
6
+ class Client
7
+ include ApiMethods
8
+
9
+ def initialize
10
+ end
11
+
12
+ def send_get(path, params = nil)
13
+ send_request(:get, path, params)
14
+ end
15
+
16
+ def send_request(method, path, params = nil)
17
+ response = kokkai_connection.send(method, path, params)
18
+ Kokkai::Response.new(response)
19
+ end
20
+
21
+ def kokkai_connection
22
+ @kokkai_connection ||= Faraday.new(faraday_options) do |c|
23
+ c.request :url_encoded
24
+ c.response :xml, :content_type => /\bxml$/
25
+ c.adapter Faraday.default_adapter
26
+ c.options.params_encoder = ParamsEncoder
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def faraday_options
33
+ {
34
+ url: faraday_url,
35
+ headers: faraday_headers
36
+ }
37
+ end
38
+
39
+ def default_headers
40
+ {
41
+ 'Accept' => 'application/xml',
42
+ 'User-Agent' => "Kokkai Ruby Gem #{Kokkai::VERSION}"
43
+ }
44
+ end
45
+
46
+ def faraday_headers
47
+ default_headers
48
+ end
49
+
50
+ def faraday_url
51
+ 'http://kokkai.ndl.go.jp'
52
+ end
53
+ end
54
+
55
+ class ParamsEncoder
56
+ def self.encode(params)
57
+ str = params.map {|(key, value)|
58
+ "#{key}=#{value}"
59
+ }.join('&')
60
+ return ERB::Util.url_encode(str)
61
+ end
62
+
63
+ def self.to_query
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,31 @@
1
+ require 'kokkai/utils/string_formatter.rb'
2
+ require 'kokkai/speech'
3
+ module Kokkai
4
+ class Data
5
+ using Utils::StringFormatter
6
+
7
+ attr_reader :raw_data
8
+
9
+ ATTRIBUTES = %i(number_of_records number_of_return start_record next_record_position records).freeze
10
+
11
+ ATTRIBUTES.each do |attr|
12
+ define_method(attr) do
13
+ @raw_data ? @raw_data[attr.to_s.to_camel] : nil
14
+ end
15
+ end
16
+
17
+ def initialize(raw_data)
18
+ @raw_data = raw_data
19
+ end
20
+
21
+ def records
22
+ @raw_data.dig("records", "record").map { |attrs| classify(attrs["recordData"].keys[0]).new(attrs) }
23
+ end
24
+
25
+ private
26
+
27
+ def classify(name)
28
+ Object.const_get("Kokkai::#{name.gsub(/Record$/, '').to_pascal}")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ module Kokkai
2
+ class KokkaiError < StandardError; end
3
+ class ServiceUnavailableError < KokkaiError; end
4
+ end
@@ -0,0 +1,10 @@
1
+ require "kokkai/data"
2
+ module Kokkai
3
+ class Parser
4
+ attr_reader :raw_data, :data
5
+
6
+ def initialize(raw_data)
7
+ @data = Data.new(raw_data.dig("data"))
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,28 @@
1
+ require 'kokkai/utils/string_formatter.rb'
2
+ require 'pry'
3
+ module Kokkai
4
+ class Record
5
+ using Utils::StringFormatter
6
+
7
+ attr_reader :raw, :raw_record
8
+
9
+ DEFAULT_ATTRIBUTES = %i(session number_of_house name_of_meeting issue date meeting_url pdf_url).freeze
10
+
11
+ class << self
12
+ def define_attribute_methods(attrs)
13
+ attrs.each do |attr|
14
+ define_method(attr) do
15
+ @raw_record ? @raw_record[attr.to_s.to_camel] : nil
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ define_attribute_methods(DEFAULT_ATTRIBUTES)
22
+
23
+ def initialize(raw)
24
+ @raw = raw
25
+ @raw_record = @raw.dig("recordData")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ require "pry"
2
+ require "kokkai/parser"
3
+
4
+ module Kokkai
5
+ class Response
6
+ def initialize(faraday_response)
7
+ @raw_body = faraday_response.body
8
+ @raw_headers = faraday_response.headers
9
+ @raw_status = faraday_response.status
10
+ end
11
+
12
+ def body
13
+ Parser.new(@raw_body)
14
+ end
15
+
16
+ def headers
17
+ @headers ||= @raw_headers.inject({}) do |result, (key, value)|
18
+ result.merge(key.split("-").map(&:capitalize).join("-") => value)
19
+ end
20
+ end
21
+
22
+ def status
23
+ @raw_status
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ require 'kokkai/record'
2
+ module Kokkai
3
+ class Speech < Record
4
+ SPEECH_ATTRIBUTES = %i(speech_order speaker speech)
5
+
6
+ define_attribute_methods(SPEECH_ATTRIBUTES)
7
+ end
8
+ end
@@ -0,0 +1,37 @@
1
+ module Kokkai
2
+ module Utils
3
+ module StringFormatter
4
+ refine String do
5
+ def to_chain()
6
+ normalize().gsub(" ", "-")
7
+ end
8
+
9
+ def to_snake()
10
+ normalize().gsub(" ", "_")
11
+ end
12
+
13
+ def to_camel()
14
+ to_pascal().sub(/./) { $&.downcase }
15
+ end
16
+
17
+ def to_pascal()
18
+ normalize().split.map { |e| e.capitalize }.join
19
+ end
20
+
21
+ private
22
+ def normalize()
23
+ text = self
24
+ if text =~ / /
25
+ text.downcase
26
+ elsif text =~ /-/
27
+ text.gsub("-", " ").downcase
28
+ elsif text =~ /_/
29
+ text.gsub("_", " ").downcase
30
+ else
31
+ text.split(/(?=[A-Z])/).join(" ").downcase
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Kokkai
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,232 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kokkai
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kimihito
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
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_middleware
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: multi_xml
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.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: vcr
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rspec-nc
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: http://kokkai.ndl.go.jp/api.html client library, written in Ruby
182
+ email:
183
+ - tatsurotamashiro@gmail.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".gitignore"
189
+ - Gemfile
190
+ - Guardfile
191
+ - MIT-LICENSE
192
+ - README.md
193
+ - Rakefile
194
+ - bin/console
195
+ - bin/setup
196
+ - kokkai.gemspec
197
+ - lib/kokkai.rb
198
+ - lib/kokkai/api_methods.rb
199
+ - lib/kokkai/client.rb
200
+ - lib/kokkai/data.rb
201
+ - lib/kokkai/errors.rb
202
+ - lib/kokkai/parser.rb
203
+ - lib/kokkai/record.rb
204
+ - lib/kokkai/response.rb
205
+ - lib/kokkai/speech.rb
206
+ - lib/kokkai/utils/string_formatter.rb
207
+ - lib/kokkai/version.rb
208
+ homepage: https://github.com/kimihito/kokkai
209
+ licenses:
210
+ - MIT
211
+ metadata: {}
212
+ post_install_message:
213
+ rdoc_options: []
214
+ require_paths:
215
+ - lib
216
+ required_ruby_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ required_rubygems_version: !ruby/object:Gem::Requirement
222
+ requirements:
223
+ - - ">="
224
+ - !ruby/object:Gem::Version
225
+ version: '0'
226
+ requirements: []
227
+ rubyforge_project:
228
+ rubygems_version: 2.7.6
229
+ signing_key:
230
+ specification_version: 4
231
+ summary: http://kokkai.ndl.go.jp/api.html client library, written in Ruby
232
+ test_files: []