desklickrb 1.0.0 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dce7bc139bef0b1e3b315ac5337a0bff169bdbcb
4
- data.tar.gz: ef4b093b5436c65dbad5b94254f4b28bc7f2a092
3
+ metadata.gz: e813cf97bd58e1daacedaf596cde45d0f269406e
4
+ data.tar.gz: 8e1998847806288f11180098ff963a1375197197
5
5
  SHA512:
6
- metadata.gz: 4f28349514ed9248615d02fcd2b30fd0756fd7ed350b05d2c99723526763999e5aeed97e93353f3fe26c825b5fa014c6431add30acb392005f177d6938d6d689
7
- data.tar.gz: 04d285c06be4b0993e27f53b4c80ace24280cf24eed8527e2ddecb70858adf3e0a3a2d6a4e7b5b1ef8c1f8d671df780e35fb4b215d577ba0fb66fb87b0ebc39b
6
+ metadata.gz: c43a301bfd9c7b6d2b57af4ec2003c05532a9d0d4912419e9c539eeeb4e43a4d6e3dd3a4c16e84d493c381bf2e9fc83559af667807d57da48e6546110982ac3b
7
+ data.tar.gz: e5baabf64d0b8031b0468e6b9520f5aac167c3034db062af56cd128eb1a64f722c19cb5596089343861b661577817bd02eb07540d89bc55e7ade07b825962930
data/bin/desklickrb CHANGED
@@ -2,13 +2,15 @@
2
2
 
3
3
  require 'desklickrb'
4
4
 
5
+ include Desklickrb
6
+
5
7
  USAGE =<<EOU
6
8
  #$0 [-v] [-k flickr-api-key] [-o filename] [gallery options]
7
9
 
8
10
  -v: verbose
9
11
  -k: API key created on https://www.flickr.com/services/apps/create/
10
12
  -u: download picture of user-id
11
- -o: download picture to filename (default: #{@filename})
13
+ -o: download picture to filename (default: #{filename})
12
14
 
13
15
  gallery options:
14
16
  -u user-id: gallery of user-id
@@ -19,13 +21,12 @@ EOU
19
21
  abort USAGE unless params = ARGV.getopts('hk:u:o:t:v')
20
22
  abort USAGE if params['h']
21
23
 
22
- api_key = params['k']
23
- desklickrb = Desklickrb.new(api_key)
24
- desklickrb.verbose = params['v']
25
- desklickrb.user_id = params['u']
26
- desklickrb.tag = params['t']
27
- desklickrb.filename = params['o'] if params['o']
24
+ @api_key = params['k']
25
+ @verbose = params['v']
26
+ @user_id = params['u']
27
+ @tag = params['t']
28
+ @filename = params['o'] if params['o']
28
29
 
29
- abort "no photos" unless size = desklickrb.choose_photo
30
- desklickrb.write_file(size)
31
- desklickrb.apply_desktop_picture
30
+ abort "no photos" unless size = choose_photo
31
+ write_file(size)
32
+ apply_desktop_picture
@@ -1,3 +1,3 @@
1
- class Desklickrb
2
- VERSION = "1.0.0"
1
+ module Desklickrb
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/desklickrb.rb CHANGED
@@ -3,31 +3,31 @@ require 'optparse'
3
3
  require 'flickr.rb'
4
4
  require 'fileutils'
5
5
 
6
- class Desklickrb
6
+ module Desklickrb
7
7
 
8
- attr_accessor :filename
9
- attr_accessor :tag
10
- attr_accessor :verbose
11
- attr_accessor :user_id
12
-
13
- def initialize(api_key)
14
- @filename = "/tmp/desklickrb.jpg"
8
+ def filename
9
+ @filename ||= "/tmp/desklickrb.jpg"
10
+ end
15
11
 
16
- raise 'API Key must be created at https://www.flickr.com/services/apps/create/' unless api_key
17
- @flickr = Flickr.new(api_key)
12
+ def flickr
13
+ unless @flickr
14
+ raise 'API Key must be created at https://www.flickr.com/services/apps/create/' unless @api_key
15
+ @flickr = Flickr.new(@api_key)
16
+ end
17
+ @flickr
18
18
  end
19
19
 
20
20
  def choose_photo
21
21
  if @tag
22
22
  puts "picking up a photo by a tag #{@tag}" if @verbose
23
- photos = @flickr.tag(@tag)
23
+ photos = flickr.tag(@tag)
24
24
  elsif @user_id
25
25
  puts "picking up a photo of a user #{@user_id}" if @verbose
26
- abort "unknown user: #{@user_id}" unless user = @flickr.users(@user_id)
26
+ abort "unknown user: #{@user_id}" unless user = flickr.users(@user_id)
27
27
  photos = user.photos
28
28
  else
29
29
  puts "picking up a photo from interestingness" if @verbose
30
- photos = @flickr.photos_request('interestingness.getList')
30
+ photos = flickr.photos_request('interestingness.getList')
31
31
  end
32
32
 
33
33
  return nil if photos.size < 1
@@ -47,27 +47,27 @@ class Desklickrb
47
47
  end
48
48
 
49
49
  def write_file(size)
50
- puts "downloading image file to #{@filename}" if @verbose
50
+ puts "downloading image file to #{filename}" if @verbose
51
51
  file = Net::HTTP.get_response(URI.parse(size['source'])).body
52
- open(@filename, 'w') do |io|
52
+ open(filename, 'w') do |io|
53
53
  io.puts file
54
54
  end
55
55
  end
56
56
 
57
57
  def apply_desktop_picture
58
58
 
59
- puts "applying desktop picture to #{@filename}" if @verbose
59
+ puts "applying desktop picture to #{filename}" if @verbose
60
60
 
61
61
  # set desktop picture with another filename because Dock does not change
62
62
  # the picture of the same filename with previous.
63
- another_file = @filename + ".jpg"
64
- FileUtils.cp(@filename, another_file)
63
+ another_file = filename + ".jpg"
64
+ FileUtils.cp(filename, another_file)
65
65
 
66
66
  IO.popen("/usr/bin/osascript", "r+") do |io|
67
67
  io.puts <<EOS
68
68
  tell application "System Events"
69
69
  set picture of every desktop to "#{another_file}"
70
- set picture of every desktop to "#{@filename}"
70
+ set picture of every desktop to "#{filename}"
71
71
  end tell
72
72
  EOS
73
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: desklickrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - fukuda, minoru