chore: Split google-apis-core into a separate gem (#2134)
This commit is contained in:
parent
1bc1737dc1
commit
a6a5b6071e
32
Rakefile
32
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"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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'
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
--color
|
||||
--format documentation
|
|
@ -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
|
|
@ -0,0 +1,2 @@
|
|||
# Release History
|
||||
|
|
@ -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
|
|
@ -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.
|
|
@ -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.
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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.
|
|
@ -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.
|
|
@ -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.
|
|
@ -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.
|
|
@ -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.
|
|
@ -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.
|
|
@ -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.
|
|
@ -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.
|
|
@ -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.
|
|
@ -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
|
|
@ -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.
|
|
@ -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.
|
|
@ -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
|
|
@ -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')
|
|
@ -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'
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue