gbizinfo-ruby 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.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +19 -0
  3. data/.gitignore +6 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +23 -0
  6. data/CHANGELOG.md +5 -0
  7. data/Gemfile +3 -0
  8. data/LICENSE +21 -0
  9. data/README.md +55 -0
  10. data/Rakefile +10 -0
  11. data/gbizinfo-ruby.gemspec +31 -0
  12. data/lib/gbizinfo/api/endpoints/hojin.rb +18 -0
  13. data/lib/gbizinfo/api/endpoints/hojin_certification.rb +18 -0
  14. data/lib/gbizinfo/api/endpoints/hojin_commendation.rb +18 -0
  15. data/lib/gbizinfo/api/endpoints/hojin_finance.rb +18 -0
  16. data/lib/gbizinfo/api/endpoints/hojin_patent.rb +18 -0
  17. data/lib/gbizinfo/api/endpoints/hojin_procurement.rb +18 -0
  18. data/lib/gbizinfo/api/endpoints/hojin_search.rb +75 -0
  19. data/lib/gbizinfo/api/endpoints/hojin_subsidy.rb +18 -0
  20. data/lib/gbizinfo/api/endpoints/hojin_update_info.rb +23 -0
  21. data/lib/gbizinfo/api/endpoints/hojin_update_info_certification.rb +23 -0
  22. data/lib/gbizinfo/api/endpoints/hojin_update_info_commendation.rb +23 -0
  23. data/lib/gbizinfo/api/endpoints/hojin_update_info_finance.rb +23 -0
  24. data/lib/gbizinfo/api/endpoints/hojin_update_info_patent.rb +23 -0
  25. data/lib/gbizinfo/api/endpoints/hojin_update_info_procurement.rb +23 -0
  26. data/lib/gbizinfo/api/endpoints/hojin_update_info_subsidy.rb +23 -0
  27. data/lib/gbizinfo/api/endpoints/hojin_update_info_workplace.rb +23 -0
  28. data/lib/gbizinfo/api/endpoints/hojin_workplace.rb +18 -0
  29. data/lib/gbizinfo/api/endpoints.rb +41 -0
  30. data/lib/gbizinfo/api/error.rb +73 -0
  31. data/lib/gbizinfo/client.rb +27 -0
  32. data/lib/gbizinfo/config.rb +33 -0
  33. data/lib/gbizinfo/faraday/connection.rb +25 -0
  34. data/lib/gbizinfo/faraday/request.rb +27 -0
  35. data/lib/gbizinfo/version.rb +5 -0
  36. data/lib/gbizinfo.rb +11 -0
  37. metadata +178 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1e8d7dcfab1378f851b365b6ba7059b19a86520627ebc408230dd96d715e684d
4
+ data.tar.gz: e590d4be152b21ff38be9538109fa4f8d377d03b0b472625c58ae49fe1e67ab5
5
+ SHA512:
6
+ metadata.gz: 61621947e210f41d42c1c9abdb287c66018bdd6875e49fc60b9170daf9399bc25b868f9562c46c268c2a6b43cbf5483c05aa4c431c77527c9d35b9feb92b0d2e
7
+ data.tar.gz: 8920be6dfbc6bd2edee46baf444b511245ead25a1a992195488de1c0cb699cca968014c9a49e69fe00dbddadee8f21d8645b035bb30c57c6f792899eed8855e7
@@ -0,0 +1,19 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby 3.0
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: 3.0
18
+ bundler-cache: true
19
+ - run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ /.bundle/
2
+ /vendor/bundle
3
+ Gemfile.lock
4
+ log
5
+ .env
6
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - spec/**/*.rb
7
+ - '*.gemspec'
8
+
9
+ Metrics/CyclomaticComplexity:
10
+ Exclude:
11
+ - lib/gbizinfo/api/error.rb
12
+
13
+ Metrics/MethodLength:
14
+ Max: 20
15
+
16
+ Style/FrozenStringLiteralComment:
17
+ Enabled: false
18
+
19
+ Style/Documentation:
20
+ Enabled: false
21
+
22
+ Style/ModuleFunction:
23
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-12-15
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Ryoma Ono
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,55 @@
1
+ # gBizINFO Ruby Client
2
+
3
+ [![CI](https://github.com/ryoma123/gbizinfo-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/ryoma123/gbizinfo-ruby/actions/workflows/ci.yml)
4
+
5
+ A Ruby client for gBizINFO APIs.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gbizinfo-ruby'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gbizinfo-ruby
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ client = Gbizinfo::Client.new(
27
+ token: 'xxxxxxxxxx'
28
+ )
29
+
30
+ # Search for a corporation
31
+ options = { name: '経済産業省' }
32
+ client.hojin_search(options)
33
+
34
+ # Fetch corporate information
35
+ client.hojin(corporate_number: '4000012090001')
36
+ ```
37
+
38
+ ### Global Settings
39
+
40
+ The following global settings are supported via `Gbizinfo.configure`.
41
+
42
+ setting | description
43
+ --------------------|-------------------------------------------------------------------------------------------------
44
+ token | gBizINFO API token.
45
+ user_agent | User-agent.
46
+ endpoint | gBizINFO API endpoint.
47
+ adapter | Optional HTTP adapter to use, defaults to `Faraday.default_adapter`.
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ryoma123/gbizinfo-ruby.
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require 'rubocop/rake_task'
7
+
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: %i[spec rubocop]
@@ -0,0 +1,31 @@
1
+ require_relative 'lib/gbizinfo/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'gbizinfo-ruby'
5
+ spec.version = Gbizinfo::VERSION
6
+ spec.authors = ['ryoma123']
7
+ spec.email = ['ryoma.ono.2661@gmail.com']
8
+ spec.summary = 'gBizINFO API client for Ruby.'
9
+ spec.description = 'gBizINFO API client for Ruby.'
10
+ spec.homepage = 'https://github.com/ryoma123/gbizinfo-ruby'
11
+ spec.license = 'MIT'
12
+ spec.required_ruby_version = '>= 3.0.3'
13
+
14
+ spec.metadata['source_code_uri'] = 'https://github.com/ryoma123/gbizinfo-ruby'
15
+ spec.metadata['changelog_uri'] = 'https://github.com/ryoma123/gbizinfo-ruby/blob/master/CHANGELOG.md'
16
+
17
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'faraday'
25
+ spec.add_dependency 'faraday_middleware'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'rubocop'
29
+ spec.add_development_dependency 'vcr'
30
+ spec.add_development_dependency 'webmock'
31
+ end
@@ -0,0 +1,18 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module Hojin
5
+ #
6
+ # Returns the basic information of a given corporate number.
7
+ #
8
+ # @param [String] :corporate_number
9
+ # A corporate number.
10
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
11
+ def hojin(corporate_number:)
12
+ throw ArgumentError.new('Required arguments :corporate_number missing') if corporate_number.nil?
13
+ get("hojin/#{corporate_number}")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinCertification
5
+ #
6
+ # Returns basic corporate information of a given corporate number.
7
+ #
8
+ # @param [String] :corporate_number
9
+ # A corporate number.
10
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
11
+ def hojin_certification(corporate_number:)
12
+ throw ArgumentError.new('Required arguments :corporate_number missing') if corporate_number.nil?
13
+ get("hojin/#{corporate_number}/certification")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinCommendation
5
+ #
6
+ # Returns the commendation information of a given corporate number.
7
+ #
8
+ # @param [String] :corporate_number
9
+ # A corporate number.
10
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
11
+ def hojin_commendation(corporate_number:)
12
+ throw ArgumentError.new('Required arguments :corporate_number missing') if corporate_number.nil?
13
+ get("hojin/#{corporate_number}/commendation")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinFinance
5
+ #
6
+ # Returns the financial information of a given corporate number.
7
+ #
8
+ # @param [String] :corporate_number
9
+ # A corporate number.
10
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
11
+ def hojin_finance(corporate_number:)
12
+ throw ArgumentError.new('Required arguments :corporate_number missing') if corporate_number.nil?
13
+ get("hojin/#{corporate_number}/finance")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinPatent
5
+ #
6
+ # Returns the patent information of a given corporate number.
7
+ #
8
+ # @param [String] :corporate_number
9
+ # A corporate number.
10
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
11
+ def hojin_patent(corporate_number:)
12
+ throw ArgumentError.new('Required arguments :corporate_number missing') if corporate_number.nil?
13
+ get("hojin/#{corporate_number}/patent")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinProcurement
5
+ #
6
+ # Returns the procurement information of a given corporate number.
7
+ #
8
+ # @param [String] :corporate_number
9
+ # A corporate number.
10
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
11
+ def hojin_procurement(corporate_number:)
12
+ throw ArgumentError.new('Required arguments :corporate_number missing') if corporate_number.nil?
13
+ get("hojin/#{corporate_number}/procurement")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,75 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinSearch
5
+ #
6
+ # Search for corporate information registered in gBizINFO.
7
+ #
8
+ # @option options [String] :corporate_number
9
+ # A corporate number.
10
+ # @option options [String] :name
11
+ # A corporate name.
12
+ # @option options [String] :exist_flg
13
+ # A corporate activity information.
14
+ # @option options [String] :corporate_type
15
+ # A corporate type.
16
+ # @option options [String] :prefecture
17
+ # A location prefecture.
18
+ # @option options [String] :city
19
+ # A location city.
20
+ # @option options [String] :capital_stock_from
21
+ # A lower limit of capital.
22
+ # @option options [String] :capital_stock_to
23
+ # An upper limit of capital.
24
+ # @option options [String] :employee_number_from
25
+ # A lower limit of the number of employees.
26
+ # @option options [String] :employee_number_to
27
+ # A maximum number of employees.
28
+ # @option options [String] :founded_year
29
+ # A year of establishment.
30
+ # @option options [String] :sales_area
31
+ # A business area.
32
+ # @option options [String] :business_item
33
+ # A business items.
34
+ # @option options [String] :unified_qualification
35
+ # A government unified participation qualification.
36
+ # @option options [String] :net_sales_summary_of_business_results_from
37
+ # A lower limit of sales.
38
+ # @option options [String] :net_sales_summary_of_business_results_to
39
+ # An upper limit of sales.
40
+ # @option options [String] :net_income_loss_summary_of_business_results_from
41
+ # A lower limit of net income or net loss.
42
+ # @option options [String] :net_income_loss_summary_of_business_results_to
43
+ # An upper limit of net income or net loss.
44
+ # @option options [String] :total_assets_summary_of_business_results_from
45
+ # A lower limit of total assets.
46
+ # @option options [String] :total_assets_summary_of_business_results_to
47
+ # A set an upper limit for total assets.
48
+ # @option options [String] :name_major_shareholders
49
+ # A major shareholder name.
50
+ # @option options [String] :average_continuous_service_years
51
+ # An average number of years of continuous service.
52
+ # @option options [String] :average_age
53
+ # An average age of employees.
54
+ # @option options [String] :month_average_predetermined_overtime_hours
55
+ # A monthly average overtime hours.
56
+ # @option options [String] :female_workers_proportion
57
+ # A percentage of female workers among workers.
58
+ # @option options [String] :year
59
+ # The year.
60
+ # @option options [String] :ministry
61
+ # A ministry in charge.
62
+ # @option options [String] :source
63
+ # A source.
64
+ # @option options [String] :page
65
+ # A number of pages in search results.
66
+ # @option options [String] :limit
67
+ # A number of search results per page.
68
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
69
+ def hojin_search(options = {})
70
+ get('hojin', options)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,18 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinSubsidy
5
+ #
6
+ # Returns the subsidy information of a given corporate number.
7
+ #
8
+ # @param [String] :corporate_number
9
+ # A corporate number.
10
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
11
+ def hojin_subsidy(corporate_number:)
12
+ throw ArgumentError.new('Required arguments :corporate_number missing') if corporate_number.nil?
13
+ get("hojin/#{corporate_number}/subsidy")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinUpdateInfo
5
+ #
6
+ # Returns basic corporate information added or updated within a given period.
7
+ #
8
+ # @option options [String] :from
9
+ # Start date to retrieve the corporate information for, expressed as yyyyMMdd.
10
+ # @option options [String] :to
11
+ # End date to retrieve the corporate information for, expressed as yyyyMMdd.
12
+ # @option options [String] :limit
13
+ # Number of pages in search results.
14
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
15
+ def hojin_update_info(options = {})
16
+ throw ArgumentError.new('Required arguments :from missing') if options[:from].nil?
17
+ throw ArgumentError.new('Required arguments :to missing') if options[:to].nil?
18
+ get('hojin/updateInfo', options)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinUpdateInfoCertification
5
+ #
6
+ # Returns basic corporate information added or updated within a given period.
7
+ #
8
+ # @option options [String] :from
9
+ # Start date to retrieve the corporate information for, expressed as yyyyMMdd.
10
+ # @option options [String] :to
11
+ # End date to retrieve the corporate information for, expressed as yyyyMMdd.
12
+ # @option options [String] :limit
13
+ # Number of pages in search results.
14
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
15
+ def hojin_update_info_certification(options = {})
16
+ throw ArgumentError.new('Required arguments :from missing') if options[:from].nil?
17
+ throw ArgumentError.new('Required arguments :to missing') if options[:to].nil?
18
+ get('hojin/updateInfo/certification', options)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinUpdateInfoCommendation
5
+ #
6
+ # Returns the commendation information added or updated within a given period.
7
+ #
8
+ # @option options [String] :from
9
+ # Start date to retrieve the corporate information for, expressed as yyyyMMdd.
10
+ # @option options [String] :to
11
+ # End date to retrieve the corporate information for, expressed as yyyyMMdd.
12
+ # @option options [String] :limit
13
+ # Number of pages in search results.
14
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
15
+ def hojin_update_info_commendation(options = {})
16
+ throw ArgumentError.new('Required arguments :from missing') if options[:from].nil?
17
+ throw ArgumentError.new('Required arguments :to missing') if options[:to].nil?
18
+ get('hojin/updateInfo/commendation', options)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinUpdateInfoFinance
5
+ #
6
+ # Returns the financial information added or updated within a given period.
7
+ #
8
+ # @option options [String] :from
9
+ # Start date to retrieve the corporate information for, expressed as yyyyMMdd.
10
+ # @option options [String] :to
11
+ # End date to retrieve the corporate information for, expressed as yyyyMMdd.
12
+ # @option options [String] :limit
13
+ # Number of pages in search results.
14
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
15
+ def hojin_update_info_finance(options = {})
16
+ throw ArgumentError.new('Required arguments :from missing') if options[:from].nil?
17
+ throw ArgumentError.new('Required arguments :to missing') if options[:to].nil?
18
+ get('hojin/updateInfo/finance', options)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinUpdateInfoPatent
5
+ #
6
+ # Returns the patent information added or updated within a given period.
7
+ #
8
+ # @option options [String] :from
9
+ # Start date to retrieve the corporate information for, expressed as yyyyMMdd.
10
+ # @option options [String] :to
11
+ # End date to retrieve the corporate information for, expressed as yyyyMMdd.
12
+ # @option options [String] :limit
13
+ # Number of pages in search results.
14
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
15
+ def hojin_update_info_patent(options = {})
16
+ throw ArgumentError.new('Required arguments :from missing') if options[:from].nil?
17
+ throw ArgumentError.new('Required arguments :to missing') if options[:to].nil?
18
+ get('hojin/updateInfo/patent', options)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinUpdateInfoProcurement
5
+ #
6
+ # Returns the procurement information added or updated within a given period.
7
+ #
8
+ # @option options [String] :from
9
+ # Start date to retrieve the corporate information for, expressed as yyyyMMdd.
10
+ # @option options [String] :to
11
+ # End date to retrieve the corporate information for, expressed as yyyyMMdd.
12
+ # @option options [String] :limit
13
+ # Number of pages in search results.
14
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
15
+ def hojin_update_info_procurement(options = {})
16
+ throw ArgumentError.new('Required arguments :from missing') if options[:from].nil?
17
+ throw ArgumentError.new('Required arguments :to missing') if options[:to].nil?
18
+ get('hojin/updateInfo/procurement', options)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinUpdateInfoSubsidy
5
+ #
6
+ # Returns the subsidy information added or updated within a given period.
7
+ #
8
+ # @option options [String] :from
9
+ # Start date to retrieve the corporate information for, expressed as yyyyMMdd.
10
+ # @option options [String] :to
11
+ # End date to retrieve the corporate information for, expressed as yyyyMMdd.
12
+ # @option options [String] :limit
13
+ # Number of pages in search results.
14
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
15
+ def hojin_update_info_subsidy(options = {})
16
+ throw ArgumentError.new('Required arguments :from missing') if options[:from].nil?
17
+ throw ArgumentError.new('Required arguments :to missing') if options[:to].nil?
18
+ get('hojin/updateInfo/subsidy', options)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinUpdateInfoWorkplace
5
+ #
6
+ # Returns the workplace information added or updated within a given period.
7
+ #
8
+ # @option options [String] :from
9
+ # Start date to retrieve the corporate information for, expressed as yyyyMMdd.
10
+ # @option options [String] :to
11
+ # End date to retrieve the corporate information for, expressed as yyyyMMdd.
12
+ # @option options [String] :limit
13
+ # Number of pages in search results.
14
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
15
+ def hojin_update_info_workplace(options = {})
16
+ throw ArgumentError.new('Required arguments :from missing') if options[:from].nil?
17
+ throw ArgumentError.new('Required arguments :to missing') if options[:to].nil?
18
+ get('hojin/updateInfo/workplace', options)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ module Gbizinfo
2
+ module Api
3
+ module Endpoints
4
+ module HojinWorkplace
5
+ #
6
+ # Returns the workplace information of a given corporate number.
7
+ #
8
+ # @param [String] :corporate_number
9
+ # A corporate number.
10
+ # @see https://info.gbiz.go.jp/hojin/swagger-ui.html
11
+ def hojin_workplace(corporate_number:)
12
+ throw ArgumentError.new('Required arguments :corporate_number missing') if corporate_number.nil?
13
+ get("hojin/#{corporate_number}/workplace")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,41 @@
1
+ require_relative 'endpoints/hojin'
2
+ require_relative 'endpoints/hojin_certification'
3
+ require_relative 'endpoints/hojin_commendation'
4
+ require_relative 'endpoints/hojin_finance'
5
+ require_relative 'endpoints/hojin_patent'
6
+ require_relative 'endpoints/hojin_procurement'
7
+ require_relative 'endpoints/hojin_search'
8
+ require_relative 'endpoints/hojin_subsidy'
9
+ require_relative 'endpoints/hojin_update_info'
10
+ require_relative 'endpoints/hojin_update_info_certification'
11
+ require_relative 'endpoints/hojin_update_info_commendation'
12
+ require_relative 'endpoints/hojin_update_info_finance'
13
+ require_relative 'endpoints/hojin_update_info_patent'
14
+ require_relative 'endpoints/hojin_update_info_procurement'
15
+ require_relative 'endpoints/hojin_update_info_subsidy'
16
+ require_relative 'endpoints/hojin_update_info_workplace'
17
+ require_relative 'endpoints/hojin_workplace'
18
+
19
+ module Gbizinfo
20
+ module Api
21
+ module Endpoints
22
+ include Hojin
23
+ include HojinCertification
24
+ include HojinCommendation
25
+ include HojinFinance
26
+ include HojinPatent
27
+ include HojinProcurement
28
+ include HojinSearch
29
+ include HojinSubsidy
30
+ include HojinUpdateInfo
31
+ include HojinUpdateInfoCertification
32
+ include HojinUpdateInfoCommendation
33
+ include HojinUpdateInfoFinance
34
+ include HojinUpdateInfoPatent
35
+ include HojinUpdateInfoProcurement
36
+ include HojinUpdateInfoSubsidy
37
+ include HojinUpdateInfoWorkplace
38
+ include HojinWorkplace
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,73 @@
1
+ module Gbizinfo
2
+ module Api
3
+ class Error < StandardError
4
+ def self.from_response(response)
5
+ klass =
6
+ case response.status
7
+ when 400 then Gbizinfo::Api::BadRequest
8
+ when 401 then Gbizinfo::Api::Unauthorized
9
+ when 403 then Gbizinfo::Api::Forbidden
10
+ when 404 then Gbizinfo::Api::NotFound
11
+ when 400..499 then Gbizinfo::Api::ClientError
12
+ when 500 then Gbizinfo::Api::InternalServerError
13
+ when 502 then Gbizinfo::Api::BadGateway
14
+ when 503 then Gbizinfo::Api::ServiceUnavailable
15
+ when 500..599 then Gbizinfo::Api::ServerError
16
+ end
17
+ klass&.new(response)
18
+ end
19
+
20
+ def initialize(response = nil)
21
+ @response = response
22
+ super(build_error_message)
23
+ end
24
+
25
+ private
26
+
27
+ def build_error_message
28
+ return nil if @response.nil?
29
+
30
+ message = "#{@response.env.method.upcase} #{@response.env.url}"
31
+ message << " status_code: #{@response.status}" unless @response.status.nil?
32
+ message << " body: #{@response.body}" unless @response.body.nil?
33
+ message
34
+ end
35
+ end
36
+
37
+ # A 4xx class HTTP error occurred.
38
+ class ClientError < Error
39
+ end
40
+
41
+ # A 400 HTTP error occurred.
42
+ class BadRequest < ClientError
43
+ end
44
+
45
+ # A 401 HTTP error occurred.
46
+ class Unauthorized < ClientError
47
+ end
48
+
49
+ # A 403 HTTP error occurred.
50
+ class Forbidden < ClientError
51
+ end
52
+
53
+ # A 404 HTTP error occurred.
54
+ class NotFound < ClientError
55
+ end
56
+
57
+ # A 5xx class HTTP error occurred.
58
+ class ServerError < Error
59
+ end
60
+
61
+ # A 500 HTTP error occurred.
62
+ class InternalServerError < ServerError
63
+ end
64
+
65
+ # A 502 HTTP error occurred.
66
+ class BadGateway < ServerError
67
+ end
68
+
69
+ # A 503 HTTP error occurred.
70
+ class ServiceUnavailable < ServerError
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,27 @@
1
+ module Gbizinfo
2
+ class Client
3
+ include Faraday::Connection
4
+ include Faraday::Request
5
+ include Api::Endpoints
6
+
7
+ attr_accessor(*Config::ATTRIBUTES)
8
+
9
+ def initialize(options = {})
10
+ Gbizinfo::Config::ATTRIBUTES.each do |key|
11
+ send("#{key}=", options.fetch(key, Gbizinfo.config.send(key)))
12
+ end
13
+
14
+ @token ||= Gbizinfo.config.token
15
+ end
16
+
17
+ class << self
18
+ def configure
19
+ block_given? ? yield(Config) : Config
20
+ end
21
+
22
+ def config
23
+ Config
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ module Gbizinfo
2
+ module Config
3
+ extend self
4
+
5
+ ATTRIBUTES = %i[
6
+ user_agent
7
+ endpoint
8
+ token
9
+ adapter
10
+ ].freeze
11
+
12
+ attr_accessor(*Config::ATTRIBUTES)
13
+
14
+ def reset
15
+ self.endpoint = 'https://info.gbiz.go.jp/hojin/v1/'
16
+ self.user_agent = "gBizINFO Ruby Client/#{Gbizinfo::VERSION}"
17
+ self.token = nil
18
+ self.adapter = ::Faraday.default_adapter
19
+ end
20
+ end
21
+
22
+ class << self
23
+ def configure
24
+ block_given? ? yield(Config) : Config
25
+ end
26
+
27
+ def config
28
+ Config
29
+ end
30
+ end
31
+ end
32
+
33
+ Gbizinfo::Config.reset
@@ -0,0 +1,25 @@
1
+ module Gbizinfo
2
+ module Faraday
3
+ module Connection
4
+ private
5
+
6
+ def connection
7
+ @connection ||=
8
+ begin
9
+ headers = {
10
+ 'Accept' => 'application/json'
11
+ }
12
+
13
+ headers['User-Agent'] = user_agent if user_agent
14
+ headers['X-hojinInfo-api-token'] = token if token
15
+
16
+ ::Faraday.new(endpoint, headers: headers) do |builder|
17
+ builder.request :url_encoded
18
+ builder.response :json
19
+ builder.adapter ::Faraday.default_adapter
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ module Gbizinfo
2
+ module Faraday
3
+ module Request
4
+ def get(path, options = {})
5
+ request(:get, path, options)
6
+ end
7
+
8
+ private
9
+
10
+ def request(method, path, options)
11
+ response = connection.send(method) do |request|
12
+ request.url(path, options)
13
+ request.options.merge!(options.delete(:request)) if options.key?(:request)
14
+ end
15
+
16
+ fail_or_return_response_body(response)
17
+ end
18
+
19
+ def fail_or_return_response_body(response)
20
+ error = Gbizinfo::Api::Error.from_response(response)
21
+ raise(error) if error
22
+
23
+ response.body
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gbizinfo
4
+ VERSION = '0.1.0'
5
+ end
data/lib/gbizinfo.rb ADDED
@@ -0,0 +1,11 @@
1
+ require_relative 'gbizinfo/version'
2
+
3
+ require 'faraday'
4
+ require 'faraday_middleware'
5
+
6
+ require_relative 'gbizinfo/config'
7
+ require_relative 'gbizinfo/faraday/connection'
8
+ require_relative 'gbizinfo/faraday/request'
9
+ require_relative 'gbizinfo/api/endpoints'
10
+ require_relative 'gbizinfo/api/error'
11
+ require_relative 'gbizinfo/client'
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gbizinfo-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ryoma123
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-12-15 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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
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: vcr
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: webmock
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
+ description: gBizINFO API client for Ruby.
112
+ email:
113
+ - ryoma.ono.2661@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".github/workflows/ci.yml"
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".rubocop.yml"
122
+ - CHANGELOG.md
123
+ - Gemfile
124
+ - LICENSE
125
+ - README.md
126
+ - Rakefile
127
+ - gbizinfo-ruby.gemspec
128
+ - lib/gbizinfo.rb
129
+ - lib/gbizinfo/api/endpoints.rb
130
+ - lib/gbizinfo/api/endpoints/hojin.rb
131
+ - lib/gbizinfo/api/endpoints/hojin_certification.rb
132
+ - lib/gbizinfo/api/endpoints/hojin_commendation.rb
133
+ - lib/gbizinfo/api/endpoints/hojin_finance.rb
134
+ - lib/gbizinfo/api/endpoints/hojin_patent.rb
135
+ - lib/gbizinfo/api/endpoints/hojin_procurement.rb
136
+ - lib/gbizinfo/api/endpoints/hojin_search.rb
137
+ - lib/gbizinfo/api/endpoints/hojin_subsidy.rb
138
+ - lib/gbizinfo/api/endpoints/hojin_update_info.rb
139
+ - lib/gbizinfo/api/endpoints/hojin_update_info_certification.rb
140
+ - lib/gbizinfo/api/endpoints/hojin_update_info_commendation.rb
141
+ - lib/gbizinfo/api/endpoints/hojin_update_info_finance.rb
142
+ - lib/gbizinfo/api/endpoints/hojin_update_info_patent.rb
143
+ - lib/gbizinfo/api/endpoints/hojin_update_info_procurement.rb
144
+ - lib/gbizinfo/api/endpoints/hojin_update_info_subsidy.rb
145
+ - lib/gbizinfo/api/endpoints/hojin_update_info_workplace.rb
146
+ - lib/gbizinfo/api/endpoints/hojin_workplace.rb
147
+ - lib/gbizinfo/api/error.rb
148
+ - lib/gbizinfo/client.rb
149
+ - lib/gbizinfo/config.rb
150
+ - lib/gbizinfo/faraday/connection.rb
151
+ - lib/gbizinfo/faraday/request.rb
152
+ - lib/gbizinfo/version.rb
153
+ homepage: https://github.com/ryoma123/gbizinfo-ruby
154
+ licenses:
155
+ - MIT
156
+ metadata:
157
+ source_code_uri: https://github.com/ryoma123/gbizinfo-ruby
158
+ changelog_uri: https://github.com/ryoma123/gbizinfo-ruby/blob/master/CHANGELOG.md
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: 3.0.3
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubygems_version: 3.2.32
175
+ signing_key:
176
+ specification_version: 4
177
+ summary: gBizINFO API client for Ruby.
178
+ test_files: []