unsplash 2.0.1 → 2.1.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/lib/unsplash/client.rb +20 -0
- data/lib/unsplash/connection.rb +9 -9
- data/lib/unsplash/photo.rb +14 -2
- data/lib/unsplash/user.rb +0 -1
- data/lib/unsplash/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: 02a138e4c3f28999bbac53d0c82eed72a938ead58fb95fb4ec86236f6a6aa8a3
|
4
|
+
data.tar.gz: a0dd3304cdb088fd8859dfde19a0bf7722fd6444eec0e4699aeb25ebfda41492
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15db231f6a97b37af4d8448c02206245a9230ff5c1d7aaf52bf2140c010c94fd744cee4eb9ee9db09f65d72810f869053b906ef5e38ecba51d6523c4f268d4c7
|
7
|
+
data.tar.gz: fb1437ae056f0fb62ea7060c66a7abc66b0810904db29c9c886904b0aa4ef6ae6dfea434a9e58bbcac3a9210f2c607a605c1e8a914552967a8ffc8a04cd4386d
|
data/lib/unsplash/client.rb
CHANGED
@@ -7,6 +7,7 @@ module Unsplash # :nodoc:
|
|
7
7
|
# @param attrs [Hash]
|
8
8
|
def initialize(attrs = {})
|
9
9
|
@attributes = OpenStruct.new(attrs)
|
10
|
+
add_utm_to_links
|
10
11
|
end
|
11
12
|
|
12
13
|
# (Re)load full object details from Unsplash.
|
@@ -39,6 +40,25 @@ module Unsplash # :nodoc:
|
|
39
40
|
self.class.connection
|
40
41
|
end
|
41
42
|
|
43
|
+
# @private
|
44
|
+
def add_utm_params(url)
|
45
|
+
uri = URI.parse(url)
|
46
|
+
|
47
|
+
qs = Rack::Utils.parse_nested_query(uri.query)
|
48
|
+
qs.merge!(connection.utm_params)
|
49
|
+
|
50
|
+
uri.query = Rack::Utils.build_query(qs)
|
51
|
+
|
52
|
+
uri.to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
# @private
|
56
|
+
def add_utm_to_links
|
57
|
+
(@attributes["links"] || {}).each do |key, url|
|
58
|
+
@attributes["links"][key] = add_utm_params(url)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
42
62
|
class << self
|
43
63
|
# The connection object being used to communicate with Unsplash.
|
44
64
|
# @return [Unsplash::Connection] the connection
|
data/lib/unsplash/connection.rb
CHANGED
@@ -94,6 +94,14 @@ module Unsplash #:nodoc:
|
|
94
94
|
request :delete, path, params
|
95
95
|
end
|
96
96
|
|
97
|
+
def utm_params
|
98
|
+
{
|
99
|
+
"utm_source" => Unsplash.configuration.utm_source || "api_app",
|
100
|
+
"utm_medium" => "referral",
|
101
|
+
"utm_campaign" => "api-credit"
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
97
105
|
private
|
98
106
|
|
99
107
|
def request(verb, path, params = {})
|
@@ -102,7 +110,7 @@ module Unsplash #:nodoc:
|
|
102
110
|
params.merge!(utm_params)
|
103
111
|
|
104
112
|
if !Unsplash.configuration.utm_source
|
105
|
-
url = "https://
|
113
|
+
url = "https://help.unsplash.com/api-guidelines/unsplash-api-guidelines"
|
106
114
|
Unsplash.configuration.logger.warn "utm_source is required as part of API Terms: #{url}"
|
107
115
|
end
|
108
116
|
|
@@ -150,14 +158,6 @@ module Unsplash #:nodoc:
|
|
150
158
|
{ "Authorization" => "Client-ID #{@application_access_key}" }
|
151
159
|
end
|
152
160
|
|
153
|
-
def utm_params
|
154
|
-
{
|
155
|
-
utm_source: Unsplash.configuration.utm_source || "api_app",
|
156
|
-
utm_medium: "referral",
|
157
|
-
utm_campaign: "api-credit"
|
158
|
-
}
|
159
|
-
end
|
160
|
-
|
161
161
|
def refresh_token!
|
162
162
|
return if !@oauth_token.expired?
|
163
163
|
|
data/lib/unsplash/photo.rb
CHANGED
@@ -3,6 +3,11 @@ module Unsplash # :nodoc:
|
|
3
3
|
# Unsplash Photo operations.
|
4
4
|
class Photo < Client
|
5
5
|
|
6
|
+
def initialize(attrs)
|
7
|
+
super
|
8
|
+
add_utm_to_urls
|
9
|
+
end
|
10
|
+
|
6
11
|
# Like a photo for the current user.
|
7
12
|
# @return [Boolean] True if successful. Will raise on error.
|
8
13
|
def like!
|
@@ -23,6 +28,12 @@ module Unsplash # :nodoc:
|
|
23
28
|
connection.get(links.download_location)["url"]
|
24
29
|
end
|
25
30
|
|
31
|
+
def add_utm_to_urls
|
32
|
+
(@attributes["urls"] || {}).each do |key, url|
|
33
|
+
@attributes["urls"][key] = add_utm_params(url)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
26
37
|
class << self
|
27
38
|
|
28
39
|
# Get a photo. Can be cropped or resized using the optional parameters.
|
@@ -35,7 +46,7 @@ module Unsplash # :nodoc:
|
|
35
46
|
end
|
36
47
|
|
37
48
|
# Get a random photo or set of photos. The photo selection pool can be narrowed using
|
38
|
-
# a combination of optional parameters.
|
49
|
+
# a combination of optional parameters.
|
39
50
|
# @param count [Integer] Number of photos required. Default=1, Max=30
|
40
51
|
# @param featured [Boolean] Limit selection to featured photos.
|
41
52
|
# @param user [String] Limit selection to given User's ID.
|
@@ -44,6 +55,8 @@ module Unsplash # :nodoc:
|
|
44
55
|
# @return [Unsplash::Photo] An Unsplash Photo if count parameter is omitted
|
45
56
|
# @return [Array] An array of Unsplash Photos if the count parameter is specified. An array is returned even if count is 1
|
46
57
|
def random(count: nil, collections: nil, featured: nil, user: nil, query: nil, orientation: nil)
|
58
|
+
Unsplash.configuration.logger.warn "You cannot combine 'collections' and 'query' parameters. 'query' will be ignored." if collections && query
|
59
|
+
|
47
60
|
params = {
|
48
61
|
collections: (collections && collections.join(",")),
|
49
62
|
featured: featured,
|
@@ -100,7 +113,6 @@ module Unsplash # :nodoc:
|
|
100
113
|
def parse_list(json)
|
101
114
|
JSON.parse(json).map { |photo| new photo }
|
102
115
|
end
|
103
|
-
|
104
116
|
end
|
105
117
|
end
|
106
118
|
end
|
data/lib/unsplash/user.rb
CHANGED
data/lib/unsplash/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unsplash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Klaassen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|