Hello community, here is the log from the commit of package rubygem-faraday for openSUSE:Factory checked in at 2015-02-11 16:46:37 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-faraday (Old) and /work/SRC/openSUSE:Factory/.rubygem-faraday.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-faraday" Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-faraday/rubygem-faraday.changes 2014-10-24 10:48:34.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.rubygem-faraday.new/rubygem-faraday.changes 2015-02-11 16:46:41.000000000 +0100 @@ -1,0 +2,7 @@ +Mon Feb 9 12:30:34 UTC 2015 - [email protected] + +- updated to version 0.9.1 + * Refactor Net:HTTP adapter so that with_net_http_connection can be overridden to allow pooled connections. (@Ben-M) + * Add configurable methods that bypass `retry_if` in the Retry request middleware. (@mike-bourgeous) + +------------------------------------------------------------------- Old: ---- faraday-0.9.0.gem New: ---- faraday-0.9.1.gem gem2rpm.yml ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-faraday.spec ++++++ --- /var/tmp/diff_new_pack.yTlvhO/_old 2015-02-11 16:46:42.000000000 +0100 +++ /var/tmp/diff_new_pack.yTlvhO/_new 2015-02-11 16:46:42.000000000 +0100 @@ -1,7 +1,7 @@ # # spec file for package rubygem-faraday # -# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -16,8 +16,15 @@ # +# +# This file was generated with a gem2rpm.yml and not just plain gem2rpm. +# All sections marked as MANUAL, license headers, summaries and descriptions +# can be maintained in that file. Please consult this file before editing any +# of those fields +# + Name: rubygem-faraday -Version: 0.9.0 +Version: 0.9.1 Release: 0 %define mod_name faraday %define mod_full_name %{mod_name}-%{version} @@ -27,6 +34,7 @@ BuildRequires: ruby-macros >= 5 Url: https://github.com/lostisland/faraday Source: http://rubygems.org/gems/%{mod_full_name}.gem +Source1: gem2rpm.yml Summary: HTTP/REST API client library License: MIT Group: Development/Languages/Ruby ++++++ faraday-0.9.0.gem -> faraday-0.9.1.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/CHANGELOG.md new/CHANGELOG.md --- old/CHANGELOG.md 2014-01-16 06:07:48.000000000 +0100 +++ new/CHANGELOG.md 2015-01-07 18:04:33.000000000 +0100 @@ -1,5 +1,10 @@ # Faraday Changelog +## v0.9.1 + +* Refactor Net:HTTP adapter so that with_net_http_connection can be overridden to allow pooled connections. (@Ben-M) +* Add configurable methods that bypass `retry_if` in the Retry request middleware. (@mike-bourgeous) + ## v0.9.0 * Add HTTPClient adapter (@hakanensari) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/CONTRIBUTING.md new/CONTRIBUTING.md --- old/CONTRIBUTING.md 2014-01-16 06:07:48.000000000 +0100 +++ new/CONTRIBUTING.md 2015-01-07 18:04:33.000000000 +0100 @@ -28,9 +28,9 @@ 2. if they have features not present in included adapters. We are pushing towards a 1.0 release, when we will have to follow [Semantic -Versioning][semver]. If your patch includes changes to break compatiblitity, +Versioning][semver]. If your patch includes changes to break compatibility, note that so we can add it to the [Changelog][]. [semver]: http://semver.org/ -[changelog]: https://github.com/technoweenie/faraday/wiki/Changelog -[faraday_middleware]: https://github.com/pengwynn/faraday_middleware/wiki +[changelog]: https://github.com/lostisland/faraday/wiki/Changelog +[faraday_middleware]: https://github.com/lostisland/faraday_middleware/wiki diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Gemfile new/Gemfile --- old/Gemfile 2014-01-16 06:07:48.000000000 +0100 +++ new/Gemfile 2015-01-07 18:04:33.000000000 +0100 @@ -13,17 +13,13 @@ gem 'leftright', '>= 0.9', :require => false gem 'mime-types', '~> 1.25', :platforms => [:jruby, :ruby_18] gem 'minitest', '>= 5.0.5' - gem 'net-http-persistent', '>= 2.5', :require => false + gem 'net-http-persistent', '>= 2.9.4' gem 'patron', '>= 0.4.2', :platforms => :ruby gem 'rack-test', '>= 0.6', :require => 'rack/test' + gem 'rest-client', '~> 1.6.0', :platforms => [:jruby, :ruby_18] gem 'simplecov' gem 'sinatra', '~> 1.3' gem 'typhoeus', '~> 0.3.3', :platforms => :ruby end -platforms :rbx do - gem 'rubinius-coverage' - gem 'rubysl' -end - gemspec diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/README.md new/README.md --- old/README.md 2014-01-16 06:07:48.000000000 +0100 +++ new/README.md 2015-01-07 18:04:33.000000000 +0100 @@ -11,6 +11,7 @@ * [Typhoeus][] * [Patron][] * [EventMachine][] +* [HTTPClient][] It also includes a Rack adapter for hitting loaded Rack applications through Rack::Test, and a Test adapter for stubbing requests by hand. @@ -29,7 +30,7 @@ response = conn.get '/nigiri/sake.json' # GET http://sushi.com/nigiri/sake.json response.body -conn.get '/nigiri', { :name => 'Maguro' } # GET /nigiri?name=Maguro +conn.get '/nigiri', { :name => 'Maguro' } # GET http://sushi.com/nigiri?name=Maguro conn.get do |req| # GET http://sushi.com/search?page=2&limit=100 req.url '/search', :page => 2 @@ -56,10 +57,10 @@ end ``` -If you don't need to set up anything, you can roll with just the bare minimum: +If you don't need to set up anything, you can roll with just the default middleware +stack and default adapter (see [Faraday::RackBuilder#initialize](https://github.com/lostisland/faraday/blob/master/lib/faraday/rack_builder.rb)): ```ruby -# using the default stack: response = Faraday.get 'http://sushi.com/nigiri/sake.json' ``` @@ -106,11 +107,13 @@ the request/response cycle. ```ruby -def call(env) +def call(request_env) # do something with the request + # request_env[:request_headers].merge!(...) - @app.call(env).on_complete do + @app.call(request_env).on_complete do |response_env| # do something with the response + # response_env[:response_headers].merge!(...) end end ``` @@ -140,20 +143,20 @@ ```ruby # It's possible to define stubbed request outside a test adapter block. stubs = Faraday::Adapter::Test::Stubs.new do |stub| - stub.get('/tamago') { [200, {}, 'egg'] } + stub.get('/tamago') { |env| [200, {}, 'egg'] } end # You can pass stubbed request to the test adapter or define them in a block # or a combination of the two. test = Faraday.new do |builder| builder.adapter :test, stubs do |stub| - stub.get('/ebi') {[ 200, {}, 'shrimp' ]} + stub.get('/ebi') { |env| [ 200, {}, 'shrimp' ]} end end # It's also possible to stub additional requests after the connection has # been initialized. This is useful for testing. -stubs.get('/uni') {[ 200, {}, 'urchin' ]} +stubs.get('/uni') { |env| [ 200, {}, 'urchin' ]} resp = test.get '/tamago' resp.body # => 'egg' @@ -211,6 +214,7 @@ [typhoeus]: https://github.com/typhoeus/typhoeus#readme [patron]: http://toland.github.com/patron/ [eventmachine]: https://github.com/igrigorik/em-http-request#readme +[httpclient]: https://github.com/nahi/httpclient [jruby]: http://jruby.org/ [rubinius]: http://rubini.us/ [license]: LICENSE.md Files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday/adapter/net_http.rb new/lib/faraday/adapter/net_http.rb --- old/lib/faraday/adapter/net_http.rb 2014-01-16 06:07:48.000000000 +0100 +++ new/lib/faraday/adapter/net_http.rb 2015-01-07 18:04:33.000000000 +0100 @@ -25,29 +25,31 @@ ] NET_HTTP_EXCEPTIONS << OpenSSL::SSL::SSLError if defined?(OpenSSL) + NET_HTTP_EXCEPTIONS << Net::OpenTimeout if defined?(Net::OpenTimeout) def call(env) super - http = net_http_connection(env) - configure_ssl(http, env[:ssl]) if env[:url].scheme == 'https' and env[:ssl] + with_net_http_connection(env) do |http| + configure_ssl(http, env[:ssl]) if env[:url].scheme == 'https' and env[:ssl] - req = env[:request] - http.read_timeout = http.open_timeout = req[:timeout] if req[:timeout] - http.open_timeout = req[:open_timeout] if req[:open_timeout] - - begin - http_response = perform_request(http, env) - rescue *NET_HTTP_EXCEPTIONS => err - if defined?(OpenSSL) && OpenSSL::SSL::SSLError === err - raise Faraday::SSLError, err - else - raise Error::ConnectionFailed, err + req = env[:request] + http.read_timeout = http.open_timeout = req[:timeout] if req[:timeout] + http.open_timeout = req[:open_timeout] if req[:open_timeout] + + begin + http_response = perform_request(http, env) + rescue *NET_HTTP_EXCEPTIONS => err + if defined?(OpenSSL) && OpenSSL::SSL::SSLError === err + raise Faraday::SSLError, err + else + raise Error::ConnectionFailed, err + end end - end - save_response(env, http_response.code.to_i, http_response.body || '') do |response_headers| - http_response.each_header do |key, value| - response_headers[key] = value + save_response(env, http_response.code.to_i, http_response.body || '') do |response_headers| + http_response.each_header do |key, value| + response_headers[key] = value + end end end @@ -81,6 +83,10 @@ end end + def with_net_http_connection(env) + yield net_http_connection(env) + end + def net_http_connection(env) if proxy = env[:request][:proxy] Net::HTTP::Proxy(proxy[:uri].host, proxy[:uri].port, proxy[:user], proxy[:password]) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday/adapter/net_http_persistent.rb new/lib/faraday/adapter/net_http_persistent.rb --- old/lib/faraday/adapter/net_http_persistent.rb 2014-01-16 06:07:48.000000000 +0100 +++ new/lib/faraday/adapter/net_http_persistent.rb 2015-01-07 18:04:33.000000000 +0100 @@ -8,7 +8,7 @@ class NetHttpPersistent < NetHttp dependency 'net/http/persistent' - def net_http_connection(env) + def with_net_http_connection(env) if proxy = env[:request][:proxy] proxy_uri = ::URI::HTTP === proxy[:uri] ? proxy[:uri].dup : ::URI.parse(proxy[:uri].to_s) proxy_uri.user = proxy_uri.password = nil @@ -18,7 +18,8 @@ define_method(:password) { proxy[:password] } end if proxy[:user] end - Net::HTTP::Persistent.new 'Faraday', proxy_uri + + yield Net::HTTP::Persistent.new 'Faraday', proxy_uri end def perform_request(http, env) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday/adapter/patron.rb new/lib/faraday/adapter/patron.rb --- old/lib/faraday/adapter/patron.rb 2014-01-16 06:07:48.000000000 +0100 +++ new/lib/faraday/adapter/patron.rb 2015-01-07 18:04:33.000000000 +0100 @@ -39,7 +39,11 @@ @app.call env rescue ::Patron::TimeoutError => err - raise Faraday::Error::TimeoutError, err + if err.message == "Connection time-out" + raise Faraday::Error::ConnectionFailed, err + else + raise Faraday::Error::TimeoutError, err + end rescue ::Patron::Error => err if err.message.include?("code 407") raise Error::ConnectionFailed, %{407 "Proxy Authentication Required "} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday/autoload.rb new/lib/faraday/autoload.rb --- old/lib/faraday/autoload.rb 2014-01-16 06:07:48.000000000 +0100 +++ new/lib/faraday/autoload.rb 2015-01-07 18:04:33.000000000 +0100 @@ -69,7 +69,6 @@ :UrlEncoded => 'url_encoded', :Multipart => 'multipart', :Retry => 'retry', - :Timeout => 'timeout', :Authorization => 'authorization', :BasicAuthentication => 'basic_authentication', :TokenAuthentication => 'token_authentication', diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday/parameters.rb new/lib/faraday/parameters.rb --- old/lib/faraday/parameters.rb 2014-01-16 06:07:48.000000000 +0100 +++ new/lib/faraday/parameters.rb 2015-01-07 18:04:33.000000000 +0100 @@ -1,15 +1,10 @@ +require "forwardable" + module Faraday module NestedParamsEncoder - ESCAPE_RE = /[^a-zA-Z0-9 .~_-]/ - - def self.escape(s) - return s.to_s.gsub(ESCAPE_RE) { - '%' + $&.unpack('H2' * $&.bytesize).join('%').upcase - }.tr(' ', '+') - end - - def self.unescape(s) - CGI.unescape(s.to_s) + class << self + extend Forwardable + def_delegators :'Faraday::Utils', :escape, :unescape end def self.encode(params) @@ -117,16 +112,9 @@ end module FlatParamsEncoder - ESCAPE_RE = /[^a-zA-Z0-9 .~_-]/ - - def self.escape(s) - return s.to_s.gsub(ESCAPE_RE) { - '%' + $&.unpack('H2' * $&.bytesize).join('%').upcase - }.tr(' ', '+') - end - - def self.unescape(s) - CGI.unescape(s.to_s) + class << self + extend Forwardable + def_delegators :'Faraday::Utils', :escape, :unescape end def self.encode(params) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday/request/retry.rb new/lib/faraday/request/retry.rb --- old/lib/faraday/request/retry.rb 2014-01-16 06:07:48.000000000 +0100 +++ new/lib/faraday/request/retry.rb 2015-01-07 18:04:33.000000000 +0100 @@ -19,7 +19,13 @@ # interval that is random between 0.1 and 0.15 # class Request::Retry < Faraday::Middleware - class Options < Faraday::Options.new(:max, :interval, :interval_randomness, :backoff_factor, :exceptions) + + IDEMPOTENT_METHODS = [:delete, :get, :head, :options, :put] + + class Options < Faraday::Options.new(:max, :interval, :interval_randomness, :backoff_factor, + :exceptions, :methods, :retry_if) + DEFAULT_CHECK = lambda { |env,exception| false } + def self.from(value) if Fixnum === value new(value) @@ -49,6 +55,14 @@ Error::TimeoutError]) end + def methods + Array(self[:methods] ||= IDEMPOTENT_METHODS) + end + + def retry_if + self[:retry_if] ||= DEFAULT_CHECK + end + end # Public: Initialize middleware @@ -66,6 +80,15 @@ # given as Class, Module, or String. (default: # [Errno::ETIMEDOUT, Timeout::Error, # Error::TimeoutError]) + # methods - A list of HTTP methods to retry without calling retry_if. Pass + # an empty Array to call retry_if for all exceptions. + # (defaults to the idempotent HTTP methods in IDEMPOTENT_METHODS) + # retry_if - block that will receive the env object and the exception raised + # and should decide if the code should retry still the action or + # not independent of the retry count. This would be useful + # if the exception produced is non-recoverable or if the + # the HTTP method called is not idempotent. + # (defaults to return false) def initialize(app, options = nil) super(app) @options = Options.from(options) @@ -85,8 +108,8 @@ begin env[:body] = request_body # after failure env[:body] is set to the response body @app.call(env) - rescue @errmatch - if retries > 0 + rescue @errmatch => exception + if retries > 0 && retry_request?(env, exception) retries -= 1 sleep sleep_amount(retries + 1) retry @@ -114,5 +137,12 @@ end matcher end + + private + + def retry_request?(env, exception) + @options.methods.include?(env[:method]) || @options.retry_if.call(env, exception) + end + end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday/response/logger.rb new/lib/faraday/response/logger.rb --- old/lib/faraday/response/logger.rb 2014-01-16 06:07:48.000000000 +0100 +++ new/lib/faraday/response/logger.rb 2015-01-07 18:04:33.000000000 +0100 @@ -4,12 +4,15 @@ class Response::Logger < Response::Middleware extend Forwardable - def initialize(app, logger = nil) + DEFAULT_OPTIONS = { :bodies => false } + + def initialize(app, logger = nil, options = {}) super(app) @logger = logger || begin require 'logger' ::Logger.new(STDOUT) end + @options = DEFAULT_OPTIONS.merge(options) end def_delegators :@logger, :debug, :info, :warn, :error, :fatal @@ -17,12 +20,14 @@ def call(env) info "#{env.method} #{env.url.to_s}" debug('request') { dump_headers env.request_headers } + debug('request') { dump_body(env[:body]) } if env[:body] && log_body?(:request) super end def on_complete(env) info('Status') { env.status.to_s } debug('response') { dump_headers env.response_headers } + debug('response') { dump_body env[:body] } if env[:body] && log_body?(:response) end private @@ -30,5 +35,25 @@ def dump_headers(headers) headers.map { |k, v| "#{k}: #{v.inspect}" }.join("\n") end + + def dump_body(body) + if body.respond_to?(:to_str) + body.to_str + else + pretty_inspect(body) + end + end + + def pretty_inspect(body) + require 'pp' unless body.respond_to?(:pretty_inspect) + body.pretty_inspect + end + + def log_body?(type) + case @options[:bodies] + when Hash then @options[:bodies][type] + else @options[:bodies] + end + end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday/response.rb new/lib/faraday/response.rb --- old/lib/faraday/response.rb 2014-01-16 06:07:48.000000000 +0100 +++ new/lib/faraday/response.rb 2015-01-07 18:04:33.000000000 +0100 @@ -61,8 +61,8 @@ def finish(env) raise "response already finished" if finished? - @env = Env.from(env) @on_complete_callbacks.each { |callback| callback.call(env) } + @env = Env.from(env) return self end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday.rb new/lib/faraday.rb --- old/lib/faraday.rb 2014-01-16 06:07:48.000000000 +0100 +++ new/lib/faraday.rb 2015-01-07 18:04:33.000000000 +0100 @@ -14,7 +14,7 @@ # conn.get '/' # module Faraday - VERSION = "0.9.0" + VERSION = "0.9.1" class << self # Public: Gets or sets the root path that Faraday is being loaded from. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2014-01-16 06:07:48.000000000 +0100 +++ new/metadata 2015-01-07 18:04:33.000000000 +0100 @@ -1,14 +1,14 @@ --- !ruby/object:Gem::Specification name: faraday version: !ruby/object:Gem::Version - version: 0.9.0 + version: 0.9.1 platform: ruby authors: - Rick Olson autorequire: bindir: bin cert_chain: [] -date: 2014-01-16 00:00:00.000000000 Z +date: 2015-01-07 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: multipart-post @@ -92,11 +92,13 @@ - lib/faraday/response/raise_error.rb - lib/faraday/upload_io.rb - lib/faraday/utils.rb +- script/cached-bundle - script/console - script/generate_certs - script/package - script/proxy-server - script/release +- script/s3-put - script/server - script/test - test/adapters/default_test.rb @@ -123,6 +125,7 @@ - test/middleware_stack_test.rb - test/multibyte.txt - test/options_test.rb +- test/parameters_test.rb - test/request_middleware_test.rb - test/response_middleware_test.rb - test/strawberry.rb @@ -147,7 +150,7 @@ version: 1.3.5 requirements: [] rubyforge_project: -rubygems_version: 2.2.0 +rubygems_version: 2.2.2 signing_key: specification_version: 2 summary: HTTP/REST API client library. @@ -175,6 +178,7 @@ - test/middleware/retry_test.rb - test/middleware_stack_test.rb - test/options_test.rb +- test/parameters_test.rb - test/request_middleware_test.rb - test/response_middleware_test.rb - test/strawberry.rb diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/script/cached-bundle new/script/cached-bundle --- old/script/cached-bundle 1970-01-01 01:00:00.000000000 +0100 +++ new/script/cached-bundle 2015-01-07 18:04:33.000000000 +0100 @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# Usage: cached-bundle install --deployment +# +# After running `bundle`, caches the `./bundle` directory to S3. +# On the next run, restores the cached directory before running `bundle`. +# When `Gemfile` changes, the cache gets rebuilt. +# +# Requirements: +# - Gemfile +# - TRAVIS_REPO_SLUG +# - TRAVIS_RUBY_VERSION +# - AMAZON_S3_BUCKET +# - script/s3-put +# - bundle +# - curl +# +# Author: Mislav Marohnić + +set -e + +compute_md5() { + local output="$(openssl md5)" + echo "${output##* }" +} + +download() { + curl --tcp-nodelay -qsfL "$1" -o "$2" +} + +bundle_path="bundle" +gemfile_hash="$(compute_md5 <"${BUNDLE_GEMFILE:-Gemfile}")" +cache_name="${TRAVIS_RUBY_VERSION}-${gemfile_hash}.tgz" +fetch_url="http://${AMAZON_S3_BUCKET}.s3.amazonaws.com/${TRAVIS_REPO_SLUG}/${cache_name}" + +if download "$fetch_url" "$cache_name"; then + echo "Reusing cached bundle ${cache_name}" + tar xzf "$cache_name" +fi + +bundle "$@" + +if [ ! -f "$cache_name" ] && [ -n "$AMAZON_SECRET_ACCESS_KEY" ]; then + echo "Caching \`${bundle_path}' to S3" + tar czf "$cache_name" "$bundle_path" + script/s3-put "$cache_name" "${AMAZON_S3_BUCKET}:${TRAVIS_REPO_SLUG}/${cache_name}" +fi diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/script/s3-put new/script/s3-put --- old/script/s3-put 1970-01-01 01:00:00.000000000 +0100 +++ new/script/s3-put 2015-01-07 18:04:33.000000000 +0100 @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +# Usage: s3-put <FILE> <S3_BUCKET>[:<PATH>] [<CONTENT_TYPE>] +# +# Uploads a file to the Amazon S3 service. +# Outputs the URL for the newly uploaded file. +# +# Requirements: +# - AMAZON_ACCESS_KEY_ID +# - AMAZON_SECRET_ACCESS_KEY +# - openssl +# - curl +# +# Author: Mislav Marohnić + +set -e + +authorization() { + local signature="$(string_to_sign | hmac_sha1 | base64)" + echo "AWS ${AMAZON_ACCESS_KEY_ID?}:${signature}" +} + +hmac_sha1() { + openssl dgst -binary -sha1 -hmac "${AMAZON_SECRET_ACCESS_KEY?}" +} + +base64() { + openssl enc -base64 +} + +bin_md5() { + openssl dgst -binary -md5 +} + +string_to_sign() { + echo "$http_method" + echo "$content_md5" + echo "$content_type" + echo "$date" + echo "x-amz-acl:$acl" + printf "/$bucket/$remote_path" +} + +date_string() { + LC_TIME=C date "+%a, %d %h %Y %T %z" +} + +file="$1" +bucket="${2%%:*}" +remote_path="${2#*:}" +content_type="$3" + +if [ -z "$remote_path" ] || [ "$remote_path" = "$bucket" ]; then + remote_path="${file##*/}" +fi + +http_method=PUT +acl="public-read" +content_md5="$(bin_md5 < "$file" | base64)" +date="$(date_string)" + +url="https://$bucket.s3.amazonaws.com/$remote_path" + +curl -qsSf -T "$file" \ + -H "Authorization: $(authorization)" \ + -H "x-amz-acl: $acl" \ + -H "Date: $date" \ + -H "Content-MD5: $content_md5" \ + -H "Content-Type: $content_type" \ + "$url" + +echo "$url" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/adapters/logger_test.rb new/test/adapters/logger_test.rb --- old/test/adapters/logger_test.rb 2014-01-16 06:07:48.000000000 +0100 +++ new/test/adapters/logger_test.rb 2015-01-07 18:04:33.000000000 +0100 @@ -4,17 +4,27 @@ module Adapters class LoggerTest < Faraday::TestCase - def setup - @io = StringIO.new - @logger = Logger.new(@io) - @logger.level = Logger::DEBUG + def conn(logger, logger_options={}) + rubbles = ['Barney', 'Betty', 'Bam Bam'] - @conn = Faraday.new do |b| - b.response :logger, @logger + Faraday.new do |b| + b.response :logger, logger, logger_options b.adapter :test do |stubs| stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'hello'] } + stubs.post('/ohai') { [200, {'Content-Type' => 'text/html'}, 'fred'] } + stubs.get('/ohno') { [200, {'Content-Type' => 'text/html'}, 'wilma'] } + stubs.post('/ohyes') { [200, {'Content-Type' => 'text/html'}, 'pebbles'] } + stubs.get('/rubbles') { [200, {'Content-Type' => 'application/json'}, rubbles] } end end + end + + def setup + @io = StringIO.new + @logger = Logger.new(@io) + @logger.level = Logger::DEBUG + + @conn = conn(@logger) @resp = @conn.get '/hello', nil, :accept => 'text/html' end @@ -33,5 +43,40 @@ def test_logs_response_headers assert_match %(Content-Type: "text/html), @io.string end + + def test_does_not_log_request_body_by_default + @conn.post '/ohai', 'name=Unagi', :accept => 'text/html' + refute_match %(name=Unagi), @io.string + end + + def test_does_not_log_response_body_by_default + @conn.post '/ohai', 'name=Toro', :accept => 'text/html' + refute_match %(fred), @io.string + end + + def test_log_request_body + app = conn(@logger, :bodies => { :request => true }) + app.post '/ohyes', 'name=Tamago', :accept => 'text/html' + assert_match %(name=Tamago), @io.string + end + + def test_log_response_body + app = conn(@logger, :bodies => { :response => true }) + app.get '/ohno', :accept => 'text/html' + assert_match %(wilma), @io.string + end + + def test_log_request_and_response_body + app = conn(@logger, :bodies => true) + app.post '/ohyes', 'name=Ebi', :accept => 'text/html' + assert_match %(name=Ebi), @io.string + assert_match %(pebbles), @io.string + end + + def test_log_response_body_object + app = conn(@logger, :bodies => true) + app.get '/rubbles', nil, :accept => 'text/html' + assert_match %([\"Barney\", \"Betty\", \"Bam Bam\"]\n), @io.string + end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/env_test.rb new/test/env_test.rb --- old/test/env_test.rb 2014-01-16 06:07:48.000000000 +0100 +++ new/test/env_test.rb 2015-01-07 18:04:33.000000000 +0100 @@ -166,6 +166,14 @@ end end + def test_body_is_parsed_on_finish + response = Faraday::Response.new + response.on_complete { |env| env[:body] = env[:body].upcase } + response.finish(@env) + + assert_equal "YIKES", response.body + end + def test_not_success assert [email protected]? end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/helper.rb new/test/helper.rb --- old/test/helper.rb 2014-01-16 06:07:48.000000000 +0100 +++ new/test/helper.rb 2015-01-07 18:04:33.000000000 +0100 @@ -1,14 +1,14 @@ -require 'rubygems' # rubygems/version doesn't work by itself -require 'rubygems/version' # for simplecov-html -require 'simplecov' -require 'coveralls' +if RUBY_VERSION >= '1.9' + require 'simplecov' + require 'coveralls' -SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ - SimpleCov::Formatter::HTMLFormatter, - Coveralls::SimpleCov::Formatter -] -SimpleCov.start do - add_filter '/bundle/' + SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter] + + SimpleCov.start do + add_filter '/bundle/' + add_filter '/test/' + minimum_coverage(87.27) + end end gem 'minitest' if defined? Bundler diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/middleware/retry_test.rb new/test/middleware/retry_test.rb --- old/test/middleware/retry_test.rb 2014-01-16 06:07:48.000000000 +0100 +++ new/test/middleware/retry_test.rb 2015-01-07 18:04:33.000000000 +0100 @@ -10,43 +10,57 @@ Faraday.new do |b| b.request :retry, *retry_args b.adapter :test do |stub| - stub.post('/unstable') { - @times_called += 1 - @explode.call @times_called - } + ['get', 'post'].each do |method| + stub.send(method, '/unstable') { + @times_called += 1 + @explode.call @times_called + } + end end end end def test_unhandled_error @explode = lambda {|n| raise "boom!" } - assert_raises(RuntimeError) { conn.post("/unstable") } + assert_raises(RuntimeError) { conn.get("/unstable") } assert_equal 1, @times_called end def test_handled_error @explode = lambda {|n| raise Errno::ETIMEDOUT } - assert_raises(Errno::ETIMEDOUT) { conn.post("/unstable") } + assert_raises(Errno::ETIMEDOUT) { conn.get("/unstable") } assert_equal 3, @times_called end def test_legacy_max_retries @explode = lambda {|n| raise Errno::ETIMEDOUT } - assert_raises(Errno::ETIMEDOUT) { conn(1).post("/unstable") } + assert_raises(Errno::ETIMEDOUT) { conn(1).get("/unstable") } assert_equal 2, @times_called end + def test_legacy_max_negative_retries + @explode = lambda {|n| raise Errno::ETIMEDOUT } + assert_raises(Errno::ETIMEDOUT) { conn(-9).get("/unstable") } + assert_equal 1, @times_called + end + def test_new_max_retries @explode = lambda {|n| raise Errno::ETIMEDOUT } - assert_raises(Errno::ETIMEDOUT) { conn(:max => 3).post("/unstable") } + assert_raises(Errno::ETIMEDOUT) { conn(:max => 3).get("/unstable") } assert_equal 4, @times_called end + def test_new_max_negative_retries + @explode = lambda { |n| raise Errno::ETIMEDOUT } + assert_raises(Errno::ETIMEDOUT) { conn(:max => -9).get("/unstable") } + assert_equal 1, @times_called + end + def test_interval @explode = lambda {|n| raise Errno::ETIMEDOUT } started = Time.now assert_raises(Errno::ETIMEDOUT) { - conn(:max => 2, :interval => 0.1).post("/unstable") + conn(:max => 2, :interval => 0.1).get("/unstable") } assert_in_delta 0.2, Time.now - started, 0.04 end @@ -70,7 +84,7 @@ retry_middleware.sleep_amount_retries = [2, 1] assert_raises(Errno::ETIMEDOUT) { - retry_middleware.call({}) + retry_middleware.call({:method => :get}) } assert_empty retry_middleware.sleep_amount_retries @@ -101,9 +115,63 @@ def test_custom_exceptions @explode = lambda {|n| raise "boom!" } assert_raises(RuntimeError) { - conn(:exceptions => StandardError).post("/unstable") + conn(:exceptions => StandardError).get("/unstable") + } + assert_equal 3, @times_called + end + + def test_should_stop_retrying_if_block_returns_false_checking_env + @explode = lambda {|n| raise Errno::ETIMEDOUT } + check = lambda { |env,exception| env[:method] != :post } + assert_raises(Errno::ETIMEDOUT) { + conn(:retry_if => check).post("/unstable") + } + assert_equal 1, @times_called + end + + def test_should_stop_retrying_if_block_returns_false_checking_exception + @explode = lambda {|n| raise Errno::ETIMEDOUT } + check = lambda { |env,exception| !exception.kind_of?(Errno::ETIMEDOUT) } + assert_raises(Errno::ETIMEDOUT) { + conn(:retry_if => check).post("/unstable") + } + assert_equal 1, @times_called + end + + def test_should_not_call_retry_if_for_idempotent_methods_if_methods_unspecified + @explode = lambda {|n| raise Errno::ETIMEDOUT } + check = lambda { |env,exception| raise "this should have never been called" } + assert_raises(Errno::ETIMEDOUT) { + conn(:retry_if => check).get("/unstable") + } + assert_equal 3, @times_called + end + + def test_should_not_retry_for_non_idempotent_method_if_methods_unspecified + @explode = lambda {|n| raise Errno::ETIMEDOUT } + assert_raises(Errno::ETIMEDOUT) { + conn.post("/unstable") + } + assert_equal 1, @times_called + end + + def test_should_not_call_retry_if_for_specified_methods + @explode = lambda {|n| raise Errno::ETIMEDOUT } + check = lambda { |env,exception| raise "this should have never been called" } + assert_raises(Errno::ETIMEDOUT) { + conn(:retry_if => check, :methods => [:post]).post("/unstable") } assert_equal 3, @times_called end + + def test_should_call_retry_if_for_empty_method_list + @explode = lambda {|n| raise Errno::ETIMEDOUT } + check = lambda { |env,exception| @times_called < 2 } + assert_raises(Errno::ETIMEDOUT) { + conn(:retry_if => check, :methods => []).get("/unstable") + } + assert_equal 2, @times_called + end + end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/parameters_test.rb new/test/parameters_test.rb --- old/test/parameters_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/parameters_test.rb 2015-01-07 18:04:33.000000000 +0100 @@ -0,0 +1,64 @@ +require File.expand_path("../helper", __FILE__) + +class TestParameters < Faraday::TestCase + # emulates ActiveSupport::SafeBuffer#gsub + FakeSafeBuffer = Struct.new(:string) do + def to_s() self end + def gsub(regex) + string.gsub(regex) { + match, = $&, '' =~ /a/ + yield(match) + } + end + end + + def test_escaping_safe_buffer_nested + monies = FakeSafeBuffer.new("$32,000.00") + assert_equal "a=%2432%2C000.00", Faraday::NestedParamsEncoder.encode("a" => monies) + end + + def test_escaping_safe_buffer_flat + monies = FakeSafeBuffer.new("$32,000.00") + assert_equal "a=%2432%2C000.00", Faraday::FlatParamsEncoder.encode("a" => monies) + end + + def test_raises_typeerror_nested + error = assert_raises TypeError do + Faraday::NestedParamsEncoder.encode("") + end + assert_equal "Can't convert String into Hash.", error.message + end + + def test_raises_typeerror_flat + error = assert_raises TypeError do + Faraday::FlatParamsEncoder.encode("") + end + assert_equal "Can't convert String into Hash.", error.message + end + + def test_decode_array_nested + query = "a[1]=one&a[2]=two&a[3]=three" + expected = {"a" => ["one", "two", "three"]} + assert_equal expected, Faraday::NestedParamsEncoder.decode(query) + end + + def test_decode_array_flat + query = "a=one&a=two&a=three" + expected = {"a" => ["one", "two", "three"]} + assert_equal expected, Faraday::FlatParamsEncoder.decode(query) + end + + def test_nested_decode_hash + query = "a[b1]=one&a[b2]=two&a[b][c]=foo" + expected = {"a" => {"b1" => "one", "b2" => "two", "b" => {"c" => "foo"}}} + assert_equal expected, Faraday::NestedParamsEncoder.decode(query) + end + + def test_encode_nil_nested + assert_equal "a=", Faraday::NestedParamsEncoder.encode("a" => nil) + end + + def test_encode_nil_flat + assert_equal "a", Faraday::FlatParamsEncoder.encode("a" => nil) + end +end ++++++ gem2rpm.yml ++++++ # --- # ## used by gem2rpm # :summary: this is a custom summary # ## used by gem2rpm # :description: |- # this is a custom description # # it can be multiline # ## used by gem2rpm # :license: MIT or Ruby # ## used by gem2rpm and gem_packages # :version_suffix: -x_y # ## used by gem2rpm and gem_packages # :disable_docs: true # ## used by gem2rpm # :disable_automatic_rdoc_dep: true # ## used by gem2rpm # :preamble: |- # BuildRequires: foobar # Requires: foobar # ## used by gem2rpm # :patches: # foo.patch: -p1 # bar.patch: # ## used by gem2rpm :sources: # - foo.desktop # - bar.desktop # :gem_install_args: '....' # ## used by gem2rpm # :pre_install: |- # %if 0%{?use_system_libev} # export USE_VENDORED_LIBEV="no" # %endif # ## used by gem2rpm # :post_install: |- # # delete custom files here or do other fancy stuff # install -D -m 0644 %{S:1} %{buildroot}%{_bindir}/gem2rpm-opensuse # ## used by gem2rpm # :testsuite_command: |- # (pushd %{buildroot}%{gem_base}/gems/%{mod_full_name} && rake test) # ## used by gem2rpm # :filelist: |- # /usr/bin/gem2rpm-opensuse # ## used by gem2rpm # :scripts: # :post: |- # /bin/echo foo # ## used by gem_packages # :main: # :preamble: |- # Requires: util-linux # Recommends: pwgen # :filelist: |- # /usr/bin/gem2rpm-opensuse # ## used by gem_packages # :custom: # apache: # :preamble: |- # Requires: ..... # :filelist: |- # /etc/apache2/conf.d/passenger.conf # :summary: Custom summary is optional # :description: |- # Custom description is optional # # bar # :post: |- # /bin/echo foo # -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
