flickr 2.0.1 → 2.0.2

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: 99a84720ee6e0bdd7c794e4a2ea48948ab7afd2c6319e3df9d87f7abac40d507
4
- data.tar.gz: 5b2499fa37c7b1008679f2132558a06f2c47a40f036b82363ef050d5ad57df0e
3
+ metadata.gz: 65cb1e57a0b7ff7ce2f05da2b7e2bcf910c417b79e66d1ad5b32bd4f3c1c8ca7
4
+ data.tar.gz: 2fe80a2e1db250bf7f8e297da921891e5baa97f106186fe5876f698c82cfc10e
5
5
  SHA512:
6
- metadata.gz: 64cdc4ad80d21472105030ef54ab2f57681d6521324f23092036c36ba3856911787b799295ef0857449fed4bd33fd6900333806f741034e1464ad0137509e84b
7
- data.tar.gz: 9f55e63e17f5ca0bee74a37707203e58a35c4776f48ae9f0048b876eb2123346c7b1b0d4a68755962de767bb83ea0426257f8eddc8aa922f680e936afcc3350c
6
+ metadata.gz: a494a33e313ab2f06a971f2ae4afaab55a75e7221f6a24dd9484fd59b0c04830f4b2e74f3434d121b1d6a072560eed70c81732863e98dc86dcef556fb3781edc
7
+ data.tar.gz: 80b7dca89da88c74055fcbba17ff858965d8ae075e036e0a84fc9d97831babaddfb6210e0e46ef4855e9a1934415d5fca489e02dd7bcb4047649a99488afec55
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /html/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ /flickr-*.gem
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.3
5
+ - 2.4
6
+ - 2.5
7
+ - 2.6
8
+ - jruby
9
+ script:
10
+ - bundle exec rake
11
+ - bundle exec bundle-audit check --update
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 2.0.2 - 2019-06-05
8
+ ### Added
9
+ - Updated upload and replace endpoints
7
10
 
8
11
  ## 2.0.1 - 2019-03-17
9
12
  ### Added
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,251 @@
1
+ # Flickr [![Build Status](https://travis-ci.org/cyclotron3k/flickr.svg?branch=master)](https://travis-ci.org/cyclotron3k/flickr)
2
+
3
+ Flickr (formerly FlickRaw) is a library to access the [Flickr](https://flickr.com) API in a simple way.
4
+ It maps exactly the methods described in [the official API documentation](https://www.flickr.com/services/api/).
5
+ It also tries to present the data returned in a simple and intuitive way.
6
+ The methods are fetched from Flickr when loading the library by using introspection capabilities.
7
+ So it is always up-to-date with regards to new methods added by Flickr.
8
+
9
+ The github repository: https://github.com/cyclotron3k/flickr
10
+
11
+ # Upgrading from FlickRaw?
12
+
13
+ If you're upgrading from FlickRaw 0.9.x there are a few breaking changes to be aware of:
14
+ * Instantiate a new object with `client = Flickr.new` instead of `FlickRaw::Flickr.new`.
15
+ * The global `flickr` variable is no longer created.
16
+ * Local caching of the Flickr API specification is no longer achieved with a separate gem.
17
+
18
+
19
+ # Installation
20
+ Type this in a console (you might need to be superuser)
21
+
22
+ gem install flickr
23
+
24
+ This will recreate the documentation by fetching the method descriptions from Flickr and then virtually plugging them in standard rdoc documentation.
25
+
26
+ $ cd flickr
27
+ $ rake rdoc
28
+
29
+ # Features
30
+
31
+ * Minimal dependencies
32
+ * Complete support of Flickr API. This doesn't require an update of the library
33
+ * Ruby syntax similar to the Flickr API
34
+ * Flickr authentication
35
+ * HTTPS Support
36
+ * Photo upload
37
+ * Proxy support
38
+ * Flickr URLs helpers
39
+
40
+
41
+ # Usage
42
+
43
+ ## Getting started
44
+
45
+ To use the Flickr API, you must first obtain an API key and shared secret from Flickr.
46
+ You can do this by logging in to Flickr and creating an application [here](https://www.flickr.com/services/apps/create/apply).
47
+ API keys are usually granted automatically and instantly.
48
+
49
+ ```ruby
50
+ require 'flickr'
51
+
52
+ # The credentials can be provided as parameters:
53
+
54
+ flickr = Flickr.new "YOUR API KEY", "YOUR SHARED SECRET"
55
+
56
+ # Alternatively, if the API key and Shared Secret are not provided, Flickr will attempt to read them
57
+ # from environment variables:
58
+ # ENV['FLICKR_API_KEY']
59
+ # ENV['FLICKR_SHARED_SECRET']
60
+
61
+ flickr = Flickr.new
62
+
63
+ # Flickr will raise an error if either parameter is not explicitly provided, or available via environment variables.
64
+ ```
65
+
66
+ ## Simple
67
+
68
+ ```ruby
69
+ list = flickr.photos.getRecent
70
+
71
+ id = list[0].id
72
+ secret = list[0].secret
73
+ info = flickr.photos.getInfo :photo_id => id, :secret => secret
74
+
75
+ puts info.title # => "PICT986"
76
+ puts info.dates.taken # => "2006-07-06 15:16:18"
77
+
78
+ sizes = flickr.photos.getSizes :photo_id => id
79
+
80
+ original = sizes.find { |s| s.label == 'Original' }
81
+ puts original.width # => "800" -- may fail if they have no original marked image
82
+ ```
83
+
84
+ ## Authentication
85
+
86
+ ```ruby
87
+ token = flickr.get_request_token
88
+ auth_url = flickr.get_authorize_url(token['oauth_token'], :perms => 'delete')
89
+
90
+ puts "Open this url in your browser to complete the authentication process: #{auth_url}"
91
+ puts "Copy here the number given when you complete the process."
92
+ verify = gets.strip
93
+
94
+ begin
95
+ flickr.get_access_token(token['oauth_token'], token['oauth_token_secret'], verify)
96
+ login = flickr.test.login
97
+ puts "You are now authenticated as #{login.username} with token #{flickr.access_token} and secret #{flickr.access_secret}"
98
+ rescue Flickr::FailedResponse => e
99
+ puts "Authentication failed : #{e.msg}"
100
+ end
101
+ ```
102
+
103
+ If the user has already been authenticated, you can reuse the access token and access secret:
104
+
105
+ ```ruby
106
+ flickr.access_token = "... Your access token ..."
107
+ flickr.access_secret = "... Your access secret ..."
108
+
109
+ # From here you are logged:
110
+ login = flickr.test.login
111
+ puts "You are now authenticated as #{login.username}"
112
+ ```
113
+
114
+ If you need to have several users authenticated at the same time in your application (ex: a public web application) you need to create separate Flickr objects since it keeps the authentication data internally.
115
+
116
+ ```ruby
117
+ flickr = Flickr.new
118
+ ```
119
+
120
+ ## Upload
121
+
122
+ ```ruby
123
+ PHOTO_PATH = 'photo.jpg'
124
+
125
+ # You need to be authenticated to do that, see the previous examples.
126
+ flickr.upload_photo PHOTO_PATH, :title => "Title", :description => "This is the description"
127
+ ```
128
+
129
+ ## Caching
130
+
131
+ The first time the Flickr object is instantiated, it will download the current Flickr API definition and dynamically create all the required classes and
132
+ objects.
133
+ This is how the gem remains up-to-date without requiring updates.
134
+
135
+ Unfortunately this adds a significant delay to startup, but the Flickr gem can be configured to cache the API definition to a local file.
136
+ Just set a file location before the Flickr class is instantiated:
137
+
138
+ ```ruby
139
+ Flickr.cache = '/tmp/flickr-api.yml'
140
+ flickr = Flickr.new
141
+ ```
142
+
143
+ ## Proxy
144
+
145
+ ```ruby
146
+ require 'flickr'
147
+ Flickr.proxy = "https://user:pass@proxy.example.com:3129/"
148
+ ```
149
+
150
+ ### Server Certificate Verification
151
+
152
+ Server certificate verification is enabled by default. If you don't want to check the server certificate:
153
+
154
+ ```ruby
155
+ require 'flickr'
156
+ Flickr.check_certificate = false
157
+ ```
158
+
159
+ ### CA Certificate File Path
160
+
161
+ `OpenSSL::X509::DEFAULT_CERT_FILE` is used as a CA certificate file. If you want to change the path:
162
+
163
+ ```ruby
164
+ require 'flickr'
165
+ Flickr.ca_file = '/path/to/cacert.pem'
166
+ ```
167
+
168
+ You can also specify a path to a directory with a number of certifications:
169
+
170
+ ```ruby
171
+ Flickr.ca_path = '/path/to/certificates'
172
+ ```
173
+
174
+ ## Flickr URL Helpers
175
+
176
+ There are some helpers to build Flickr urls:
177
+
178
+ ### url, url_m, url_s, url_t, url_b, url_z, url_q, url_n, url_c, url_o
179
+
180
+ ```ruby
181
+ # url_s : Square
182
+ # url_q : Large Square
183
+ # url_t : Thumbnail
184
+ # url_m : Small
185
+ # url_n : Small 320
186
+ # url : Medium
187
+ # url_z : Medium 640
188
+ # url_c : Medium 800
189
+ # url_b : Large
190
+ # url_o : Original
191
+
192
+ info = flickr.photos.getInfo(:photo_id => "3839885270")
193
+ Flickr.url_b(info) # => "https://farm3.static.flickr.com/2485/3839885270_6fb8b54e06_b.jpg"
194
+ ```
195
+
196
+ ### url_profile
197
+
198
+ ```ruby
199
+ info = flickr.photos.getInfo(:photo_id => "3839885270")
200
+ Flickr.url_profile(info) # => "https://www.flickr.com/people/41650587@N02/"
201
+ ```
202
+
203
+ ### url_photopage
204
+
205
+ ```ruby
206
+ info = flickr.photos.getInfo(:photo_id => "3839885270")
207
+ Flickr.url_photopage(info) # => "https://www.flickr.com/photos/41650587@N02/3839885270"
208
+ ```
209
+
210
+ ### url_photoset, url_photosets
211
+
212
+ ```ruby
213
+ info = flickr.photos.getInfo(:photo_id => "3839885270")
214
+ Flickr.url_photosets(info) # => "https://www.flickr.com/photos/41650587@N02/sets/"
215
+ ```
216
+
217
+ ### url_short, url_short_m, url_short_s, url_short_t
218
+
219
+ ```ruby
220
+ info = flickr.photos.getInfo(:photo_id => "3839885270")
221
+ Flickr.url_short(info) # => "https://flic.kr/p/6Rjq7s"
222
+ ```
223
+
224
+ ### url_photostream
225
+
226
+ ```ruby
227
+ info = flickr.photos.getInfo(:photo_id => "3839885270")
228
+ Flickr.url_photostream(info) # => "https://www.flickr.com/photos/41650587@N02/"
229
+ ```
230
+
231
+ ## Troubleshooting
232
+
233
+ If you see an error like this:
234
+
235
+ There was an error while loading `flickr.gemspec`: invalid byte sequence in US-ASCII. Bundler cannot continue.
236
+
237
+ It probably means you're trying to use `Flickr` in a default Ruby docker container. The official Ruby Docker image does not specify a locale, and so it defaults to `US-ASCII`. This causes issues because the `Flickr` gem includes `UTF-8` encoded characters.
238
+
239
+ If you were affected by this problem, you will need to set your container's environment variables to something like the following:
240
+
241
+ export LANG=C.UTF-8
242
+ export LC_ALL=C.UTF-8
243
+ export LC_CTYPE=C.UTF-8
244
+
245
+ A popular alternative to `C.UTF-8` would be `en_US.UTF-8`
246
+
247
+ Also please consider adding a +1 to [this issue](https://github.com/docker-library/ruby/issues/45) on GitHub.
248
+
249
+ ## Examples
250
+
251
+ See the *examples* directory to find more examples.
@@ -0,0 +1,33 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require 'flickr/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "flickr"
6
+ s.summary = "Flickr (formerly FlickRaw) is full-featured client for the Flickr API"
7
+ s.authors = ["Mael Clerambault", "Aidan Samuel"]
8
+ s.email = "aidan.samuel@gmail.com"
9
+ s.license = "MIT"
10
+ s.version = Flickr::VERSION
11
+ s.homepage = "https://github.com/cyclotron3k/flickr"
12
+ s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
13
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ end
15
+
16
+ s.metadata = {
17
+ "bug_tracker_uri" => "https://github.com/cyclotron3k/flickr/issues",
18
+ "changelog_uri" => "https://github.com/cyclotron3k/flickr/blob/master/CHANGELOG.md",
19
+ "documentation_uri" => "https://github.com/cyclotron3k/flickr/blob/v#{Flickr::VERSION}/README.md",
20
+ "source_code_uri" => "https://github.com/cyclotron3k/flickr",
21
+ }
22
+
23
+ s.add_development_dependency "rake", "~> 12.0"
24
+ s.add_development_dependency "pry", "~> 0.11"
25
+ s.add_development_dependency "nokogiri", "~> 1.0"
26
+ s.add_development_dependency "webmock", "~> 2.0"
27
+ s.add_development_dependency "minitest", "~> 5.0"
28
+ s.add_development_dependency "bundler-audit", "~> 0.6"
29
+ s.add_development_dependency "vcr", "~> 4.0"
30
+
31
+ s.required_ruby_version = '>= 2.3'
32
+
33
+ end
@@ -55,14 +55,14 @@ module RDoc
55
55
  m.singleton = false
56
56
 
57
57
  m.start_collecting_tokens
58
- m.add_token FakedToken.new( %{
59
- # Generated automatically from flickr api
60
- def #{name}(*args)
61
- @flickr.call '#{flickr_method}', *args
62
- end
63
- } )
58
+ m.add_token FakedToken.new(<<~HEREDOC)
59
+ # Generated automatically from flickr api
60
+ def #{name}(*args)
61
+ @flickr.call '#{flickr_method}', *args
62
+ end
63
+ HEREDOC
64
64
  doc.add_method m
65
- @stats.add_method m
65
+ @stats.add_method m
66
66
  }
67
67
  end
68
68
 
@@ -10,14 +10,15 @@ require 'flickr/response_list'
10
10
 
11
11
  class Flickr
12
12
 
13
- USER_AGENT = "Flickr/#{VERSION} (+https://github.com/hanklords/flickraw)".freeze
13
+ USER_AGENT = "Flickr/#{VERSION} (+https://github.com/cyclotron3k/flickr)".freeze
14
14
  END_POINT = 'https://api.flickr.com/services'.freeze
15
+ UPLOAD_END_POINT = 'https://up.flickr.com/services'.freeze
15
16
  FLICKR_OAUTH_REQUEST_TOKEN = (END_POINT + '/oauth/request_token').freeze
16
17
  FLICKR_OAUTH_AUTHORIZE = (END_POINT + '/oauth/authorize').freeze
17
18
  FLICKR_OAUTH_ACCESS_TOKEN = (END_POINT + '/oauth/access_token').freeze
18
19
  REST_PATH = (END_POINT + '/rest/').freeze
19
- UPLOAD_PATH = (END_POINT + '/upload/').freeze
20
- REPLACE_PATH = (END_POINT + '/replace/').freeze
20
+ UPLOAD_PATH = (UPLOAD_END_POINT + '/upload/').freeze
21
+ REPLACE_PATH = (UPLOAD_END_POINT + '/replace/').freeze
21
22
  PHOTO_SOURCE_URL = 'https://farm%s.staticflickr.com/%s/%s_%s%s.%s'.freeze
22
23
  URL_PROFILE = 'https://www.flickr.com/people/'.freeze
23
24
  URL_PHOTOSTREAM = 'https://www.flickr.com/photos/'.freeze
@@ -54,7 +55,7 @@ class Flickr
54
55
  # This is the central method. It does the actual request to the Flickr server.
55
56
  #
56
57
  # Raises FailedResponse if the response status is _failed_.
57
- def call(req, args={}, &block)
58
+ def call(req, args = {}, &block)
58
59
  oauth_args = args.delete(:oauth) || {}
59
60
  http_response = @oauth_consumer.post_form(REST_PATH, @access_secret, {:oauth_token => @access_token}.merge(oauth_args), build_args(args, req))
60
61
  process_response(req, http_response.body)
@@ -88,7 +89,7 @@ class Flickr
88
89
  # flickr.upload_photo '/path/to/the/photo', :title => 'Title', :description => 'This is the description'
89
90
  #
90
91
  # See https://www.flickr.com/services/api/upload.api.html for more information on the arguments.
91
- def upload_photo(file, args={})
92
+ def upload_photo(file, args = {})
92
93
  upload_flickr(UPLOAD_PATH, file, args)
93
94
  end
94
95
 
@@ -97,7 +98,7 @@ class Flickr
97
98
  # flickr.replace_photo '/path/to/the/photo', :photo_id => id
98
99
  #
99
100
  # See https://www.flickr.com/services/api/replace.api.html for more information on the arguments.
100
- def replace_photo(file, args={})
101
+ def replace_photo(file, args = {})
101
102
  upload_flickr(REPLACE_PATH, file, args)
102
103
  end
103
104
 
@@ -157,7 +158,7 @@ class Flickr
157
158
 
158
159
  end
159
160
 
160
- def build_args(args={}, method_name=nil)
161
+ def build_args(args = {}, method_name = nil)
161
162
  args['method'] = method_name if method_name
162
163
  args.merge('format' => 'json', 'nojsoncallback' => '1')
163
164
  end
@@ -189,7 +190,7 @@ class Flickr
189
190
  end
190
191
  end
191
192
 
192
- def upload_flickr(method, file, args={})
193
+ def upload_flickr(method, file, args = {})
193
194
  oauth_args = args.delete(:oauth) || {}
194
195
  args = build_args(args)
195
196
  if file.respond_to? :read
@@ -242,17 +243,18 @@ class Flickr
242
243
  r
243
244
  end
244
245
 
245
- def url(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '', 'jpg'] end
246
- def url_m(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_m', 'jpg'] end
247
- def url_s(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_s', 'jpg'] end
248
- def url_t(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_t', 'jpg'] end
249
- def url_b(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_b', 'jpg'] end
250
- def url_z(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_z', 'jpg'] end
251
- def url_q(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_q', 'jpg'] end
252
- def url_n(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_n', 'jpg'] end
253
- def url_c(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_c', 'jpg'] end
254
- def url_h(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_h', 'jpg'] end
255
- def url_k(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_k', 'jpg'] end
246
+ def gen_url(r, type)
247
+ PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, type, 'jpg']
248
+ end
249
+
250
+ def url(r); gen_url(r, '') end
251
+
252
+ %W{m s t b z q n c h k}.each do |chr|
253
+ define_method "url_#{chr}" do |r|
254
+ gen_url r, "_#{chr}"
255
+ end
256
+ end
257
+
256
258
  def url_o(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.originalsecret, '_o', r.originalformat] end
257
259
  def url_profile(r); URL_PROFILE + (r.owner.respond_to?(:nsid) ? r.owner.nsid : r.owner) + '/' end
258
260
  def url_photopage(r); url_photostream(r) + r.id end