wideopenspaces-flickry 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +122 -0
- data/VERSION.yml +1 -1
- data/lib/flickry.rb +50 -1
- data/lib/flickry/license.rb +22 -0
- data/lib/flickry/photo.rb +45 -5
- metadata +31 -11
data/README.markdown
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
# Flickry (by wideopenspac.es)
|
2
|
+
|
3
|
+
Flickry is a wrapper for Flickraw that makes working with the Flickr API safe &
|
4
|
+
easy by parsing the Flickraw response into the appropriate objects.
|
5
|
+
|
6
|
+
Now features support for Comments, Tags, Locations (including woeid and place_id
|
7
|
+
for region, county, etc)!
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
sudo gem install wideopenspaces-flickry
|
12
|
+
|
13
|
+
## Using with Rails (2.2+)
|
14
|
+
|
15
|
+
In `config/environments.rb`, add:
|
16
|
+
|
17
|
+
config.gem "wideopenspaces-flickry", :source => "http://gems.github.com", :lib => 'flickry'
|
18
|
+
|
19
|
+
Add the following in `config/initializers/flickr.rb`:
|
20
|
+
|
21
|
+
# This is how to authenticate on flickr website.
|
22
|
+
# You need an API key for that, see http://www.flickr.com/services/api/keys/
|
23
|
+
API_KEY='your-api-key-here'
|
24
|
+
SHARED_SECRET='your-secret-here'
|
25
|
+
begin
|
26
|
+
FlickRaw.api_key=API_KEY
|
27
|
+
FlickRaw.shared_secret=SHARED_SECRET
|
28
|
+
rescue
|
29
|
+
end
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
pic = Flickry::Photo.new 3008067483
|
34
|
+
|
35
|
+
pic.urls
|
36
|
+
["http://www.flickr.com/photos/..."]
|
37
|
+
|
38
|
+
**Dates**
|
39
|
+
|
40
|
+
pic.uploaded_at
|
41
|
+
=> Thu Nov 06 13:27:13 -0700 2008
|
42
|
+
pic.taken_at
|
43
|
+
=> Tue Nov 04 16:39:46 -0700 2008
|
44
|
+
pic.posted_at
|
45
|
+
=> Thu Nov 06 13:27:13 -0700 2008
|
46
|
+
pic.last_updated_at
|
47
|
+
=> Sat Jan 10 14:18:29 -0700 2009
|
48
|
+
|
49
|
+
**License**
|
50
|
+
|
51
|
+
pic.license
|
52
|
+
=> "Attribution-NonCommercial-ShareAlike License"
|
53
|
+
pic.license.url
|
54
|
+
=> "http://creativecommons.org/licenses/by-nc-sa/2.0/"
|
55
|
+
|
56
|
+
**Sizes**
|
57
|
+
|
58
|
+
pic.sizes.medium
|
59
|
+
=> #<Flickry::Size source="http://farm4.static.flickr.com/....jpg", url="http://www.flickr.com/photos/.../sizes/m/", height="500", media="photo", width="334">
|
60
|
+
|
61
|
+
pic.sizes.medium.height
|
62
|
+
=> "500"
|
63
|
+
|
64
|
+
**People**
|
65
|
+
|
66
|
+
person = pic.owner
|
67
|
+
=> #<Flickry::Person location="", nsid="", realname="", username="", photosurl="", profileurl="">
|
68
|
+
|
69
|
+
person.profile
|
70
|
+
=> "http://www.flickr.com/people/.../"
|
71
|
+
|
72
|
+
person.photos
|
73
|
+
=> "http://www.flickr.com/photos/.../"
|
74
|
+
|
75
|
+
**Location**
|
76
|
+
|
77
|
+
pic.location
|
78
|
+
=> #<Flickry::Location place_id="", region="", woeid="", country="", accuracy="", county="", latitude=41.8, locality="", longitude=-87.6, neighbourhood="">
|
79
|
+
|
80
|
+
reg = pic.location.region
|
81
|
+
=> "Illinois"
|
82
|
+
|
83
|
+
reg.place_id # Look ma, that string has methods!
|
84
|
+
=> "<place_id>"
|
85
|
+
reg.woeid
|
86
|
+
=> "<woeid>"
|
87
|
+
|
88
|
+
country, region, county, locality, and neighbourhood all *look* like strings but have woeid and place_id attributes.
|
89
|
+
|
90
|
+
**Tags**
|
91
|
+
|
92
|
+
pic.tags
|
93
|
+
=> ["hdr", "trump", "skyscraper", "skyline"]
|
94
|
+
|
95
|
+
pic.tag_list
|
96
|
+
=> "hdr, trump, skyscraper, skyline"
|
97
|
+
|
98
|
+
**Comments**
|
99
|
+
|
100
|
+
pic.comments
|
101
|
+
=> ["beautiful", "That HDR trumps others I've seen! Nice work! :)"]
|
102
|
+
|
103
|
+
pic.comments.last
|
104
|
+
=> "That HDR trumps others I've seen! Nice work! :)"
|
105
|
+
|
106
|
+
pic.comments.last.author
|
107
|
+
=> #<Flickry::Person location="", nsid="", realname="", username="", photosurl="", profileurl="">
|
108
|
+
|
109
|
+
pic.comments.last.comment_id
|
110
|
+
=> "215779-3008067483-72157608738732709"
|
111
|
+
|
112
|
+
pic.comments.last.created_at
|
113
|
+
=> Fri Nov 07 10:38:42 -0700 2008
|
114
|
+
|
115
|
+
pic.comments.last.permalink
|
116
|
+
=> "http://www.flickr.com/photos/unquiet/3008067483/#comment72157608738732709"
|
117
|
+
|
118
|
+
|
119
|
+
## Contributing
|
120
|
+
|
121
|
+
This thing needs tests! I was running tests against the flickr api directly but want
|
122
|
+
to stub those. If you feel like getting there before I do, go right ahead!
|
data/VERSION.yml
CHANGED
data/lib/flickry.rb
CHANGED
@@ -1,10 +1,59 @@
|
|
1
|
-
require 'flickraw'
|
1
|
+
#require 'flickraw'
|
2
|
+
require 'httparty'
|
2
3
|
require 'super_struct'
|
3
4
|
|
4
5
|
require 'flickry/base'
|
5
6
|
require 'flickry/location'
|
6
7
|
require 'flickry/tag'
|
7
8
|
require 'flickry/person'
|
9
|
+
require 'flickry/comment'
|
10
|
+
require 'flickry/size'
|
8
11
|
require 'flickry/sizes'
|
12
|
+
require 'flickry/license'
|
9
13
|
require 'flickry/photo'
|
10
14
|
|
15
|
+
module Flickry
|
16
|
+
VERSION='0.3.0'
|
17
|
+
|
18
|
+
FLICKR_HOST='api.flickr.com'.freeze
|
19
|
+
|
20
|
+
# Path of flickr REST API
|
21
|
+
REST_PATH='/services/rest/?'.freeze
|
22
|
+
|
23
|
+
# Path of flickr auth page
|
24
|
+
AUTH_PATH='/services/auth/?'.freeze
|
25
|
+
|
26
|
+
# Path of flickr upload
|
27
|
+
UPLOAD_PATH='/services/upload/'.freeze
|
28
|
+
|
29
|
+
class Flickr
|
30
|
+
include HTTParty
|
31
|
+
base_uri FLICKR_HOST
|
32
|
+
|
33
|
+
def initialize # :nodoc:
|
34
|
+
end
|
35
|
+
|
36
|
+
def authorize(args={})
|
37
|
+
full_args = {:api_key => Flickry.api_key, :perms => 'read'}
|
38
|
+
args.each {|k, v| full_args[k.to_sym] = v }
|
39
|
+
full_args[:api_sig] = Flickry.api_sig(full_args) if Flickry.shared_secret
|
40
|
+
url = 'http://' + Flickry::FLICKR_HOST + Flickry::AUTH_PATH + full_args.collect { |a, v| "#{a}=#{v}" }.join('&')
|
41
|
+
puts url
|
42
|
+
self.class.get(url)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class << self
|
47
|
+
# Your flickr API key, see http://www.flickr.com/services/api/keys for more information
|
48
|
+
attr_accessor :api_key
|
49
|
+
|
50
|
+
# The shared secret of _api_key_, see http://www.flickr.com/services/api/keys for more information
|
51
|
+
attr_accessor :shared_secret
|
52
|
+
|
53
|
+
|
54
|
+
# Returns the signature of hsh. This is meant to be passed in the _api_sig_ parameter.
|
55
|
+
def api_sig(hsh)
|
56
|
+
MD5.md5(Flickry.shared_secret + hsh.sort{|a, b| a[0].to_s <=> b[0].to_s }.flatten.join).to_s
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Flickr has an API method for getting information about licenses
|
2
|
+
# but it probably doesn't change all that often.
|
3
|
+
module Flickry
|
4
|
+
class License < String
|
5
|
+
attr_accessor :name, :url
|
6
|
+
def initialize(license)
|
7
|
+
@name, @url = case id.to_i # License Name Information URL
|
8
|
+
when 1: ["Attribution-NonCommercial-ShareAlike License", "http://creativecommons.org/licenses/by-nc-sa/2.0/"]
|
9
|
+
when 2: ["Attribution-NonCommercial License", "http://creativecommons.org/licenses/by-nc/2.0/"]
|
10
|
+
when 3: ["Attribution-NonCommercial-NoDerivs License", "http://creativecommons.org/licenses/by-nc-nd/2.0/"]
|
11
|
+
when 4: ["Attribution License", "http://creativecommons.org/licenses/by/2.0/"]
|
12
|
+
when 5: ["Attribution-ShareAlike License", "http://creativecommons.org/licenses/by-sa/2.0/"]
|
13
|
+
when 6: ["Attribution-NoDerivs License", "http://creativecommons.org/licenses/by-nd/2.0/"]
|
14
|
+
when 7: ["No known copyright restrictions", "http://flickr.com/commons/usage/"]
|
15
|
+
else
|
16
|
+
["All Rights Reserved", ""]
|
17
|
+
end
|
18
|
+
|
19
|
+
super(@name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/flickry/photo.rb
CHANGED
@@ -6,9 +6,9 @@ module Flickry
|
|
6
6
|
self.raw_photo = foto
|
7
7
|
self.photo_id = flickr_id
|
8
8
|
|
9
|
-
extract_attrs!(foto, [:dateuploaded, :description, :farm, :id, :isfavorite,
|
9
|
+
extract_attrs!(foto, [:dateuploaded, :description, :farm, :id, :isfavorite,
|
10
10
|
:media, :notes, :originalformat, :originalsecret, :rotation, :secret, :server, :tags,
|
11
|
-
:title
|
11
|
+
:title])
|
12
12
|
extract_attrs_into_substructs!(foto, {
|
13
13
|
:dates => [:lastupdate, :posted, :taken, :takengranularity],
|
14
14
|
:editability => [:canaddmeta, :cancomment],
|
@@ -17,19 +17,24 @@ module Flickry
|
|
17
17
|
:visibility => [:isfamily, :isfriend, :ispublic]
|
18
18
|
})
|
19
19
|
self.location = Flickry::Location.new(foto.respond_to?(:location) ? foto.location : nil)
|
20
|
-
self.owner = Flickry::Person.
|
21
|
-
|
20
|
+
self.owner = Flickry::Person.find(foto.respond_to?(:owner) ? foto.owner.nsid : nil)
|
21
|
+
self.license = Flickry::License.new(foto.respond_to?(:license) ? foto.license : 99)
|
22
22
|
_tags = self.tags.dup
|
23
23
|
self.tags = _tags.collect do |t|
|
24
24
|
Flickry::Tag.new(t)
|
25
25
|
end
|
26
|
+
self.urls = foto.urls.collect { |u| u.to_s }
|
26
27
|
end
|
27
28
|
|
29
|
+
## Sizes
|
30
|
+
|
28
31
|
# Lazily fetches the photo's sizes when called, memoizes so later calls are faster...
|
29
32
|
def sizes
|
30
33
|
@sizes ||= Flickry::Sizes.new(flickr.photos.getSizes(:photo_id => self.photo_id))
|
31
34
|
end
|
32
35
|
|
36
|
+
## Comments
|
37
|
+
|
33
38
|
# Lazily fetches the photo's comments when called, memoizes so later calls are faster...
|
34
39
|
def comments
|
35
40
|
return @comments if @comments
|
@@ -44,13 +49,40 @@ module Flickry
|
|
44
49
|
end
|
45
50
|
end
|
46
51
|
return @comments
|
47
|
-
end
|
52
|
+
end
|
53
|
+
|
54
|
+
## Time/Dates
|
55
|
+
def last_updated_at
|
56
|
+
dates_to_time(:lastupdate)
|
57
|
+
end
|
58
|
+
|
59
|
+
def posted_at
|
60
|
+
dates_to_time(:posted)
|
61
|
+
end
|
62
|
+
|
63
|
+
def taken_at
|
64
|
+
Time.parse(self.dates.taken)
|
65
|
+
end
|
66
|
+
|
67
|
+
def uploaded_at
|
68
|
+
uploaded = self.dateuploaded.to_i
|
69
|
+
return nil if uploaded == 0
|
70
|
+
Time.at(uploaded)
|
71
|
+
end
|
72
|
+
|
73
|
+
## Tags
|
48
74
|
|
49
75
|
# Join tags into a single string
|
50
76
|
def tag_list(separator = ', ')
|
51
77
|
self.tags.join(separator)
|
52
78
|
end
|
53
79
|
|
80
|
+
#W Booleans
|
81
|
+
|
82
|
+
def favorite?
|
83
|
+
self.isfavorite == 1
|
84
|
+
end
|
85
|
+
|
54
86
|
def visible_to_family?
|
55
87
|
self.visibility.isfamily == 1
|
56
88
|
end
|
@@ -63,5 +95,13 @@ module Flickry
|
|
63
95
|
self.visibility.ispublic == 1
|
64
96
|
end
|
65
97
|
|
98
|
+
private
|
99
|
+
|
100
|
+
def dates_to_time(src)
|
101
|
+
time = self.dates.send(src).to_i
|
102
|
+
return nil if time == 0
|
103
|
+
Time.at(time)
|
104
|
+
end
|
105
|
+
|
66
106
|
end
|
67
107
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wideopenspaces-flickry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Jacob Stetser
|
@@ -9,18 +15,24 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2009-01-
|
13
|
-
default_executable:
|
18
|
+
date: 2009-01-22 00:00:00 Z
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: wideopenspaces-flickraw
|
17
|
-
|
18
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
19
25
|
requirements:
|
20
26
|
- - ">="
|
21
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 15
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 5
|
32
|
+
- 2
|
22
33
|
version: 0.5.2
|
23
|
-
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
24
36
|
description: Interface to Flickr API to make working with API responses safer and easier. DO NOT USE ME YET!
|
25
37
|
email: jake@wideopenspac.es
|
26
38
|
executables: []
|
@@ -30,10 +42,11 @@ extensions: []
|
|
30
42
|
extra_rdoc_files: []
|
31
43
|
|
32
44
|
files:
|
45
|
+
- README.markdown
|
33
46
|
- VERSION.yml
|
34
|
-
- lib/flickry
|
35
47
|
- lib/flickry/base.rb
|
36
48
|
- lib/flickry/comment.rb
|
49
|
+
- lib/flickry/license.rb
|
37
50
|
- lib/flickry/location.rb
|
38
51
|
- lib/flickry/person.rb
|
39
52
|
- lib/flickry/photo.rb
|
@@ -45,8 +58,9 @@ files:
|
|
45
58
|
- lib/super_struct.rb
|
46
59
|
- test/flickry_test.rb
|
47
60
|
- test/test_helper.rb
|
48
|
-
has_rdoc: true
|
49
61
|
homepage: http://github.com/wideopenspaces/flickry
|
62
|
+
licenses: []
|
63
|
+
|
50
64
|
post_install_message:
|
51
65
|
rdoc_options:
|
52
66
|
- --inline-source
|
@@ -54,21 +68,27 @@ rdoc_options:
|
|
54
68
|
require_paths:
|
55
69
|
- lib
|
56
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
57
72
|
requirements:
|
58
73
|
- - ">="
|
59
74
|
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
60
78
|
version: "0"
|
61
|
-
version:
|
62
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
63
81
|
requirements:
|
64
82
|
- - ">="
|
65
83
|
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
66
87
|
version: "0"
|
67
|
-
version:
|
68
88
|
requirements: []
|
69
89
|
|
70
90
|
rubyforge_project:
|
71
|
-
rubygems_version: 1.2
|
91
|
+
rubygems_version: 1.7.2
|
72
92
|
signing_key:
|
73
93
|
specification_version: 2
|
74
94
|
summary: Friendlier interface to flickr API, uses flickraw underneath
|