unsplash 1.3.1 → 1.4.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
  SHA1:
3
- metadata.gz: e6883b2d6a8deb3a58d175b12696ab781fd95ba6
4
- data.tar.gz: 043df11035a46a1eca2a380d3250f5554bdaf69a
3
+ metadata.gz: 4e502e452a28e94ceccf4bdcb5adc9d9bef9e630
4
+ data.tar.gz: 8fe977a313d140877a63ac23fdedeeff0b839be0
5
5
  SHA512:
6
- metadata.gz: ed50d74a7eeb5c7216d21ec8283a7d20971c48503a395ada073846e4052596d2bedf397aac972d1450abe827ae0994f0ea8996c3ea3b27e71fc45c60b21b289f
7
- data.tar.gz: 8135c81774d593a5fcb0b71a5ae90cd43f4a66521f1e88e1f305343fb6567eece3c189549a03e2bdcef9a9e2a1e15e6c6d4e884d38e60c431f38bcf1c841c959
6
+ metadata.gz: 446d3c4363e234c11d7c6758b050df3363ed33a42dd5b7cc44116550d3d34adc43a4d75178be0295f1517e9675e88bd0d127d7a17005b8f7b2919a2fa233d31d
7
+ data.tar.gz: c1ae6a56978d8d4c0a7fad854522cf4dbbb944d379a1e5b4209eadec0f12d07c776dc51fa7d715cda938cb0ef1ff0c67b62b70821885fac24610eb22f66a7063
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.1.6
1
+ ruby-2.3.0
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.5
3
+ - 2.2.5
4
+ - 2.3.1
4
5
  before_install: gem install bundler -v 1.10.2
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # unsplash_rb
2
2
 
3
- [ ![Codeship Status for CrewLabs/unsplash_rb](https://codeship.com/projects/0d395ea0-fe45-0132-5e19-022bf5e0402e/status?branch=master)](https://codeship.com/projects/88039)
3
+ [![Build Status](https://travis-ci.org/unsplash/unsplash_rb.svg?branch=travis)](https://travis-ci.org/unsplash/unsplash_rb)
4
+ [![Coverage Status](https://coveralls.io/repos/github/unsplash/unsplash_rb/badge.svg?branch=master&gh_cache_bust=1)](https://coveralls.io/github/unsplash/unsplash_rb?branch=master)
4
5
 
5
6
  A ruby client for [the Unsplash API](https://unsplash.com/documentation).
6
7
 
@@ -37,8 +38,7 @@ end
37
38
 
38
39
  ### Public-scope actions
39
40
 
40
- If you are *only* making public requests (i.e. nothing requiring a specific logged-in user,
41
- for example photo uploads or private user details), then you're ready to go!
41
+ If you are *only* making public requests (i.e. nothing requiring a specific logged-in user, for example liking photos or accessing private user details), then you're ready to go!
42
42
 
43
43
  Looking for details of a specific photo? Find it by ID:
44
44
 
@@ -52,7 +52,7 @@ Want a bunch of pictures of cats? You're on the internet; of course you do.
52
52
  search_results = Unsplash::Photo.search("cats")
53
53
  ```
54
54
 
55
- For a complete list of available actions, see our [documentation details](http://www.rubydoc.info/github/CrewLabs/unsplash_rb).
55
+ For a complete list of available actions, see our [documentation details](http://www.rubydoc.info/github/unsplash/unsplash_rb/).
56
56
 
57
57
  ### User Authorization
58
58
 
@@ -88,7 +88,7 @@ To install this gem onto your local machine, run `bundle exec rake install`.
88
88
 
89
89
  ## Contributing
90
90
 
91
- Bug reports and pull requests are welcome on GitHub at https://github.com/crewlabs/unsplash_rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
91
+ Bug reports and pull requests are welcome on GitHub at https://github.com/unsplash/unsplash_rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
92
92
 
93
93
 
94
94
  ## License
@@ -4,7 +4,7 @@ module Unsplash # :nodoc:
4
4
  class Client
5
5
 
6
6
  # Build an Unsplash object with the given attributes.
7
- # @param attrs [Hash]
7
+ # @param attrs [Hash]
8
8
  def initialize(attrs = {})
9
9
  @attributes = OpenStruct.new(attrs)
10
10
  end
@@ -23,7 +23,8 @@ module Unsplash # :nodoc:
23
23
 
24
24
  # @private
25
25
  def method_missing(method, *args, &block)
26
- @attributes.send(method, *args, &block)
26
+ attribute = @attributes.send(method, *args, &block)
27
+ attribute.is_a?(Hash) ? Client.new(attribute) : attribute
27
28
  end
28
29
 
29
30
  # The connection object being used to communicate with Unsplash.
@@ -32,7 +33,7 @@ module Unsplash # :nodoc:
32
33
  self.class.connection
33
34
  end
34
35
 
35
- class << self
36
+ class << self
36
37
  # The connection object being used to communicate with Unsplash.
37
38
  # @return [Unsplash::Connection] the connection
38
39
  def connection
@@ -52,6 +52,18 @@ module Unsplash # :nodoc:
52
52
  Unsplash::Collection.new JSON.parse(connection.post("/collections", params).body)
53
53
  end
54
54
 
55
+ # Get a single page of collection results for a query.
56
+ # @param query [String] Keywords to search for.
57
+ # @param page [Integer] Which page of search results to return.
58
+ # @return [Array] a list of +Unsplash::Collection+ objects.
59
+ def search(query, page = 1)
60
+ params = {
61
+ query: query,
62
+ page: page
63
+ }
64
+ Unsplash::Search.search("/search/collections", self, params)
65
+ end
66
+
55
67
  end
56
68
 
57
69
  def initialize(options = {})
@@ -114,4 +126,4 @@ module Unsplash # :nodoc:
114
126
  end
115
127
 
116
128
  end
117
- end
129
+ end
@@ -3,10 +3,12 @@ module Unsplash # :nodoc:
3
3
  attr_accessor :application_id
4
4
  attr_accessor :application_secret
5
5
  attr_accessor :application_redirect_uri
6
+ attr_accessor :logger
6
7
  attr_writer :test
7
8
 
8
9
  def initialize
9
10
  @test = true
11
+ @logger = Logger.new(STDOUT)
10
12
  end
11
13
 
12
14
  def test?
@@ -93,10 +93,14 @@ module Unsplash #:nodoc:
93
93
  param_key = verb == :post ? :body : :params
94
94
  @oauth_token.public_send(verb, @api_base_uri + path, param_key => params, headers: headers)
95
95
 
96
- else
96
+ else
97
97
  self.class.public_send verb, path, query: params, headers: public_auth_header
98
98
  end
99
99
 
100
+ if response.headers["Warning"]
101
+ Unsplash.configuration.logger.warn response.headers["Warning"]
102
+ end
103
+
100
104
  status_code = response.respond_to?(:status) ? response.status : response.code
101
105
 
102
106
  if !(200..299).include?(status_code)
@@ -36,16 +36,19 @@ module Unsplash # :nodoc:
36
36
  photo
37
37
  end
38
38
 
39
- # Get a random photo. The photo selection pool can be narrowed using
39
+ # Get a random photo or set of photos. The photo selection pool can be narrowed using
40
40
  # a combination of optional parameters. Can also optionally specify a custom image size.
41
+ # @param count [Integer] Number of photos required. Default=1, Max=30
41
42
  # @param categories [Array] Limit selection to given category ID's.
42
43
  # @param featured [Boolean] Limit selection to featured photos.
43
44
  # @param user [String] Limit selection to given User's ID.
44
45
  # @param query [String] Limit selection to given search query.
45
46
  # @param width [Integer] Width of customized version of the photo.
46
47
  # @param height [Integer] Height of the customized version of the photo.
47
- # @return [Unsplash::Photo] An Unsplash Photo.
48
- def random(categories: nil, collections: nil, featured: nil, user: nil, query: nil, width: nil, height: nil)
48
+ # @param orientation [String] Filter by orientation of the photo. Valid values are landscape, portrait, and squarish.
49
+ # @return [Unsplash::Photo] An Unsplash Photo if count parameter is omitted
50
+ # @return [Array] An array of Unsplash Photos if the count parameter is specified. An array is returned even if count is 1
51
+ def random(count: nil,categories: nil, collections: nil, featured: nil, user: nil, query: nil, width: nil, height: nil, orientation: nil)
49
52
  params = {
50
53
  category: (categories && categories.join(",")),
51
54
  collections: (collections && collections.join(",")),
@@ -53,30 +56,37 @@ module Unsplash # :nodoc:
53
56
  username: user,
54
57
  query: query,
55
58
  w: width,
56
- h: height
59
+ h: height,
60
+ orientation: orientation
57
61
  }.select { |k,v| v }
58
-
59
- photo = Unsplash::Photo.new JSON.parse(connection.get("/photos/random", params).body)
60
- photo.user = Unsplash::User.new photo.user
61
- photo
62
+ if count
63
+ params[:count] = count
64
+ photos = parse_list connection.get("/photos/random/", params).body
65
+ photos.map { |photo|
66
+ photo.user = Unsplash::User.new photo[:user]
67
+ photo
68
+ }
69
+ else
70
+ photo = Unsplash::Photo.new JSON.parse(connection.get("/photos/random", params).body)
71
+ photo.user = Unsplash::User.new photo.user
72
+ photo
73
+ end
62
74
  end
63
75
 
64
76
  # Search for photos by keyword.
65
77
  # @param query [String] Keywords to search for.
66
78
  # @param page [Integer] Which page of search results to return.
67
- # @param per_page [Integer] The number of search results per page.
68
- def search(query, page = 1, per_page = 10)
79
+ def search(query, page = 1)
69
80
  params = {
70
81
  query: query,
71
- page: page,
72
- per_page: per_page
82
+ page: page
73
83
  }
74
- parse_list connection.get("/photos/search/", params).body
84
+ Unsplash::Search.search("/search/photos", self, params)
75
85
  end
76
86
 
77
87
  # Get a list of all photos.
78
88
  # @param page [Integer] Which page of search results to return.
79
- # @param per_page [Integer] The number of search results per page.
89
+ # @param per_page [Integer] The number of search results per page.
80
90
  # @return [Array] A single page of +Unsplash::Photo+ search results.
81
91
  def all(page = 1, per_page = 10)
82
92
  params = {
@@ -86,14 +96,26 @@ module Unsplash # :nodoc:
86
96
  parse_list connection.get("/photos/", params).body
87
97
  end
88
98
 
99
+ # Get a single page from the list of the curated photos (front-page’s photos).
100
+ # @param page [Integer] Which page of search results to return.
101
+ # @param per_page [Integer] The number of search results per page.
102
+ # @param order_by [String] How to sort the photos.
103
+ # @return [Array] A single page of +Unsplash::Photo+ search results.
104
+ def curated(page = 1, per_page = 10, order_by = "popular")
105
+ params = {
106
+ page: page,
107
+ per_page: per_page,
108
+ order_by: order_by
109
+ }
110
+ parse_list connection.get("/photos/curated", params).body
111
+ end
112
+
89
113
  # Upload a photo on behalf of the current user.
90
114
  # @param filepath [String] The local path of the image file to upload.
91
115
  # @return [Unsplash::Photo] The uploaded photo.
116
+ # <b>DEPRECATED</b>
92
117
  def create(filepath)
93
- file = Faraday::UploadIO.new(filepath, "image/jpeg")
94
- photo = Unsplash::Photo.new JSON.parse(connection.post("/photos", photo: file).body)
95
- photo.user = Unsplash::User.new photo.user
96
- photo
118
+ raise Unsplash::Error.new "API photo-upload endpoint has been deprecated and removed."
97
119
  end
98
120
 
99
121
  private
@@ -104,4 +126,4 @@ module Unsplash # :nodoc:
104
126
 
105
127
  end
106
128
  end
107
- end
129
+ end
@@ -0,0 +1,19 @@
1
+ module Unsplash # :nodoc:
2
+
3
+ # Unsplash Search operations
4
+ class Search < Client
5
+ class << self
6
+ # Helper class to facilitate search on multiple classes
7
+ # @param url [String] Url to be searched into
8
+ # @param klass [Class] Class to instantiate the contents with
9
+ # @param params [Hash] Params for the search
10
+ def search(url, klass, params)
11
+ list = JSON.parse(connection.get(url, params).body)
12
+
13
+ list["results"].map do |content|
14
+ klass.new content.to_hash
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/unsplash/user.rb CHANGED
@@ -25,30 +25,63 @@ module Unsplash # nodoc:
25
25
  Unsplash::User.new JSON.parse(connection.put("/me", params).body)
26
26
  end
27
27
 
28
+ # Get a single page of user results for a query.
29
+ # @param query [String] Keywords to search for.
30
+ # @param page [Integer] Which page of search results to return.
31
+ # @return [Array] a list of +Unsplash::User+ objects.
32
+ def search(query, page = 1)
33
+ params = {
34
+ query: query,
35
+ page: page
36
+ }
37
+ Unsplash::Search.search("/search/users", self, params)
38
+ end
39
+
28
40
  end
29
41
 
30
42
  # Get a list of photos uploaded by the user.
31
- # @return [Array] a list of +Unsplash::Photo+ objects.
32
- def photos
33
- list = JSON.parse(connection.get("/users/#{username}/photos").body)
43
+ # @param page [Integer] Which page of results to return.
44
+ # @param per_page [Integer] The number of results per page.
45
+ # @return [Array] a list of +Unsplash::Photo+ objects.
46
+ def photos(page = 1, per_page = 10)
47
+ params = {
48
+ page: page,
49
+ per_page: per_page
50
+ }
51
+
52
+ list = JSON.parse(connection.get("/users/#{username}/photos", params).body)
34
53
  list.map do |photo|
35
54
  Unsplash::Photo.new photo.to_hash
36
55
  end
37
56
  end
38
57
 
39
58
  # Get a list of photos liked by the user.
40
- # @return [Array] a list of +Unsplash::Photo+ objects.
41
- def likes
42
- list = JSON.parse(connection.get("/users/#{username}/likes").body)
59
+ # @param page [Integer] Which page of results to return.
60
+ # @param per_page [Integer] The number of results per page.
61
+ # @return [Array] a list of +Unsplash::Photo+ objects.
62
+ def likes(page = 1, per_page = 10)
63
+ params = {
64
+ page: page,
65
+ per_page: per_page
66
+ }
67
+
68
+ list = JSON.parse(connection.get("/users/#{username}/likes", params).body)
43
69
  list.map do |photo|
44
70
  Unsplash::Photo.new photo.to_hash
45
71
  end
46
72
  end
47
73
 
48
- # Get a list of photos liked by the user.
49
- # @return [Array] a list of +Unsplash::Collection+ objects.
50
- def collections
51
- list = JSON.parse(connection.get("/users/#{username}/collections").body)
74
+ # Get a list of collections created by the user.
75
+ # @param page [Integer] Which page of results to return.
76
+ # @param per_page [Integer] The number of results per page.
77
+ # @return [Array] a list of +Unsplash::Collection+ objects.
78
+ def collections(page = 1, per_page = 10)
79
+ params = {
80
+ page: page,
81
+ per_page: per_page
82
+ }
83
+
84
+ list = JSON.parse(connection.get("/users/#{username}/collections", params).body)
52
85
  list.map do |collection|
53
86
  Unsplash::Collection.new collection.to_hash
54
87
  end
@@ -56,4 +89,4 @@ module Unsplash # nodoc:
56
89
 
57
90
  end
58
91
 
59
- end
92
+ end
@@ -1,4 +1,4 @@
1
1
  module Unsplash # :nodoc:
2
2
  # :nodoc:
3
- VERSION = "1.3.1"
3
+ VERSION = "1.4.0"
4
4
  end
data/lib/unsplash.rb CHANGED
@@ -12,6 +12,7 @@ require "unsplash/category"
12
12
  require "unsplash/curated_batch"
13
13
  require "unsplash/collection"
14
14
  require "unsplash/stats"
15
+ require "unsplash/search"
15
16
 
16
17
  module Unsplash
17
18
  class << self
data/unsplash.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "unsplash"
8
8
  spec.version = Unsplash::VERSION
9
9
  spec.authors = ["Aaron Klaassen"]
10
- spec.email = ["aaron@crew.co"]
10
+ spec.email = ["aaron@unsplash.com"]
11
11
 
12
12
  spec.summary = %q{Ruby wrapper for the Unsplash API.}
13
13
  spec.homepage = "https://github.com/unsplash/unsplash_rb"
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "vcr", "~> 2.9.3"
30
30
  spec.add_development_dependency "webmock", "~> 1.20.4"
31
31
  spec.add_development_dependency "pry"
32
+ spec.add_development_dependency "coveralls", '~> 0.8.12'
32
33
  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: 1.3.1
4
+ version: 1.4.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: 2016-05-06 00:00:00.000000000 Z
11
+ date: 2016-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -108,9 +108,23 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.8.12
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.8.12
111
125
  description:
112
126
  email:
113
- - aaron@crew.co
127
+ - aaron@unsplash.com
114
128
  executables: []
115
129
  extensions: []
116
130
  extra_rdoc_files: []
@@ -136,6 +150,7 @@ files:
136
150
  - lib/unsplash/curated_batch.rb
137
151
  - lib/unsplash/errors.rb
138
152
  - lib/unsplash/photo.rb
153
+ - lib/unsplash/search.rb
139
154
  - lib/unsplash/stats.rb
140
155
  - lib/unsplash/user.rb
141
156
  - lib/unsplash/version.rb
@@ -160,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
175
  version: '0'
161
176
  requirements: []
162
177
  rubyforge_project:
163
- rubygems_version: 2.4.8
178
+ rubygems_version: 2.5.1
164
179
  signing_key:
165
180
  specification_version: 4
166
181
  summary: Ruby wrapper for the Unsplash API.