diff --git a/README.md b/README.md index ad17bf4f..2a099a1e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Rakefile b/Rakefile index 078b692f..4ca5b869 100644 --- a/Rakefile +++ b/Rakefile @@ -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