carsensor 0.0.2.alpha.1

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: d46313cda8c48a71f5f6b45c944163f821a7c88940ee0b2d3766f62c2a50cbf6
4
+ data.tar.gz: c5d01d78584693f3fdab26d66e645a1cbe821d9b419ef4c63477ff0c3448099e
5
+ SHA512:
6
+ metadata.gz: 9859d0a0ccb5196cd3cc5541b4f7cff7748e594c6a1085edf8a0fbdf08762befd163225bcc60e9575ac6847f82d6a80e3b90186a3715e658a0cfc5b9338c491a
7
+ data.tar.gz: 9a32609e9235831c0c65abca9392e1b9ed2d07ff122ff8b0ac2c2e67c0736d46432e437a3ad64f90d1c6c5ed5d1cf8cc3b0f873d102472aa8aa032a9b7c036bc
@@ -0,0 +1,16 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.6.0
6
+ steps:
7
+ - run: gem update bundler
8
+ - checkout
9
+ - restore_cache:
10
+ key: gem-cache-v1-{{ arch }}-{{ .Branch }}-{{ checksum "carsensor.gemspec" }}
11
+ - run: bin/setup
12
+ - save_cache:
13
+ key: gem-cache-v1-{{ arch }}-{{ .Branch }}-{{ checksum "carsensor.gemspec" }}
14
+ paths: vendor/bundle
15
+ - run: bin/rubocop
16
+ - run: bin/rake spec
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ /Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,32 @@
1
+ require:
2
+ - rubocop-rspec
3
+
4
+ inherit_from:
5
+ - .rubocop/gemspec.yml
6
+ - .rubocop/layout.yml
7
+ - .rubocop/lint.yml
8
+ - .rubocop/metrics.yml
9
+ - .rubocop/rspec.yml
10
+ - .rubocop/security.yml
11
+ - .rubocop/style.yml
12
+ - .rubocop_todo.yml
13
+
14
+ AllCops:
15
+ DisplayCopNames: true
16
+ DisplayStyleGuide: true
17
+ EnabledByDefault: true
18
+ Exclude:
19
+ - '*.gemspec'
20
+ - 'bin/*'
21
+ - 'vendor/bundle/**/*'
22
+ - 'spec/spec_helper.rb'
23
+ ExtraDetails: true
24
+ TargetRubyVersion: 2.6
25
+ UseCache: true
26
+
27
+ # temporarily disabled stuff
28
+ Metrics/LineLength:
29
+ Enabled: false
30
+
31
+ RSpec/ExampleLength:
32
+ Enabled: false
@@ -0,0 +1,2 @@
1
+ Gemspec/OrderedDependencies:
2
+ Enabled: true
@@ -0,0 +1,57 @@
1
+ Layout/ClassStructure:
2
+ Enabled: true
3
+ Categories:
4
+ module_inclusion:
5
+ - include
6
+ - prepend
7
+ - extend
8
+ ExpectedOrder:
9
+ - module_inclusion
10
+ - constants
11
+ - public_class_methods
12
+ - initializer
13
+ - public_methods
14
+ - protected_methods
15
+ - private_methods
16
+
17
+ Layout/CommentIndentation:
18
+ Enabled: true
19
+
20
+ Layout/EmptyLineAfterGuardClause:
21
+ Enabled: true
22
+
23
+ Layout/EmptyLineAfterMagicComment:
24
+ Enabled: true
25
+
26
+ Layout/EmptyLineBetweenDefs:
27
+ Enabled: true
28
+
29
+ Layout/EmptyLines:
30
+ Enabled: true
31
+
32
+ Layout/EmptyLinesAroundAccessModifier:
33
+ Enabled: true
34
+
35
+ Layout/ExtraSpacing:
36
+ Enabled: true
37
+ AllowForAlignment: false
38
+
39
+ Layout/IndentHeredoc:
40
+ Enabled: true
41
+
42
+ Layout/LeadingCommentSpace:
43
+ Enabled: false
44
+
45
+ Layout/SpaceAfterColon:
46
+ Enabled: true
47
+
48
+ Layout/SpaceInsideBlockBraces:
49
+ Enabled: true
50
+ EnforcedStyle: space
51
+ EnforcedStyleForEmptyBraces: space
52
+ SpaceBeforeBlockParameters: false
53
+
54
+ Layout/SpaceInsideHashLiteralBraces:
55
+ Enabled: true
56
+ EnforcedStyle: no_space
57
+ EnforcedStyleForEmptyBraces: no_space
@@ -0,0 +1,8 @@
1
+ Lint/MissingCopEnableDirective:
2
+ Enabled: true
3
+
4
+ Lint/NumberConversion:
5
+ Enabled: true
6
+
7
+ Lint/UselessAssignment:
8
+ Enabled: true
@@ -0,0 +1,13 @@
1
+ Metrics/BlockLength:
2
+ Enabled: true
3
+ CountComments: false
4
+ ExcludedMethods:
5
+ - context
6
+ - describe
7
+ - namespace
8
+ - refine
9
+ - task
10
+
11
+ Metrics/LineLength:
12
+ Enabled: true
13
+ IgnoreCopDirectives: true
@@ -0,0 +1,2 @@
1
+ Rails:
2
+ Enabled: false
@@ -0,0 +1,34 @@
1
+ RSpec/AlignLeftLetBrace:
2
+ Enabled: false
3
+
4
+ RSpec/AlignRightLetBrace:
5
+ Enabled: false
6
+
7
+ RSpec/AnyInstance:
8
+ Enabled: true
9
+
10
+ RSpec/ContextWording:
11
+ Enabled: true
12
+
13
+ RSpec/DescribedClass:
14
+ Enabled: true
15
+ EnforcedStyle: explicit
16
+
17
+ RSpec/EmptyLineAfterFinalLet:
18
+ Enabled: true
19
+
20
+ RSpec/ExampleLength:
21
+ Enabled: true
22
+
23
+ RSpec/LeadingSubject:
24
+ Enabled: true
25
+
26
+ RSpec/LetBeforeExamples:
27
+ Enabled: true
28
+
29
+ RSpec/NotToNot:
30
+ Enabled: true
31
+ EnforcedStyle: not_to
32
+
33
+ RSpec/ScatteredLet:
34
+ Enabled: true
@@ -0,0 +1,2 @@
1
+ Security/MarshalLoad:
2
+ Enabled: true
@@ -0,0 +1,91 @@
1
+ Style/AccessModifierDeclarations:
2
+ Enabled: false
3
+
4
+ Style/BlockDelimiters:
5
+ Enabled: true
6
+ EnforcedStyle: braces_for_chaining
7
+
8
+ Style/CharacterLiteral:
9
+ Enabled: false
10
+
11
+ Style/CollectionMethods:
12
+ Enabled: true
13
+
14
+ Style/Copyright:
15
+ Enabled: false
16
+
17
+ Style/Documentation:
18
+ Enabled: true
19
+ Exclude:
20
+ - spec/**/*
21
+
22
+ Style/ExpandPathArguments:
23
+ Enabled: true
24
+
25
+ Style/FormatString:
26
+ Enabled: true
27
+ EnforcedStyle: percent
28
+
29
+ Style/FormatStringToken:
30
+ Enabled: false
31
+
32
+ Style/FrozenStringLiteralComment:
33
+ Enabled: true
34
+
35
+ Style/GlobalVars:
36
+ Enabled: true
37
+
38
+ Style/HashSyntax:
39
+ Enabled: true
40
+ EnforcedStyle: ruby19
41
+
42
+ Style/LambdaCall:
43
+ EnforcedStyle: braces
44
+
45
+ Style/MethodCalledOnDoEndBlock:
46
+ Enabled: true
47
+
48
+ Style/MethodCallWithArgsParentheses:
49
+ Enabled: true
50
+ IgnoreMacros: true
51
+ IgnoredMethods:
52
+ # Language core
53
+ - raise
54
+ - require
55
+ # Rspec
56
+ - be
57
+ - describe
58
+ - expect
59
+ - include_context
60
+ - not_to
61
+ - shared_context
62
+ - to
63
+ # Rake
64
+ - task
65
+ # gem/bundler
66
+ - add_dependency
67
+ - add_development_dependency
68
+ - source
69
+
70
+ Style/MutableConstant:
71
+ Enabled: true
72
+
73
+ Style/PercentLiteralDelimiters:
74
+ Enabled: false
75
+
76
+ Style/Semicolon:
77
+ Enabled: true
78
+ AllowAsExpressionSeparator: true
79
+
80
+ Style/Send:
81
+ Enabled: true
82
+
83
+ Style/StringHashKeys:
84
+ Enabled: false
85
+
86
+ Style/StringLiterals:
87
+ Enabled: true
88
+ EnforcedStyle: single_quotes
89
+
90
+ Style/UnneededPercentQ:
91
+ Enabled: true
@@ -0,0 +1,7 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config --no-auto-gen-timestamp`
3
+ # using RuboCop version 0.62.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in carsensor.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 OZAWA Sakuro
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
+ # Carsensor
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/carsensor/api`. 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 'carsensor'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install carsensor
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]/carsensor.
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,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "rubygems"
12
+
13
+ m = Module.new do
14
+ module_function
15
+
16
+ def invoked_as_script?
17
+ File.expand_path($0) == File.expand_path(__FILE__)
18
+ end
19
+
20
+ def env_var_version
21
+ ENV["BUNDLER_VERSION"]
22
+ end
23
+
24
+ def cli_arg_version
25
+ return unless invoked_as_script? # don't want to hijack other binstubs
26
+ return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27
+ bundler_version = nil
28
+ update_index = nil
29
+ ARGV.each_with_index do |a, i|
30
+ if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
+ bundler_version = a
32
+ end
33
+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
+ bundler_version = $1 || ">= 0.a"
35
+ update_index = i
36
+ end
37
+ bundler_version
38
+ end
39
+
40
+ def gemfile
41
+ gemfile = ENV["BUNDLE_GEMFILE"]
42
+ return gemfile if gemfile && !gemfile.empty?
43
+
44
+ File.expand_path("../../Gemfile", __FILE__)
45
+ end
46
+
47
+ def lockfile
48
+ lockfile =
49
+ case File.basename(gemfile)
50
+ when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51
+ else "#{gemfile}.lock"
52
+ end
53
+ File.expand_path(lockfile)
54
+ end
55
+
56
+ def lockfile_version
57
+ return unless File.file?(lockfile)
58
+ lockfile_contents = File.read(lockfile)
59
+ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60
+ Regexp.last_match(1)
61
+ end
62
+
63
+ def bundler_version
64
+ @bundler_version ||= begin
65
+ env_var_version || cli_arg_version ||
66
+ lockfile_version || "#{Gem::Requirement.default}.a"
67
+ end
68
+ end
69
+
70
+ def load_bundler!
71
+ ENV["BUNDLE_GEMFILE"] ||= gemfile
72
+
73
+ # must dup string for RG < 1.8 compatibility
74
+ activate_bundler(bundler_version.dup)
75
+ end
76
+
77
+ def activate_bundler(bundler_version)
78
+ if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
79
+ bundler_version = "< 2"
80
+ end
81
+ gem_error = activation_error_handling do
82
+ gem "bundler", bundler_version
83
+ end
84
+ return if gem_error.nil?
85
+ require_error = activation_error_handling do
86
+ require "bundler/version"
87
+ end
88
+ return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
89
+ warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
90
+ exit 42
91
+ end
92
+
93
+ def activation_error_handling
94
+ yield
95
+ nil
96
+ rescue StandardError, LoadError => e
97
+ e
98
+ end
99
+ end
100
+
101
+ m.load_bundler!
102
+
103
+ if m.invoked_as_script?
104
+ load Gem.bin_path("bundler", "bundle")
105
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "carsensor/api"
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,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rubocop", "rubocop")
@@ -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,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'yard' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("yard", "yard")
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'yardoc' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("yard", "yardoc")
data/bin/yri ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'yri' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("yard", "yri")
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'carsensor/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'carsensor'
9
+ spec.version = Carsensor::VERSION
10
+ spec.authors = ['OZAWA Sakuro']
11
+ spec.email = ['sakuro@2238.club']
12
+
13
+ spec.summary = %q{Ruby binding to Carsensor API}
14
+ spec.description = %q{Ruby binding to Carsensor API(https://webservice.recruit.co.jp/carsensor/reference.html)}
15
+ spec.homepage = 'https://github.com/sakuro/carsensor'
16
+ spec.license = 'MIT'
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_dependency 'rack'
28
+ spec.add_dependency 'retriable', '~> 3.1'
29
+ spec.add_dependency 'dry-struct'
30
+ spec.add_dependency 'dry-types', '~> 0.11.0'
31
+
32
+ spec.add_development_dependency 'bundler', '~> 2.0'
33
+ spec.add_development_dependency 'pry-byebug'
34
+ spec.add_development_dependency 'rake', '>= 10.0'
35
+ spec.add_development_dependency 'rspec', '~> 3.0'
36
+ spec.add_development_dependency 'rubocop'
37
+ spec.add_development_dependency 'rubocop-rspec'
38
+ spec.add_development_dependency 'yard'
39
+ spec.add_development_dependency 'webmock'
40
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'carsensor/api'
4
+ require 'carsensor/types'
@@ -0,0 +1,175 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+ require 'uri'
5
+ require 'open-uri'
6
+ require 'rack/utils'
7
+ require 'retriable'
8
+
9
+ module Carsensor
10
+ # A thin wrapper for Carsensor Web API at https://webservice.recruit.co.jp/carsensor/reference.html
11
+ class API
12
+ # Exception class for errors which would occur during invocation of Carsensor API
13
+ class Error < StandardError
14
+ # @param message [String] Message for the exception
15
+ # @param code [Integer,String] Error code of API itself or error status of HTTP
16
+ def initialize(message:, code: nil)
17
+ if code
18
+ super('%s(code: %s)' % [message, code])
19
+ else
20
+ super(message)
21
+ end
22
+ end
23
+ end
24
+
25
+ ENDPOINT_BASE_URI = URI('http://webservice.recruit.co.jp')
26
+
27
+ # A class for metadata of responses from Carsensor API
28
+ module Metadata
29
+ attr_accessor :metadata
30
+ end
31
+
32
+ # @param key [String] The API key
33
+ def initialize(key:, logger: Logger.new(STDOUT), tries: 3)
34
+ raise ArgumentError, 'key: must be a String' unless key.is_a?(String)
35
+
36
+ @key = key
37
+ @logger = logger
38
+ @tries = tries
39
+ end
40
+
41
+ # Returns bodies for given criterion
42
+ #
43
+ # @param query [Hash] options to specify criterion
44
+ # @return [Array<Hash>,Carsensor::API::Metadata] bodies and metadata
45
+ def bodies(**query)
46
+ call_api(:body, '/carsensor/body/v1', query)
47
+ end
48
+
49
+ # Returns brands for given criterion
50
+ #
51
+ # @param query [Hash] options to specify criterion
52
+ # @return [Array<Hash>,Carsensor::API::Metadata] brands and metadata
53
+ def brands(**query)
54
+ call_api(:brand, '/carsensor/brand/v1', query)
55
+ end
56
+
57
+ # Returns colors for given criterion
58
+ #
59
+ # @param query [Hash] options to specify criterion
60
+ # @return [Array<Hash>,Carsensor::API::Metadata] colors and metadata
61
+ def colors(**query)
62
+ call_api(:color, '/carsensor/color/v1', query)
63
+ end
64
+
65
+ # Returns countries for given criterion
66
+ #
67
+ # @param query [Hash] options to specify criterion
68
+ # @return [Array<Hash>,Carsensor::API::Metadata] countries and metadata
69
+ def countries(**query)
70
+ call_api(:country, '/carsensor/country/v1', query)
71
+ end
72
+
73
+ # Returns large areas for given criterion
74
+ #
75
+ # @param query [Hash] options to specify criterion
76
+ # @return [Array<Hash>,Carsensor::API::Metadata] large areas and metadata
77
+ def large_areas(**query)
78
+ call_api(:large_area, '/carsensor/large_area/v1', query)
79
+ end
80
+
81
+ # Returns prefectures for given criterion
82
+ #
83
+ # @param query [Hash] options to specify criterion
84
+ # @return [Array<Hash>,Carsensor::API::Metadata] prefectures and metadata
85
+ def prefectures(**query)
86
+ call_api(:pref, '/carsensor/pref/v1', query)
87
+ end
88
+
89
+ # Returns used cars for given criterion
90
+ #
91
+ # @param query [Hash] options to specify criterion
92
+ # @return [Array<Hash>,Carsensor::API::Metadata] used cars and metadata
93
+ def used_cars(**query)
94
+ call_api(:usedcar, '/carsensor/usedcar/v1', query)
95
+ end
96
+
97
+ # Returns number of total available used cars.
98
+ #
99
+ # @return [Integer] number of total available used cars
100
+ def total_available
101
+ area_codes = large_areas.map {|area| area[:code] }
102
+ area_codes.sort!
103
+ used_cars(large_area: area_codes.join(','), start: 1, count: 1).metadata[:results_available]
104
+ end
105
+
106
+ private
107
+
108
+ def call_api(root, path, **query)
109
+ Retriable.retriable(tries: @tries, on: [Error], on_retry: on_retry_proc(path, query)) do
110
+ (method(:build_uri) >> method(:read_uri) >> method(:parse_body) >> method(:extract_result).curry[root]).(path, query)
111
+ end
112
+ end
113
+
114
+ def on_retry_proc(path, **query)
115
+ lambda do |exception, _try, _elapsed_time, _next_interval|
116
+ return unless @logger
117
+
118
+ @logger.info(retry_message(exception, path, query))
119
+ end
120
+ end
121
+
122
+ def retry_message(exception, path, **query)
123
+ query_string = build_query_string(query)
124
+ request = query_string.length.zero? ? path : path + '?' + query_string
125
+ '%s %s %s' % [exception.class, exception.message, request]
126
+ end
127
+
128
+ def build_query_string(**query)
129
+ Rack::Utils.build_query(key: @key, format: 'json', **query.transform_values {|v| v.is_a?(Array) ? v.join(',') : v })
130
+ end
131
+
132
+ def build_uri(path, **query)
133
+ ENDPOINT_BASE_URI.dup.tap do |u|
134
+ u.path = path
135
+ u.query = build_query_string(query)
136
+ end
137
+ end
138
+
139
+ def read_uri(uri)
140
+ uri.read
141
+ rescue OpenURI::HTTPError => e
142
+ status = e.io.status
143
+ raise Error.new(message: status[1], code: status[0])
144
+ rescue SocketError => e
145
+ raise Error.new(message: e.message)
146
+ end
147
+
148
+ def parse_body(body)
149
+ JSON.parse(body, symbolize_names: true).tap do |data|
150
+ api_error = data.dig(:results, :error, 0)
151
+ raise Error.new(**api_error) if api_error
152
+ end
153
+ rescue JSON::ParserError => e
154
+ raise Error.new(message: e.message)
155
+ end
156
+
157
+ def extract_result(root, data)
158
+ (data.dig(:results, root) || []).tap do |result|
159
+ result.extend(Metadata)
160
+ result.metadata = extract_metadata(data).freeze
161
+ end
162
+ end
163
+
164
+ def extract_metadata(data)
165
+ %i[api_version results_available results_returned results_start].each_with_object({}) do |field, metadata|
166
+ metadata[field] = extract_metadata_field(data, field)
167
+ end
168
+ end
169
+
170
+ def extract_metadata_field(data, field)
171
+ value = data.dig(:results, field)
172
+ field.match?(/\Aresults_/) && !value.is_a?(Integer) ? Integer(value, 10) : value # rubocop:disable Performance/StartWith
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+ require 'dry-types'
5
+
6
+ module Carsensor
7
+ # Types for datas obtained via Carsensor API
8
+ module Types
9
+ include Dry::Types.module
10
+
11
+ # Type of body
12
+ class Body < Dry::Struct
13
+ attribute :name, Types::String.constrained(min_size: 1)
14
+ attribute :code, Types::String.constrained(size: 1)
15
+ end
16
+
17
+ # Type of country
18
+ class Country < Dry::Struct
19
+ attribute :name, Types::String.constrained(min_size: 1)
20
+ attribute :code, Types::String.constrained(size: 3)
21
+ end
22
+
23
+ # Type of brand
24
+ class Brand < Dry::Struct
25
+ attribute :name, Types::String.constrained(min_size: 1)
26
+ attribute :code, Types::String.constrained(size: 2)
27
+ end
28
+
29
+ # Type of color
30
+ class Color < Dry::Struct
31
+ attribute :name, Types::String.constrained(min_size: 1)
32
+ attribute :code, Types::String.constrained(size: 2)
33
+ end
34
+
35
+ # Type of large_area
36
+ class LargeArea < Dry::Struct
37
+ attribute :name, Types::String.constrained(min_size: 1)
38
+ attribute :code, Types::String.constrained(size: 1)
39
+ end
40
+
41
+ # Type of pref
42
+ class Prefecture < Dry::Struct
43
+ attribute :name, Types::String.constrained(min_size: 3)
44
+ attribute :code, Types::String.constrained(size: 2)
45
+ end
46
+
47
+ # Type of shop
48
+ class Shop < Dry::Struct
49
+ attribute :name, Types::String.constrained(min_size: 1)
50
+ attribute :pref, Prefecture
51
+ attribute :lat, Types::Coercible::Float
52
+ attribute :lng, Types::Coercible::Float
53
+ attribute :datum, String
54
+ end
55
+
56
+ # Type of photo/main
57
+ class Photo_Main < Dry::Struct # rubocop:disable Naming/ClassAndModuleCamelCase
58
+ attribute :l, Types::String
59
+ attribute :s, Types::String
60
+ attribute :caption, Types::String
61
+ end
62
+
63
+ # Type of photo
64
+ class Photo < Dry::Struct
65
+ attribute :main, Photo_Main
66
+ attribute :sub, Types::Array.of(Types::String)
67
+ end
68
+
69
+ # Type of sub_img
70
+ class SubImg < Dry::Struct
71
+ attribute :l, Types::String
72
+ attribute :caption, Types::String
73
+ end
74
+
75
+ # Type of urls
76
+ class Urls < Dry::Struct
77
+ attribute :pc, Types::String
78
+ attribute :mobile, Types::String
79
+ attribute :qr, Types::String
80
+ end
81
+
82
+ # TYpe of usedcar
83
+ class UsedCar < Dry::Struct
84
+ attribute :id, Types::String.constrained(min_size: 1)
85
+ attribute :brand, Brand
86
+ attribute :model, Types::String
87
+ attribute :grade, Types::String
88
+ attribute :price, Types::String
89
+ attribute :inspection, Types::String
90
+ attribute :maintenance, Types::String
91
+ attribute :warranty, Types::String
92
+ attribute :recycle, Types::String
93
+ attribute :engine, Types::String
94
+ attribute :desc, Types::String
95
+ attribute :body, Body
96
+ attribute :odd, Types::String
97
+ attribute :year, Types::String
98
+ attribute :shop, Shop
99
+ attribute :color, Types::String
100
+ attribute :maintenance_comment, Types::String
101
+ attribute :maintenance_fee, Types::String
102
+ attribute :photo, Photo
103
+ attribute :sub_img, Types::Array.of(SubImg)
104
+ attribute :urls, Urls
105
+ attribute :warranty_comment, Types::String
106
+ attribute :warranty_distance, Types::String
107
+ attribute :warranty_length, Types::String
108
+ attribute :warranty_fee, Types::String
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Carsensor
4
+ VERSION = '0.0.2.alpha.1'
5
+ end
@@ -0,0 +1,2 @@
1
+ *
2
+ !.gitignore
metadata ADDED
@@ -0,0 +1,243 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carsensor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2.alpha.1
5
+ platform: ruby
6
+ authors:
7
+ - OZAWA Sakuro
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
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: retriable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-struct
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: dry-types
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.11.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.11.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
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: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
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: rubocop-rspec
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: yard
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: webmock
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: Ruby binding to Carsensor API(https://webservice.recruit.co.jp/carsensor/reference.html)
182
+ email:
183
+ - sakuro@2238.club
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".circleci/config.yml"
189
+ - ".gitignore"
190
+ - ".rspec"
191
+ - ".rubocop.yml"
192
+ - ".rubocop/gemspec.yml"
193
+ - ".rubocop/layout.yml"
194
+ - ".rubocop/lint.yml"
195
+ - ".rubocop/metrics.yml"
196
+ - ".rubocop/rails.yml"
197
+ - ".rubocop/rspec.yml"
198
+ - ".rubocop/security.yml"
199
+ - ".rubocop/style.yml"
200
+ - ".rubocop_todo.yml"
201
+ - Gemfile
202
+ - LICENSE.txt
203
+ - README.md
204
+ - Rakefile
205
+ - bin/bundle
206
+ - bin/console
207
+ - bin/rake
208
+ - bin/rspec
209
+ - bin/rubocop
210
+ - bin/setup
211
+ - bin/yard
212
+ - bin/yardoc
213
+ - bin/yri
214
+ - carsensor.gemspec
215
+ - lib/carsensor.rb
216
+ - lib/carsensor/api.rb
217
+ - lib/carsensor/types.rb
218
+ - lib/carsensor/version.rb
219
+ - vendor/.gitignore
220
+ homepage: https://github.com/sakuro/carsensor
221
+ licenses:
222
+ - MIT
223
+ metadata: {}
224
+ post_install_message:
225
+ rdoc_options: []
226
+ require_paths:
227
+ - lib
228
+ required_ruby_version: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ version: '0'
233
+ required_rubygems_version: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - ">"
236
+ - !ruby/object:Gem::Version
237
+ version: 1.3.1
238
+ requirements: []
239
+ rubygems_version: 3.0.1
240
+ signing_key:
241
+ specification_version: 4
242
+ summary: Ruby binding to Carsensor API
243
+ test_files: []