From a6a5b6071e6dc915a06d58524ce0c8d6f7db3598 Mon Sep 17 00:00:00 2001 From: Daniel Azuma Date: Sun, 27 Dec 2020 17:31:47 -0800 Subject: [PATCH] chore: Split google-apis-core into a separate gem (#2134) --- Rakefile | 32 ++- google-api-client/Gemfile | 9 +- google-api-client/Rakefile | 59 +++++ google-api-client/google-api-client.gemspec | 19 +- google-api-client/lib/google/apis/version.rb | 22 -- google-api-client/rakelib/metrics.rake | 22 -- google-api-client/rakelib/rubocop.rake | 10 - google-api-client/rakelib/spec.rake | 11 - google-api-client/rakelib/yard.rake | 11 - .../spec/google/apis/versions_spec.rb | 5 - google-api-client/spec/spec_helper.rb | 1 - google-apis-core/.rspec | 2 + google-apis-core/.yardopts | 12 ++ google-apis-core/CHANGELOG.md | 2 + google-apis-core/Gemfile | 44 ++++ google-apis-core/LICENSE | 202 ++++++++++++++++++ google-apis-core/OVERVIEW.md | 5 + google-apis-core/Rakefile | 62 ++++++ google-apis-core/google-apis-core.gemspec | 26 +++ .../google/api_client/auth/installed_app.rb | 0 .../lib/google/api_client/auth/key_utils.rb | 0 .../lib/google/api_client/auth/storage.rb | 0 .../api_client/auth/storages/file_store.rb | 0 .../api_client/auth/storages/redis_store.rb | 0 .../lib/google/api_client/client_secrets.rb | 0 .../lib/google/apis.rb | 27 ++- google-apis-core/lib/google/apis/core.rb | 20 ++ .../lib/google/apis/core/api_command.rb | 19 +- .../lib/google/apis/core/base_service.rb | 32 ++- .../lib/google/apis/core/batch.rb | 2 +- .../lib/google/apis/core/composite_io.rb | 2 +- .../lib/google/apis/core/download.rb | 2 +- .../lib/google/apis/core/hashable.rb | 2 +- .../lib/google/apis/core/http_command.rb | 2 +- .../google/apis/core/json_representation.rb | 2 +- .../lib/google/apis/core/logging.rb | 2 +- .../lib/google/apis/core/multipart.rb | 2 +- .../lib/google/apis/core/upload.rb | 2 +- .../lib/google/apis/core/version.rb | 22 ++ .../lib/google/apis/errors.rb | 2 +- .../lib/google/apis/options.rb | 2 +- .../files/auth_stored_credentials.json | 0 .../spec/fixtures/files/child/.gitignore | 0 .../spec/fixtures/files/client_secrets.json | 0 .../spec/fixtures/files/invalid.json | 0 .../spec/fixtures/files/test.txt | 0 .../api_client/auth/installed_app_spec.rb | 0 .../google/api_client/auth/storage_spec.rb | 0 .../auth/storages/file_store_spec.rb | 0 .../auth/storages/redis_store_spec.rb | 0 .../google/api_client/client_secrets_spec.rb | 0 .../spec/google/apis/core/api_command_spec.rb | 5 +- .../spec/google/apis/core/batch_spec.rb | 0 .../google/apis/core/composite_io_spec.rb | 0 .../spec/google/apis/core/download_spec.rb | 0 .../spec/google/apis/core/hashable_spec.rb | 0 .../google/apis/core/http_command_spec.rb | 2 +- .../apis/core/json_representation_spec.rb | 0 .../spec/google/apis/core/service_spec.rb | 7 +- .../spec/google/apis/core/upload_spec.rb | 0 .../spec/google/apis/errors_spec.rb | 0 .../spec/google/apis/logging_spec.rb | 0 .../spec/google/apis/options_spec.rb | 0 .../spec/google/apis/version_spec.rb | 25 +++ google-apis-core/spec/spec_helper.rb | 152 +++++++++++++ .../spec/spec_helper/load_path_spec.rb | 25 +++ 66 files changed, 763 insertions(+), 151 deletions(-) delete mode 100644 google-api-client/rakelib/metrics.rake delete mode 100644 google-api-client/rakelib/rubocop.rake delete mode 100644 google-api-client/rakelib/spec.rake delete mode 100644 google-api-client/rakelib/yard.rake create mode 100644 google-apis-core/.rspec create mode 100644 google-apis-core/.yardopts create mode 100644 google-apis-core/CHANGELOG.md create mode 100644 google-apis-core/Gemfile create mode 100644 google-apis-core/LICENSE create mode 100644 google-apis-core/OVERVIEW.md create mode 100644 google-apis-core/Rakefile create mode 100644 google-apis-core/google-apis-core.gemspec rename {google-api-client => google-apis-core}/lib/google/api_client/auth/installed_app.rb (100%) rename {google-api-client => google-apis-core}/lib/google/api_client/auth/key_utils.rb (100%) rename {google-api-client => google-apis-core}/lib/google/api_client/auth/storage.rb (100%) rename {google-api-client => google-apis-core}/lib/google/api_client/auth/storages/file_store.rb (100%) rename {google-api-client => google-apis-core}/lib/google/api_client/auth/storages/redis_store.rb (100%) rename {google-api-client => google-apis-core}/lib/google/api_client/client_secrets.rb (100%) rename {google-api-client => google-apis-core}/lib/google/apis.rb (66%) create mode 100644 google-apis-core/lib/google/apis/core.rb rename {google-api-client => google-apis-core}/lib/google/apis/core/api_command.rb (92%) rename {google-api-client => google-apis-core}/lib/google/apis/core/base_service.rb (94%) rename {google-api-client => google-apis-core}/lib/google/apis/core/batch.rb (99%) rename {google-api-client => google-apis-core}/lib/google/apis/core/composite_io.rb (98%) rename {google-api-client => google-apis-core}/lib/google/apis/core/download.rb (99%) rename {google-api-client => google-apis-core}/lib/google/apis/core/hashable.rb (97%) rename {google-api-client => google-apis-core}/lib/google/apis/core/http_command.rb (99%) rename {google-api-client => google-apis-core}/lib/google/apis/core/json_representation.rb (99%) rename {google-api-client => google-apis-core}/lib/google/apis/core/logging.rb (96%) rename {google-api-client => google-apis-core}/lib/google/apis/core/multipart.rb (99%) rename {google-api-client => google-apis-core}/lib/google/apis/core/upload.rb (99%) create mode 100644 google-apis-core/lib/google/apis/core/version.rb rename {google-api-client => google-apis-core}/lib/google/apis/errors.rb (98%) rename {google-api-client => google-apis-core}/lib/google/apis/options.rb (99%) rename {google-api-client => google-apis-core}/spec/fixtures/files/auth_stored_credentials.json (100%) rename {google-api-client => google-apis-core}/spec/fixtures/files/child/.gitignore (100%) rename {google-api-client => google-apis-core}/spec/fixtures/files/client_secrets.json (100%) rename {google-api-client => google-apis-core}/spec/fixtures/files/invalid.json (100%) rename {google-api-client => google-apis-core}/spec/fixtures/files/test.txt (100%) rename {google-api-client => google-apis-core}/spec/google/api_client/auth/installed_app_spec.rb (100%) rename {google-api-client => google-apis-core}/spec/google/api_client/auth/storage_spec.rb (100%) rename {google-api-client => google-apis-core}/spec/google/api_client/auth/storages/file_store_spec.rb (100%) rename {google-api-client => google-apis-core}/spec/google/api_client/auth/storages/redis_store_spec.rb (100%) rename {google-api-client => google-apis-core}/spec/google/api_client/client_secrets_spec.rb (100%) rename {google-api-client => google-apis-core}/spec/google/apis/core/api_command_spec.rb (99%) rename {google-api-client => google-apis-core}/spec/google/apis/core/batch_spec.rb (100%) rename {google-api-client => google-apis-core}/spec/google/apis/core/composite_io_spec.rb (100%) rename {google-api-client => google-apis-core}/spec/google/apis/core/download_spec.rb (100%) rename {google-api-client => google-apis-core}/spec/google/apis/core/hashable_spec.rb (100%) rename {google-api-client => google-apis-core}/spec/google/apis/core/http_command_spec.rb (99%) rename {google-api-client => google-apis-core}/spec/google/apis/core/json_representation_spec.rb (100%) rename {google-api-client => google-apis-core}/spec/google/apis/core/service_spec.rb (98%) rename {google-api-client => google-apis-core}/spec/google/apis/core/upload_spec.rb (100%) rename {google-api-client => google-apis-core}/spec/google/apis/errors_spec.rb (100%) rename {google-api-client => google-apis-core}/spec/google/apis/logging_spec.rb (100%) rename {google-api-client => google-apis-core}/spec/google/apis/options_spec.rb (100%) create mode 100644 google-apis-core/spec/google/apis/version_spec.rb create mode 100644 google-apis-core/spec/spec_helper.rb create mode 100644 google-apis-core/spec/spec_helper/load_path_spec.rb diff --git a/Rakefile b/Rakefile index 7884ae6ec..00e00d5fe 100644 --- a/Rakefile +++ b/Rakefile @@ -6,30 +6,15 @@ namespace :kokoro do end task :presubmit do - cd "google-api-client" do - Bundler.with_clean_env do - sh "bundle update" - sh "bundle exec rake spec" - end - end + Rake::Task["kokoro:run_tests"].invoke end task :continuous do - cd "google-api-client" do - Bundler.with_clean_env do - sh "bundle update" - sh "bundle exec rake spec" - end - end + Rake::Task["kokoro:run_tests"].invoke end task :nightly do - cd "google-api-client" do - Bundler.with_clean_env do - sh "bundle update" - sh "bundle exec rake spec" - end - end + Rake::Task["kokoro:run_tests"].invoke end task :post do @@ -45,6 +30,17 @@ namespace :kokoro do Rake::Task["kokoro:publish_docs"].invoke end + task :run_tests do + ["google-apis-core", "google-api-client"].each do |gem_name| + cd gem_name do + Bundler.with_clean_env do + sh "bundle update" + sh "bundle exec rake spec" + end + end + end + end + task :publish_gem do require "gems" diff --git a/google-api-client/Gemfile b/google-api-client/Gemfile index 2d6d1cc32..785089159 100644 --- a/google-api-client/Gemfile +++ b/google-api-client/Gemfile @@ -3,6 +3,7 @@ source 'https://rubygems.org' # Specify your gem's dependencies in google-apis.gemspec gemspec +gem 'google-apis-core', path: '../google-apis-core' group :development do gem 'bundler', '>= 1.7' @@ -42,14 +43,6 @@ platforms :ruby do end end -platforms :mri_21, :mri_22, :mri_23 do - group :development do - gem 'derailed_benchmarks' - gem 'stackprof' - gem 'rack-test' - end -end - if ENV['RAILS_VERSION'] gem 'rails', ENV['RAILS_VERSION'] end diff --git a/google-api-client/Rakefile b/google-api-client/Rakefile index a6109f2df..a45db0dfb 100644 --- a/google-api-client/Rakefile +++ b/google-api-client/Rakefile @@ -1,3 +1,62 @@ require "bundler/gem_tasks" +namespace :metrics do + task :lines do + lines, codelines, total_lines, total_codelines = 0, 0, 0, 0 + for file_name in FileList['lib/**/*.rb', 'bin/generate-api'] + f = File.open(file_name) + while line = f.gets + lines += 1 + next if line =~ /^\s*$/ + next if line =~ /^\s*#/ + codelines += 1 + end + puts "L: #{sprintf('%4d', lines)}, " + + "LOC #{sprintf('%4d', codelines)} | #{file_name}" + total_lines += lines + total_codelines += codelines + + lines, codelines = 0, 0 + end + + puts "Total: Lines #{total_lines}, LOC #{total_codelines}" + end +end + +require 'rubocop/rake_task' + +desc 'Run RuboCop on the lib directory' +RuboCop::RakeTask.new(:rubocop) do |task| + task.patterns = ['lib/**/*.rb'] + # only show the files with failures + task.formatters = ['progress'] + # don't abort rake on failure + task.fail_on_error = false +end + +require 'rake/clean' + +CLOBBER.include('coverage') + +require 'rspec/core/rake_task' + +namespace :spec do + RSpec::Core::RakeTask.new(:all) +end + +desc 'Alias to spec:all' +task 'spec' => 'spec:all' + +begin + require 'yard' + require 'yard/rake/yardoc_task' + + YARD::Rake::YardocTask.new do |t| + t.files = ['lib/**/*.rb', 'generated/**/*.rb'] + t.options = ['--verbose', '--markup', 'markdown'] + end +rescue LoadError + puts "YARD not available" +end + task :default => :spec diff --git a/google-api-client/google-api-client.gemspec b/google-api-client/google-api-client.gemspec index b341f138e..169a18a24 100644 --- a/google-api-client/google-api-client.gemspec +++ b/google-api-client/google-api-client.gemspec @@ -13,24 +13,19 @@ Gem::Specification.new do |gem| gem.metadata = { "documentation_uri" => "https://googleapis.dev/ruby/google-api-client/v#{Google::Apis::VERSION}" } - - gem.files = `git ls-files -z` - .split("\x0") - .reject { |f| f.match(%r{^(spec|script)/|^api_names_out|synth\.metadata}) } + gem.files = Dir.glob("lib/**/*") + + Dir.glob("generated/**/*.rb") + + Dir.glob("docs/**/*") + + Dir.glob("bin/**/*") + + Dir.glob("*.md") + + [".yardopts", "LICENSE"] gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) } gem.require_paths = %w[lib generated] gem.required_ruby_version = '>= 2.4' - gem.add_runtime_dependency 'representable', '~> 3.0' - gem.add_runtime_dependency 'retriable', '>= 2.0', '< 4.0' - gem.add_runtime_dependency 'addressable', '~> 2.5', '>= 2.5.1' - gem.add_runtime_dependency 'mini_mime', '~> 1.0' - gem.add_runtime_dependency 'signet', '~> 0.12' - gem.add_runtime_dependency 'googleauth', '~> 0.9' - gem.add_runtime_dependency 'httpclient', '>= 2.8.1', '< 3.0' - gem.add_runtime_dependency 'rexml' + gem.add_runtime_dependency 'google-apis-core', '~> 0.0' gem.add_development_dependency 'thor', '~> 0.19' gem.add_development_dependency 'activesupport', '>= 4.2', '< 5.1' end diff --git a/google-api-client/lib/google/apis/version.rb b/google-api-client/lib/google/apis/version.rb index 8d240cd14..8e2570ec7 100644 --- a/google-api-client/lib/google/apis/version.rb +++ b/google-api-client/lib/google/apis/version.rb @@ -18,27 +18,5 @@ module Google module Apis # Client library version VERSION = "0.52.0".freeze - - # Current operating system - # @private - OS_VERSION = begin - if RUBY_PLATFORM =~ /mswin|win32|mingw|bccwin|cygwin/ - output, _ = Open3.capture2('ver') - output.sub(/\s*\[Version\s*/, '/').sub(']', '') - elsif RUBY_PLATFORM =~ /darwin/i - output, _ = Open3.capture2('sw_vers', '-productVersion') - "Mac OS X/#{output}" - elsif RUBY_PLATFORM == 'java' - require 'java' - name = java.lang.System.getProperty('os.name') - version = java.lang.System.getProperty('os.version') - "#{name}/#{version}" - else - output, _ = Open3.capture2('uname', '-sr') - output.sub(' ', '/') - end.strip - rescue - RUBY_PLATFORM - end end end diff --git a/google-api-client/rakelib/metrics.rake b/google-api-client/rakelib/metrics.rake deleted file mode 100644 index 812339c22..000000000 --- a/google-api-client/rakelib/metrics.rake +++ /dev/null @@ -1,22 +0,0 @@ -namespace :metrics do - task :lines do - lines, codelines, total_lines, total_codelines = 0, 0, 0, 0 - for file_name in FileList['lib/**/*.rb', 'bin/generate-api'] - f = File.open(file_name) - while line = f.gets - lines += 1 - next if line =~ /^\s*$/ - next if line =~ /^\s*#/ - codelines += 1 - end - puts "L: #{sprintf('%4d', lines)}, " + - "LOC #{sprintf('%4d', codelines)} | #{file_name}" - total_lines += lines - total_codelines += codelines - - lines, codelines = 0, 0 - end - - puts "Total: Lines #{total_lines}, LOC #{total_codelines}" - end -end diff --git a/google-api-client/rakelib/rubocop.rake b/google-api-client/rakelib/rubocop.rake deleted file mode 100644 index 61c4fe14c..000000000 --- a/google-api-client/rakelib/rubocop.rake +++ /dev/null @@ -1,10 +0,0 @@ -require 'rubocop/rake_task' - -desc 'Run RuboCop on the lib directory' -RuboCop::RakeTask.new(:rubocop) do |task| - task.patterns = ['lib/**/*.rb'] - # only show the files with failures - task.formatters = ['progress'] - # don't abort rake on failure - task.fail_on_error = false -end \ No newline at end of file diff --git a/google-api-client/rakelib/spec.rake b/google-api-client/rakelib/spec.rake deleted file mode 100644 index f118b758e..000000000 --- a/google-api-client/rakelib/spec.rake +++ /dev/null @@ -1,11 +0,0 @@ -require 'rake/clean' -require 'rspec/core/rake_task' - -CLOBBER.include('coverage') - -namespace :spec do - RSpec::Core::RakeTask.new(:all) -end - -desc 'Alias to spec:all' -task 'spec' => 'spec:all' diff --git a/google-api-client/rakelib/yard.rake b/google-api-client/rakelib/yard.rake deleted file mode 100644 index a0675a8dc..000000000 --- a/google-api-client/rakelib/yard.rake +++ /dev/null @@ -1,11 +0,0 @@ -begin - require 'yard' - require 'yard/rake/yardoc_task' - - YARD::Rake::YardocTask.new do |t| - t.files = ['lib/**/*.rb', 'generated/**/*.rb'] - t.options = ['--verbose', '--markup', 'markdown'] - end -rescue LoadError - puts "YARD not available" -end diff --git a/google-api-client/spec/google/apis/versions_spec.rb b/google-api-client/spec/google/apis/versions_spec.rb index aaf030d3b..b17053dae 100644 --- a/google-api-client/spec/google/apis/versions_spec.rb +++ b/google-api-client/spec/google/apis/versions_spec.rb @@ -17,9 +17,4 @@ require 'google/apis/version' RSpec.describe Google::Apis::VERSION do it { is_expected.to be_a(String) } - - describe Google::Apis::OS_VERSION do - it { is_expected.to be_a(String) } - it { is_expected.not_to match /\n/ } - end end diff --git a/google-api-client/spec/spec_helper.rb b/google-api-client/spec/spec_helper.rb index 424a9011f..4fa9289d3 100644 --- a/google-api-client/spec/spec_helper.rb +++ b/google-api-client/spec/spec_helper.rb @@ -16,7 +16,6 @@ SPEC_DIR = File.expand_path(File.dirname(__FILE__)) ROOT_DIR = File.expand_path(File.join(SPEC_DIR, '..')) LIB_DIR = File.expand_path(File.join(ROOT_DIR, 'lib')) GENERATED_DIR = File.expand_path(File.join(ROOT_DIR, 'generated')) -THIRD_PARTY_DIR = File.expand_path(File.join(ROOT_DIR, 'third_party')) FIXTURES_DIR = File.expand_path(File.join(SPEC_DIR, 'fixtures')) $LOAD_PATH.uniq! diff --git a/google-apis-core/.rspec b/google-apis-core/.rspec new file mode 100644 index 000000000..16f9cdb01 --- /dev/null +++ b/google-apis-core/.rspec @@ -0,0 +1,2 @@ +--color +--format documentation diff --git a/google-apis-core/.yardopts b/google-apis-core/.yardopts new file mode 100644 index 000000000..f8aa0a2df --- /dev/null +++ b/google-apis-core/.yardopts @@ -0,0 +1,12 @@ +--hide-void-return +--no-private +--verbose +--markup-provider=redcarpet +--markup=markdown +--main OVERVIEW.md + +lib/**/*.rb +- +OVERVIEW.md +CHANGELOG.md +LICENSE diff --git a/google-apis-core/CHANGELOG.md b/google-apis-core/CHANGELOG.md new file mode 100644 index 000000000..f88957a62 --- /dev/null +++ b/google-apis-core/CHANGELOG.md @@ -0,0 +1,2 @@ +# Release History + diff --git a/google-apis-core/Gemfile b/google-apis-core/Gemfile new file mode 100644 index 000000000..4a0c5da3f --- /dev/null +++ b/google-apis-core/Gemfile @@ -0,0 +1,44 @@ +source 'https://rubygems.org' + +gemspec + +group :development do + gem 'bundler', '>= 1.7' + gem 'rake', '~> 11.2' + gem 'rspec', '~> 3.1' + gem 'json_spec', '~> 1.1' + gem 'webmock', '~> 2.1' + gem 'simplecov', '~> 0.12' + gem 'coveralls', '~> 0.8' + gem 'rubocop', '~> 0.49.0' + gem 'launchy', '~> 2.4' + gem 'dotenv', '~> 2.0' + gem 'fakefs', '~> 0.6', require: "fakefs/safe" + gem 'google-id-token', '~> 1.3' + gem 'os', '~> 0.9' + gem 'rmail', '~> 1.1' + gem 'redis', '~> 3.2' + gem 'logging', '~> 2.2' + gem 'opencensus', '~> 0.4' + gem 'httparty' +end + +platforms :jruby do + group :development do + gem 'jruby-openssl' + end +end + +platforms :ruby do + group :development do + gem 'yard', '~> 0.9', '>= 0.9.11' + gem 'redcarpet', '~> 3.2' + gem 'github-markup', '~> 1.3' + gem 'pry-doc', '~> 0.8' + gem 'pry-byebug', '~> 3.2' + end +end + +if ENV['RAILS_VERSION'] + gem 'rails', ENV['RAILS_VERSION'] +end diff --git a/google-apis-core/LICENSE b/google-apis-core/LICENSE new file mode 100644 index 000000000..ef51da2b0 --- /dev/null +++ b/google-apis-core/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/google-apis-core/OVERVIEW.md b/google-apis-core/OVERVIEW.md new file mode 100644 index 000000000..7f721400e --- /dev/null +++ b/google-apis-core/OVERVIEW.md @@ -0,0 +1,5 @@ +# Core classes for Google REST Clients + +This library includes common base classes and dependencies used by REST clients +for Google APIs. It is used by client libraries, but you should not need to +install it by itself. diff --git a/google-apis-core/Rakefile b/google-apis-core/Rakefile new file mode 100644 index 000000000..a45db0dfb --- /dev/null +++ b/google-apis-core/Rakefile @@ -0,0 +1,62 @@ +require "bundler/gem_tasks" + +namespace :metrics do + task :lines do + lines, codelines, total_lines, total_codelines = 0, 0, 0, 0 + for file_name in FileList['lib/**/*.rb', 'bin/generate-api'] + f = File.open(file_name) + while line = f.gets + lines += 1 + next if line =~ /^\s*$/ + next if line =~ /^\s*#/ + codelines += 1 + end + puts "L: #{sprintf('%4d', lines)}, " + + "LOC #{sprintf('%4d', codelines)} | #{file_name}" + total_lines += lines + total_codelines += codelines + + lines, codelines = 0, 0 + end + + puts "Total: Lines #{total_lines}, LOC #{total_codelines}" + end +end + +require 'rubocop/rake_task' + +desc 'Run RuboCop on the lib directory' +RuboCop::RakeTask.new(:rubocop) do |task| + task.patterns = ['lib/**/*.rb'] + # only show the files with failures + task.formatters = ['progress'] + # don't abort rake on failure + task.fail_on_error = false +end + +require 'rake/clean' + +CLOBBER.include('coverage') + +require 'rspec/core/rake_task' + +namespace :spec do + RSpec::Core::RakeTask.new(:all) +end + +desc 'Alias to spec:all' +task 'spec' => 'spec:all' + +begin + require 'yard' + require 'yard/rake/yardoc_task' + + YARD::Rake::YardocTask.new do |t| + t.files = ['lib/**/*.rb', 'generated/**/*.rb'] + t.options = ['--verbose', '--markup', 'markdown'] + end +rescue LoadError + puts "YARD not available" +end + +task :default => :spec diff --git a/google-apis-core/google-apis-core.gemspec b/google-apis-core/google-apis-core.gemspec new file mode 100644 index 000000000..4df4909a1 --- /dev/null +++ b/google-apis-core/google-apis-core.gemspec @@ -0,0 +1,26 @@ +require File.expand_path("lib/google/apis/core/version", __dir__) + +Gem::Specification.new do |gem| + gem.name = "google-apis-core" + gem.version = Google::Apis::Core::VERSION + gem.authors = ["Google LLC"] + gem.email = "googleapis-packages@google.com" + gem.summary = "Common utility and base classes for legacy Google REST clients" + gem.homepage = "https://github.com/google/google-api-ruby-client" + gem.license = "Apache-2.0" + gem.metadata = { + "documentation_uri" => "https://googleapis.dev/ruby/google-apis-core/v#{Google::Apis::Core::VERSION}" + } + gem.files = Dir.glob("lib/**/*.rb") + Dir.glob("*.md") + [".yardopts", "LICENSE"] + gem.require_paths = ["lib"] + gem.required_ruby_version = '>= 2.4' + + gem.add_runtime_dependency "representable", "~> 3.0" + gem.add_runtime_dependency "retriable", ">= 2.0", "< 4.0" + gem.add_runtime_dependency "addressable", "~> 2.5", ">= 2.5.1" + gem.add_runtime_dependency "mini_mime", "~> 1.0" + gem.add_runtime_dependency "signet", "~> 0.12" + gem.add_runtime_dependency "googleauth", "~> 0.9" + gem.add_runtime_dependency "httpclient", ">= 2.8.1", "< 3.0" + gem.add_runtime_dependency "rexml" +end diff --git a/google-api-client/lib/google/api_client/auth/installed_app.rb b/google-apis-core/lib/google/api_client/auth/installed_app.rb similarity index 100% rename from google-api-client/lib/google/api_client/auth/installed_app.rb rename to google-apis-core/lib/google/api_client/auth/installed_app.rb diff --git a/google-api-client/lib/google/api_client/auth/key_utils.rb b/google-apis-core/lib/google/api_client/auth/key_utils.rb similarity index 100% rename from google-api-client/lib/google/api_client/auth/key_utils.rb rename to google-apis-core/lib/google/api_client/auth/key_utils.rb diff --git a/google-api-client/lib/google/api_client/auth/storage.rb b/google-apis-core/lib/google/api_client/auth/storage.rb similarity index 100% rename from google-api-client/lib/google/api_client/auth/storage.rb rename to google-apis-core/lib/google/api_client/auth/storage.rb diff --git a/google-api-client/lib/google/api_client/auth/storages/file_store.rb b/google-apis-core/lib/google/api_client/auth/storages/file_store.rb similarity index 100% rename from google-api-client/lib/google/api_client/auth/storages/file_store.rb rename to google-apis-core/lib/google/api_client/auth/storages/file_store.rb diff --git a/google-api-client/lib/google/api_client/auth/storages/redis_store.rb b/google-apis-core/lib/google/api_client/auth/storages/redis_store.rb similarity index 100% rename from google-api-client/lib/google/api_client/auth/storages/redis_store.rb rename to google-apis-core/lib/google/api_client/auth/storages/redis_store.rb diff --git a/google-api-client/lib/google/api_client/client_secrets.rb b/google-apis-core/lib/google/api_client/client_secrets.rb similarity index 100% rename from google-api-client/lib/google/api_client/client_secrets.rb rename to google-apis-core/lib/google/api_client/client_secrets.rb diff --git a/google-api-client/lib/google/apis.rb b/google-apis-core/lib/google/apis.rb similarity index 66% rename from google-api-client/lib/google/apis.rb rename to google-apis-core/lib/google/apis.rb index a37bd14d0..a69e96bd3 100644 --- a/google-api-client/lib/google/apis.rb +++ b/google-apis-core/lib/google/apis.rb @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,13 +12,36 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'google/apis/version' +require 'google/apis/core/version' require 'logger' +require 'open3' module Google module Apis ROOT = File.expand_path('..', File.dirname(__dir__)) + # Current operating system + # @private + OS_VERSION = begin + if RUBY_PLATFORM =~ /mswin|win32|mingw|bccwin|cygwin/ + output, _ = Open3.capture2('ver') + output.sub(/\s*\[Version\s*/, '/').sub(']', '') + elsif RUBY_PLATFORM =~ /darwin/i + output, _ = Open3.capture2('sw_vers', '-productVersion') + "Mac OS X/#{output}" + elsif RUBY_PLATFORM == 'java' + require 'java' + name = java.lang.System.getProperty('os.name') + version = java.lang.System.getProperty('os.version') + "#{name}/#{version}" + else + output, _ = Open3.capture2('uname', '-sr') + output.sub(' ', '/') + end.strip + rescue + RUBY_PLATFORM + end + # @!attribute [rw] logger # @return [Logger] The logger. def self.logger diff --git a/google-apis-core/lib/google/apis/core.rb b/google-apis-core/lib/google/apis/core.rb new file mode 100644 index 000000000..e6768102b --- /dev/null +++ b/google-apis-core/lib/google/apis/core.rb @@ -0,0 +1,20 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module Google + module Apis + module Core + end + end +end diff --git a/google-api-client/lib/google/apis/core/api_command.rb b/google-apis-core/lib/google/apis/core/api_command.rb similarity index 92% rename from google-api-client/lib/google/apis/core/api_command.rb rename to google-apis-core/lib/google/apis/core/api_command.rb index f68c497db..499088aa3 100644 --- a/google-api-client/lib/google/apis/core/api_command.rb +++ b/google-apis-core/lib/google/apis/core/api_command.rb @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -48,6 +48,21 @@ module Google # @return [Object] attr_accessor :response_class + # Client library version. + # @return [String] + attr_accessor :client_version + + # @param [symbol] method + # HTTP method + # @param [String,Addressable::URI, Addressable::Template] url + # HTTP URL or template + # @param [String, #read] body + # Request body + def initialize(method, url, body: nil, client_version: nil) + super(method, url, body: body) + self.client_version = client_version || '0.0' + end + # Serialize the request body # # @return [void] @@ -136,7 +151,7 @@ module Google .split .find_all { |s| s !~ %r{^gl-ruby/|^gdcl/} } .join(' ') - xgac = "gl-ruby/#{RUBY_VERSION} gdcl/#{Google::Apis::VERSION}" + xgac = "gl-ruby/#{RUBY_VERSION} gdcl/#{client_version}" xgac = old_xgac.empty? ? xgac : "#{old_xgac} #{xgac}" header.delete_if { |k, v| k.downcase == 'x-goog-api-client' } header['X-Goog-Api-Client'] = xgac diff --git a/google-api-client/lib/google/apis/core/base_service.rb b/google-apis-core/lib/google/apis/core/base_service.rb similarity index 94% rename from google-api-client/lib/google/apis/core/base_service.rb rename to google-apis-core/lib/google/apis/core/base_service.rb index 38496f2c6..a1a7062a3 100644 --- a/google-api-client/lib/google/apis/core/base_service.rb +++ b/google-apis-core/lib/google/apis/core/base_service.rb @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,7 +14,8 @@ require 'addressable/uri' require 'addressable/template' -require 'google/apis/version' +require 'google/apis' +require 'google/apis/core/version' require 'google/apis/core/api_command' require 'google/apis/core/batch' require 'google/apis/core/upload' @@ -120,14 +121,24 @@ module Google # @return [Google::Apis::RequestOptions] attr_accessor :request_options + # Client library name. + # @return [String] + attr_accessor :client_name + + # Client library version. + # @return [String] + attr_accessor :client_version + # @param [String,Addressable::URI] root_url # Root URL for the API # @param [String,Addressable::URI] base_path # Additional path prefix for all API methods # @api private - def initialize(root_url, base_path) + def initialize(root_url, base_path, client_name: nil, client_version: nil) self.root_url = root_url self.base_path = base_path + self.client_name = client_name || 'google-api-ruby-client' + self.client_version = client_version || Google::Apis::Core::VERSION self.upload_path = "upload/#{base_path}" self.batch_path = 'batch' self.client_options = Google::Apis::ClientOptions.default.dup @@ -242,7 +253,7 @@ module Google # @return [String] HTTP response body def http(method, url, params: nil, body: nil, download_dest: nil, options: nil, &block) if download_dest - command = DownloadCommand.new(method, url, body: body) + command = DownloadCommand.new(method, url, body: body, client_version: client_version) else command = HttpCommand.new(method, url, body: body) end @@ -297,9 +308,9 @@ module Google def make_upload_command(method, path, options) template = Addressable::Template.new(root_url + upload_path + path) if batch? - command = MultipartUploadCommand.new(method, template) + command = MultipartUploadCommand.new(method, template, client_version: client_version) else - command = ResumableUploadCommand.new(method, template) + command = ResumableUploadCommand.new(method, template, client_version: client_version) end command.options = request_options.merge(options) apply_command_defaults(command) @@ -317,7 +328,7 @@ module Google # @return [Google::Apis::Core::DownloadCommand] def make_download_command(method, path, options) template = Addressable::Template.new(root_url + base_path + path) - command = DownloadCommand.new(method, template) + command = DownloadCommand.new(method, template, client_version: client_version) command.options = request_options.merge(options) command.query['alt'] = 'media' apply_command_defaults(command) @@ -341,7 +352,7 @@ module Google base_path + path end template = Addressable::Template.new(root_url + full_path) - command = ApiCommand.new(method, template) + command = ApiCommand.new(method, template, client_version: client_version) command.options = request_options.merge(options) apply_command_defaults(command) command @@ -435,10 +446,11 @@ module Google # Build the user agent header # @return [String] def user_agent - sprintf('%s/%s google-api-ruby-client/%s %s (gzip)', + sprintf('%s/%s %s/%s %s (gzip)', client_options.application_name, client_options.application_version, - Google::Apis::VERSION, + client_name, + client_version, Google::Apis::OS_VERSION) end end diff --git a/google-api-client/lib/google/apis/core/batch.rb b/google-apis-core/lib/google/apis/core/batch.rb similarity index 99% rename from google-api-client/lib/google/apis/core/batch.rb rename to google-apis-core/lib/google/apis/core/batch.rb index bf20051e3..e2fdbeaf7 100644 --- a/google-api-client/lib/google/apis/core/batch.rb +++ b/google-apis-core/lib/google/apis/core/batch.rb @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google-api-client/lib/google/apis/core/composite_io.rb b/google-apis-core/lib/google/apis/core/composite_io.rb similarity index 98% rename from google-api-client/lib/google/apis/core/composite_io.rb rename to google-apis-core/lib/google/apis/core/composite_io.rb index 0f3e03ebc..9f703a0d5 100644 --- a/google-api-client/lib/google/apis/core/composite_io.rb +++ b/google-apis-core/lib/google/apis/core/composite_io.rb @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google-api-client/lib/google/apis/core/download.rb b/google-apis-core/lib/google/apis/core/download.rb similarity index 99% rename from google-api-client/lib/google/apis/core/download.rb rename to google-apis-core/lib/google/apis/core/download.rb index fd18ca493..0c58b50eb 100644 --- a/google-api-client/lib/google/apis/core/download.rb +++ b/google-apis-core/lib/google/apis/core/download.rb @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google-api-client/lib/google/apis/core/hashable.rb b/google-apis-core/lib/google/apis/core/hashable.rb similarity index 97% rename from google-api-client/lib/google/apis/core/hashable.rb rename to google-apis-core/lib/google/apis/core/hashable.rb index ea63e3c0e..8c5c423a5 100644 --- a/google-api-client/lib/google/apis/core/hashable.rb +++ b/google-apis-core/lib/google/apis/core/hashable.rb @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google-api-client/lib/google/apis/core/http_command.rb b/google-apis-core/lib/google/apis/core/http_command.rb similarity index 99% rename from google-api-client/lib/google/apis/core/http_command.rb rename to google-apis-core/lib/google/apis/core/http_command.rb index d9281ebc6..62429b6ae 100644 --- a/google-api-client/lib/google/apis/core/http_command.rb +++ b/google-apis-core/lib/google/apis/core/http_command.rb @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google-api-client/lib/google/apis/core/json_representation.rb b/google-apis-core/lib/google/apis/core/json_representation.rb similarity index 99% rename from google-api-client/lib/google/apis/core/json_representation.rb rename to google-apis-core/lib/google/apis/core/json_representation.rb index 914d81f32..edc6f5c2e 100644 --- a/google-api-client/lib/google/apis/core/json_representation.rb +++ b/google-apis-core/lib/google/apis/core/json_representation.rb @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google-api-client/lib/google/apis/core/logging.rb b/google-apis-core/lib/google/apis/core/logging.rb similarity index 96% rename from google-api-client/lib/google/apis/core/logging.rb rename to google-apis-core/lib/google/apis/core/logging.rb index 5d0bdc0de..9c7f2e99c 100644 --- a/google-api-client/lib/google/apis/core/logging.rb +++ b/google-apis-core/lib/google/apis/core/logging.rb @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google-api-client/lib/google/apis/core/multipart.rb b/google-apis-core/lib/google/apis/core/multipart.rb similarity index 99% rename from google-api-client/lib/google/apis/core/multipart.rb rename to google-apis-core/lib/google/apis/core/multipart.rb index d2d678d67..d176ce9ec 100644 --- a/google-api-client/lib/google/apis/core/multipart.rb +++ b/google-apis-core/lib/google/apis/core/multipart.rb @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google-api-client/lib/google/apis/core/upload.rb b/google-apis-core/lib/google/apis/core/upload.rb similarity index 99% rename from google-api-client/lib/google/apis/core/upload.rb rename to google-apis-core/lib/google/apis/core/upload.rb index 08e2a67c6..c72ec7053 100644 --- a/google-api-client/lib/google/apis/core/upload.rb +++ b/google-apis-core/lib/google/apis/core/upload.rb @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google-apis-core/lib/google/apis/core/version.rb b/google-apis-core/lib/google/apis/core/version.rb new file mode 100644 index 000000000..ea2f31ddd --- /dev/null +++ b/google-apis-core/lib/google/apis/core/version.rb @@ -0,0 +1,22 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module Google + module Apis + module Core + # Core version + VERSION = "0.0.1".freeze + end + end +end diff --git a/google-api-client/lib/google/apis/errors.rb b/google-apis-core/lib/google/apis/errors.rb similarity index 98% rename from google-api-client/lib/google/apis/errors.rb rename to google-apis-core/lib/google/apis/errors.rb index 85628f0a0..9a9e05621 100644 --- a/google-api-client/lib/google/apis/errors.rb +++ b/google-apis-core/lib/google/apis/errors.rb @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google-api-client/lib/google/apis/options.rb b/google-apis-core/lib/google/apis/options.rb similarity index 99% rename from google-api-client/lib/google/apis/options.rb rename to google-apis-core/lib/google/apis/options.rb index 3af941c83..b9106e3a8 100644 --- a/google-api-client/lib/google/apis/options.rb +++ b/google-apis-core/lib/google/apis/options.rb @@ -1,4 +1,4 @@ -# Copyright 2015 Google Inc. +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google-api-client/spec/fixtures/files/auth_stored_credentials.json b/google-apis-core/spec/fixtures/files/auth_stored_credentials.json similarity index 100% rename from google-api-client/spec/fixtures/files/auth_stored_credentials.json rename to google-apis-core/spec/fixtures/files/auth_stored_credentials.json diff --git a/google-api-client/spec/fixtures/files/child/.gitignore b/google-apis-core/spec/fixtures/files/child/.gitignore similarity index 100% rename from google-api-client/spec/fixtures/files/child/.gitignore rename to google-apis-core/spec/fixtures/files/child/.gitignore diff --git a/google-api-client/spec/fixtures/files/client_secrets.json b/google-apis-core/spec/fixtures/files/client_secrets.json similarity index 100% rename from google-api-client/spec/fixtures/files/client_secrets.json rename to google-apis-core/spec/fixtures/files/client_secrets.json diff --git a/google-api-client/spec/fixtures/files/invalid.json b/google-apis-core/spec/fixtures/files/invalid.json similarity index 100% rename from google-api-client/spec/fixtures/files/invalid.json rename to google-apis-core/spec/fixtures/files/invalid.json diff --git a/google-api-client/spec/fixtures/files/test.txt b/google-apis-core/spec/fixtures/files/test.txt similarity index 100% rename from google-api-client/spec/fixtures/files/test.txt rename to google-apis-core/spec/fixtures/files/test.txt diff --git a/google-api-client/spec/google/api_client/auth/installed_app_spec.rb b/google-apis-core/spec/google/api_client/auth/installed_app_spec.rb similarity index 100% rename from google-api-client/spec/google/api_client/auth/installed_app_spec.rb rename to google-apis-core/spec/google/api_client/auth/installed_app_spec.rb diff --git a/google-api-client/spec/google/api_client/auth/storage_spec.rb b/google-apis-core/spec/google/api_client/auth/storage_spec.rb similarity index 100% rename from google-api-client/spec/google/api_client/auth/storage_spec.rb rename to google-apis-core/spec/google/api_client/auth/storage_spec.rb diff --git a/google-api-client/spec/google/api_client/auth/storages/file_store_spec.rb b/google-apis-core/spec/google/api_client/auth/storages/file_store_spec.rb similarity index 100% rename from google-api-client/spec/google/api_client/auth/storages/file_store_spec.rb rename to google-apis-core/spec/google/api_client/auth/storages/file_store_spec.rb diff --git a/google-api-client/spec/google/api_client/auth/storages/redis_store_spec.rb b/google-apis-core/spec/google/api_client/auth/storages/redis_store_spec.rb similarity index 100% rename from google-api-client/spec/google/api_client/auth/storages/redis_store_spec.rb rename to google-apis-core/spec/google/api_client/auth/storages/redis_store_spec.rb diff --git a/google-api-client/spec/google/api_client/client_secrets_spec.rb b/google-apis-core/spec/google/api_client/client_secrets_spec.rb similarity index 100% rename from google-api-client/spec/google/api_client/client_secrets_spec.rb rename to google-apis-core/spec/google/api_client/client_secrets_spec.rb diff --git a/google-api-client/spec/google/apis/core/api_command_spec.rb b/google-apis-core/spec/google/apis/core/api_command_spec.rb similarity index 99% rename from google-api-client/spec/google/apis/core/api_command_spec.rb rename to google-apis-core/spec/google/apis/core/api_command_spec.rb index e7d3cc8dd..106789287 100644 --- a/google-api-client/spec/google/apis/core/api_command_spec.rb +++ b/google-apis-core/spec/google/apis/core/api_command_spec.rb @@ -32,11 +32,12 @@ RSpec.describe Google::Apis::Core::ApiCommand do end end - let(:x_goog_api_client_value) { "gl-ruby/#{RUBY_VERSION} gdcl/#{Google::Apis::VERSION}" } + let(:client_version) { "1.2.3" } + let(:x_goog_api_client_value) { "gl-ruby/#{RUBY_VERSION} gdcl/#{client_version}" } context('with preparation') do let(:command) do - Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals') + Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals', client_version: client_version) end it 'should set X-Goog-Api-Client header if none is set' do diff --git a/google-api-client/spec/google/apis/core/batch_spec.rb b/google-apis-core/spec/google/apis/core/batch_spec.rb similarity index 100% rename from google-api-client/spec/google/apis/core/batch_spec.rb rename to google-apis-core/spec/google/apis/core/batch_spec.rb diff --git a/google-api-client/spec/google/apis/core/composite_io_spec.rb b/google-apis-core/spec/google/apis/core/composite_io_spec.rb similarity index 100% rename from google-api-client/spec/google/apis/core/composite_io_spec.rb rename to google-apis-core/spec/google/apis/core/composite_io_spec.rb diff --git a/google-api-client/spec/google/apis/core/download_spec.rb b/google-apis-core/spec/google/apis/core/download_spec.rb similarity index 100% rename from google-api-client/spec/google/apis/core/download_spec.rb rename to google-apis-core/spec/google/apis/core/download_spec.rb diff --git a/google-api-client/spec/google/apis/core/hashable_spec.rb b/google-apis-core/spec/google/apis/core/hashable_spec.rb similarity index 100% rename from google-api-client/spec/google/apis/core/hashable_spec.rb rename to google-apis-core/spec/google/apis/core/hashable_spec.rb diff --git a/google-api-client/spec/google/apis/core/http_command_spec.rb b/google-apis-core/spec/google/apis/core/http_command_spec.rb similarity index 99% rename from google-api-client/spec/google/apis/core/http_command_spec.rb rename to google-apis-core/spec/google/apis/core/http_command_spec.rb index 2b6bed69f..e3f383059 100644 --- a/google-api-client/spec/google/apis/core/http_command_spec.rb +++ b/google-apis-core/spec/google/apis/core/http_command_spec.rb @@ -442,7 +442,7 @@ RSpec.describe Google::Apis::Core::HttpCommand do command.execute(client) end - it 'should prepend user query parameters from options and not remove initial query parameters', :focus do + it 'should prepend user query parameters from options and not remove initial query parameters' do stub_request(:get, 'https://www.googleapis.com/zoo/animals?a=1&a=2&a=3&b=false&foo=bar') .to_return(status: [200, '']) command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals?foo=bar') diff --git a/google-api-client/spec/google/apis/core/json_representation_spec.rb b/google-apis-core/spec/google/apis/core/json_representation_spec.rb similarity index 100% rename from google-api-client/spec/google/apis/core/json_representation_spec.rb rename to google-apis-core/spec/google/apis/core/json_representation_spec.rb diff --git a/google-api-client/spec/google/apis/core/service_spec.rb b/google-apis-core/spec/google/apis/core/service_spec.rb similarity index 98% rename from google-api-client/spec/google/apis/core/service_spec.rb rename to google-apis-core/spec/google/apis/core/service_spec.rb index be994e1b0..b45f78eca 100644 --- a/google-api-client/spec/google/apis/core/service_spec.rb +++ b/google-apis-core/spec/google/apis/core/service_spec.rb @@ -20,9 +20,10 @@ require 'google/apis/core/json_representation' RSpec.describe Google::Apis::Core::BaseService do include TestHelpers - let(:service) { Google::Apis::Core::BaseService.new('https://www.googleapis.com/', '') } - let(:service_with_base_path) { Google::Apis::Core::BaseService.new('https://www.googleapis.com/', 'my_service/v1/') } - let(:x_goog_api_client_value) { "gl-ruby/#{RUBY_VERSION} gdcl/#{Google::Apis::VERSION}" } + let(:client_version) { "1.2.3" } + let(:service) { Google::Apis::Core::BaseService.new('https://www.googleapis.com/', '', client_version: client_version) } + let(:service_with_base_path) { Google::Apis::Core::BaseService.new('https://www.googleapis.com/', 'my_service/v1/', client_version: client_version) } + let(:x_goog_api_client_value) { "gl-ruby/#{RUBY_VERSION} gdcl/#{client_version}" } before do Google::Apis::ClientOptions.default.application_name = 'test' diff --git a/google-api-client/spec/google/apis/core/upload_spec.rb b/google-apis-core/spec/google/apis/core/upload_spec.rb similarity index 100% rename from google-api-client/spec/google/apis/core/upload_spec.rb rename to google-apis-core/spec/google/apis/core/upload_spec.rb diff --git a/google-api-client/spec/google/apis/errors_spec.rb b/google-apis-core/spec/google/apis/errors_spec.rb similarity index 100% rename from google-api-client/spec/google/apis/errors_spec.rb rename to google-apis-core/spec/google/apis/errors_spec.rb diff --git a/google-api-client/spec/google/apis/logging_spec.rb b/google-apis-core/spec/google/apis/logging_spec.rb similarity index 100% rename from google-api-client/spec/google/apis/logging_spec.rb rename to google-apis-core/spec/google/apis/logging_spec.rb diff --git a/google-api-client/spec/google/apis/options_spec.rb b/google-apis-core/spec/google/apis/options_spec.rb similarity index 100% rename from google-api-client/spec/google/apis/options_spec.rb rename to google-apis-core/spec/google/apis/options_spec.rb diff --git a/google-apis-core/spec/google/apis/version_spec.rb b/google-apis-core/spec/google/apis/version_spec.rb new file mode 100644 index 000000000..04e157afe --- /dev/null +++ b/google-apis-core/spec/google/apis/version_spec.rb @@ -0,0 +1,25 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'spec_helper' +require 'google/apis' + +describe Google::Apis::Core::VERSION do + it { is_expected.to be_a(String) } +end + +describe Google::Apis::OS_VERSION do + it { is_expected.to be_a(String) } + it { is_expected.not_to match /\n/ } +end diff --git a/google-apis-core/spec/spec_helper.rb b/google-apis-core/spec/spec_helper.rb new file mode 100644 index 000000000..ce264e33e --- /dev/null +++ b/google-apis-core/spec/spec_helper.rb @@ -0,0 +1,152 @@ +# Copyright 2015 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SPEC_DIR = File.expand_path(File.dirname(__FILE__)) +ROOT_DIR = File.expand_path(File.join(SPEC_DIR, '..')) +LIB_DIR = File.expand_path(File.join(ROOT_DIR, 'lib')) +FIXTURES_DIR = File.expand_path(File.join(SPEC_DIR, 'fixtures')) + +$LOAD_PATH.uniq! + +if defined?(JRUBY_VERSION) + puts 'Skipping coverage on JRuby' +else + # set up coverage + require 'simplecov' + require 'coveralls' + + SimpleCov.formatters = [ + Coveralls::SimpleCov::Formatter, + SimpleCov::Formatter::HTMLFormatter + ] + SimpleCov.start do + add_filter '/spec/' + add_filter '/generated/' + end +end + +require 'rspec' +require 'webmock/rspec' +require 'fakefs/spec_helpers' +require 'json_spec' +require 'logging' +require 'ostruct' +require 'rspec/logging_helper' +require 'google/apis' +require 'google/apis/core/base_service' + +# Configure RSpec to capture log messages for each test. The output from the +# logs will be stored in the @log_output variable. It is a StringIO instance. +RSpec.configure do |config| + include RSpec::LoggingHelper + config.include FakeFS::SpecHelpers, fakefs: true + config.include JsonSpec::Helpers + config.include WebMock::API + config.capture_log_messages + + Google::Apis.logger.level = Logger::DEBUG + WebMock::Config.instance.query_values_notation = :flat_array +end + +[JsonSpec::Matchers::BeJsonEql, + JsonSpec::Matchers::IncludeJson, + JsonSpec::Matchers::HaveJsonType, + JsonSpec::Matchers::HaveJsonSize, + JsonSpec::Matchers::HaveJsonPath].each do |klass| + klass.send(:alias_method, :===, :matches?) +end + +RSpec.shared_context 'HTTP client' do + let(:client) do + Google::Apis::Core::BaseService.new('', '').client + end +end + +module TestHelpers + include WebMock::API + include WebMock::Matchers +end + +# Enable retries for tests +Google::Apis::RequestOptions.default.retries = 5 + +# Allow testing different adapters +Google::Apis::ClientOptions.default.use_net_http = true if ENV['USE_NET_HTTP'] +# Temporarily patch WebMock to allow chunked responses for Net::HTTP +module Net + module WebMockHTTPResponse + def eval_chunk(chunk) + chunk if chunk.is_a?(String) + chunk.read if chunk.is_a?(IO) + chunk.call if chunk.is_a?(Proc) + fail chunk if chunk.is_a?(Class) + chunk + end + + def read_body(dest = nil, &block) + if !(defined?(@__read_body_previously_called).nil?) && @__read_body_previously_called + return super + end + return @body if dest.nil? && block.nil? + fail ArgumentError.new('both arg and block given for HTTP method') if dest && block + return nil if @body.nil? + + dest ||= ::Net::ReadAdapter.new(block) + body_parts = Array(@body) + body_parts.each do |chunk| + chunk = eval_chunk(chunk) + dest << chunk + end + @body = dest + ensure + # allow subsequent calls to #read_body to proceed as normal, without our hack... + @__read_body_previously_called = true + end + end +end + +class WebMockHTTPClient + def eval_chunk(chunk) + chunk if chunk.is_a?(String) + chunk.read if chunk.is_a?(IO) + chunk.call if chunk.is_a?(Proc) + fail HTTPClient::TimeoutError if chunk == ::Timeout::Error + fail chunk if chunk.is_a?(Class) + chunk + end + + def build_httpclient_response(webmock_response, stream = false, req_header = nil, &block) + body = stream ? StringIO.new(webmock_response.body) : webmock_response.body + response = HTTP::Message.new_response(body, req_header) + response.header.init_response(webmock_response.status[0]) + response.reason = webmock_response.status[1] + webmock_response.headers.to_a.each { |name, value| response.header.set(name, value) } + + raise HTTPClient::TimeoutError if webmock_response.should_timeout + webmock_response.raise_error_if_any + + body_parts = Array(webmock_response.body) + body_parts.each do |chunk| + chunk = eval_chunk(chunk) + block.call(response, chunk) if block + end + + response + end +end + + +def run_integration_tests? + ENV['GOOGLE_APPLICATION_CREDENTIALS'] && ENV['GOOGLE_PROJECT_ID'] +end diff --git a/google-apis-core/spec/spec_helper/load_path_spec.rb b/google-apis-core/spec/spec_helper/load_path_spec.rb new file mode 100644 index 000000000..d982aeb6b --- /dev/null +++ b/google-apis-core/spec/spec_helper/load_path_spec.rb @@ -0,0 +1,25 @@ +# Copyright 2015 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'spec_helper' + +RSpec.describe $LOAD_PATH do + it('should contain SPEC_DIR') do + expect($LOAD_PATH).to include(SPEC_DIR) + end + + it('should contain LIB_DIR') do + expect($LOAD_PATH).to include(LIB_DIR) + end +end