nightcrawler_swift 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changelog.md +5 -0
- data/README.md +5 -1
- data/lib/nightcrawler_swift/cli/opt_parser.rb +10 -0
- data/lib/nightcrawler_swift/commands/upload.rb +4 -0
- data/lib/nightcrawler_swift/version.rb +1 -1
- data/spec/lib/nightcrawler_swift/cli/opt_parser_spec.rb +14 -0
- data/spec/lib/nightcrawler_swift/cli/runner_spec.rb +15 -0
- data/spec/lib/nightcrawler_swift/commands/upload_spec.rb +17 -0
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 07c444535368e4be022b752521e3f719f8931bf6
         | 
| 4 | 
            +
              data.tar.gz: b0db704983287ac4708f7e7fb5d9517ae4dde0de
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: aa23ca377ea692d7b13acb8c1cff296f679e503595da164c7bfe5a37dda84462e64406631fb3fb6280c2086715d7a5cf5ddbda1e09437bae74aeeabaf07bfbb9
         | 
| 7 | 
            +
              data.tar.gz: 08887d4a0f6b4cf079f35b43e0a054a968e9a72fd59c8fa65230523048f73024f83f268f51386710998d6957a443dce2701764e74fadc883f8b39b92160c556d
         | 
    
        data/Changelog.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -89,7 +89,11 @@ config.nightcrawler_swift.logger = Logger.new(STDOUT) | |
| 89 89 |  | 
| 90 90 | 
             
            > max_age
         | 
| 91 91 |  | 
| 92 | 
            -
             | 
| 92 | 
            +
            Defines the *Cache-Control:max-age=<value>* header.
         | 
| 93 | 
            +
             | 
| 94 | 
            +
            > content_encoding
         | 
| 95 | 
            +
             | 
| 96 | 
            +
            Defines the *Content-Encoding:<vaule>* header
         | 
| 93 97 |  | 
| 94 98 | 
             
            > retries
         | 
| 95 99 |  | 
| @@ -35,6 +35,7 @@ module NightcrawlerSwift::CLI | |
| 35 35 | 
             
                  @parser.separator "options:"
         | 
| 36 36 | 
             
                  configure_option_bucket
         | 
| 37 37 | 
             
                  configure_option_max_age
         | 
| 38 | 
            +
                  configure_option_content_encoding
         | 
| 38 39 | 
             
                  configure_option_config
         | 
| 39 40 | 
             
                  configure_option_no_cache
         | 
| 40 41 | 
             
                  configure_option_help
         | 
| @@ -59,6 +60,15 @@ module NightcrawlerSwift::CLI | |
| 59 60 | 
             
                  end
         | 
| 60 61 | 
             
                end
         | 
| 61 62 |  | 
| 63 | 
            +
                def configure_option_content_encoding
         | 
| 64 | 
            +
                  desc = "Custom content-encoding value"
         | 
| 65 | 
            +
                  @parser.on("--content-encoding=VALUE", String, desc) do |value|
         | 
| 66 | 
            +
                    content_encoding = value.to_s
         | 
| 67 | 
            +
                    @runner.options.config_hash[:content_encoding] = content_encoding
         | 
| 68 | 
            +
                    @runner.log "Using content-encoding: #{content_encoding}"
         | 
| 69 | 
            +
                  end
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
             | 
| 62 72 | 
             
                def configure_option_config
         | 
| 63 73 | 
             
                  @parser.on("-c", "--config=PATH", String, "Alternative '#{NightcrawlerSwift::CLI::CONFIG_FILE}' file") do |path|
         | 
| 64 74 | 
             
                    path = File.expand_path(path.strip)
         | 
| @@ -8,11 +8,15 @@ module NightcrawlerSwift | |
| 8 8 | 
             
                  max_age = opts[:max_age] || options.max_age
         | 
| 9 9 | 
             
                  headers.merge!(cache_control: "public, max-age=#{max_age}", expires: expires(max_age)) if max_age
         | 
| 10 10 |  | 
| 11 | 
            +
                  content_encoding = opts[:content_encoding] || options.content_encoding
         | 
| 12 | 
            +
                  headers.merge!(content_encoding: content_encoding.to_s) if content_encoding
         | 
| 13 | 
            +
             | 
| 11 14 | 
             
                  response = put "#{connection.upload_url}/#{path}", body: body, headers: headers
         | 
| 12 15 | 
             
                  [200, 201].include?(response.code)
         | 
| 13 16 | 
             
                end
         | 
| 14 17 |  | 
| 15 18 | 
             
                private
         | 
| 19 | 
            +
             | 
| 16 20 | 
             
                def content_type file
         | 
| 17 21 | 
             
                  MultiMime.by_file(file).content_type
         | 
| 18 22 | 
             
                end
         | 
| @@ -132,6 +132,20 @@ describe NightcrawlerSwift::CLI::OptParser do | |
| 132 132 | 
             
                  end
         | 
| 133 133 | 
             
                end
         | 
| 134 134 |  | 
| 135 | 
            +
                ["--content-encoding=VALUE"].each do |switch|
         | 
| 136 | 
            +
                  context switch do
         | 
| 137 | 
            +
                    let(:content_encoding) { 'gzip' }
         | 
| 138 | 
            +
                    let(:command) { switch.gsub(/VALUE/, content_encoding) }
         | 
| 139 | 
            +
             | 
| 140 | 
            +
                    it "configures the content-encoding" do
         | 
| 141 | 
            +
                      allow(runner).to receive(:argv).and_return([command])
         | 
| 142 | 
            +
                      allow(runner).to receive(:log)
         | 
| 143 | 
            +
                      subject.parse!
         | 
| 144 | 
            +
                      expect(runner.options.config_hash).to include(content_encoding: content_encoding)
         | 
| 145 | 
            +
                    end
         | 
| 146 | 
            +
                  end
         | 
| 147 | 
            +
                end
         | 
| 148 | 
            +
             | 
| 135 149 | 
             
                ["--no-cache"].each do |switch|
         | 
| 136 150 | 
             
                  context switch do
         | 
| 137 151 | 
             
                    it "configures use_cache with false" do
         | 
| @@ -154,6 +154,21 @@ describe NightcrawlerSwift::CLI::Runner do | |
| 154 154 | 
             
                  end
         | 
| 155 155 | 
             
                end
         | 
| 156 156 |  | 
| 157 | 
            +
                context "with a custom content-encoding" do
         | 
| 158 | 
            +
                  let(:content_encoding) { 'gzip' }
         | 
| 159 | 
            +
             | 
| 160 | 
            +
                  before do
         | 
| 161 | 
            +
                    subject.send :configure_default_options
         | 
| 162 | 
            +
                    expect(subject.options.config_hash).to eql({})
         | 
| 163 | 
            +
                  end
         | 
| 164 | 
            +
             | 
| 165 | 
            +
                  it "sets the content-encoding" do
         | 
| 166 | 
            +
                    allow(subject).to receive(:parse_parameters) { subject.options.config_hash[:content_encoding] = content_encoding }
         | 
| 167 | 
            +
                    subject.run
         | 
| 168 | 
            +
                    expect(NightcrawlerSwift.options.content_encoding).to eql content_encoding
         | 
| 169 | 
            +
                  end
         | 
| 170 | 
            +
                end
         | 
| 171 | 
            +
             | 
| 157 172 | 
             
                context "with no-cache flag" do
         | 
| 158 173 | 
             
                  before do
         | 
| 159 174 | 
             
                    subject.send :configure_default_options
         | 
| @@ -111,6 +111,23 @@ describe NightcrawlerSwift::Upload do | |
| 111 111 | 
             
                  end
         | 
| 112 112 | 
             
                end
         | 
| 113 113 |  | 
| 114 | 
            +
                context "content_encoding" do
         | 
| 115 | 
            +
                  let :default_headers do
         | 
| 116 | 
            +
                    {content_type: "text/css", etag: etag}
         | 
| 117 | 
            +
                  end
         | 
| 118 | 
            +
             | 
| 119 | 
            +
                  it "allows custom content_encoding" do
         | 
| 120 | 
            +
                    NightcrawlerSwift.configure
         | 
| 121 | 
            +
                    subject.execute path, file, content_encoding: 'gzip'
         | 
| 122 | 
            +
                    expect(subject).to have_received(:put).with(
         | 
| 123 | 
            +
                      anything,
         | 
| 124 | 
            +
                      hash_including(
         | 
| 125 | 
            +
                        headers: hash_including(content_encoding: "gzip")
         | 
| 126 | 
            +
                      )
         | 
| 127 | 
            +
                    )
         | 
| 128 | 
            +
                  end
         | 
| 129 | 
            +
                end
         | 
| 130 | 
            +
             | 
| 114 131 | 
             
                context "when response code is 200" do
         | 
| 115 132 | 
             
                  let(:response) { double(:response, code: 200) }
         | 
| 116 133 | 
             
                  it { expect(execute).to be true }
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: nightcrawler_swift
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.9.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - tulios
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2015- | 
| 12 | 
            +
            date: 2015-10-28 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: rest-client
         |