e-stat 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: af052d02b9384f91e053813038cd3a37d6227381
4
+ data.tar.gz: af45419db940d2cded082de1067e85b162b9f2b9
5
+ SHA512:
6
+ metadata.gz: 9a407c531781505d2f1f41ac89b968b165cdd57e8d34074b3b49f9be16081570777dc018f770d4c52c5a1fbabeaaaa01f22b23408d62b52105a7b8ea8a8585d5
7
+ data.tar.gz: 036baa059806e9885a836c1d8bf600f32a0d8ff574f72f5e2a109865fc8c2933002de0e88981d9787d49ef9e68d27d9c114932dbc8c322822d5e9c45c07a056d
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/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at TODO: Write your email address. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in e-stat.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ The MIT License (MIT)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # EStat
2
+
3
+ A Ruby wrapper for the e-Stat API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'e-stat'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install e-stat
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'e-stat'
25
+
26
+ EStat.configure do |config|
27
+ config.app_id = 'YOUR_APP_ID'
28
+ end
29
+
30
+ EStat.stats_list(openYears: '2016', statsCode: '00200502', searchKind: '3', statsNameList: 'Y')
31
+ ```
32
+
33
+
34
+ ```ruby
35
+ require 'e-stat'
36
+
37
+ client = EStat::Client.new(app_id: 'YOUR_APP_ID')
38
+ list = client.stats_list(openYears: '2016', statsCode: '00200502', searchKind: '3')
39
+ stats = client.stats_data(statsDataId: list['GET_STATS_LIST']['DATALIST_INF']['TABLE_INF'][0]['@id'])
40
+ ```
41
+
42
+ ## Test
43
+
44
+ ```
45
+ $ export APP_ID=YOUR_APP_ID
46
+ $ bundle exec rspec spec
47
+ ```
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "e-stat"
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
@@ -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
data/e-stat.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'e-stat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "e-stat"
8
+ spec.version = EStat::VERSION
9
+ spec.authors = ["shimada227"]
10
+ spec.email = ["yoshihiro.shimada@coconala.com"]
11
+
12
+ spec.summary = %q{A Ruby wrapper for the e-Stat API}
13
+ spec.description = %q{A Ruby wrapper for the e-Stat API}
14
+ spec.homepage = "https://github.com/yshimada0330/e-stat"
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_runtime_dependency "faraday", [">= 0.7", "< 0.10"]
23
+ spec.add_runtime_dependency "faraday_middleware", "~> 0.8"
24
+ spec.add_development_dependency "bundler", "~> 1.11"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "webmock"
28
+ spec.add_development_dependency "vcr"
29
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../connection', __FILE__)
2
+ require File.expand_path('../request', __FILE__)
3
+ require File.expand_path('../configuration', __FILE__)
4
+ require File.expand_path('../endpoint', __FILE__)
5
+
6
+ module EStat
7
+ class Client
8
+ attr_accessor(*Configuration::OPTIONS_KEYS)
9
+
10
+ def initialize(options = {})
11
+ options = EStat.options.merge(options)
12
+ Configuration::OPTIONS_KEYS.each do |key|
13
+ send("#{key}=", options[key])
14
+ end
15
+ end
16
+
17
+ include Connection
18
+ include Request
19
+ include Endpoint
20
+
21
+ def endpoint
22
+ return base_url if format.nil?
23
+
24
+ "#{base_url}/#{format}"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,45 @@
1
+ require 'faraday'
2
+
3
+ module EStat
4
+ module Configuration
5
+ OPTIONS_KEYS = [:app_id, :lang, :version, :format, :base_url, :adapter].freeze
6
+
7
+ DEFAULT_APP_ID = nil
8
+
9
+ # J or E. defulat 'J'
10
+ DEFAULT_LANG = nil
11
+
12
+ DEFAULT_VERSION = '2.0'
13
+
14
+ DEFAULT_FORMAT = 'json'
15
+
16
+ DEFAULT_BASE_URL = 'http://api.e-stat.go.jp/rest/'.freeze
17
+
18
+ DEFAULT_ADAPTER = Faraday.default_adapter
19
+
20
+ attr_accessor *OPTIONS_KEYS
21
+
22
+ def self.extended(base)
23
+ base.reset
24
+ end
25
+
26
+ def configure
27
+ yield self
28
+ end
29
+
30
+ def options
31
+ OPTIONS_KEYS.inject({}) do |option, key|
32
+ option.merge!(key => send(key))
33
+ end
34
+ end
35
+
36
+ def reset
37
+ self.app_id = DEFAULT_APP_ID
38
+ self.lang = DEFAULT_LANG
39
+ self.version = DEFAULT_VERSION
40
+ self.format = DEFAULT_FORMAT
41
+ self.base_url = "#{DEFAULT_BASE_URL}#{DEFAULT_VERSION}/app"
42
+ self.adapter = DEFAULT_ADAPTER
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,22 @@
1
+ require 'faraday_middleware'
2
+
3
+ module EStat
4
+ module Connection
5
+
6
+ private
7
+
8
+ def connection
9
+ options = {
10
+ :headers => { 'Accept': 'application/json; charset=utf-8' },
11
+ :url => endpoint,
12
+ }
13
+
14
+ Faraday::Connection.new(options) do |connection|
15
+ connection.use Faraday::Request::Multipart
16
+ connection.use Faraday::Request::UrlEncoded
17
+ connection.use Faraday::Response::ParseJson
18
+ connection.adapter(adapter)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ module EStat
2
+ module Endpoint
3
+ def stats_list(params = {})
4
+ get('getStatsList', params)
5
+ end
6
+
7
+ def meta_info(params = {})
8
+ get('getMetaInfo', params)
9
+ end
10
+
11
+ def stats_data(params = {})
12
+ get('getStatsData', params)
13
+ end
14
+
15
+ def post_dataset(params = {})
16
+ post('postDataset', params)
17
+ end
18
+
19
+ def ref_dataset(params = {})
20
+ get('refDataset', params)
21
+ end
22
+
23
+ def data_catalog(params = {})
24
+ get('getDataCatalog', params)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ module EStat
2
+ module Request
3
+ def get(path, options={})
4
+ request(:get, path, options)
5
+ end
6
+
7
+ def post(path, options={})
8
+ request(:post, path, options)
9
+ end
10
+
11
+ private
12
+
13
+ def request(method, path, options)
14
+ options = options.merge(appId: app_id)
15
+ response = connection.send(method) do |request|
16
+ case method
17
+ when :get, :delete
18
+ request.url(path, options)
19
+ when :post, :put
20
+ request.path = path
21
+ request.body = options unless options.empty?
22
+ end
23
+ end
24
+ return response.body
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module EStat
2
+ VERSION = "0.1.0"
3
+ end
data/lib/e-stat.rb ADDED
@@ -0,0 +1,20 @@
1
+ require_relative 'e-stat/configuration'
2
+ require_relative 'e-stat/client'
3
+ require_relative 'e-stat/version'
4
+
5
+ module EStat
6
+ extend Configuration
7
+
8
+ def self.client(options = {})
9
+ EStat::Client.new(options)
10
+ end
11
+
12
+ def self.method_missing(method, *args, &block)
13
+ return super unless client.respond_to?(method)
14
+ client.send(method, *args, &block)
15
+ end
16
+
17
+ def self.respond_to?(method, include_all = false)
18
+ return client.respond_to?(method, include_all) || super
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: e-stat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - shimada227
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-07 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.7'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '0.10'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0.7'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.10'
33
+ - !ruby/object:Gem::Dependency
34
+ name: faraday_middleware
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.8'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.8'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.11'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.11'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: webmock
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: vcr
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ description: A Ruby wrapper for the e-Stat API
118
+ email:
119
+ - yoshihiro.shimada@coconala.com
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files: []
123
+ files:
124
+ - ".gitignore"
125
+ - ".rspec"
126
+ - ".travis.yml"
127
+ - CODE_OF_CONDUCT.md
128
+ - Gemfile
129
+ - LICENSE.txt
130
+ - README.md
131
+ - Rakefile
132
+ - bin/console
133
+ - bin/setup
134
+ - e-stat.gemspec
135
+ - lib/e-stat.rb
136
+ - lib/e-stat/client.rb
137
+ - lib/e-stat/configuration.rb
138
+ - lib/e-stat/connection.rb
139
+ - lib/e-stat/endpoint.rb
140
+ - lib/e-stat/request.rb
141
+ - lib/e-stat/version.rb
142
+ homepage: https://github.com/yshimada0330/e-stat
143
+ licenses:
144
+ - MIT
145
+ metadata: {}
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubyforge_project:
162
+ rubygems_version: 2.4.5.1
163
+ signing_key:
164
+ specification_version: 4
165
+ summary: A Ruby wrapper for the e-Stat API
166
+ test_files: []