unsplash 1.4.3 → 1.5.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: 595420e78fad1a215cec6dc35751366feb94f7d8
4
- data.tar.gz: 782561f5e238a39f3b179f87ab890b195c4047a4
3
+ metadata.gz: 6e38d0698ca01b7ff19c93da8ee6485081268d23
4
+ data.tar.gz: 6ee07125feb0c023259edc2fccb028f182ea1f7c
5
5
  SHA512:
6
- metadata.gz: 36a82849af0ba7c5fe9be5391c11a34bbf60b28a6b799b31d19914c419eecd1bf726c809b0e240c82af1d7d17e2bb3d1b1c63532dee98a7d1e6381d6a96512b7
7
- data.tar.gz: 1bc74aa561b0d6050eb7871729bc31bc818056efcb77910e99118a0dc8122ff26e8bb2d19a51dc652c59641a321985c90ff89039499665d8c293ec6252076cf7
6
+ metadata.gz: 50b9cc311c3268802f4c04e873efeee092aec52419427d300b654dc4e8b8534c4fdc93c7719914e4733e48f4aa8d0d2b28ddb437f1d1a166bfa8a360da88230e
7
+ data.tar.gz: f2c9cca9709aba66789c67a40ef8eb37f61d315e7c8b857b04844775c987dc9c3bc65bd5e3b55bfb21ff201c9621fdae0215fd7f3cf8a477c8fda8afb0734a42
data/README.md CHANGED
@@ -33,9 +33,14 @@ Unsplash.configure do |config|
33
33
  config.application_id = "YOUR APPLICATION ID"
34
34
  config.application_secret = "YOUR APPLICATION SECRET"
35
35
  config.application_redirect_uri = "https://your-application.com/oauth/callback"
36
+ config.utm_source = "alices_terrific_client_app"
36
37
  end
37
38
  ```
38
39
 
40
+ #### UTM parameters
41
+
42
+ As part of [the API guidelines](https://community.unsplash.com/developersblog/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.
43
+
39
44
  ### Public-scope actions
40
45
 
41
46
  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!
@@ -4,6 +4,7 @@ module Unsplash # :nodoc:
4
4
  attr_accessor :application_secret
5
5
  attr_accessor :application_redirect_uri
6
6
  attr_accessor :logger
7
+ attr_accessor :utm_source
7
8
  attr_writer :test
8
9
 
9
10
  def initialize
@@ -22,8 +22,8 @@ module Unsplash #:nodoc:
22
22
  @application_secret = Unsplash.configuration.application_secret
23
23
  @api_version = version
24
24
  @api_base_uri = api_base_uri
25
-
26
- oauth_base_uri = oauth_base_uri
25
+
26
+ oauth_base_uri = oauth_base_uri
27
27
  @oauth = ::OAuth2::Client.new(@application_id, @application_secret, site: oauth_base_uri) do |http|
28
28
  http.request :multipart
29
29
  http.request :url_encoded
@@ -49,6 +49,24 @@ module Unsplash #:nodoc:
49
49
  # TODO check if it succeeded
50
50
  end
51
51
 
52
+ # Extract hash with OAuth token attributes. Extracted token attributes can
53
+ # be used with create_and_assign_token to prevent the need for
54
+ # reauthorization.
55
+ # @return [Hash, nil] @oauth_token converted to a hash.
56
+ def extract_token
57
+ @oauth_token.to_hash if @oauth_token
58
+ end
59
+
60
+ # Create and assign new access token from extracted token. To be used with
61
+ # extract_token to reauthorize app without api call.
62
+ # @param token_extract [Hash] OAuth token hash from #extract_token.
63
+ # @return [OAuth2::AccessToken, nil] New access token object.
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
68
+ end
69
+
52
70
  # Perform a GET request.
53
71
  # @param path [String] The path at which to make ther request.
54
72
  # @param params [Hash] A hash of request parameters.
@@ -82,6 +100,13 @@ module Unsplash #:nodoc:
82
100
  def request(verb, path, params = {})
83
101
  raise ArgumentError.new "Invalid http verb #{verb}" if ![:get, :post, :put, :delete].include?(verb)
84
102
 
103
+ params.merge!(utm_params)
104
+
105
+ if !Unsplash.configuration.utm_source
106
+ url = "https://community.unsplash.com/developersblog/unsplash-api-guidelines"
107
+ Unsplash.configuration.logger.warn "utm_source is required as part of API Terms: #{url}"
108
+ end
109
+
85
110
  headers = {
86
111
  "Accept-Version" => @api_version
87
112
  # Anything else? User agent?
@@ -92,7 +117,6 @@ module Unsplash #:nodoc:
92
117
 
93
118
  param_key = verb == :post ? :body : :params
94
119
  @oauth_token.public_send(verb, @api_base_uri + path, param_key => params, headers: headers)
95
-
96
120
  else
97
121
  self.class.public_send verb, path, query: params, headers: public_auth_header
98
122
  end
@@ -116,11 +140,18 @@ module Unsplash #:nodoc:
116
140
  { "Authorization" => "Client-ID #{@application_id}" }
117
141
  end
118
142
 
143
+ def utm_params
144
+ {
145
+ utm_source: Unsplash.configuration.utm_source || "api_app",
146
+ utm_medium: "referral",
147
+ utm_campaign: "api-credit"
148
+ }
149
+ end
150
+
119
151
  def refresh_token!
120
152
  return if !@oauth_token.expired?
121
153
 
122
154
  @oauth_token = @oauth_token.refresh_token
123
155
  end
124
156
  end
125
-
126
157
  end
@@ -1,4 +1,4 @@
1
1
  module Unsplash # :nodoc:
2
2
  # :nodoc:
3
- VERSION = "1.4.3"
3
+ VERSION = "1.5.0"
4
4
  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.4.3
4
+ version: 1.5.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: 2017-02-27 00:00:00.000000000 Z
11
+ date: 2017-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty