unsplash 2.0.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a89f4db0c073875c05c83221e2ff912ff8b414c316b55e6166fb33fb552b84da
4
- data.tar.gz: cf552d1afd53ff88378bbdacdfc4ec58af9fb006587360c2f02e759408393660
3
+ metadata.gz: 1670b64a1e1eca437b55de57e5442ff0ef0ed7500f229e41697353ea80548179
4
+ data.tar.gz: 98e2b13105ed4c143c1174608ae9c29ac9c54102869271e446c5e7c5e7c3799e
5
5
  SHA512:
6
- metadata.gz: dea3bf58a7a162fe55b1fb169da19c3efc365ca1f0eff1157589f0e3a63cf28c4240fb83ab2e0734d598c6d76abb2fd045bf6f65a9cd9b4d70391347d8432380
7
- data.tar.gz: 602969d85b3584fc6fc0b9422b8e7240665c71cd2cddeaaa566015a6faf13d2909d0070e6dc470ae1f17b22468d0ec3da776c350e60d95470fee81407c91b891
6
+ metadata.gz: 70bfc60287b19221bc0a55a9ef52c61c07f9b34834c01951ab98f670a2b406b674d564375cd09f9191004abe1f0f1f5308b2209a27488cc96973ee191732a789
7
+ data.tar.gz: 70a8ea544b238f1e48afc9b23b5a2c51f837b4d4036fb2017aff2f79da9576e2a0de9615ace3926945c52db0c6718864ba79cc36ff6fe9439c5c9587c2cece1b
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.5.3
1
+ 3.1.2
data/.travis.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.8
4
- - 2.4.5
5
- - 2.5.4
6
- - 2.6.2
3
+ - 2.7.6
4
+ - 3.0.4
5
+ - 3.1.2
7
6
  before_install: gem install bundler
@@ -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
@@ -1,3 +1,5 @@
1
+ require 'faraday/multipart'
2
+
1
3
  module Unsplash #:nodoc:
2
4
 
3
5
  # HTTP connection to and communication with the Unsplash API.
@@ -23,7 +25,6 @@ module Unsplash #:nodoc:
23
25
  @api_version = version
24
26
  @api_base_uri = api_base_uri
25
27
 
26
- oauth_base_uri = oauth_base_uri
27
28
  @oauth = ::OAuth2::Client.new(@application_access_key, @application_secret, site: oauth_base_uri) do |http|
28
29
  http.request :multipart
29
30
  http.request :url_encoded
@@ -94,6 +95,14 @@ module Unsplash #:nodoc:
94
95
  request :delete, path, params
95
96
  end
96
97
 
98
+ def utm_params
99
+ {
100
+ "utm_source" => Unsplash.configuration.utm_source || "api_app",
101
+ "utm_medium" => "referral",
102
+ "utm_campaign" => "api-credit"
103
+ }
104
+ end
105
+
97
106
  private
98
107
 
99
108
  def request(verb, path, params = {})
@@ -102,7 +111,7 @@ module Unsplash #:nodoc:
102
111
  params.merge!(utm_params)
103
112
 
104
113
  if !Unsplash.configuration.utm_source
105
- url = "https://community.unsplash.com/developersblog/unsplash-api-guidelines"
114
+ url = "https://help.unsplash.com/api-guidelines/unsplash-api-guidelines"
106
115
  Unsplash.configuration.logger.warn "utm_source is required as part of API Terms: #{url}"
107
116
  end
108
117
 
@@ -121,7 +130,7 @@ module Unsplash #:nodoc:
121
130
  self.class.public_send verb, path, query: params, headers: public_auth_header
122
131
  end
123
132
  rescue OAuth2::Error => e
124
- OpenStruct.new(headers: {}, status: 403, body: e.error_message(e.response.body))
133
+ OpenStruct.new(headers: {}, status: 403, body: e.message)
125
134
  end
126
135
 
127
136
  if response.headers["Warning"]
@@ -150,14 +159,6 @@ module Unsplash #:nodoc:
150
159
  { "Authorization" => "Client-ID #{@application_access_key}" }
151
160
  end
152
161
 
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
162
  def refresh_token!
162
163
  return if !@oauth_token.expired?
163
164
 
@@ -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. Can also optionally specify a custom image size.
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
@@ -88,6 +88,5 @@ module Unsplash # :nodoc:
88
88
  Unsplash::Collection.new collection.to_hash
89
89
  end
90
90
  end
91
-
92
91
  end
93
92
  end
@@ -1,4 +1,4 @@
1
1
  module Unsplash # :nodoc:
2
2
  # :nodoc:
3
- VERSION = "2.0.1"
3
+ VERSION = "3.0.0"
4
4
  end
data/unsplash.gemspec CHANGED
@@ -18,17 +18,18 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.required_ruby_version = ">= 2.3.0"
21
+ spec.required_ruby_version = ">= 2.7.0"
22
22
 
23
- spec.add_dependency "httparty", "~> 0.16"
24
- spec.add_dependency "oauth2", "~> 1"
23
+ spec.add_dependency "httparty", "~> 0.20"
24
+ spec.add_dependency "oauth2", ">= 2.0.8"
25
+ spec.add_dependency "faraday-multipart", "~> 1.0.4"
25
26
 
26
27
  spec.add_development_dependency "rake", "~> 12.3.2"
27
28
  spec.add_development_dependency "rspec", "~> 3.8.0"
28
- spec.add_development_dependency "vcr", "~> 3.0.0"
29
- spec.add_development_dependency "webmock", "~> 3.5.1"
29
+ spec.add_development_dependency "vcr", "~> 6.1.0"
30
+ spec.add_development_dependency "webmock", "~> 3.18.1"
30
31
  spec.add_development_dependency "pry"
31
- spec.add_development_dependency "coveralls"
32
+ spec.add_development_dependency "coveralls_reborn", "~> 0.25.0"
32
33
  spec.add_development_dependency "dotenv"
33
34
  spec.add_development_dependency "rb-readline"
34
35
  end
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.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Klaassen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-16 00:00:00.000000000 Z
11
+ date: 2022-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -16,28 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.16'
19
+ version: '0.20'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.16'
26
+ version: '0.20'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.8
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.8
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday-multipart
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '1'
47
+ version: 1.0.4
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '1'
54
+ version: 1.0.4
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,28 +86,28 @@ dependencies:
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 3.0.0
89
+ version: 6.1.0
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 3.0.0
96
+ version: 6.1.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: webmock
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 3.5.1
103
+ version: 3.18.1
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: 3.5.1
110
+ version: 3.18.1
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: pry
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -109,19 +123,19 @@ dependencies:
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
- name: coveralls
126
+ name: coveralls_reborn
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - ">="
129
+ - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '0'
131
+ version: 0.25.0
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - ">="
136
+ - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '0'
138
+ version: 0.25.0
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: dotenv
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -150,7 +164,7 @@ dependencies:
150
164
  - - ">="
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
153
- description:
167
+ description:
154
168
  email:
155
169
  - aaron@unsplash.com
156
170
  executables: []
@@ -189,7 +203,7 @@ homepage: https://github.com/unsplash/unsplash_rb
189
203
  licenses:
190
204
  - MIT
191
205
  metadata: {}
192
- post_install_message:
206
+ post_install_message:
193
207
  rdoc_options: []
194
208
  require_paths:
195
209
  - lib
@@ -197,15 +211,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
211
  requirements:
198
212
  - - ">="
199
213
  - !ruby/object:Gem::Version
200
- version: 2.3.0
214
+ version: 2.7.0
201
215
  required_rubygems_version: !ruby/object:Gem::Requirement
202
216
  requirements:
203
217
  - - ">="
204
218
  - !ruby/object:Gem::Version
205
219
  version: '0'
206
220
  requirements: []
207
- rubygems_version: 3.0.3
208
- signing_key:
221
+ rubygems_version: 3.3.7
222
+ signing_key:
209
223
  specification_version: 4
210
224
  summary: Ruby wrapper for the Unsplash API.
211
225
  test_files: []