flickr_badge_maker 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/flickr_badge_maker +26 -0
- data/lib/flickr_badge_maker.rb +2 -0
- data/lib/flickr_badge_maker/client.rb +131 -0
- data/lib/flickr_badge_maker/maker.rb +73 -0
- metadata +81 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
4
|
+
|
5
|
+
require "flickr_badge_maker"
|
6
|
+
|
7
|
+
client = FlickrBadgeMaker::Client.new
|
8
|
+
|
9
|
+
case ARGV[0]
|
10
|
+
when "info"
|
11
|
+
client.get_set_info(ARGV[1])
|
12
|
+
when "yaml"
|
13
|
+
client.get_badge_yaml(ARGV[1])
|
14
|
+
when "badge"
|
15
|
+
client.make_badge(ARGV[1])
|
16
|
+
when "configure"
|
17
|
+
client.configure
|
18
|
+
else
|
19
|
+
puts "Usage: flickr_badge_maker <command> <options>\n"
|
20
|
+
puts "\nAvailable commands:"
|
21
|
+
puts " configure - Walks through the configuration process. *Do this first.*"
|
22
|
+
puts " info <set id> - Shows complete information for a photoset."
|
23
|
+
puts " yaml <set id> - Shows abbreviated yaml style info for a photoset."
|
24
|
+
puts " badge <set id> - Shows a HTML badge snippet for a photoset."
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'flickr_badge_maker'
|
3
|
+
require 'yaml'
|
4
|
+
require 'ap'
|
5
|
+
|
6
|
+
module FlickrBadgeMaker
|
7
|
+
class Client
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@config_path = File.join(Dir.home, ".flickr_config")
|
11
|
+
config = read_config
|
12
|
+
@maker = Maker.new(config)
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure
|
16
|
+
begin
|
17
|
+
puts "Enter your flickr API key. If you don't have one, you can request it at this url:"
|
18
|
+
puts " http://www.flickr.com/services/apps/create/apply"
|
19
|
+
print "Key>>"
|
20
|
+
api_key = STDIN.gets.strip
|
21
|
+
|
22
|
+
puts "\nNow enter the 'secret' code associated with the API Key."
|
23
|
+
print "Secret>> "
|
24
|
+
shared_secret = STDIN.gets.strip
|
25
|
+
|
26
|
+
config = @maker.config
|
27
|
+
config['api_key'] = api_key
|
28
|
+
config['shared_secret'] = shared_secret
|
29
|
+
|
30
|
+
# Reconfigure the maker now that we have the keys.
|
31
|
+
@maker.configure(config)
|
32
|
+
|
33
|
+
request_token = @maker.get_request_token
|
34
|
+
auth_url = @maker.get_authorize_url(request_token)
|
35
|
+
|
36
|
+
puts "Open this url in your web browser to complete the authentication process\n #{auth_url}\n"
|
37
|
+
puts "Copy and paste the number given when you complete the process."
|
38
|
+
print "Code>> "
|
39
|
+
verify_lambda = STDIN.gets.strip
|
40
|
+
|
41
|
+
access = @maker.authenticate(request_token, verify_lambda)
|
42
|
+
login = @maker.test_login
|
43
|
+
puts "\nSuccessfully authenticated as #{login.username}"
|
44
|
+
|
45
|
+
config['access_token'] = access[:access_token]
|
46
|
+
config['access_secret'] = access[:access_secret]
|
47
|
+
|
48
|
+
write_config(config)
|
49
|
+
rescue FlickRaw::FailedResponse => e
|
50
|
+
puts "Error>> Authentication failed : #{e.msg}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_set_info(set)
|
55
|
+
begin
|
56
|
+
ap @maker.get_photos(set)
|
57
|
+
rescue FlickRaw::FailedResponse => e
|
58
|
+
puts "Error>> Flickr communication failed : #{e.msg}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_badge_yaml(set)
|
63
|
+
begin
|
64
|
+
photos = @maker.get_photos(set)
|
65
|
+
display_info = get_display_info(photos)
|
66
|
+
print YAML.dump(display_info)
|
67
|
+
rescue FlickRaw::FailedResponse => e
|
68
|
+
puts "Error>> Flickr communication failed : #{e.msg}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def make_badge(set)
|
73
|
+
begin
|
74
|
+
photos = @maker.get_photos(set)
|
75
|
+
photos = get_display_info(photos)
|
76
|
+
puts "<ul>"
|
77
|
+
photos.each do |p|
|
78
|
+
puts "<li><a href=\"#{p['enlarge_image_url']}\"><img src=\"#{p['preview_image_url']}\"/></a>"
|
79
|
+
puts "<br/><a href=\"#{p['view_url']}\">#{p['caption']}</a>"
|
80
|
+
end
|
81
|
+
puts "</ul>"
|
82
|
+
rescue FlickRaw::FailedResponse => e
|
83
|
+
puts "Error>> Flickr communication failed : #{e.msg}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def read_config
|
90
|
+
if (File.exists?(@config_path))
|
91
|
+
config = YAML.load_file(@config_path)
|
92
|
+
else
|
93
|
+
config =
|
94
|
+
{
|
95
|
+
'api_key' => '',
|
96
|
+
'shared_secret' => '',
|
97
|
+
'access_token' => '',
|
98
|
+
'access_secret' => '',
|
99
|
+
'display' =>
|
100
|
+
{
|
101
|
+
'enlarge_image_url' => 'med_image_url',
|
102
|
+
'preview_image_url' => 'small_image_url',
|
103
|
+
'view_url' => 'view_url',
|
104
|
+
'caption' => 'caption'
|
105
|
+
}
|
106
|
+
}
|
107
|
+
write_config(config)
|
108
|
+
end
|
109
|
+
config
|
110
|
+
end
|
111
|
+
|
112
|
+
def write_config(config)
|
113
|
+
puts "Creating config file in #{@config_path}."
|
114
|
+
File.open(@config_path, 'w') {|f| f.write(YAML.dump(config)) }
|
115
|
+
end
|
116
|
+
|
117
|
+
def get_display_info(photos)
|
118
|
+
display_mapping = @maker.config['display']
|
119
|
+
display_photos = []
|
120
|
+
photos.each do |photo|
|
121
|
+
display_info = {}
|
122
|
+
display_mapping.keys.each do |key|
|
123
|
+
display_info[key] = photo[display_mapping[key]]
|
124
|
+
end
|
125
|
+
display_photos << display_info
|
126
|
+
end
|
127
|
+
display_photos
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'flickraw'
|
2
|
+
|
3
|
+
module FlickrBadgeMaker
|
4
|
+
class Maker
|
5
|
+
attr_reader :config
|
6
|
+
|
7
|
+
def initialize(config)
|
8
|
+
configure(config)
|
9
|
+
end
|
10
|
+
|
11
|
+
def configure(config)
|
12
|
+
@config = config
|
13
|
+
begin
|
14
|
+
FlickRaw.api_key=config['api_key']
|
15
|
+
FlickRaw.shared_secret=config['shared_secret']
|
16
|
+
flickr.access_token = config['access_token']
|
17
|
+
flickr.access_secret = config['access_secret']
|
18
|
+
rescue FlickRaw::FailedResponse => e
|
19
|
+
puts "Warning: Unable to initialize flickr library. Check your configuration."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_photos(set_id)
|
24
|
+
flickr_photos = flickr.photosets.getPhotos( :photoset_id => set_id )
|
25
|
+
build_full_photo_info(flickr_photos)
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_request_token()
|
29
|
+
flickr.get_request_token
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_authorize_url(request_token)
|
33
|
+
flickr.get_authorize_url(request_token['oauth_token'], :perms => 'read')
|
34
|
+
end
|
35
|
+
|
36
|
+
def authenticate(request_token, verify_lambda)
|
37
|
+
flickr.get_access_token(request_token['oauth_token'], request_token['oauth_token_secret'], verify_lambda)
|
38
|
+
{
|
39
|
+
:access_token => flickr.access_token,
|
40
|
+
:access_secret => flickr.access_secret
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_login()
|
45
|
+
flickr.test.login
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
|
51
|
+
def build_full_photo_info(flickr_photos)
|
52
|
+
gallery_photos = []
|
53
|
+
|
54
|
+
flickr_photos.photo.each do |p|
|
55
|
+
info = flickr.photos.getInfo(:photo_id => p.id)
|
56
|
+
|
57
|
+
gallery_photos <<
|
58
|
+
{
|
59
|
+
'squarethumb_image_url' => FlickRaw.url_s(info),
|
60
|
+
'thumb_image_url' => FlickRaw.url_t(info),
|
61
|
+
'small_image_url' => FlickRaw.url_m(info),
|
62
|
+
'med_image_url' => FlickRaw.url(info),
|
63
|
+
'large_image_url' => FlickRaw.url_b(info),
|
64
|
+
'orig_image_url' => FlickRaw.url_o(info),
|
65
|
+
'caption' => info.title,
|
66
|
+
'host' => "Flickr",
|
67
|
+
'view_url' => FlickRaw.url_photopage(info)
|
68
|
+
}
|
69
|
+
end
|
70
|
+
gallery_photos
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flickr_badge_maker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- lynnfaraday@github
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: flickraw
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.9'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.9'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: awesome_print
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.0'
|
46
|
+
description: Convenient access to Flickr photosets for creating a photo gallery badge.
|
47
|
+
email:
|
48
|
+
executables:
|
49
|
+
- flickr_badge_maker
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- bin/flickr_badge_maker
|
54
|
+
- lib/flickr_badge_maker/client.rb
|
55
|
+
- lib/flickr_badge_maker/maker.rb
|
56
|
+
- lib/flickr_badge_maker.rb
|
57
|
+
homepage: http://github.com/lynnfaraday/flickr_badge_maker
|
58
|
+
licenses: []
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.8.24
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Flickr photo gallery badge helper.
|
81
|
+
test_files: []
|