Add script to update the OpenAPI specification

Also fixes the task to retrieve a CA bundle which broke on the upgrade
from rest-client to Faraday.
This commit is contained in:
Brandur 2017-03-14 16:51:11 -07:00
parent 8564d3b629
commit 3b193db847
2 changed files with 36 additions and 6 deletions

View File

@ -140,6 +140,10 @@ Update bundled CA certificates from the [Mozilla cURL release][curl]:
bundle exec rake update_certs
Update bundled OpenAPI specification from the canonical repository:
bundle exec rake update_spec
[api-keys]: https://dashboard.stripe.com/account/apikeys
[connect]: https://stripe.com/connect
[curl]: http://curl.haxx.se/docs/caextract.html

View File

@ -6,12 +6,38 @@ Rake::TestTask.new do |t|
t.pattern = './test/**/*_test.rb'
end
desc "update bundled certs"
desc "Update bundled certs"
task :update_certs do
require "restclient"
File.open(File.join(File.dirname(__FILE__), 'lib', 'data', 'ca-certificates.crt'), 'w') do |file|
resp = Faraday.get "https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt"
abort("bad response when fetching bundle") unless resp.code == 200
file.write(resp.to_str)
require "faraday"
fetch_file "https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt",
File.expand_path("../lib/data/ca-certificates.crt", __FILE__)
end
desc "Update OpenAPI specification"
task :update_spec do
require "faraday"
["fixtures.json", "fixtures.yaml", "spec.json", "spec.yaml"].map { |file|
Thread.new do
fetch_file "https://raw.githubusercontent.com/stripe/openapi/master/spec/#{file}",
File.expand_path("../spec/#{file}", __FILE__)
end
}.map { |t| t.join }
end
#
# helpers
#
def fetch_file(url, dest)
File.open(dest, 'w') do |file|
resp = Faraday.get(url)
unless resp.status == 200
abort("bad response when fetching: #{url}\n" \
"Status #{resp.status}: #{resp.body}")
end
file.write(resp.body)
puts "Successfully fetched: #{url}"
end
end