unsplash 1.5.6 → 2.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: 2baf82aec25861dec27432935378a12e49344a1920e8c6d2a0f3972cf80ae275
4
- data.tar.gz: 6964813d9ed8b4bf69122900ed31c6e498cac94ab2748f33f7277086772ea42d
3
+ metadata.gz: d581307faeeb1e5d04567b3f78448e7cb78d461a0f1a5d5fc4df9b1fcb956fbb
4
+ data.tar.gz: e1f9433a95e64812f5f987e826a3e590a66c16f89932ccb4f2c1c4b31465fbc0
5
5
  SHA512:
6
- metadata.gz: 241302c561d0633f1403c483e3fb787dfe1a13319bdf868dc65fe55c17ab9d170adb4d28473a29b1e4ef6ed71ac5d6098a5cde69249d65c9f4ef3546ba3a2b32
7
- data.tar.gz: eaa1640eccffbe19204a2c5a959d3a67533819f6879a35e0bda1bb7469e07396eec791abd4ddb2ca05981849935adfe881e209ef4882aa4e7d14bedc33f2d83c
6
+ metadata.gz: df3a61dfe8ce5343708ec01727ba70270e3795aa61465a93b56e4a75f0ef2c44800c8ac32f2c9ec255a4a7f5e825c597f1528f47f1a976c91d264f60f69cd5f5
7
+ data.tar.gz: 1da020da45c5f45baf522da57fa6cb2ed2a7d36ab32e436f0ab3ab1d2f26f5ddbd5ca2edbc8aca660f099ee319d3ee53b9143b993eddf71d3d117a5ddca18677
data/.gitignore CHANGED
@@ -7,4 +7,6 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- .idea/
10
+ .idea/
11
+
12
+ config.env
@@ -1 +1 @@
1
- ruby-2.4.0
1
+ ruby-2.5.3
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.5
4
- - 2.3.1
5
- - 2.4.0
6
- before_install: gem install bundler -v 1.10.2
3
+ - 2.3.8
4
+ - 2.4.5
5
+ - 2.5.4
6
+ - 2.6.2
7
+ before_install: gem install bundler
data/README.md CHANGED
@@ -34,14 +34,17 @@ Unsplash.configure do |config|
34
34
  config.application_secret = "YOUR APPLICATION SECRET"
35
35
  config.application_redirect_uri = "https://your-application.com/oauth/callback"
36
36
  config.utm_source = "alices_terrific_client_app"
37
+
38
+ # optional:
39
+ config.logger = MyCustomLogger.new
37
40
  end
38
41
  ```
39
42
 
40
43
  #### API Guidelines
41
44
 
42
- All API applications must abide by the [API Guidelines](https://medium.com/unsplash/unsplash-api-guidelines-28e0216e6daa).
45
+ All API applications must abide by the [API Guidelines](https://help.unsplash.com/api-guidelines/unsplash-api-guidelines).
43
46
 
44
- As part of [the API guidelines](https://medium.com/unsplash/unsplash-api-guidelines-28e0216e6daa), all API uses are required to use utm links when providing credit to photographers and Unsplash. Set the `config.utm_source` to your app's name to automatically append the utm source.
47
+ As part of [the API guidelines](https://help.unsplash.com/api-guidelines/unsplash-api-guidelines), all API uses are required to use utm links when providing credit to photographers and Unsplash. Set the `config.utm_source` to your app's name to automatically append the utm source.
45
48
 
46
49
  ### Public-scope actions
47
50
 
@@ -83,7 +86,7 @@ permission scopes you requested and the user authorized.
83
86
 
84
87
  ### Hotlinking
85
88
 
86
- Hotlinking the [Unsplash image files is required](https://medium.com/@lukechesser/unsplash-api-guidelines-hotlinking-images-6c6b51030d2a)
89
+ Hotlinking the [Unsplash image files is required](https://help.unsplash.com/api-guidelines/more-on-each-guideline/guideline-hotlinking-images)
87
90
 
88
91
  Unlike most APIs, Unsplash requires for the image URLs returned by the API to be directly used or embedded in your applications (generally referred to as hotlinking). By using the CDN and embedding the photo URLs in your application, Unsplash can better track photo views and pass those stats on to the photographer, providing them with context for how popular their photo is and how it's being used.
89
92
 
@@ -0,0 +1,5 @@
1
+ UNSPLASH_ACCESS_KEY=abc123
2
+ UNSPLASH_SECRET_KEY=def456
3
+ UNSPLASH_BEARER_TOKEN=ghi789
4
+ UNSPLASH_API_URI=https://api.unsplash.com/
5
+ UNSPLASH_OAUTH_URI=https://unsplash.com/
@@ -9,8 +9,6 @@ require "unsplash/client"
9
9
  require "unsplash/connection"
10
10
  require "unsplash/user"
11
11
  require "unsplash/photo"
12
- require "unsplash/category"
13
- require "unsplash/curated_batch"
14
12
  require "unsplash/collection"
15
13
  require "unsplash/stats"
16
14
  require "unsplash/search"
@@ -8,9 +8,8 @@ module Unsplash # :nodoc:
8
8
  # Get a specific collection.
9
9
  # @param id [Integer] The ID of the collection.
10
10
  # @return [Unsplash::Collection] The requested collection.
11
- def find(id, curated = false)
12
- url = ["/collections", (curated ? "curated" : nil), id].compact.join("/")
13
- Unsplash::Collection.new JSON.parse(connection.get(url).body)
11
+ def find(id)
12
+ Unsplash::Collection.new JSON.parse(connection.get("/collections/#{id}").body)
14
13
  end
15
14
 
16
15
  # Get a list of all collections.
@@ -40,19 +39,6 @@ module Unsplash # :nodoc:
40
39
  list.map { |data| Unsplash::Collection.new(data) }
41
40
  end
42
41
 
43
- # Get a list of all curated collections.
44
- # @param page [Integer] Which page of search results to return.
45
- # @param per_page [Integer] The number of search results per page. (default: 10, maximum: 30)
46
- # @return [Array] A single page of the +Unsplash::Collection+ list.
47
- def curated(page = 1, per_page = 10)
48
- params = {
49
- page: page,
50
- per_page: per_page
51
- }
52
- list = JSON.parse(connection.get("/collections/curated", params).body)
53
- list.map { |data| Unsplash::Collection.new(data) }
54
- end
55
-
56
42
  # Create a new collection on behalf of current user.
57
43
  # @param title [String] The title of the collection.
58
44
  # @param description [String] The collection's description. (optional)
@@ -15,15 +15,5 @@ module Unsplash # :nodoc:
15
15
  def test?
16
16
  !!@test
17
17
  end
18
-
19
- def application_id=(key)
20
- logger.warn "Configuring application_id is deprecated. Use application_access_key."
21
- self.application_access_key = key
22
- end
23
-
24
- def application_id
25
- application_access_key
26
- end
27
-
28
18
  end
29
19
  end
@@ -62,9 +62,8 @@ module Unsplash #:nodoc:
62
62
  # @param token_extract [Hash] OAuth token hash from #extract_token.
63
63
  # @return [OAuth2::AccessToken, nil] New access token object.
64
64
  def create_and_assign_token(token_extract)
65
- unless token_extract.nil?
66
- @oauth_token = OAuth2::AccessToken.from_hash(@oauth, token_extract)
67
- end
65
+ return if !token_extract
66
+ @oauth_token = OAuth2::AccessToken.from_hash(@oauth, token_extract)
68
67
  end
69
68
 
70
69
  # Perform a GET request.
@@ -112,13 +111,17 @@ module Unsplash #:nodoc:
112
111
  # Anything else? User agent?
113
112
  }
114
113
 
115
- response = if @oauth_token
116
- refresh_token!
114
+ response = begin
115
+ if @oauth_token
116
+ refresh_token!
117
117
 
118
- param_key = verb == :post ? :body : :params
119
- @oauth_token.public_send(verb, @api_base_uri + path, param_key => params, headers: headers)
120
- else
121
- self.class.public_send verb, path, query: params, headers: public_auth_header
118
+ param_key = verb == :post ? :body : :params
119
+ @oauth_token.public_send(verb, @api_base_uri + path, param_key => params, headers: headers)
120
+ else
121
+ self.class.public_send verb, path, query: params, headers: public_auth_header
122
+ end
123
+ rescue OAuth2::Error => e
124
+ OpenStruct.new(headers: {}, status: 403, body: e.error_message(e.response.body))
122
125
  end
123
126
 
124
127
  if response.headers["Warning"]
@@ -127,14 +130,17 @@ module Unsplash #:nodoc:
127
130
 
128
131
  status_code = response.respond_to?(:status) ? response.status : response.code
129
132
 
130
- begin
131
- if !(200..299).include?(status_code)
132
- body = JSON.parse(response.body)
133
- msg = body["error"] || body["errors"].join(" ")
134
- raise Unsplash::Error.new msg
135
- end
136
- rescue JSON::ParserError
137
- raise Unsplash::Error.new response.body
133
+ case status_code
134
+ when 200..299
135
+ response
136
+ when 401
137
+ raise Unsplash::UnauthorizedError.new(error_message(response))
138
+ when 403
139
+ raise Unsplash::ForbiddenError.new(error_message(response))
140
+ when 404
141
+ raise Unsplash::NotFoundError.new(error_message(response))
142
+ else
143
+ raise Unsplash::Error.new(error_message(response))
138
144
  end
139
145
 
140
146
  response
@@ -157,5 +163,12 @@ module Unsplash #:nodoc:
157
163
 
158
164
  @oauth_token = @oauth_token.refresh_token
159
165
  end
166
+
167
+ def error_message(response)
168
+ body = JSON.parse(response.body)
169
+ body["error"] || body["errors"].join(" ")
170
+ rescue JSON::ParserError
171
+ raise Unsplash::Error.new(response.body)
172
+ end
160
173
  end
161
174
  end
@@ -3,4 +3,8 @@ module Unsplash # :nodoc:
3
3
  class Error < StandardError; end
4
4
  # Raise for deprecation errors
5
5
  class DeprecationError < Error; end
6
+
7
+ class UnauthorizedError < Error; end
8
+ class ForbiddenError < Error; end
9
+ class NotFoundError < Error; end
6
10
  end
@@ -17,9 +17,9 @@ module Unsplash # :nodoc:
17
17
  true
18
18
  end
19
19
 
20
- # Download a photo.
20
+ # Track the download of a photo.
21
21
  # @return [String] URL of image file for download.
22
- def download!
22
+ def track_download
23
23
  connection.get(links.download_location)["url"]
24
24
  end
25
25
 
@@ -27,17 +27,9 @@ module Unsplash # :nodoc:
27
27
 
28
28
  # Get a photo. Can be cropped or resized using the optional parameters.
29
29
  # @param id [String] The ID of the photo to retrieve.
30
- # @param width [Integer] Width of customized version of the photo.
31
- # @param height [Integer] Height of the customized version of the photo.
32
- # @param crop_rect [String] A comma-separated list (x,y,width,height) of the rectangle to crop from the photo.
33
30
  # @return [Unsplash::Photo] The Unsplash Photo.
34
- def find(id, width: nil, height: nil, crop_rect: nil)
35
- custom = {
36
- w: width,
37
- h: height,
38
- rect: crop_rect
39
- }.select { |k,v| v }
40
- photo = Unsplash::Photo.new JSON.parse(connection.get("/photos/#{id}", custom).body)
31
+ def find(id)
32
+ photo = Unsplash::Photo.new JSON.parse(connection.get("/photos/#{id}").body)
41
33
  photo.user = Unsplash::User.new photo.user
42
34
  photo
43
35
  end
@@ -45,24 +37,18 @@ module Unsplash # :nodoc:
45
37
  # Get a random photo or set of photos. The photo selection pool can be narrowed using
46
38
  # a combination of optional parameters. Can also optionally specify a custom image size.
47
39
  # @param count [Integer] Number of photos required. Default=1, Max=30
48
- # @param categories [Array] Limit selection to given category ID's.
49
40
  # @param featured [Boolean] Limit selection to featured photos.
50
41
  # @param user [String] Limit selection to given User's ID.
51
42
  # @param query [String] Limit selection to given search query.
52
- # @param width [Integer] Width of customized version of the photo.
53
- # @param height [Integer] Height of the customized version of the photo.
54
43
  # @param orientation [String] Filter by orientation of the photo. Valid values are landscape, portrait, and squarish.
55
44
  # @return [Unsplash::Photo] An Unsplash Photo if count parameter is omitted
56
45
  # @return [Array] An array of Unsplash Photos if the count parameter is specified. An array is returned even if count is 1
57
- def random(count: nil, categories: nil, collections: nil, featured: nil, user: nil, query: nil, width: nil, height: nil, orientation: nil)
46
+ def random(count: nil, collections: nil, featured: nil, user: nil, query: nil, orientation: nil)
58
47
  params = {
59
- category: (categories && categories.join(",")),
60
48
  collections: (collections && collections.join(",")),
61
49
  featured: featured,
62
50
  username: user,
63
51
  query: query,
64
- w: width,
65
- h: height,
66
52
  orientation: orientation
67
53
  }.select { |k,v| v }
68
54
  if count
@@ -109,28 +95,6 @@ module Unsplash # :nodoc:
109
95
  parse_list connection.get("/photos/", params).body
110
96
  end
111
97
 
112
- # Get a single page from the list of the curated photos (front-page’s photos).
113
- # @param page [Integer] Which page of search results to return.
114
- # @param per_page [Integer] The number of search results per page. (default: 10, maximum: 30)
115
- # @param order_by [String] How to sort the photos. (Valid values: latest, oldest, popular; default: latest)
116
- # @return [Array] A single page of +Unsplash::Photo+ search results.
117
- def curated(page = 1, per_page = 10, order_by = "latest")
118
- params = {
119
- page: page,
120
- per_page: per_page,
121
- order_by: order_by
122
- }
123
- parse_list connection.get("/photos/curated", params).body
124
- end
125
-
126
- # Upload a photo on behalf of the current user.
127
- # @param filepath [String] The local path of the image file to upload.
128
- # @return [Unsplash::Photo] The uploaded photo.
129
- # <b>DEPRECATED</b>
130
- def create(filepath)
131
- raise Unsplash::DeprecationError.new "API photo-upload endpoint has been deprecated and removed."
132
- end
133
-
134
98
  private
135
99
 
136
100
  def parse_list(json)
@@ -1,4 +1,4 @@
1
1
  module Unsplash # :nodoc:
2
2
  # :nodoc:
3
- VERSION = "1.5.6"
3
+ VERSION = "2.0.0"
4
4
  end
@@ -18,16 +18,17 @@ 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.0.0"
21
+ spec.required_ruby_version = ">= 2.3.0"
22
22
 
23
- spec.add_dependency "httparty", "~> 0.14.0"
23
+ spec.add_dependency "httparty", "~> 0.16.4"
24
24
  spec.add_dependency "oauth2", "~> 1"
25
25
 
26
- # spec.add_development_dependency "bundler", "~> 1.10"
27
- spec.add_development_dependency "rake", "~> 12.0"
28
- spec.add_development_dependency "rspec", "~> 3.5.0"
26
+ spec.add_development_dependency "rake", "~> 12.3.2"
27
+ spec.add_development_dependency "rspec", "~> 3.8.0"
29
28
  spec.add_development_dependency "vcr", "~> 3.0.0"
30
- spec.add_development_dependency "webmock", "~> 2.3.0"
29
+ spec.add_development_dependency "webmock", "~> 3.5.1"
31
30
  spec.add_development_dependency "pry"
32
- spec.add_development_dependency "coveralls", '~> 0.8.17'
31
+ spec.add_development_dependency "coveralls"
32
+ spec.add_development_dependency "dotenv"
33
+ spec.add_development_dependency "rb-readline"
33
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unsplash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.6
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Klaassen
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.14.0
19
+ version: 0.16.4
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.14.0
26
+ version: 0.16.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: oauth2
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '12.0'
47
+ version: 12.3.2
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '12.0'
54
+ version: 12.3.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 3.5.0
61
+ version: 3.8.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 3.5.0
68
+ version: 3.8.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: vcr
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 2.3.0
89
+ version: 3.5.1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 2.3.0
96
+ version: 3.5.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pry
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -112,16 +112,44 @@ dependencies:
112
112
  name: coveralls
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 0.8.17
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: dotenv
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rb-readline
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
123
144
  - !ruby/object:Gem::Version
124
- version: 0.8.17
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
125
153
  description:
126
154
  email:
127
155
  - aaron@unsplash.com
@@ -144,13 +172,12 @@ files:
144
172
  - Rakefile
145
173
  - bin/console
146
174
  - bin/setup
175
+ - config.env.example
147
176
  - lib/unsplash.rb
148
- - lib/unsplash/category.rb
149
177
  - lib/unsplash/client.rb
150
178
  - lib/unsplash/collection.rb
151
179
  - lib/unsplash/configuration.rb
152
180
  - lib/unsplash/connection.rb
153
- - lib/unsplash/curated_batch.rb
154
181
  - lib/unsplash/errors.rb
155
182
  - lib/unsplash/photo.rb
156
183
  - lib/unsplash/search.rb
@@ -170,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
197
  requirements:
171
198
  - - ">="
172
199
  - !ruby/object:Gem::Version
173
- version: 2.0.0
200
+ version: 2.3.0
174
201
  required_rubygems_version: !ruby/object:Gem::Requirement
175
202
  requirements:
176
203
  - - ">="
@@ -1,33 +0,0 @@
1
- module Unsplash # :nodoc:
2
-
3
- # Unsplash Category operations.
4
- class Category < Client
5
-
6
- class << self
7
-
8
- # Get a list of all of the Unsplash photo categories.
9
- # @return [Array] The list categories.
10
- # <b>DEPRECATED</b>
11
- def all
12
- raise Unsplash::DeprecationError.new "Category has been deprecated and removed."
13
- end
14
-
15
- # Get an Unsplash Category.
16
- # @param id [Integer] The ID of the category to retrieve.
17
- # @return [Unsplash::Category] The specified category.
18
- # <b>DEPRECATED</b>
19
- def find(id)
20
- raise Unsplash::DeprecationError.new "Category has been deprecated and removed."
21
- end
22
- end
23
-
24
- # Get a list of all photos in this category.
25
- # @param page [Integer] Which page of search results to return.
26
- # @param per_page [Integer] The number of search results per page.
27
- # @return [Array] A single page of +Unsplash::Photo+s.
28
- # <b>DEPRECATED</b>
29
- def photos(page = 1, per_page = 10)
30
- raise Unsplash::DeprecationError.new "Category has been deprecated and removed."
31
- end
32
- end
33
- end
@@ -1,43 +0,0 @@
1
- module Unsplash # :nodoc:
2
-
3
- # Unsplash Curated Batch operations.
4
- class CuratedBatch < Client
5
-
6
- class << self
7
-
8
- # Get a specific curated batch.
9
- # @param id [Integer] The ID of the batch.
10
- # @return [Unsplash::CuratedBatch] The requested batch.
11
- def find(id)
12
- batch = Unsplash::CuratedBatch.new JSON.parse(connection.get("/curated_batches/#{id}").body)
13
- batch.curator = Unsplash::User.new batch.curator
14
- batch
15
- end
16
-
17
- # Get a list of all curated batches.
18
- # @param page [Integer] Which page of search results to return.
19
- # @param per_page [Integer] The number of search results per page.
20
- # @return [Array] A single page of the +Unsplash::CuratedBatch+ list.
21
- def all(page = 1, per_page = 10)
22
- params = {
23
- page: page,
24
- per_page: per_page
25
- }
26
- list = JSON.parse(connection.get("/curated_batches/", params).body)
27
- list.map do |cb|
28
- batch = Unsplash::CuratedBatch.new cb
29
- batch.curator = Unsplash::User.new batch.curator
30
- batch
31
- end
32
- end
33
- end
34
-
35
- # Get a list of the photos contained in this batch.
36
- # @return [Array] The list of +Unsplash::Photo+s in the batch.
37
- def photos
38
- list = JSON.parse(connection.get("/curated_batches/#{id}/photos").body)
39
- list.map { |photo| Unsplash::Photo.new photo }
40
- end
41
-
42
- end
43
- end