Class: FlickrBadgeMaker::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/flickr_badge_maker/client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/flickr_badge_maker/client.rb', line 9

def initialize
  @config_path = File.join(Dir.home, ".flickr_config")
  config = read_config
  @maker = Maker.new(config)
end

Instance Method Details

#configureObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/flickr_badge_maker/client.rb', line 15

def configure
  begin
    puts "Enter your flickr API key.  If you don't have one, you can request it at this url:"
    puts "   http://www.flickr.com/services/apps/create/apply"
    print "Key>>"
    api_key = STDIN.gets.strip

    puts "\nNow enter the 'secret' code associated with the API Key."
    print "Secret>> "
    shared_secret = STDIN.gets.strip

    config = @maker.config
    config['api_key'] = api_key
    config['shared_secret'] = shared_secret

    # Reconfigure the maker now that we have the keys.
    @maker.configure(config)
    
    request_token = @maker.get_request_token
    auth_url = @maker.get_authorize_url(request_token)

    puts "Open this url in your web browser to complete the authentication process\n   #{auth_url}\n"
    puts "Copy and paste the number given when you complete the process."
    print "Code>> "
    verify_lambda = STDIN.gets.strip

    access = @maker.authenticate(request_token, verify_lambda)
     = @maker.
    puts "\nSuccessfully authenticated as #{.username}"

    config['access_token'] = access[:access_token]
    config['access_secret'] = access[:access_secret]

    write_config(config)
  rescue FlickRaw::FailedResponse => e
    puts "Error>> Authentication failed : #{e.msg}"
  end
end

#get_badge_yaml(set) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/flickr_badge_maker/client.rb', line 62

def get_badge_yaml(set)
  begin
    photos = @maker.get_photos(set)
    display_info = get_display_info(photos)
    print YAML.dump(display_info)
  rescue FlickRaw::FailedResponse => e
    puts "Error>> Flickr communication failed : #{e.msg}"
  end        
end

#get_set_info(set) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/flickr_badge_maker/client.rb', line 54

def get_set_info(set)
  begin
    ap @maker.get_photos(set)
  rescue FlickRaw::FailedResponse => e
    puts "Error>> Flickr communication failed : #{e.msg}"
  end        
end

#make_badge(set) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/flickr_badge_maker/client.rb', line 72

def make_badge(set)
  begin
    photos = @maker.get_photos(set)
    photos = get_display_info(photos)
    puts "<ul>"
    photos.each do |p|
      puts "<li><a href=\"#{p['enlarge_image_url']}\"><img src=\"#{p['preview_image_url']}\"/></a>"
      puts "<br/><a href=\"#{p['view_url']}\">#{p['caption']}</a>"
    end
    puts "</ul>"
  rescue FlickRaw::FailedResponse => e
    puts "Error>> Flickr communication failed : #{e.msg}"
  end        
end