unsplash_image 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -7
- data/lib/unsplash_image/download.rb +1 -1
- data/lib/unsplash_image/helper.rb +2 -2
- data/lib/unsplash_image/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b7ddef2272d5f672ffca89e34aa489d14a3d650d9231507b1a7c36f4e691e27
|
4
|
+
data.tar.gz: 00b61f02431292c30016be945784d2bb8fd91e42feafd36272b8ac5748b74ba4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae2bc4d0d81bd78cdd7b8a75ea0bca782efbc9fa40b86c9c98c42c689e11b1911bbcaa1703652bbe4e7e3677244b2bc33fd288fdf4cad9b775bfd00a2c17b83c
|
7
|
+
data.tar.gz: 7b7d7e60cfdb763e52316e8e7d501ebfba57b63f38722ce4b48062bc8c80a2394a1ff8ba69ccdd1abb8d0b699dbfb70288ed1790272f75c7c2a5cfddce53c631
|
data/README.md
CHANGED
@@ -10,23 +10,23 @@ This is the easiest way to fill your Rails app with real photos.
|
|
10
10
|
|
11
11
|
1. as Rails helper to generate dummy images:
|
12
12
|
```ruby
|
13
|
-
|
13
|
+
<%= image_tag unsplash_image_url(size: '300x200', tags: 'cat, dog') %>
|
14
14
|
|
15
|
-
|
15
|
+
<%= image_tag unsplash_image_url(size: '800x600', tags: 'building') %>
|
16
16
|
|
17
|
-
|
17
|
+
<%= image_tag unsplash_image_url(tags: 'nature') %>
|
18
18
|
```
|
19
19
|
|
20
20
|
2. as a tool to download images from Unsplash.com and use them for your seeds or specs.
|
21
21
|
|
22
22
|
```bash
|
23
|
-
unsplash_image download --path images/cats --tags cat -n 20
|
23
|
+
unsplash_image download --path images/cats --tags cat -n 20
|
24
24
|
```
|
25
25
|
|
26
26
|
3. If you need to have a `File` object with a random image.
|
27
27
|
|
28
28
|
```ruby
|
29
|
-
|
29
|
+
file = UnsplashImage.tempfile(size: '500x500', tags: 'cat')
|
30
30
|
```
|
31
31
|
|
32
32
|
### CLI
|
@@ -49,14 +49,14 @@ You can get random image url inside your views using `unsplash_image_url`.
|
|
49
49
|
|
50
50
|
Example:
|
51
51
|
```erb
|
52
|
-
|
52
|
+
<%= image_tag unsplash_image_url(size: '300x200', tags: 'cat, dog') %>
|
53
53
|
```
|
54
54
|
|
55
55
|
Also you can get it as a file with `UnsplashImage.tempfile`.
|
56
56
|
|
57
57
|
Example:
|
58
58
|
```ruby
|
59
|
-
|
59
|
+
file = UnsplashImage.tempfile(size: '500x500', tags: 'cat')
|
60
60
|
```
|
61
61
|
|
62
62
|
## Installation
|
@@ -78,6 +78,10 @@ To use CLI anywhere in the system you can install gem globally:
|
|
78
78
|
gem install unsplash_image
|
79
79
|
```
|
80
80
|
|
81
|
+
## Unit Tests
|
82
|
+
|
83
|
+
We have simple tests, just run: `ruby test/unsplash_image_test.rb`.
|
84
|
+
|
81
85
|
## Contributing
|
82
86
|
|
83
87
|
You are welcome to contribute. See list of `TODO's` below.
|
@@ -4,7 +4,7 @@ require "tempfile"
|
|
4
4
|
module UnsplashImage
|
5
5
|
module Download
|
6
6
|
def tempfile(size: nil, filename: "image.jpeg", tags: nil)
|
7
|
-
file = Tempfile.new(filename)
|
7
|
+
file = Tempfile.new(filename, binmode: true)
|
8
8
|
begin
|
9
9
|
file.write(URI.parse(UnsplashImage::Helper.unsplash_image_url(size: size, tags: tags)).read)
|
10
10
|
file.rewind
|
@@ -4,10 +4,10 @@ module UnsplashImage
|
|
4
4
|
|
5
5
|
BASE = "https://source.unsplash.com/random".freeze
|
6
6
|
|
7
|
-
def unsplash_image_url(size
|
7
|
+
def unsplash_image_url(size: nil, tags: nil)
|
8
8
|
options = [BASE]
|
9
9
|
|
10
|
-
options << size
|
10
|
+
options << size if size
|
11
11
|
options << "?#{tags}" if tags
|
12
12
|
|
13
13
|
options.join("/")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unsplash_image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Kasyanchuk
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-07-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|