shrine-flickr 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +50 -11
- data/lib/shrine/storage/flickr.rb +28 -13
- data/shrine-flickr.gemspec +1 -1
- 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: 4761bed9ab500b93b20b470079e6f250306e5022
|
4
|
+
data.tar.gz: 444f254394e988529d323b1f725b5f2e26338c77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d1b39cb97e7917b7b12edd804e0d826fd927090b7a0b17aa8987fc96171198f8cff1aa814e34a34058e9b0f6667454a89ffd7c727ef6e099596af5b86a1c6e8
|
7
|
+
data.tar.gz: cbaacdf09623d2f40cd2326ecf599ed0ccc579902e726ef100a117580b33d51cfe980de16a2cbda60ad47036c81928b7d574a467253a8950d38b9ed307766cbe
|
data/README.md
CHANGED
@@ -31,33 +31,60 @@ require "shrine/storage/flickr"
|
|
31
31
|
Shrine::Storage::Flickr.new(access_token: ["key", "secret"])
|
32
32
|
```
|
33
33
|
|
34
|
-
### URL
|
34
|
+
### URL, width and height
|
35
35
|
|
36
|
-
After the image is uploaded,
|
37
|
-
|
36
|
+
After the image is uploaded, URLs, widths and heighs of all sizes will be saved
|
37
|
+
to "flickr_sizes" metadata key:
|
38
38
|
|
39
39
|
```rb
|
40
|
-
user.avatar.metadata #=>
|
41
|
-
#
|
42
|
-
#
|
43
|
-
# "
|
44
|
-
# "
|
45
|
-
# "
|
40
|
+
user.avatar.metadata["flickr_sizes"] #=>
|
41
|
+
# [
|
42
|
+
# {
|
43
|
+
# "name" => "Square 75",
|
44
|
+
# "url" => "https://farm6.staticflickr.com/5706/23367159280_36d62093cf_s.jpg",
|
45
|
+
# "width" => 75,
|
46
|
+
# "height" => 75
|
47
|
+
# },
|
48
|
+
# {
|
49
|
+
# "name" => "Thumbnail",
|
50
|
+
# "url" => "https://farm6.staticflickr.com/5706/23367159280_36d62093cf_t.jpg",
|
51
|
+
# "width" => 100,
|
52
|
+
# "height" => 67
|
53
|
+
# },
|
54
|
+
# {
|
55
|
+
# "name" => "Original",
|
56
|
+
# "url" => "https://farm6.staticflickr.com/5706/23367159280_499ddf155e_o.jpg",
|
57
|
+
# "width" => 100,
|
58
|
+
# "height" => 67
|
46
59
|
# }
|
47
|
-
#
|
60
|
+
# ]
|
48
61
|
```
|
49
62
|
|
50
|
-
You can pass
|
63
|
+
You can pass the size name to `#url`, `#width` and `#height`:
|
51
64
|
|
52
65
|
```rb
|
53
66
|
user.avatar.url(size: "Medium 500")
|
67
|
+
user.avatar.width(size: "Thumbnail")
|
68
|
+
user.avatar.height(size: "Small 320")
|
69
|
+
|
70
|
+
# alternative notation
|
54
71
|
user.avatar.url(size: :medium_500)
|
72
|
+
user.avatar.width(size: :thumbnail)
|
73
|
+
user.avatar.height(size: :small_320)
|
74
|
+
|
75
|
+
# defaults to "Original"
|
76
|
+
user.avatar.url
|
77
|
+
user.avatar.width
|
78
|
+
user.avatar.height
|
55
79
|
```
|
56
80
|
|
57
81
|
All possible sizes are: "Square 75", "Thumbnail", "Square 150", "Small 240",
|
58
82
|
"Small 320", "Medium 500", "Medium 640", "Medium 800", "Large 1024", "Large
|
59
83
|
1600", "Large 2048" and "Original".
|
60
84
|
|
85
|
+
Note that when using storage-flickr you shouldn't load the `store_dimensions`
|
86
|
+
plugin, because they're not compatible.
|
87
|
+
|
61
88
|
### Album
|
62
89
|
|
63
90
|
You can choose to upload all your photos in an album by giving the album ID:
|
@@ -102,6 +129,18 @@ flickr = Shrine::Storage::Flickr.new(access_token: ["...", "..."])
|
|
102
129
|
flickr.clear!(:confirm)
|
103
130
|
```
|
104
131
|
|
132
|
+
### Linking back
|
133
|
+
|
134
|
+
In Flickr's guidelines it states that if you're displaying photos from Flickr
|
135
|
+
on another webiste, you should always link back to Flickr. For that you can
|
136
|
+
use `#flickr_url`:
|
137
|
+
|
138
|
+
```erb
|
139
|
+
<a href="<%= @user.avatar.flickr_url %>">
|
140
|
+
<img src="<%= @user.avatar.url(size: "Small 320") %>">
|
141
|
+
</a>
|
142
|
+
```
|
143
|
+
|
105
144
|
## Contributing
|
106
145
|
|
107
146
|
First you need to create an `.env` file where you will store your credentials:
|
@@ -22,10 +22,16 @@ class Shrine
|
|
22
22
|
id.replace(photo_id)
|
23
23
|
album.add_photo(id) if album
|
24
24
|
|
25
|
-
metadata["flickr_sizes"] =
|
25
|
+
metadata["flickr_sizes"] = []
|
26
26
|
photo = photo(id).get_sizes!
|
27
27
|
photo.available_sizes.each do |size|
|
28
|
-
|
28
|
+
photo.size!(size)
|
29
|
+
metadata["flickr_sizes"] << {
|
30
|
+
"name" => size,
|
31
|
+
"url" => photo.source_url,
|
32
|
+
"width" => photo.width,
|
33
|
+
"height" => photo.height,
|
34
|
+
}
|
29
35
|
end
|
30
36
|
end
|
31
37
|
|
@@ -76,7 +82,7 @@ class Shrine
|
|
76
82
|
module FileMethods
|
77
83
|
def download
|
78
84
|
if storage.is_a?(Storage::Flickr)
|
79
|
-
Down.download(
|
85
|
+
Down.download(url)
|
80
86
|
else
|
81
87
|
super
|
82
88
|
end
|
@@ -84,19 +90,32 @@ class Shrine
|
|
84
90
|
|
85
91
|
def url(**options)
|
86
92
|
if storage.is_a?(Storage::Flickr)
|
87
|
-
|
88
|
-
size = size.to_s.tr("_", " ").capitalize if size.is_a?(Symbol)
|
89
|
-
flickr_sizes.fetch(size)
|
90
|
-
else
|
91
|
-
original_url
|
92
|
-
end
|
93
|
+
size_attribute("url", **options)
|
93
94
|
else
|
94
95
|
super
|
95
96
|
end
|
96
97
|
end
|
97
98
|
|
99
|
+
def width(**options)
|
100
|
+
size_attribute("width", **options)
|
101
|
+
end
|
102
|
+
|
103
|
+
def height(**options)
|
104
|
+
size_attribute("height", **options)
|
105
|
+
end
|
106
|
+
|
107
|
+
def flickr_url
|
108
|
+
"https://www.flickr.com/photos/#{storage.person.id}/#{id}"
|
109
|
+
end
|
110
|
+
|
98
111
|
private
|
99
112
|
|
113
|
+
def size_attribute(key, size: "Original")
|
114
|
+
size = size.to_s.tr("_", " ").capitalize if size.is_a?(Symbol)
|
115
|
+
hash = flickr_sizes.find { |hash| hash["name"] == size }
|
116
|
+
hash.fetch(key) if hash
|
117
|
+
end
|
118
|
+
|
100
119
|
def io
|
101
120
|
if storage.is_a?(Storage::Flickr)
|
102
121
|
@io ||= download
|
@@ -105,10 +124,6 @@ class Shrine
|
|
105
124
|
end
|
106
125
|
end
|
107
126
|
|
108
|
-
def original_url
|
109
|
-
flickr_sizes.fetch("Original")
|
110
|
-
end
|
111
|
-
|
112
127
|
def flickr_sizes
|
113
128
|
metadata["flickr_sizes"]
|
114
129
|
end
|
data/shrine-flickr.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shrine-flickr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: flickr-objects
|