shrine-transloadit 0.4.1 → 0.4.2
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/README.md +65 -29
- data/lib/shrine/plugins/transloadit.rb +1 -1
- data/shrine-transloadit.gemspec +2 -2
- metadata +4 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 18fd0d46656fbf432fae2922e916d1e77cd3d9ba
         | 
| 4 | 
            +
              data.tar.gz: 34a4619f1dc4b5672a00942a29917c73b5cb0171
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: c4bf1ba126d1b27db9fd2141b646f4189b6be7d2282179f0dae469f79001fc41d48ab6370a8b1e3807dc906099fb5d3d27e59da2a80f6071eb71d97d83d0538f
         | 
| 7 | 
            +
              data.tar.gz: a1a579e0ea60d5b19920ad4216c1f94a73ad3d5effffa9fb27bb0c8dbf98acf91534905287353de8ef37475435d9521fc3aa57164494c3cc051112ca76581333
         | 
    
        data/README.md
    CHANGED
    
    | @@ -35,9 +35,11 @@ Shrine.storages = { | |
| 35 35 | 
             
              store: Shrine::Storage::S3.new(prefix: "store", **s3_options),
         | 
| 36 36 | 
             
            }
         | 
| 37 37 |  | 
| 38 | 
            -
            Shrine | 
| 39 | 
            -
               | 
| 40 | 
            -
             | 
| 38 | 
            +
            class TransloaditUploader < Shrine
         | 
| 39 | 
            +
              plugin :transloadit,
         | 
| 40 | 
            +
                auth_key: "your transloadit key",
         | 
| 41 | 
            +
                auth_secret: "your transloadit secret"
         | 
| 42 | 
            +
            end
         | 
| 41 43 | 
             
            ```
         | 
| 42 44 |  | 
| 43 45 | 
             
            This setup assumes you're doing direct S3 uploads, but you can also do [direct
         | 
| @@ -62,12 +64,16 @@ as a good baseline for your own implementation. | |
| 62 64 |  | 
| 63 65 | 
             
            ## Usage
         | 
| 64 66 |  | 
| 67 | 
            +
            We loaded the `transloadit` plugin in a `TransloaditUploader` base uploader
         | 
| 68 | 
            +
            class, so that any uploaders that you want to do Transloadit processing with
         | 
| 69 | 
            +
            can just inherit from that class.
         | 
| 70 | 
            +
             | 
| 65 71 | 
             
            Transloadit assemblies are built inside `#transloadit_process` method in your
         | 
| 66 72 | 
             
            uploader, and you can use some convenient helper methods which the plugin
         | 
| 67 73 | 
             
            provides.
         | 
| 68 74 |  | 
| 69 75 | 
             
            ```rb
         | 
| 70 | 
            -
            class  | 
| 76 | 
            +
            class ImageUploader < TransloaditUploader # inherit from our Transloadit base uploader class
         | 
| 71 77 | 
             
              def transloadit_process(io, context)
         | 
| 72 78 | 
             
                resized = transloadit_file(io)
         | 
| 73 79 | 
             
                  .add_step("resize", "/image/resize", width: 800)
         | 
| @@ -93,7 +99,7 @@ With Transloadit you can create multiple files in a single assembly, and this | |
| 93 99 | 
             
            plugin allows you to leverage that in form of a hash of versions.
         | 
| 94 100 |  | 
| 95 101 | 
             
            ```rb
         | 
| 96 | 
            -
            class  | 
| 102 | 
            +
            class ImageUploader < TransloaditUploader
         | 
| 97 103 | 
             
              plugin :versions
         | 
| 98 104 |  | 
| 99 105 | 
             
              def transloadit_process(io, context)
         | 
| @@ -114,10 +120,9 @@ Transloadit performs its processing asynchronously, and you can provide a URL | |
| 114 120 | 
             
            where you want Transloadit to POST results of processing once it's finished.
         | 
| 115 121 |  | 
| 116 122 | 
             
            ```rb
         | 
| 117 | 
            -
            class  | 
| 123 | 
            +
            class ImageUploader < TransloaditUploader
         | 
| 118 124 | 
             
              def transloadit_process(io, context)
         | 
| 119 125 | 
             
                # ...
         | 
| 120 | 
            -
             | 
| 121 126 | 
             
                transloadit_assembly(files, notify_url: "http://myapp.com/webhooks/transloadit")
         | 
| 122 127 | 
             
              end
         | 
| 123 128 | 
             
            end
         | 
| @@ -128,7 +133,8 @@ automatically save the results to the attachment column in Shrine's format. | |
| 128 133 |  | 
| 129 134 | 
             
            ```rb
         | 
| 130 135 | 
             
            post "/webhooks/transloadit" do
         | 
| 131 | 
            -
               | 
| 136 | 
            +
              TransloaditUploader::Attacher.transloadit_save(params)
         | 
| 137 | 
            +
              # return 200 status
         | 
| 132 138 | 
             
            end
         | 
| 133 139 | 
             
            ```
         | 
| 134 140 |  | 
| @@ -142,6 +148,24 @@ on upload, along with a [jQuery plugin] for easy integration. Generally you | |
| 142 148 | 
             
            only want to do some light processing on direct uploads, and without any
         | 
| 143 149 | 
             
            exporting, so that you have better control over your Transloadit bandwidth.
         | 
| 144 150 |  | 
| 151 | 
            +
            ```js
         | 
| 152 | 
            +
            // Using https://github.com/transloadit/jquery-sdk
         | 
| 153 | 
            +
            $("#upload-form").transloadit({
         | 
| 154 | 
            +
              wait: true,
         | 
| 155 | 
            +
              params: {
         | 
| 156 | 
            +
                auth: {key: "YOUR_TRANSLOADIT_AUTH_KEY"},
         | 
| 157 | 
            +
                steps: {
         | 
| 158 | 
            +
                  extract_thumbnails: {
         | 
| 159 | 
            +
                    robot:  "/video/thumbs",
         | 
| 160 | 
            +
                    use:    ":original",
         | 
| 161 | 
            +
                    count:  8,
         | 
| 162 | 
            +
                    format: "png",
         | 
| 163 | 
            +
                  }
         | 
| 164 | 
            +
                }
         | 
| 165 | 
            +
              }
         | 
| 166 | 
            +
            });
         | 
| 167 | 
            +
            ```
         | 
| 168 | 
            +
             | 
| 145 169 | 
             
            When direct upload finishes, Transloadit returns information about the uploaded
         | 
| 146 170 | 
             
            file(s), one of which is a temporary URL to the file. You want to save this URL
         | 
| 147 171 | 
             
            as cached attachment, so that you can display it to the user and use it for
         | 
| @@ -175,6 +199,9 @@ representation, using the URL as the "id": | |
| 175 199 | 
             
            }
         | 
| 176 200 | 
             
            ```
         | 
| 177 201 |  | 
| 202 | 
            +
            If the result of direct upload processing are multiple files (e.g. video
         | 
| 203 | 
            +
            thumbnails), you need to assign them to individual records.
         | 
| 204 | 
            +
             | 
| 178 205 | 
             
            See the **[demo app]** for a complete implementation of direct uploads.
         | 
| 179 206 |  | 
| 180 207 | 
             
            ### Templates
         | 
| @@ -186,25 +213,31 @@ Here is an example where the whole processing is defined inside a template, | |
| 186 213 | 
             
            and we just set the location of the imported file.
         | 
| 187 214 |  | 
| 188 215 | 
             
            ```rb
         | 
| 189 | 
            -
            # Your saved  | 
| 216 | 
            +
            # Your Transloadit template saved as "my_template"
         | 
| 190 217 | 
             
            {
         | 
| 191 218 | 
             
              steps: {
         | 
| 192 | 
            -
                import: {
         | 
| 193 | 
            -
                  robot: "/http/import",
         | 
| 194 | 
            -
                  url: "..."
         | 
| 195 | 
            -
                },
         | 
| 196 219 | 
             
                resize: {
         | 
| 197 220 | 
             
                  robot: "/image/resize",
         | 
| 198 | 
            -
                  use: "import",
         | 
| 221 | 
            +
                  use: "import", # the "import" step will be passed in
         | 
| 199 222 | 
             
                  width: 800
         | 
| 223 | 
            +
                },
         | 
| 224 | 
            +
                export: {
         | 
| 225 | 
            +
                  robot: "/s3/store",
         | 
| 226 | 
            +
                  use: "resize",
         | 
| 227 | 
            +
                  bucket: "YOUR_AWS_BUCKET",
         | 
| 228 | 
            +
                  key: "YOUR_AWS_KEY",
         | 
| 229 | 
            +
                  secret: "YOUR_AWS_SECRET",
         | 
| 230 | 
            +
                  bucket_region: "YOUR_AWS_REGION",
         | 
| 231 | 
            +
                  path: "videos/${unique_prefix}/${file.url_name}"
         | 
| 200 232 | 
             
                }
         | 
| 201 233 | 
             
              }
         | 
| 202 234 | 
             
            }
         | 
| 203 235 | 
             
            ```
         | 
| 204 236 | 
             
            ```rb
         | 
| 205 | 
            -
            class  | 
| 237 | 
            +
            class ImageUplaoder < TransloaditUploader
         | 
| 206 238 | 
             
              def transloadit_process(io, context)
         | 
| 207 | 
            -
                 | 
| 239 | 
            +
                import = transloadit_import_step("import", io)
         | 
| 240 | 
            +
                transloadit_assembly("my_template", steps: [import])
         | 
| 208 241 | 
             
              end
         | 
| 209 242 | 
             
            end
         | 
| 210 243 | 
             
            ```
         | 
| @@ -212,18 +245,24 @@ end | |
| 212 245 | 
             
            ### Backgrounding
         | 
| 213 246 |  | 
| 214 247 | 
             
            Even though submitting a Transloadit assembly doesn't require any uploading, it
         | 
| 215 | 
            -
            still does two HTTP requests, so you might want to put  | 
| 216 | 
            -
             | 
| 248 | 
            +
            still does two HTTP requests, so you might want to put them into a background
         | 
| 249 | 
            +
            job. You can configure that in the `TransloaditUploader` base uploader class:
         | 
| 217 250 |  | 
| 218 251 | 
             
            ```rb
         | 
| 219 | 
            -
             | 
| 252 | 
            +
            class TransloaditUploader < Shrine
         | 
| 253 | 
            +
              plugin :transloadit,
         | 
| 254 | 
            +
                auth_key: "your transloadit key",
         | 
| 255 | 
            +
                auth_secret: "your transloadit secret"
         | 
| 256 | 
            +
             | 
| 257 | 
            +
              Attacher.promote { |data| TransloaditJob.perform_async(data) }
         | 
| 258 | 
            +
            end
         | 
| 220 259 | 
             
            ```
         | 
| 221 260 | 
             
            ```rb
         | 
| 222 261 | 
             
            class TransloaditJob
         | 
| 223 262 | 
             
              include Sidekiq::Worker
         | 
| 224 263 |  | 
| 225 264 | 
             
              def perform(data)
         | 
| 226 | 
            -
                 | 
| 265 | 
            +
                TransloaditUploader::Attacher.transloadit_process(data)
         | 
| 227 266 | 
             
              end
         | 
| 228 267 | 
             
            end
         | 
| 229 268 | 
             
            ```
         | 
| @@ -324,9 +363,9 @@ your steps, it only requires you to return an instance of | |
| 324 363 | 
             
            `Transloadit::Assembly`.
         | 
| 325 364 |  | 
| 326 365 | 
             
            ```rb
         | 
| 327 | 
            -
            class MyUploader <  | 
| 366 | 
            +
            class MyUploader < TransloaditUploader
         | 
| 328 367 | 
             
              def transloadit_process(io, context)
         | 
| 329 | 
            -
                #  | 
| 368 | 
            +
                # ...
         | 
| 330 369 | 
             
                transloadit #=> #<Transloadit>
         | 
| 331 370 | 
             
                transloadit.assembly(options)
         | 
| 332 371 | 
             
              end
         | 
| @@ -337,7 +376,7 @@ The import/export helper methods simply generate a `Transloadit::Step` object, | |
| 337 376 | 
             
            and you can pass additional options:
         | 
| 338 377 |  | 
| 339 378 | 
             
            ```rb
         | 
| 340 | 
            -
            class MyUploader <  | 
| 379 | 
            +
            class MyUploader < TransloaditUploader
         | 
| 341 380 | 
             
              def transloadit_process(io, context)
         | 
| 342 381 | 
             
                transloadit_import_step("import", io)             #=> #<Transloadit::Step>
         | 
| 343 382 | 
             
                transloadit_export_step("export", path: "mypath") #=> #<Transloadit::Step>
         | 
| @@ -355,7 +394,7 @@ as an external service cannot access your localhost. In this case you can just | |
| 355 394 | 
             
            do polling:
         | 
| 356 395 |  | 
| 357 396 | 
             
            ```rb
         | 
| 358 | 
            -
            class MyUploader <  | 
| 397 | 
            +
            class MyUploader < TransloaditUploader
         | 
| 359 398 | 
             
              def transloadit_process(io, context)
         | 
| 360 399 | 
             
                # ...
         | 
| 361 400 |  | 
| @@ -376,15 +415,12 @@ class TransloaditJob | |
| 376 415 | 
             
              include Sidekiq::Worker
         | 
| 377 416 |  | 
| 378 417 | 
             
              def perform(data)
         | 
| 379 | 
            -
                attacher =  | 
| 418 | 
            +
                attacher = TransloaditUploader::Attacher.transloadit_process(data)
         | 
| 380 419 |  | 
| 381 420 | 
             
                # Webhooks won't work in development, so we can just use polling.
         | 
| 382 421 | 
             
                unless ENV["RACK_ENV"] == "production"
         | 
| 383 422 | 
             
                  response = attacher.get.transloadit_response
         | 
| 384 | 
            -
                   | 
| 385 | 
            -
                    sleep 1
         | 
| 386 | 
            -
                    response.reload!
         | 
| 387 | 
            -
                  end
         | 
| 423 | 
            +
                  response.reload_until_finished!
         | 
| 388 424 | 
             
                  attacher.transloadit_save(response.body)
         | 
| 389 425 | 
             
                end
         | 
| 390 426 | 
             
              end
         | 
| @@ -81,7 +81,7 @@ class Shrine | |
| 81 81 | 
             
                      assembly = store.transloadit_process(cached_file, context)
         | 
| 82 82 | 
             
                      assembly.options[:fields] ||= {}
         | 
| 83 83 | 
             
                      assembly.options[:fields]["attacher"] = self.dump.merge("attachment" => cached_file.to_json)
         | 
| 84 | 
            -
                      response = assembly. | 
| 84 | 
            +
                      response = assembly.create!
         | 
| 85 85 | 
             
                      raise Error, "#{response["error"]}: #{response["message"]}" if response["error"]
         | 
| 86 86 | 
             
                      cached_file.metadata["transloadit_response"] = response.body.to_json
         | 
| 87 87 | 
             
                      swap(cached_file) or _set(cached_file)
         | 
    
        data/shrine-transloadit.gemspec
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            Gem::Specification.new do |gem|
         | 
| 2 2 | 
             
              gem.name          = "shrine-transloadit"
         | 
| 3 | 
            -
              gem.version       = "0.4. | 
| 3 | 
            +
              gem.version       = "0.4.2"
         | 
| 4 4 |  | 
| 5 5 | 
             
              gem.required_ruby_version = ">= 2.1"
         | 
| 6 6 |  | 
| @@ -14,7 +14,7 @@ Gem::Specification.new do |gem| | |
| 14 14 | 
             
              gem.require_path = "lib"
         | 
| 15 15 |  | 
| 16 16 | 
             
              gem.add_dependency "shrine", "~> 2.2"
         | 
| 17 | 
            -
              gem.add_dependency "transloadit", "~>  | 
| 17 | 
            +
              gem.add_dependency "transloadit", "~> 2.0"
         | 
| 18 18 |  | 
| 19 19 | 
             
              gem.add_development_dependency "rake"
         | 
| 20 20 | 
             
              gem.add_development_dependency "minitest"
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: shrine-transloadit
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.4. | 
| 4 | 
            +
              version: 0.4.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Janko Marohnić
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2017-01-14 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: shrine
         | 
| @@ -30,14 +30,14 @@ dependencies: | |
| 30 30 | 
             
                requirements:
         | 
| 31 31 | 
             
                - - "~>"
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: ' | 
| 33 | 
            +
                    version: '2.0'
         | 
| 34 34 | 
             
              type: :runtime
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 38 | 
             
                - - "~>"
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            -
                    version: ' | 
| 40 | 
            +
                    version: '2.0'
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: rake
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         |