acts_as_unvlogable_fork 1.0.1 → 1.0.4

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: 545aa3f92a727be2a2e858696d9c4ec0302840c6
4
- data.tar.gz: 418e212fd1e518789177f1cbc8ac2b6cad83ccbd
3
+ metadata.gz: f89902ced9fed282dd39b29f4bfd38becac5a9ca
4
+ data.tar.gz: d8628c4a3cf9d5e655856058ec1a21007ac34828
5
5
  SHA512:
6
- metadata.gz: ca5d1ae0c6ed2f958b61740c07765aa917acf8fe69228a939ccad5292f5fef8b027ad899b7ac5b2c0ece5037a495974a2ffe9b36a2cbdbb90a2d8ec43f90a575
7
- data.tar.gz: 8d4a5a3d1d59cc0272e8e664264be1cdda30b147947f01e19e1c479761c43262faf58ea3380e3c22d969a060664c55c9ab08ae8f78b845e63d1844dcb409c562
6
+ metadata.gz: 42050181b96d8d661016e6596a39f4753903766010d4d777c99a31eb084fcf5c064d38ee2c3de0bcc92bae205d0ac5fb044ea7b0e0464b6557b0043cc0265001
7
+ data.tar.gz: 589289989f5aed1796e480cc185a4c615b88aa210f4f26eafef97f1b2049431fcbf3db32c08aa3761ba254299ac33836d47b05a2dca28289bb93597e15ce7100
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore CHANGED
@@ -2,5 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
-
5
+ coverage
6
6
  .DS_Store
data/.travis.yml CHANGED
@@ -6,8 +6,11 @@ rvm:
6
6
 
7
7
  branches:
8
8
  only:
9
+ - master
9
10
  - refactor
10
11
 
12
+ script: "bundle exec rspec"
13
+
11
14
  notifications:
12
15
  email:
13
16
  recipients:
data/Gemfile CHANGED
@@ -1,14 +1,10 @@
1
1
  source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in acts_as_unvlogable.gemspec
4
2
  gemspec
5
3
 
6
4
  group :development do
7
- gem "bundler", "> 1.0.0"
8
- gem "debugger"
9
- end
10
-
11
- group :development, :test do
12
- gem "shoulda"
5
+ gem "bundler", "> 1.3"
13
6
  end
14
7
 
8
+ group :test do
9
+ gem 'coveralls', require: false
10
+ end
data/README.markdown CHANGED
@@ -1,5 +1,5 @@
1
- Acts as unvlogable
2
- ==================
1
+ # Acts as unvlogable [![Build Status](https://travis-ci.org/mamuso/acts_as_unvlogable.svg?branch=master)](https://travis-ci.org/mamuso/acts_as_unvlogable) [![Coverage Status](https://coveralls.io/repos/mamuso/acts_as_unvlogable/badge.png?branch=master)](https://coveralls.io/r/mamuso/acts_as_unvlogable?branch=master)
2
+
3
3
 
4
4
  What the hell is this!
5
5
  ----------------------
@@ -15,14 +15,12 @@ To include [this video](http://www.youtube.com/watch?v=GPQnbtldFyo) in [this pos
15
15
  @aha.thumbnail => "http://i4.ytimg.com/vi/GPQnbtldFyo/default.jpg"
16
16
  @aha.embed_url => "http://www.youtube.com/v/GPQnbtldFyo"
17
17
  @aha.embed_html(width, height) => "<object [...]</object>"
18
- @aha.flv => "http://...flv"
19
18
  # all together :)
20
19
  @aha.video_details(width, height) => {
21
20
  :title => ...,
22
21
  :thumbnail => ...,
23
22
  :embed_url => ...,
24
23
  :embed_html => ...,
25
- :flv => ...
26
24
  }
27
25
 
28
26
  With this plugin we have an unique way to manage multiple services :)
@@ -35,16 +33,9 @@ Install it!
35
33
 
36
34
  gem "acts_as_unvlogable"
37
35
 
38
- 2. Optionally you can create the `config/unvlogable.yml` to store keys for the different services. You have in the plugin a [sample file](http://github.com/mamuso/acts_as_unvlogable/tree/master/unvlogable_sample.yml). At this moment you only need specify keys for flickr.
39
-
40
-
41
- Dependencies
42
- ------------
43
-
44
- The plugin depends on [youtube-it](https://github.com/kylejginavan/youtube_it), [xml-simple](http://xml-simple.rubyforge.org/) and [hpricot](https://code.whytheluckystiff.net/hpricot/).
45
-
46
- We have included a modified version of the flickr gem to skip the gem dependency and manage video capabilities.
36
+ 2. Optionally you can create the `config/unvlogable.yml` to store keys for the different services. You have in the plugin a [sample file](http://github.com/mamuso/acts_as_unvlogable/tree/master/unvlogable_sample.yml).
47
37
 
38
+ 2.1. 'yt' gem will need an API key from google in order to get the youtube video information properly, without dealing with API limits. They explain it better than me [here](https://github.com/Fullscreen/yt#apps-that-do-not-require-user-interactions)
48
39
 
49
40
  Use it!
50
41
  -------
@@ -81,10 +72,7 @@ Then we have methods to know the 'basics' for use this video on your application
81
72
  videotron.embed_html(400, 300)
82
73
  => "<object width='400' height='300'><param name='mo [...] 300'></embed></object>"
83
74
 
84
- - __flv:__ Gets the flv url. In this edition we implement this method in all the services, but is possible that we can't get the flv in some scenarios. Remember that in some services the flv url expires and in most of their terms don't allow use the flv without its player.
85
-
86
- videotron.flv
87
- => "http://www.vimeo.com/moogaloop/play/clip:1785993/ [...] 8ee400/video.flv"
75
+ - __flv:__ **DEPRECATED**
88
76
 
89
77
  - __video\_details(width, height):__ All together :), returns all the previous elements in a hash. Width and height can be specified to build the embed\_html.
90
78
 
@@ -107,21 +95,11 @@ At this moment we support the following video services:
107
95
  - [Myspace](http://vids.myspace.com/)
108
96
  - [Ted Talks](http://www.ted.com/talks/)
109
97
  - [11870.com](http://11870.com/)
110
- - [Marca.tv](http://www.marca.tv/)
111
98
  - [Dalealplay](http://www.dalealplay.com/)
112
99
  - [RuTube](http://www.rutube.ru/)
100
+ - [Wistia](http://wistia.com/)
101
+ - [Pleer — Audio](http://pleer.com/)
113
102
 
114
- Broken services
115
- ---------------
116
-
117
- These services were implemented but due to changes in the website they don't work anymore. Any patch for fixing them would be great ;)
118
-
119
- - [Qik](http://qik.com/)
120
- - [MTV](http://www.mtvhive.com/)
121
-
122
- You can detect new broken services when running the tests.
123
-
124
- We are always open to incude new services.
125
103
 
126
104
  And... what else?
127
105
  -----------------
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
1
  require 'bundler'
2
- Bundler::GemHelper.install_tasks
2
+ Bundler::GemHelper.install_tasks
@@ -6,8 +6,9 @@ Gem::Specification.new do |s|
6
6
  s.name = "acts_as_unvlogable_fork"
7
7
  s.version = ActsAsUnvlogable::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
+ s.required_ruby_version = '>= 1.9.3'
9
10
  s.authors = ["Manuel Muñoz", "Fernando Blat", "Alberto Romero"]
10
- s.email = ["mamusino@gmail.com", "ferblape@gmail.com", "denegro@gmail.com"]
11
+ s.email = ["mamuso@mamuso.net", "ferblape@gmail.com", "denegro@gmail.com"]
11
12
  s.homepage = "https://github.com/mamuso/acts_as_unvlogable"
12
13
  s.summary = %q{An easy way to include external video services in a rails app}
13
14
  s.description = %q{An easy way to include external video services in a rails app. This gem provides you wrappers for the most common video services, such as Youtube, Vimeo, Flickr, and so on...}
@@ -15,11 +16,14 @@ Gem::Specification.new do |s|
15
16
  s.rubyforge_project = "acts_as_unvlogable"
16
17
 
17
18
  s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test}/*`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
21
  s.require_paths = ["lib"]
21
- s.add_development_dependency "shoulda"
22
- s.add_dependency("xml-simple")
23
- s.add_dependency("youtube_it")
24
- s.add_dependency("hpricot")
22
+
23
+ s.add_development_dependency 'bundler', '~> 1.3'
24
+ s.add_development_dependency 'rake'
25
+ s.add_development_dependency 'rspec'
26
+ s.add_runtime_dependency("nokogiri")
27
+ s.add_runtime_dependency("xml-simple")
28
+ s.add_runtime_dependency("yt")
25
29
  end
@@ -1,32 +1,33 @@
1
- require "rubygems"
2
1
  require "bundler/setup"
3
-
4
- require "xmlsimple"
5
- require "youtube_it"
6
- require "hpricot"
7
- require "net/http"
2
+ require "cgi"
8
3
  require "json"
9
-
4
+ require "net/http"
5
+ require 'rexml/document'
6
+ require "yt"
7
+ require "nokogiri"
10
8
  require "acts_as_unvlogable/flickr"
11
- # Extensions
9
+
10
+
12
11
  if defined?(ActiveSupport).nil?
13
12
  require "acts_as_unvlogable/string_base"
14
13
  require "acts_as_unvlogable/object_base"
15
14
  end
16
15
  require "acts_as_unvlogable/string_extend"
17
16
 
18
- # Video classes
17
+
18
+ # Video Services
19
19
  videolibs = File.join(File.dirname(__FILE__), "acts_as_unvlogable", "vg_*.rb")
20
20
  Dir.glob(videolibs).each {|file| require file}
21
21
 
22
+
22
23
  class UnvlogIt
23
-
24
+
24
25
  def initialize(url=nil, options={})
25
26
  @object = VideoFactory.new(url, options).load_service
26
27
  end
27
28
 
28
29
  def title
29
- @object.title #rescue nil
30
+ @object.title rescue nil
30
31
  end
31
32
 
32
33
  def thumbnail
@@ -48,18 +49,18 @@ class UnvlogIt
48
49
  def embed_html(width=425, height=344, options={}, params={})
49
50
  @object.embed_html(width, height, options, params) rescue nil
50
51
  end
51
-
52
- def flv
53
- @object.flv #rescue nil
54
- end
55
-
56
- def download_url
57
- @object.download_url rescue nil
58
- end
59
52
 
60
53
  def service
61
54
  @object.service rescue nil
62
55
  end
56
+
57
+ # Deprecated
58
+ def flv
59
+ end
60
+
61
+ # Deprecated
62
+ def download_url
63
+ end
63
64
 
64
65
  def video_details(width=425, height=344)
65
66
  {
@@ -67,8 +68,8 @@ class UnvlogIt
67
68
  :thumbnail => @object.thumbnail,
68
69
  :embed_url => @object.embed_url,
69
70
  :embed_html => @object.embed_html(width, height),
70
- :flv => @object.flv,
71
- :download_url => @object.download_url,
71
+ :flv => nil, # Deprecated
72
+ :download_url => nil, # Deprecated
72
73
  :service => @object.service,
73
74
  :duration => @object.duration
74
75
  }
@@ -83,7 +84,6 @@ class UnvlogIt
83
84
 
84
85
  def load_service
85
86
  @object = service_object
86
-
87
87
  validate_embed(@object)
88
88
  end
89
89
 
@@ -91,7 +91,7 @@ class UnvlogIt
91
91
 
92
92
  def validate_embed(object)
93
93
  unless object.instance_variable_get("@details").nil? || !object.instance_variable_get("@details").respond_to?("noembed")
94
- if object.instance_variable_get("@details").noembed
94
+ if !object.instance_variable_get("@details").embeddable?
95
95
  raise ArgumentError.new("Embedding disabled by request")
96
96
  end
97
97
  end
@@ -102,7 +102,7 @@ class UnvlogIt
102
102
  class_name = "vg_#{get_domain.downcase}".camelize
103
103
  class_name.constantize.new(@url, @options)
104
104
  rescue NameError
105
- raise ArgumentError.new("Unsuported url or service. class: #{class_name}, url: #{@url}")
105
+ raise ArgumentError.new("Unsuported url or service")
106
106
  end
107
107
 
108
108
  def get_domain
@@ -1,40 +1,6 @@
1
1
  # included here to skip the gem dependency and modified to manage video capabilities.
2
2
  # this is the updated version from http://github.com/ctagg/flickr/tree/master/lib/flickr.rb
3
-
4
- # = Flickr
5
- # An insanely easy interface to the Flickr photo-sharing service. By Scott Raymond.
6
- #
7
- # Author:: Scott Raymond <sco@redgreenblu.com>
8
- # Copyright:: Copyright (c) 2005 Scott Raymond <sco@redgreenblu.com>. Additional content by Patrick Plattes and Chris Taggart (http://pushrod.wordpress.com)
9
- # License:: MIT <http://www.opensource.org/licenses/mit-license.php>
10
- #
11
- # BASIC USAGE:
12
- # require 'flickr'
13
- # flickr = Flickr.new('some_flickr_api_key') # create a flickr client (get an API key from http://www.flickr.com/services/api/)
14
- # user = flickr.users('sco@scottraymond.net') # lookup a user
15
- # user.name # get the user's name
16
- # user.location # and location
17
- # user.photos # grab their collection of Photo objects...
18
- # user.groups # ...the groups they're in...
19
- # user.contacts # ...their contacts...
20
- # user.favorites # ...favorite photos...
21
- # user.photosets # ...their photo sets...
22
- # user.tags # ...and their tags
23
- # recentphotos = flickr.photos # get the 100 most recent public photos
24
- # photo = recentphotos.first # or very most recent one
25
- # photo.url # see its URL,
26
- # photo.title # title,
27
- # photo.description # and description,
28
- # photo.owner # and its owner.
29
- # File.open(photo.filename, 'w') do |file|
30
- # file.puts p.file # save the photo to a local file
31
- # end
32
- # flickr.photos.each do |p| # get the last 100 public photos...
33
- # File.open(p.filename, 'w') do |f|
34
- # f.puts p.file('Square') # ...and save a local copy of their square thumbnail
35
- # end
36
- # end
37
-
3
+ # Modified and simplified to keep only the used methods
38
4
 
39
5
  require 'cgi'
40
6
  require 'net/http'
@@ -46,7 +12,7 @@ class Flickr
46
12
  attr_reader :api_key, :auth_token
47
13
  attr_accessor :user
48
14
 
49
- HOST_URL = 'http://flickr.com'
15
+ HOST_URL = 'https://flickr.com'
50
16
  API_PATH = '/services/rest'
51
17
 
52
18
  # Flickr, annoyingly, uses a number of representations to specify the size
@@ -92,87 +58,6 @@ class Flickr
92
58
  end
93
59
  end
94
60
 
95
- # Gets authentication token given a Flickr frob, which is returned when user
96
- # allows access to their account for the application with the api_key which
97
- # made the request
98
- def get_token_from(frob)
99
- auth_response = request("auth.getToken", :frob => frob)['auth']
100
- @auth_token = auth_response['token']
101
- @user = User.new( 'id' => auth_response['user']['nsid'],
102
- 'username' => auth_response['user']['username'],
103
- 'name' => auth_response['user']['fullname'],
104
- 'client' => self)
105
- @auth_token
106
- end
107
-
108
- # Stores authentication credentials to use on all subsequent calls.
109
- # If authentication succeeds, returns a User object.
110
- # NB This call is no longer in API and will result in an error if called
111
- def login(email='', password='')
112
- @email = email
113
- @password = password
114
- user = request('test.login')['user'] rescue fail
115
- @user = User.new(user['id'], nil, nil, nil, @api_key)
116
- end
117
-
118
- # Implements flickr.urls.lookupGroup and flickr.urls.lookupUser
119
- def find_by_url(url)
120
- response = urls_lookupUser('url'=>url) rescue urls_lookupGroup('url'=>url) rescue nil
121
- (response['user']) ? User.new(response['user']['id'], nil, nil, nil, @api_key) : Group.new(response['group']['id'], @api_key) unless response.nil?
122
- end
123
-
124
- # Implements flickr.photos.getRecent and flickr.photos.search
125
- def photos(*criteria)
126
- criteria ? photos_search(*criteria) : recent
127
- end
128
-
129
- # flickr.photos.getRecent
130
- # 100 newest photos from everyone
131
- def recent
132
- photos_request('photos.getRecent')
133
- end
134
-
135
- def photos_search(params={})
136
- photos_request('photos.search', params)
137
- end
138
- alias_method :search, :photos_search
139
-
140
- # Gets public photos with a given tag
141
- def tag(tag)
142
- photos('tags'=>tag)
143
- end
144
-
145
- # Implements flickr.people.findByEmail and flickr.people.findByUsername.
146
- def users(lookup=nil)
147
- user = people_findByEmail('find_email'=>lookup)['user'] rescue people_findByUsername('username'=>lookup)['user']
148
- return User.new("id" => user["nsid"], "username" => user["username"], "client" => self)
149
- end
150
-
151
- # Implements flickr.groups.search
152
- def groups(group_name, options={})
153
- collection = groups_search({"text" => group_name}.merge(options))['groups']['group']
154
- collection = [collection] if collection.is_a? Hash
155
-
156
- collection.collect { |group| Group.new( "id" => group['nsid'],
157
- "name" => group['name'],
158
- "eighteenplus" => group['eighteenplus'],
159
- "client" => self) }
160
- end
161
-
162
- # Implements flickr.tags.getRelated
163
- def related_tags(tag)
164
- tags_getRelated('tag'=>tag)['tags']['tag']
165
- end
166
-
167
- # Implements flickr.photos.licenses.getInfo
168
- def licenses
169
- photos_licenses_getInfo['licenses']['license']
170
- end
171
-
172
- # Returns url for user to login in to Flickr to authenticate app for a user
173
- def login_url(perms)
174
- "http://flickr.com/services/auth/?api_key=#{@api_key}&perms=#{perms}&api_sig=#{signature_from('api_key'=>@api_key, 'perms' => perms)}"
175
- end
176
61
 
177
62
  # Implements everything else.
178
63
  # Any method not defined explicitly will be passed on to the Flickr API,
@@ -182,11 +67,6 @@ class Flickr
182
67
  request(method_id.id2name.gsub(/_/, '.'), params)
183
68
  end
184
69
 
185
- # Does an HTTP GET on a given URL and returns the response body
186
- def http_get(url)
187
- Net::HTTP.get_response(URI.parse(url)).body.to_s
188
- end
189
-
190
70
  # Takes a Flickr API method name and set of parameters; returns an XmlSimple object with the response
191
71
  def request(method, params={})
192
72
  url = request_url(method, params)
@@ -194,12 +74,6 @@ class Flickr
194
74
  raise response['err']['msg'] if response['stat'] != 'ok'
195
75
  response
196
76
  end
197
-
198
- # acts like request but returns a PhotoCollection (a list of Photo objects)
199
- def photos_request(method, params={})
200
- photos = request(method, params)
201
- PhotoCollection.new(photos, @api_key)
202
- end
203
77
 
204
78
  # Builds url for Flickr API REST request from given the flickr method name
205
79
  # (exclusing the 'flickr.' that begins each method call) and params (where
@@ -228,10 +102,6 @@ class Flickr
228
102
  # builds a PhotoCollection from given params, such as those returned from
229
103
  # photos.search API call
230
104
  def initialize(photos_api_response={}, api_key=nil)
231
- [ "page", "pages", "perpage", "total" ].each { |i| instance_variable_set("@#{i}", photos_api_response["photos"][i])}
232
- collection = photos_api_response['photos']['photo'] || []
233
- collection = [collection] if collection.is_a? Hash
234
- collection.each { |photo| self << Photo.new(photo.delete('id'), api_key, photo) }
235
105
  end
236
106
  end
237
107
 
@@ -280,110 +150,6 @@ class Flickr
280
150
  @client.login(@email, @password) if @email and @password # this is now irrelevant as Flickr API no longer supports authentication this way
281
151
  end
282
152
 
283
- def username
284
- @username.nil? ? getInfo.username : @username
285
- end
286
- def name
287
- @name.nil? ? getInfo.name : @name
288
- end
289
- def location
290
- @location.nil? ? getInfo.location : @location
291
- end
292
- def count
293
- @count.nil? ? getInfo.count : @count
294
- end
295
- def firstdate
296
- @firstdate.nil? ? getInfo.firstdate : @firstdate
297
- end
298
- def firstdatetaken
299
- @firstdatetaken.nil? ? getInfo.firstdatetaken : @firstdatetaken
300
- end
301
-
302
- # Builds url for user's photos page as per
303
- # http://www.flickr.com/services/api/misc.urls.html
304
- def photos_url
305
- "http://www.flickr.com/photos/#{id}/"
306
- end
307
-
308
- # Builds url for user's profile page as per
309
- # http://www.flickr.com/services/api/misc.urls.html
310
- def url
311
- "http://www.flickr.com/people/#{id}/"
312
- end
313
-
314
- def pretty_url
315
- @pretty_url ||= @client.urls_getUserProfile('user_id'=>@id)['user']['url']
316
- end
317
-
318
- # Implements flickr.people.getPublicGroups
319
- def groups
320
- collection = @client.people_getPublicGroups('user_id'=>@id)['groups']['group']
321
- collection = [collection] if collection.is_a? Hash
322
- collection.collect { |group| Group.new( "id" => group['nsid'],
323
- "name" => group['name'],
324
- "eighteenplus" => group['eighteenplus'],
325
- "client" => @client) }
326
- end
327
-
328
- # Implements flickr.people.getPublicPhotos. Options hash allows you to add
329
- # extra restrictions as per flickr.people.getPublicPhotos docs, e.g.
330
- # user.photos('per_page' => '25', 'extras' => 'date_taken')
331
- def photos(options={})
332
- @client.photos_request('people.getPublicPhotos', {'user_id' => @id}.merge(options))
333
- # what about non-public photos?
334
- end
335
-
336
- # Gets photos with a given tag
337
- def tag(tag)
338
- @client.photos('user_id'=>@id, 'tags'=>tag)
339
- end
340
-
341
- # Implements flickr.contacts.getPublicList and flickr.contacts.getList
342
- def contacts
343
- @client.contacts_getPublicList('user_id'=>@id)['contacts']['contact'].collect { |contact| User.new(contact['nsid'], contact['username'], nil, nil, @api_key) }
344
- #or
345
- end
346
-
347
- # Implements flickr.favorites.getPublicList
348
- def favorites
349
- @client.photos_request('favorites.getPublicList', 'user_id' => @id)
350
- end
351
-
352
- # Implements flickr.photosets.getList
353
- def photosets
354
- @client.photosets_getList('user_id'=>@id)['photosets']['photoset'].collect { |photoset| Photoset.new(photoset['id'], @api_key) }
355
- end
356
-
357
- # Implements flickr.tags.getListUser
358
- def tags
359
- @client.tags_getListUser('user_id'=>@id)['who']['tags']['tag'].collect { |tag| tag }
360
- end
361
-
362
- # Implements flickr.photos.getContactsPublicPhotos and flickr.photos.getContactsPhotos
363
- def contactsPhotos
364
- @client.photos_request('photos.getContactsPublicPhotos', 'user_id' => @id)
365
- end
366
-
367
- def to_s
368
- @name
369
- end
370
-
371
-
372
-
373
- private
374
-
375
- # Implements flickr.people.getInfo, flickr.urls.getUserPhotos, and flickr.urls.getUserProfile
376
- def getInfo
377
- info = @client.people_getInfo('user_id'=>@id)['person']
378
- @username = info['username']
379
- @name = info['realname']
380
- @location = info['location']
381
- @count = info['photos']['count']
382
- @firstdate = info['photos']['firstdate']
383
- @firstdatetaken = info['photos']['firstdatetaken']
384
- self
385
- end
386
-
387
153
  end
388
154
 
389
155
  class Photo
@@ -396,192 +162,20 @@ class Flickr
396
162
  extra_params.each { |k,v| self.instance_variable_set("@#{k}", v) } # convert extra_params into instance variables
397
163
  @client = Flickr.new @api_key
398
164
  end
399
-
400
- # Allows access to all photos instance variables through hash like
401
- # interface, e.g. photo["datetaken"] returns @datetaken instance
402
- # variable. Useful for accessing any weird and wonderful parameter
403
- # that may have been returned by Flickr when finding the photo,
404
- # e.g. those returned by the extras argument in
405
- # flickr.people.getPublicPhotos
406
- def [](param_name)
407
- instance_variable_get("@#{param_name}")
408
- end
409
-
165
+
410
166
  def title
411
167
  @title.nil? ? getInfo("title") : @title
412
168
  end
413
169
 
414
- # Returns the owner of the photo as a Flickr::User. If we have no info
415
- # about the owner, we make an API call to get it. If we already have
416
- # the owner's id, create a user based on that. Either way, we cache the
417
- # result so we don't need to check again
418
- def owner
419
- case @owner
420
- when Flickr::User
421
- @owner
422
- when String
423
- @owner = Flickr::User.new(@owner, nil, nil, nil, @api_key)
424
- else
425
- getInfo("owner")
426
- end
427
- end
428
-
429
- def server
430
- @server.nil? ? getInfo("server") : @server
431
- end
432
-
433
- def isfavorite
434
- @isfavorite.nil? ? getInfo("isfavorite") : @isfavorite
435
- end
436
-
437
- def license
438
- @license.nil? ? getInfo("license") : @license
439
- end
440
-
441
- def rotation
442
- @rotation.nil? ? getInfo("rotation") : @rotation
443
- end
444
-
445
- def description
446
- @description || getInfo("description")
447
- end
448
-
449
- def notes
450
- @notes.nil? ? getInfo("notes") : @notes
451
- end
452
-
453
- # Returns the URL for the photo size page
454
- # defaults to 'Medium'
455
- # other valid sizes are in the VALID_SIZES hash
456
- def size_url(size='Medium')
457
- uri_for_photo_from_self(size) || sizes(size)['url']
458
- end
459
-
460
170
  # converts string or symbol size to a capitalized string
461
171
  def normalize_size(size)
462
172
  size ? size.to_s.capitalize : size
463
173
  end
464
174
 
465
- # the URL for the main photo page
466
- # if getInfo has already been called, this will return the pretty url
467
- #
468
- # for historical reasons, an optional size can be given
469
- # 'Medium' returns the regular url; any other size returns a size page
470
- # use size_url instead
471
- def url(size = nil)
472
- if normalize_size(size) != 'Medium'
473
- size_url(size)
474
- else
475
- @url || uri_for_photo_from_self
476
- end
477
- end
478
-
479
- # the 'pretty' url for a photo
480
- # (if the user has set up a custom name)
481
- # eg, http://flickr.com/photos/granth/2584402507/ instead of
482
- # http://flickr.com/photos/23386158@N00/2584402507/
483
- def pretty_url
484
- @url || getInfo("pretty_url")
485
- end
486
-
487
175
  # Returns the URL for the image (default or any specified size)
488
176
  def source(size='Medium')
489
177
  image_source_uri_from_self(size) || sizes(size)['source']
490
178
  end
491
-
492
- # Returns the photo file data itself, in any specified size. Example: File.open(photo.title, 'w') { |f| f.puts photo.file }
493
- def file(size='Medium')
494
- Net::HTTP.get_response(URI.parse(source(size))).body
495
- end
496
-
497
- # Unique filename for the image, based on the Flickr NSID
498
- def filename
499
- "#{@id}.jpg"
500
- end
501
-
502
- # Implements flickr.photos.getContext
503
- def context
504
- context = @client.photos_getContext('photo_id'=>@id)
505
- @previousPhoto = Photo.new(context['prevphoto'].delete('id'), @api_key, context['prevphoto']) if context['prevphoto']['id']!='0'
506
- @nextPhoto = Photo.new(context['nextphoto'].delete('id'), @api_key, context['nextphoto']) if context['nextphoto']['id']!='0'
507
- return [@previousPhoto, @nextPhoto]
508
- end
509
-
510
- # Implements flickr.photos.getExif
511
- def exif
512
- @client.photos_getExif('photo_id'=>@id)['photo']
513
- end
514
-
515
- # Implements flickr.photos.getPerms
516
- def permissions
517
- @client.photos_getPerms('photo_id'=>@id)['perms']
518
- end
519
-
520
- # Implements flickr.photos.getSizes
521
- def sizes(size=nil)
522
- size = normalize_size(size)
523
- sizes = @client.photos_getSizes('photo_id'=>@id)['sizes']['size']
524
- sizes = sizes.find{|asize| asize['label']==size} if size
525
- return sizes
526
- end
527
-
528
- # flickr.tags.getListPhoto
529
- def tags
530
- @client.tags_getListPhoto('photo_id'=>@id)['photo']['tags']
531
- end
532
-
533
- # Implements flickr.photos.notes.add
534
- def add_note(note)
535
- end
536
-
537
- # Implements flickr.photos.setDates
538
- def dates=(dates)
539
- end
540
-
541
- # Implements flickr.photos.setPerms
542
- def perms=(perms)
543
- end
544
-
545
- # Implements flickr.photos.setTags
546
- def tags=(tags)
547
- end
548
-
549
- # Implements flickr.photos.setMeta
550
- def title=(title)
551
- end
552
- def description=(title)
553
- end
554
-
555
- # Implements flickr.photos.addTags
556
- def add_tag(tag)
557
- end
558
-
559
- # Implements flickr.photos.removeTag
560
- def remove_tag(tag)
561
- end
562
-
563
- # Implements flickr.photos.transform.rotate
564
- def rotate
565
- end
566
-
567
- # Implements flickr.blogs.postPhoto
568
- def postToBlog(blog_id, title='', description='')
569
- @client.blogs_postPhoto('photo_id'=>@id, 'title'=>title, 'description'=>description)
570
- end
571
-
572
- # Implements flickr.photos.notes.delete
573
- def deleteNote(note_id)
574
- end
575
-
576
- # Implements flickr.photos.notes.edit
577
- def editNote(note_id)
578
- end
579
-
580
- # Converts the Photo to a string by returning its title
581
- def to_s
582
- title
583
- end
584
-
585
179
 
586
180
  # unvlog
587
181
  def media
@@ -630,84 +224,6 @@ class Flickr
630
224
  end
631
225
  end
632
226
 
633
- # Builds uri of Flickr page for photo. By default returns the main
634
- # page for the photo, but if passed a size will return the simplified
635
- # flickr page featuring the given size of the photo
636
- # TODO: Handle "Original" size
637
- def uri_for_photo_from_self(size=nil)
638
- return unless @owner&&@id
639
- size = normalize_size(size)
640
- s_size = VALID_SIZES[size] # get the short letters array corresponding to the size
641
- s_size = s_size&&s_size[1] # the second element of this array is used to build the uri of the flickr page for this size
642
- "http://www.flickr.com/photos/#{owner.id}/#{@id}" + (s_size ? "/sizes/#{s_size}/" : "")
643
- end
644
- end
645
-
646
- # Todo:
647
- # flickr.groups.pools.add
648
- # flickr.groups.pools.getContext
649
- # flickr.groups.pools.getGroups
650
- # flickr.groups.pools.getPhotos
651
- # flickr.groups.pools.remove
652
- class Group
653
- attr_reader :id, :client, :description, :name, :eighteenplus, :members, :online, :privacy, :url#, :chatid, :chatcount
654
-
655
- def initialize(id_or_params_hash=nil, api_key=nil)
656
- if id_or_params_hash.is_a?(Hash)
657
- id_or_params_hash.each { |k,v| self.instance_variable_set("@#{k}", v) } # convert extra_params into instance variables
658
- else
659
- @id = id_or_params_hash
660
- @api_key = api_key
661
- @client = Flickr.new @api_key
662
- end
663
- end
664
-
665
- # Implements flickr.groups.getInfo and flickr.urls.getGroup
666
- # private, once we can call it as needed
667
- def getInfo
668
- info = @client.groups_getInfo('group_id'=>@id)['group']
669
- @name = info['name']
670
- @members = info['members']
671
- @online = info['online']
672
- @privacy = info['privacy']
673
- # @chatid = info['chatid']
674
- # @chatcount = info['chatcount']
675
- @url = @client.urls_getGroup('group_id'=>@id)['group']['url']
676
- self
677
- end
678
-
679
- end
680
-
681
- # Todo:
682
- # flickr.photosets.delete
683
- # flickr.photosets.editMeta
684
- # flickr.photosets.editPhotos
685
- # flickr.photosets.getContext
686
- # flickr.photosets.getInfo
687
- # flickr.photosets.getPhotos
688
- class Photoset
689
-
690
- attr_reader :id, :client, :owner, :primary, :photos, :title, :description, :url
691
-
692
- def initialize(id=nil, api_key=nil)
693
- @id = id
694
- @api_key = api_key
695
- @client = Flickr.new @api_key
696
- end
697
-
698
- # Implements flickr.photosets.getInfo
699
- # private, once we can call it as needed
700
- def getInfo
701
- info = @client.photosets_getInfo('photoset_id'=>@id)['photoset']
702
- @owner = User.new(info['owner'], nil, nil, nil, @api_key)
703
- @primary = info['primary']
704
- @photos = info['photos']
705
- @title = info['title']
706
- @description = info['description']
707
- @url = "http://www.flickr.com/photos/#{@owner.getInfo.username}/sets/#{@id}/"
708
- self
709
- end
710
-
711
227
  end
712
228
 
713
229
  end