├── .github ├── FUNDING.yml ├── dependabot.yml └── workflows │ ├── depsreview.yml │ └── main.yml ├── .gitignore ├── .rubocop.yml ├── .standard.yml ├── Gemfile ├── Gemfile.lock ├── MIT-LICENSE ├── README.md ├── Rakefile ├── bin ├── test └── unsplash_image ├── lib ├── tasks │ └── unsplash_image_tasks.rake ├── unsplash_image.rb └── unsplash_image │ ├── cli.rb │ ├── download.rb │ ├── helper.rb │ ├── railtie.rb │ └── version.rb ├── test ├── dummy │ ├── Rakefile │ ├── app │ │ ├── assets │ │ │ ├── images │ │ │ │ └── .keep │ │ │ └── stylesheets │ │ │ │ └── application.css │ │ ├── channels │ │ │ └── application_cable │ │ │ │ ├── channel.rb │ │ │ │ └── connection.rb │ │ ├── controllers │ │ │ ├── application_controller.rb │ │ │ ├── concerns │ │ │ │ └── .keep │ │ │ └── home_controller.rb │ │ ├── helpers │ │ │ └── application_helper.rb │ │ ├── jobs │ │ │ └── application_job.rb │ │ ├── mailers │ │ │ └── application_mailer.rb │ │ ├── models │ │ │ ├── application_record.rb │ │ │ └── concerns │ │ │ │ └── .keep │ │ └── views │ │ │ ├── home │ │ │ └── index.html.erb │ │ │ └── layouts │ │ │ ├── application.html.erb │ │ │ ├── mailer.html.erb │ │ │ └── mailer.text.erb │ ├── bin │ │ ├── rails │ │ ├── rake │ │ └── setup │ ├── config.ru │ ├── config │ │ ├── application.rb │ │ ├── boot.rb │ │ ├── cable.yml │ │ ├── database.yml │ │ ├── environment.rb │ │ ├── environments │ │ │ ├── development.rb │ │ │ ├── production.rb │ │ │ └── test.rb │ │ ├── initializers │ │ │ ├── content_security_policy.rb │ │ │ ├── filter_parameter_logging.rb │ │ │ ├── inflections.rb │ │ │ └── permissions_policy.rb │ │ ├── locales │ │ │ └── en.yml │ │ ├── puma.rb │ │ ├── routes.rb │ │ └── storage.yml │ ├── lib │ │ └── assets │ │ │ └── .keep │ ├── log │ │ └── .keep │ └── public │ │ ├── 404.html │ │ ├── 422.html │ │ ├── 500.html │ │ ├── apple-touch-icon-precomposed.png │ │ ├── apple-touch-icon.png │ │ └── favicon.ico ├── test_helper.rb └── unsplash_image_test.rb └── unsplash_image.gemspec /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | patreon: igorkasyanchuk 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "bundler" 9 | directory: "/" 10 | schedule: 11 | interval: "daily" 12 | -------------------------------------------------------------------------------- /.github/workflows/depsreview.yml: -------------------------------------------------------------------------------- 1 | name: 'Dependency Review' 2 | 3 | on: [pull_request] 4 | 5 | permissions: 6 | contents: read 7 | 8 | jobs: 9 | dependency-review: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: 'Checkout Repository' 13 | uses: actions/checkout@v3 14 | - name: 'Dependency Review' 15 | uses: actions/dependency-review-action@v1 16 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | standardrb: 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v3 18 | - name: Set up Ruby 19 | uses: ruby/setup-ruby@v1 20 | with: 21 | bundler-cache: true 22 | ruby-version: "2.7" 23 | - name: Run standardrb 24 | run: bundle exec standardrb 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /doc/ 3 | /log/*.log 4 | /pkg/ 5 | /tmp/ 6 | /test/dummy/db/*.sqlite3 7 | /test/dummy/db/*.sqlite3-* 8 | /test/dummy/log/*.log 9 | /test/dummy/storage/ 10 | /test/dummy/tmp/ 11 | 12 | *.gem 13 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | require: standard 2 | 3 | inherit_gem: 4 | standard: config/base.yml 5 | 6 | Layout/ExtraSpacing: 7 | Enabled: false 8 | -------------------------------------------------------------------------------- /.standard.yml: -------------------------------------------------------------------------------- 1 | ignore: 2 | - '**/**': 3 | - Layout/ExtraSpacing 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 | 4 | # Specify your gem's dependencies in unsplash_image.gemspec. 5 | gemspec 6 | 7 | gem "sqlite3" 8 | 9 | gem "standard", group: [:development, :test] 10 | 11 | # Start debugger with binding.b [https://github.com/ruby/debug] 12 | # gem "debug", ">= 1.0.0" 13 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | unsplash_image (0.1.1) 5 | thor (>= 0.20) 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | actioncable (7.0.3.1) 11 | actionpack (= 7.0.3.1) 12 | activesupport (= 7.0.3.1) 13 | nio4r (~> 2.0) 14 | websocket-driver (>= 0.6.1) 15 | actionmailbox (7.0.3.1) 16 | actionpack (= 7.0.3.1) 17 | activejob (= 7.0.3.1) 18 | activerecord (= 7.0.3.1) 19 | activestorage (= 7.0.3.1) 20 | activesupport (= 7.0.3.1) 21 | mail (>= 2.7.1) 22 | net-imap 23 | net-pop 24 | net-smtp 25 | actionmailer (7.0.3.1) 26 | actionpack (= 7.0.3.1) 27 | actionview (= 7.0.3.1) 28 | activejob (= 7.0.3.1) 29 | activesupport (= 7.0.3.1) 30 | mail (~> 2.5, >= 2.5.4) 31 | net-imap 32 | net-pop 33 | net-smtp 34 | rails-dom-testing (~> 2.0) 35 | actionpack (7.0.3.1) 36 | actionview (= 7.0.3.1) 37 | activesupport (= 7.0.3.1) 38 | rack (~> 2.0, >= 2.2.0) 39 | rack-test (>= 0.6.3) 40 | rails-dom-testing (~> 2.0) 41 | rails-html-sanitizer (~> 1.0, >= 1.2.0) 42 | actiontext (7.0.3.1) 43 | actionpack (= 7.0.3.1) 44 | activerecord (= 7.0.3.1) 45 | activestorage (= 7.0.3.1) 46 | activesupport (= 7.0.3.1) 47 | globalid (>= 0.6.0) 48 | nokogiri (>= 1.8.5) 49 | actionview (7.0.3.1) 50 | activesupport (= 7.0.3.1) 51 | builder (~> 3.1) 52 | erubi (~> 1.4) 53 | rails-dom-testing (~> 2.0) 54 | rails-html-sanitizer (~> 1.1, >= 1.2.0) 55 | activejob (7.0.3.1) 56 | activesupport (= 7.0.3.1) 57 | globalid (>= 0.3.6) 58 | activemodel (7.0.3.1) 59 | activesupport (= 7.0.3.1) 60 | activerecord (7.0.3.1) 61 | activemodel (= 7.0.3.1) 62 | activesupport (= 7.0.3.1) 63 | activestorage (7.0.3.1) 64 | actionpack (= 7.0.3.1) 65 | activejob (= 7.0.3.1) 66 | activerecord (= 7.0.3.1) 67 | activesupport (= 7.0.3.1) 68 | marcel (~> 1.0) 69 | mini_mime (>= 1.1.0) 70 | activesupport (7.0.3.1) 71 | concurrent-ruby (~> 1.0, >= 1.0.2) 72 | i18n (>= 1.6, < 2) 73 | minitest (>= 5.1) 74 | tzinfo (~> 2.0) 75 | ast (2.4.2) 76 | builder (3.2.4) 77 | coderay (1.1.3) 78 | concurrent-ruby (1.1.10) 79 | crass (1.0.6) 80 | digest (3.1.0) 81 | erubi (1.10.0) 82 | faker (2.22.0) 83 | i18n (>= 1.8.11, < 2) 84 | globalid (1.0.0) 85 | activesupport (>= 5.0) 86 | i18n (1.12.0) 87 | concurrent-ruby (~> 1.0) 88 | json (2.6.2) 89 | loofah (2.18.0) 90 | crass (~> 1.0.2) 91 | nokogiri (>= 1.5.9) 92 | mail (2.7.1) 93 | mini_mime (>= 0.1.1) 94 | marcel (1.0.2) 95 | method_source (1.0.0) 96 | mini_mime (1.1.2) 97 | minitest (5.16.2) 98 | net-imap (0.2.3) 99 | digest 100 | net-protocol 101 | strscan 102 | net-pop (0.1.1) 103 | digest 104 | net-protocol 105 | timeout 106 | net-protocol (0.1.3) 107 | timeout 108 | net-smtp (0.3.1) 109 | digest 110 | net-protocol 111 | timeout 112 | nio4r (2.5.8) 113 | nokogiri (1.13.7-arm64-darwin) 114 | racc (~> 1.4) 115 | nokogiri (1.13.7-x86_64-darwin) 116 | racc (~> 1.4) 117 | nokogiri (1.13.7-x86_64-linux) 118 | racc (~> 1.4) 119 | parallel (1.22.1) 120 | parser (3.1.2.1) 121 | ast (~> 2.4.1) 122 | pry (0.14.1) 123 | coderay (~> 1.1) 124 | method_source (~> 1.0) 125 | puma (5.6.5) 126 | nio4r (~> 2.0) 127 | racc (1.6.0) 128 | rack (2.2.4) 129 | rack-test (2.0.2) 130 | rack (>= 1.3) 131 | rails (7.0.3.1) 132 | actioncable (= 7.0.3.1) 133 | actionmailbox (= 7.0.3.1) 134 | actionmailer (= 7.0.3.1) 135 | actionpack (= 7.0.3.1) 136 | actiontext (= 7.0.3.1) 137 | actionview (= 7.0.3.1) 138 | activejob (= 7.0.3.1) 139 | activemodel (= 7.0.3.1) 140 | activerecord (= 7.0.3.1) 141 | activestorage (= 7.0.3.1) 142 | activesupport (= 7.0.3.1) 143 | bundler (>= 1.15.0) 144 | railties (= 7.0.3.1) 145 | rails-dom-testing (2.0.3) 146 | activesupport (>= 4.2.0) 147 | nokogiri (>= 1.6) 148 | rails-html-sanitizer (1.4.3) 149 | loofah (~> 2.3) 150 | railties (7.0.3.1) 151 | actionpack (= 7.0.3.1) 152 | activesupport (= 7.0.3.1) 153 | method_source 154 | rake (>= 12.2) 155 | thor (~> 1.0) 156 | zeitwerk (~> 2.5) 157 | rainbow (3.1.1) 158 | rake (13.0.6) 159 | regexp_parser (2.5.0) 160 | rexml (3.2.5) 161 | rubocop (1.33.0) 162 | json (~> 2.3) 163 | parallel (~> 1.10) 164 | parser (>= 3.1.0.0) 165 | rainbow (>= 2.2.2, < 4.0) 166 | regexp_parser (>= 1.8, < 3.0) 167 | rexml (>= 3.2.5, < 4.0) 168 | rubocop-ast (>= 1.19.1, < 2.0) 169 | ruby-progressbar (~> 1.7) 170 | unicode-display_width (>= 1.4.0, < 3.0) 171 | rubocop-ast (1.21.0) 172 | parser (>= 3.1.1.0) 173 | rubocop-performance (1.14.3) 174 | rubocop (>= 1.7.0, < 2.0) 175 | rubocop-ast (>= 0.4.0) 176 | ruby-progressbar (1.11.0) 177 | sqlite3 (1.4.4) 178 | standard (1.15.0) 179 | rubocop (= 1.33.0) 180 | rubocop-performance (= 1.14.3) 181 | strscan (3.0.3) 182 | thor (1.2.1) 183 | timeout (0.3.0) 184 | tzinfo (2.0.4) 185 | concurrent-ruby (~> 1.0) 186 | unicode-display_width (2.2.0) 187 | websocket-driver (0.7.5) 188 | websocket-extensions (>= 0.1.0) 189 | websocket-extensions (0.1.5) 190 | zeitwerk (2.6.0) 191 | 192 | PLATFORMS 193 | arm64-darwin-21 194 | x86_64-darwin-21 195 | x86_64-linux 196 | 197 | DEPENDENCIES 198 | faker 199 | pry 200 | puma 201 | rails 202 | sqlite3 203 | standard 204 | unsplash_image! 205 | 206 | BUNDLED WITH 207 | 2.3.7 208 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2022 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unsplash Image Downloader & Helpers 2 | 3 | [![RailsJazz](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/my_other.svg?raw=true)](https://www.railsjazz.com) 4 | 5 | [!["Buy Me A Coffee"](https://github.com/igorkasyanchuk/get-smart/blob/main/docs/snapshot-bmc-button-small.png?raw=true)](https://buymeacoffee.com/igorkasyanchuk) 6 | 7 | A CLI and a set of Rails helpers to get free images from [Unsplash](https://unsplash.com/). 8 | 9 | This is the easiest way to fill your Rails app with real photos. 10 | 11 | ## Usage 12 | 13 | 1. as Rails helper to generate dummy images: 14 | ```ruby 15 | <%= image_tag unsplash_image_url(size: '300x200', tags: 'cat, dog') %> 16 | 17 | <%= image_tag unsplash_image_url(size: '800x600', tags: 'building') %> 18 | 19 | <%= image_tag unsplash_image_url(tags: 'nature') %> 20 | ``` 21 | 22 | 2. as a tool to download images from Unsplash.com and use them for your seeds or specs. 23 | 24 | ```bash 25 | unsplash_image download --path images/cats --tags cat -n 20 26 | ``` 27 | 28 | 3. If you need to have a `File` object with a random image. 29 | 30 | ```ruby 31 | file = UnsplashImage.tempfile(size: '500x500', tags: 'cat') 32 | ``` 33 | 34 | ### CLI 35 | 36 | By default `unsplash_image download --path ./files` will download 10 random images into a `./files` folder. 37 | 38 | You can see list of all available options by running: 39 | 40 | 41 | ```bash 42 | unsplash_image --help download 43 | ``` 44 | 45 | With additional options you can specify a destination folder, tags, resolution of the images. 46 | 47 | 48 | ### In your Rails app 49 | 50 | You can get random image url inside your views using `unsplash_image_url`. 51 | 52 | Example: 53 | ```erb 54 | <%= image_tag unsplash_image_url(size: '300x200', tags: 'cat, dog') %> 55 | ``` 56 | 57 | Also you can get it as a file with `UnsplashImage.tempfile`. 58 | 59 | Example: 60 | ```ruby 61 | file = UnsplashImage.tempfile(size: '500x500', tags: 'cat') 62 | ``` 63 | 64 | ## Installation 65 | 66 | Add this line to your application's Gemfile: 67 | 68 | ```ruby 69 | gem "unsplash_image" 70 | ``` 71 | 72 | And then execute: 73 | ```bash 74 | $ bundle 75 | ``` 76 | 77 | To use CLI anywhere in the system you can install gem globally: 78 | 79 | ```bash 80 | gem install unsplash_image 81 | ``` 82 | 83 | ## Unit Tests 84 | 85 | We have simple tests, just run: `ruby test/unsplash_image_test.rb`. 86 | 87 | ## Contributing 88 | 89 | You are welcome to contribute. See list of `TODO's` below. 90 | 91 | ## TODO 92 | 93 | - allow caching downloaded files for performance improvement (eg using in factories) 94 | - check with older Rails versions 95 | - tests or specs 96 | - make stand-alone executable installable via `brew`, `apt get`, etc? 97 | 98 | ## License 99 | 100 | The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). 101 | 102 | [](https://www.railsjazz.com/?utm_source=github&utm_medium=bottom&utm_campaign=unsplash_image) 104 | 105 | [!["Buy Me A Coffee"](https://github.com/igorkasyanchuk/get-smart/blob/main/docs/snapshot-bmc-button.png?raw=true)](https://buymeacoffee.com/igorkasyanchuk) 106 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/setup" 2 | 3 | require "bundler/gem_tasks" 4 | -------------------------------------------------------------------------------- /bin/test: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | $: << File.expand_path("../test", __dir__) 3 | 4 | require "bundler/setup" 5 | require "rails/plugin/test" 6 | -------------------------------------------------------------------------------- /bin/unsplash_image: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'unsplash_image/cli' 3 | 4 | UnsplashImage::CLI.start 5 | -------------------------------------------------------------------------------- /lib/tasks/unsplash_image_tasks.rake: -------------------------------------------------------------------------------- 1 | # desc "Explaining what the task does" 2 | # task :unsplash_image do 3 | # # Task goes here 4 | # end 5 | -------------------------------------------------------------------------------- /lib/unsplash_image.rb: -------------------------------------------------------------------------------- 1 | require "unsplash_image/version" 2 | require "unsplash_image/helper" 3 | require "unsplash_image/download" 4 | require "unsplash_image/railtie" if defined?(::Rails) 5 | 6 | module UnsplashImage 7 | end 8 | -------------------------------------------------------------------------------- /lib/unsplash_image/cli.rb: -------------------------------------------------------------------------------- 1 | require "thor" 2 | 3 | require "unsplash_image" 4 | require "pathname" 5 | 6 | module UnsplashImage 7 | class CLI < Thor 8 | package_name "UnsplashImage" 9 | 10 | map "-d" => :download 11 | map "--download" => :download 12 | 13 | default_task :info 14 | 15 | desc :info, "Print info about cli" 16 | 17 | method_option :version, type: :boolean, default: false, aliases: [:v], banner: "Print UnsplashImage version" 18 | def info 19 | if options[:version] 20 | puts "UnsplashImage #{UnsplashImage::VERSION}" 21 | else 22 | info = [ 23 | "UnsplashImage #{UnsplashImage::VERSION}", 24 | "", 25 | "Usage example: ", 26 | " unsplash_image download --path spec/files -n 10", 27 | " unsplash_image download --path images/cats -s 400x400 --tags cat -n 20", 28 | " unsplash_image download --path files/ -s 300x300 --tags cat dogs birds -n 20", 29 | "", 30 | "run 'unsplash_image download' to see awailable options" 31 | ] 32 | puts info.join("\n") 33 | end 34 | end 35 | 36 | desc "download [OPTIONS]", "Download Unsplash images" 37 | 38 | long_desc <<-LONGDESC 39 | `unsplash_image download` will download random unsplash images on your PC 40 | 41 | Example: 42 | 43 | > $ unsplash_image download --path images/cats -s 400x400 --tags cat -n 20 44 | LONGDESC 45 | 46 | DEFAULT_COUNT = 10 47 | DEFAULT_PATH = "." 48 | 49 | method_option :size, type: :string, aliases: [:s], banner: "Specify image size. Example: -s 640x480" 50 | method_option :count, type: :numeric, aliases: [:n], banner: "Specify images count. Example: -n 10" 51 | method_option :path, type: :string, banner: "Specify folder. Example: --path images/cats" 52 | method_option :tags, type: :array, aliases: [:t], banner: "Specify tags. Example: -t cats" 53 | method_option :prefix, type: :string, banner: "Specify file name prefix. Example: --prefix cat_image" 54 | def download 55 | if options.keys.empty? 56 | invoke :help, ["download"] 57 | else 58 | prefix = if !!options[:prefix] 59 | options[:prefix] 60 | else 61 | !(options[:tags].nil? || options[:tags].empty?) ? options[:tags].join("_") : "image" 62 | end 63 | tags = options[:tags]&.join(" ").to_s 64 | 65 | base_path = Pathname.new(options[:path] || DEFAULT_PATH) 66 | FileUtils.mkdir_p(base_path) 67 | 68 | puts "Downloading images to #{base_path.absolute? ? base_path : base_path.realpath.relative_path_from(Dir.pwd)}" 69 | count = (options[:count] || DEFAULT_COUNT).to_i 70 | count.times do |i| 71 | filename = count == 1 ? "#{prefix}.jpeg" : "#{prefix}_#{i + 1}.jpeg" 72 | filename = filename.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "�").strip.tr("\u{202E}%$|:;/\t\r\n\\", "-") 73 | path = File.expand_path(filename, base_path) 74 | puts "Downloading #{filename}" 75 | UnsplashImage.tempfile(size: options[:size], filename: filename, tags: tags + (" " * i)) do |tempfile| 76 | File.write(path, tempfile.read) 77 | end 78 | end 79 | puts "Done!" 80 | end 81 | end 82 | 83 | class << self 84 | def exit_on_failure? 85 | true 86 | end 87 | end 88 | end 89 | end 90 | -------------------------------------------------------------------------------- /lib/unsplash_image/download.rb: -------------------------------------------------------------------------------- 1 | require "open-uri" 2 | require "tempfile" 3 | 4 | module UnsplashImage 5 | module Download 6 | def tempfile(size: nil, filename: "image.jpeg", tags: nil) 7 | file = Tempfile.new(filename, binmode: true) 8 | begin 9 | file.write(URI.parse(UnsplashImage::Helper.unsplash_image_url(size: size, tags: tags)).read) 10 | file.rewind 11 | if block_given? 12 | yield file 13 | else 14 | file 15 | end 16 | ensure 17 | if block_given? 18 | file.close 19 | file.unlink 20 | end 21 | end 22 | end 23 | end 24 | 25 | extend Download 26 | end 27 | -------------------------------------------------------------------------------- /lib/unsplash_image/helper.rb: -------------------------------------------------------------------------------- 1 | module UnsplashImage 2 | module Helper 3 | extend self 4 | 5 | BASE = "https://source.unsplash.com/random".freeze 6 | 7 | def unsplash_image_url(size: nil, tags: nil) 8 | options = [BASE] 9 | 10 | options << size if size 11 | options << "?#{tags}" if tags 12 | 13 | options.join("/") 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/unsplash_image/railtie.rb: -------------------------------------------------------------------------------- 1 | module UnsplashImage 2 | class Railtie < ::Rails::Railtie 3 | initializer "unsplash_image.helpers", before: :load_config_initializers do 4 | ActiveSupport.on_load :action_view do 5 | include UnsplashImage::Helper 6 | end 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/unsplash_image/version.rb: -------------------------------------------------------------------------------- 1 | module UnsplashImage 2 | VERSION = "0.1.1" 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative "config/application" 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /test/dummy/app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/unsplash_image/e9f03829841cf2fcf781ca90101da1c42398fc7d/test/dummy/app/assets/images/.keep -------------------------------------------------------------------------------- /test/dummy/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* Application styles */ 2 | -------------------------------------------------------------------------------- /test/dummy/app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy/app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | end 3 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/unsplash_image/e9f03829841cf2fcf781ca90101da1c42398fc7d/test/dummy/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /test/dummy/app/controllers/home_controller.rb: -------------------------------------------------------------------------------- 1 | class HomeController < ApplicationController 2 | def index 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /test/dummy/app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | # Automatically retry jobs that encountered a deadlock 3 | # retry_on ActiveRecord::Deadlocked 4 | 5 | # Most jobs are safe to ignore if the underlying records are no longer available 6 | # discard_on ActiveJob::DeserializationError 7 | end 8 | -------------------------------------------------------------------------------- /test/dummy/app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: "from@example.com" 3 | layout "mailer" 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy/app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | primary_abstract_class 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy/app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/unsplash_image/e9f03829841cf2fcf781ca90101da1c42398fc7d/test/dummy/app/models/concerns/.keep -------------------------------------------------------------------------------- /test/dummy/app/views/home/index.html.erb: -------------------------------------------------------------------------------- 1 |

Sample Usage

2 | 3 | <%= image_tag unsplash_image_url(size: '300x200') %> 4 | <%= image_tag unsplash_image_url(size: '300x200', tags: 'cat, dog') %> 5 | <%= image_tag unsplash_image_url(size: '300x200', tags: 'car') %> 6 | <%= image_tag unsplash_image_url(size: '300x200', tags: 'blog post') %> 7 | 8 |
9 | 10 | <%= image_tag unsplash_image_url(size: '1200x90', tags: 'gradient') %> 11 | 12 |
13 | 14 | <%= image_tag unsplash_image_url(size: '200x200', tags: 'nature') %> 15 | <%= image_tag unsplash_image_url(size: '1000x200', tags: 'nature') %> 16 | -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dummy 5 | 6 | <%= csrf_meta_tags %> 7 | <%= csp_meta_tag %> 8 | 9 | 15 | 16 | 17 | 18 | <%= yield %> 19 | 20 | 21 | -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /test/dummy/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path("../config/application", __dir__) 3 | require_relative "../config/boot" 4 | require "rails/commands" 5 | -------------------------------------------------------------------------------- /test/dummy/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative "../config/boot" 3 | require "rake" 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /test/dummy/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "fileutils" 3 | 4 | # path to your application root. 5 | APP_ROOT = File.expand_path("..", __dir__) 6 | 7 | def system!(*args) 8 | system(*args) || abort("\n== Command #{args} failed ==") 9 | end 10 | 11 | FileUtils.chdir APP_ROOT do 12 | # This script is a way to set up or update your development environment automatically. 13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome. 14 | # Add necessary setup steps to this file. 15 | 16 | puts "== Installing dependencies ==" 17 | system! "gem install bundler --conservative" 18 | system("bundle check") || system!("bundle install") 19 | 20 | # puts "\n== Copying sample files ==" 21 | # unless File.exist?("config/database.yml") 22 | # FileUtils.cp "config/database.yml.sample", "config/database.yml" 23 | # end 24 | 25 | puts "\n== Preparing database ==" 26 | system! "bin/rails db:prepare" 27 | 28 | puts "\n== Removing old logs and tempfiles ==" 29 | system! "bin/rails log:clear tmp:clear" 30 | 31 | puts "\n== Restarting application server ==" 32 | system! "bin/rails restart" 33 | end 34 | -------------------------------------------------------------------------------- /test/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative "config/environment" 4 | 5 | run Rails.application 6 | Rails.application.load_server 7 | -------------------------------------------------------------------------------- /test/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative "boot" 2 | 3 | require "rails/all" 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | require "unsplash_image" 9 | 10 | module Dummy 11 | class Application < Rails::Application 12 | config.load_defaults Rails::VERSION::STRING.to_f 13 | 14 | # Configuration for the application, engines, and railties goes here. 15 | # 16 | # These settings can be overridden in specific environments using the files 17 | # in config/environments, which are processed later. 18 | # 19 | # config.time_zone = "Central Time (US & Canada)" 20 | # config.eager_load_paths << Rails.root.join("extras") 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /test/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | # Set up gems listed in the Gemfile. 2 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__) 3 | 4 | require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) 5 | $LOAD_PATH.unshift File.expand_path("../../../lib", __dir__) 6 | -------------------------------------------------------------------------------- /test/dummy/config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: test 6 | 7 | production: 8 | adapter: redis 9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 10 | channel_prefix: dummy_production 11 | -------------------------------------------------------------------------------- /test/dummy/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite. Versions 3.8.0 and up are supported. 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem "sqlite3" 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: db/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: db/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: db/production.sqlite3 26 | -------------------------------------------------------------------------------- /test/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /test/dummy/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # In the development environment your application's code is reloaded any time 7 | # it changes. This slows down response time but is perfect for development 8 | # since you don't have to restart the web server when you make code changes. 9 | config.cache_classes = false 10 | 11 | # Do not eager load code on boot. 12 | config.eager_load = false 13 | 14 | # Show full error reports. 15 | config.consider_all_requests_local = true 16 | 17 | # Enable server timing 18 | config.server_timing = true 19 | 20 | # Enable/disable caching. By default caching is disabled. 21 | # Run rails dev:cache to toggle caching. 22 | if Rails.root.join("tmp/caching-dev.txt").exist? 23 | config.action_controller.perform_caching = true 24 | config.action_controller.enable_fragment_cache_logging = true 25 | 26 | config.cache_store = :memory_store 27 | config.public_file_server.headers = { 28 | "Cache-Control" => "public, max-age=#{2.days.to_i}" 29 | } 30 | else 31 | config.action_controller.perform_caching = false 32 | 33 | config.cache_store = :null_store 34 | end 35 | 36 | # Store uploaded files on the local file system (see config/storage.yml for options). 37 | config.active_storage.service = :local 38 | 39 | # Don't care if the mailer can't send. 40 | config.action_mailer.raise_delivery_errors = false 41 | 42 | config.action_mailer.perform_caching = false 43 | 44 | # Print deprecation notices to the Rails logger. 45 | config.active_support.deprecation = :log 46 | 47 | # Raise exceptions for disallowed deprecations. 48 | config.active_support.disallowed_deprecation = :raise 49 | 50 | # Tell Active Support which deprecation messages to disallow. 51 | config.active_support.disallowed_deprecation_warnings = [] 52 | 53 | # Raise an error on page load if there are pending migrations. 54 | config.active_record.migration_error = :page_load 55 | 56 | # Highlight code that triggered database queries in logs. 57 | config.active_record.verbose_query_logs = true 58 | 59 | # Raises error for missing translations. 60 | # config.i18n.raise_on_missing_translations = true 61 | 62 | # Annotate rendered view with file names. 63 | # config.action_view.annotate_rendered_view_with_filenames = true 64 | 65 | # Uncomment if you wish to allow Action Cable access from any origin. 66 | # config.action_cable.disable_request_forgery_protection = true 67 | end 68 | -------------------------------------------------------------------------------- /test/dummy/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # Code is not reloaded between requests. 7 | config.cache_classes = true 8 | 9 | # Eager load code on boot. This eager loads most of Rails and 10 | # your application in memory, allowing both threaded web servers 11 | # and those relying on copy on write to perform better. 12 | # Rake tasks automatically ignore this option for performance. 13 | config.eager_load = true 14 | 15 | # Full error reports are disabled and caching is turned on. 16 | config.consider_all_requests_local = false 17 | config.action_controller.perform_caching = true 18 | 19 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] 20 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). 21 | # config.require_master_key = true 22 | 23 | # Disable serving static files from the `/public` folder by default since 24 | # Apache or NGINX already handles this. 25 | config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? 26 | 27 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 28 | # config.asset_host = "http://assets.example.com" 29 | 30 | # Specifies the header that your server uses for sending files. 31 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache 32 | # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX 33 | 34 | # Store uploaded files on the local file system (see config/storage.yml for options). 35 | config.active_storage.service = :local 36 | 37 | # Mount Action Cable outside main process or domain. 38 | # config.action_cable.mount_path = nil 39 | # config.action_cable.url = "wss://example.com/cable" 40 | # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] 41 | 42 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 43 | # config.force_ssl = true 44 | 45 | # Include generic and useful information about system operation, but avoid logging too much 46 | # information to avoid inadvertent exposure of personally identifiable information (PII). 47 | config.log_level = :info 48 | 49 | # Prepend all log lines with the following tags. 50 | config.log_tags = [:request_id] 51 | 52 | # Use a different cache store in production. 53 | # config.cache_store = :mem_cache_store 54 | 55 | # Use a real queuing backend for Active Job (and separate queues per environment). 56 | # config.active_job.queue_adapter = :resque 57 | # config.active_job.queue_name_prefix = "dummy_production" 58 | 59 | config.action_mailer.perform_caching = false 60 | 61 | # Ignore bad email addresses and do not raise email delivery errors. 62 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 63 | # config.action_mailer.raise_delivery_errors = false 64 | 65 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 66 | # the I18n.default_locale when a translation cannot be found). 67 | config.i18n.fallbacks = true 68 | 69 | # Don't log any deprecations. 70 | config.active_support.report_deprecations = false 71 | 72 | # Use default logging formatter so that PID and timestamp are not suppressed. 73 | config.log_formatter = ::Logger::Formatter.new 74 | 75 | # Use a different logger for distributed setups. 76 | # require "syslog/logger" 77 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") 78 | 79 | if ENV["RAILS_LOG_TO_STDOUT"].present? 80 | logger = ActiveSupport::Logger.new($stdout) 81 | logger.formatter = config.log_formatter 82 | config.logger = ActiveSupport::TaggedLogging.new(logger) 83 | end 84 | 85 | # Do not dump schema after migrations. 86 | config.active_record.dump_schema_after_migration = false 87 | end 88 | -------------------------------------------------------------------------------- /test/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | # The test environment is used exclusively to run your application's 4 | # test suite. You never need to work with it otherwise. Remember that 5 | # your test database is "scratch space" for the test suite and is wiped 6 | # and recreated between test runs. Don't rely on the data there! 7 | 8 | Rails.application.configure do 9 | # Settings specified here will take precedence over those in config/application.rb. 10 | 11 | # Turn false under Spring and add config.action_view.cache_template_loading = true. 12 | config.cache_classes = true 13 | 14 | # Eager loading loads your whole application. When running a single test locally, 15 | # this probably isn't necessary. It's a good idea to do in a continuous integration 16 | # system, or in some way before deploying your code. 17 | config.eager_load = ENV["CI"].present? 18 | 19 | # Configure public file server for tests with Cache-Control for performance. 20 | config.public_file_server.enabled = true 21 | config.public_file_server.headers = { 22 | "Cache-Control" => "public, max-age=#{1.hour.to_i}" 23 | } 24 | 25 | # Show full error reports and disable caching. 26 | config.consider_all_requests_local = true 27 | config.action_controller.perform_caching = false 28 | config.cache_store = :null_store 29 | 30 | # Raise exceptions instead of rendering exception templates. 31 | config.action_dispatch.show_exceptions = false 32 | 33 | # Disable request forgery protection in test environment. 34 | config.action_controller.allow_forgery_protection = false 35 | 36 | # Store uploaded files on the local file system in a temporary directory. 37 | config.active_storage.service = :test 38 | 39 | config.action_mailer.perform_caching = false 40 | 41 | # Tell Action Mailer not to deliver emails to the real world. 42 | # The :test delivery method accumulates sent emails in the 43 | # ActionMailer::Base.deliveries array. 44 | config.action_mailer.delivery_method = :test 45 | 46 | # Print deprecation notices to the stderr. 47 | config.active_support.deprecation = :stderr 48 | 49 | # Raise exceptions for disallowed deprecations. 50 | config.active_support.disallowed_deprecation = :raise 51 | 52 | # Tell Active Support which deprecation messages to disallow. 53 | config.active_support.disallowed_deprecation_warnings = [] 54 | 55 | # Raises error for missing translations. 56 | # config.i18n.raise_on_missing_translations = true 57 | 58 | # Annotate rendered view with file names. 59 | # config.action_view.annotate_rendered_view_with_filenames = true 60 | end 61 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Define an application-wide content security policy. 4 | # See the Securing Rails Applications Guide for more information: 5 | # https://guides.rubyonrails.org/security.html#content-security-policy-header 6 | 7 | # Rails.application.configure do 8 | # config.content_security_policy do |policy| 9 | # policy.default_src :self, :https 10 | # policy.font_src :self, :https, :data 11 | # policy.img_src :self, :https, :data 12 | # policy.object_src :none 13 | # policy.script_src :self, :https 14 | # policy.style_src :self, :https 15 | # # Specify URI for violation reports 16 | # # policy.report_uri "/csp-violation-report-endpoint" 17 | # end 18 | # 19 | # # Generate session nonces for permitted importmap and inline scripts 20 | # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } 21 | # config.content_security_policy_nonce_directives = %w(script-src) 22 | # 23 | # # Report violations without enforcing the policy. 24 | # # config.content_security_policy_report_only = true 25 | # end 26 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure parameters to be filtered from the log file. Use this to limit dissemination of 4 | # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported 5 | # notations and behaviors. 6 | Rails.application.config.filter_parameters += [ 7 | :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn 8 | ] 9 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, "\\1en" 8 | # inflect.singular /^(ox)en/i, "\\1" 9 | # inflect.irregular "person", "people" 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym "RESTful" 16 | # end 17 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/permissions_policy.rb: -------------------------------------------------------------------------------- 1 | # Define an application-wide HTTP permissions policy. For further 2 | # information see https://developers.google.com/web/updates/2018/06/feature-policy 3 | # 4 | # Rails.application.config.permissions_policy do |f| 5 | # f.camera :none 6 | # f.gyroscope :none 7 | # f.microphone :none 8 | # f.usb :none 9 | # f.fullscreen :self 10 | # f.payment :self, "https://secure.example.com" 11 | # end 12 | -------------------------------------------------------------------------------- /test/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t "hello" 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t("hello") %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # "true": "foo" 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at https://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | hello: "Hello world" 34 | -------------------------------------------------------------------------------- /test/dummy/config/puma.rb: -------------------------------------------------------------------------------- 1 | # Puma can serve each request in a thread from an internal thread pool. 2 | # The `threads` method setting takes two numbers: a minimum and maximum. 3 | # Any libraries that use thread pools should be configured to match 4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 5 | # and maximum; this matches the default thread size of Active Record. 6 | # 7 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5) 8 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } 9 | threads min_threads_count, max_threads_count 10 | 11 | # Specifies the `worker_timeout` threshold that Puma will use to wait before 12 | # terminating a worker in development environments. 13 | # 14 | worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" 15 | 16 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 17 | # 18 | port ENV.fetch("PORT", 3000) 19 | 20 | # Specifies the `environment` that Puma will run in. 21 | # 22 | environment ENV.fetch("RAILS_ENV") { "development" } 23 | 24 | # Specifies the `pidfile` that Puma will use. 25 | pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 26 | 27 | # Specifies the number of `workers` to boot in clustered mode. 28 | # Workers are forked web server processes. If using threads and workers together 29 | # the concurrency of the application would be max `threads` * `workers`. 30 | # Workers do not work on JRuby or Windows (both of which do not support 31 | # processes). 32 | # 33 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 34 | 35 | # Use the `preload_app!` method when specifying a `workers` number. 36 | # This directive tells Puma to first boot the application and load code 37 | # before forking the application. This takes advantage of Copy On Write 38 | # process behavior so workers use less memory. 39 | # 40 | # preload_app! 41 | 42 | # Allow puma to be restarted by `bin/rails restart` command. 43 | plugin :tmp_restart 44 | -------------------------------------------------------------------------------- /test/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | root "home#index" 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy/config/storage.yml: -------------------------------------------------------------------------------- 1 | test: 2 | service: Disk 3 | root: <%= Rails.root.join("tmp/storage") %> 4 | 5 | local: 6 | service: Disk 7 | root: <%= Rails.root.join("storage") %> 8 | 9 | # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10 | # amazon: 11 | # service: S3 12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 14 | # region: us-east-1 15 | # bucket: your_own_bucket-<%= Rails.env %> 16 | 17 | # Remember not to checkin your GCS keyfile to a repository 18 | # google: 19 | # service: GCS 20 | # project: your_project 21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 22 | # bucket: your_own_bucket-<%= Rails.env %> 23 | 24 | # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 25 | # microsoft: 26 | # service: AzureStorage 27 | # storage_account_name: your_account_name 28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 29 | # container: your_container_name-<%= Rails.env %> 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /test/dummy/lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/unsplash_image/e9f03829841cf2fcf781ca90101da1c42398fc7d/test/dummy/lib/assets/.keep -------------------------------------------------------------------------------- /test/dummy/log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/unsplash_image/e9f03829841cf2fcf781ca90101da1c42398fc7d/test/dummy/log/.keep -------------------------------------------------------------------------------- /test/dummy/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /test/dummy/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /test/dummy/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /test/dummy/public/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/unsplash_image/e9f03829841cf2fcf781ca90101da1c42398fc7d/test/dummy/public/apple-touch-icon-precomposed.png -------------------------------------------------------------------------------- /test/dummy/public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/unsplash_image/e9f03829841cf2fcf781ca90101da1c42398fc7d/test/dummy/public/apple-touch-icon.png -------------------------------------------------------------------------------- /test/dummy/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/unsplash_image/e9f03829841cf2fcf781ca90101da1c42398fc7d/test/dummy/public/favicon.ico -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # Configure Rails Environment 2 | ENV["RAILS_ENV"] = "test" 3 | 4 | require_relative "../test/dummy/config/environment" 5 | ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)] 6 | require "rails/test_help" 7 | 8 | # Load fixtures from the engine 9 | if ActiveSupport::TestCase.respond_to?(:fixture_path=) 10 | ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__) 11 | ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path 12 | ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files" 13 | ActiveSupport::TestCase.fixtures :all 14 | end 15 | -------------------------------------------------------------------------------- /test/unsplash_image_test.rb: -------------------------------------------------------------------------------- 1 | require_relative "test_helper" 2 | 3 | class UnsplashImageTest < ActiveSupport::TestCase 4 | test "it has a version number" do 5 | assert UnsplashImage::VERSION 6 | end 7 | 8 | test "temp file" do 9 | assert_nothing_raised do 10 | UnsplashImage.tempfile 11 | end 12 | end 13 | 14 | test "helper" do 15 | assert_nothing_raised do 16 | UnsplashImage::Helper.unsplash_image_url 17 | UnsplashImage::Helper.unsplash_image_url(size: "500x500") 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /unsplash_image.gemspec: -------------------------------------------------------------------------------- 1 | require_relative "lib/unsplash_image/version" 2 | 3 | Gem::Specification.new do |spec| 4 | spec.name = "unsplash_image" 5 | spec.version = UnsplashImage::VERSION 6 | spec.authors = ["Igor Kasyanchuk", "Liubomyr Manastyretskyi"] 7 | spec.email = ["igorkasyanchuk@gmail.com", "manastyretskyi@gmail.com"] 8 | spec.homepage = "https://github.com/railsjazz/unsplash_image" 9 | spec.summary = "Show the random images in your Rails app or download them to use for seeding a DB" 10 | spec.description = "Show the random images in your Rails app or download them to use for seeding a DB" 11 | spec.license = "MIT" 12 | 13 | spec.files = Dir.chdir(File.expand_path(__dir__)) do 14 | Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] 15 | end 16 | 17 | spec.executables << "unsplash_image" 18 | 19 | spec.add_dependency "thor", ">= 0.20" 20 | 21 | spec.add_development_dependency "rails" 22 | spec.add_development_dependency "faker" 23 | spec.add_development_dependency "pry" 24 | spec.add_development_dependency "puma" 25 | end 26 | --------------------------------------------------------------------------------