desklickrb 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dce7bc139bef0b1e3b315ac5337a0bff169bdbcb
4
+ data.tar.gz: ef4b093b5436c65dbad5b94254f4b28bc7f2a092
5
+ SHA512:
6
+ metadata.gz: 4f28349514ed9248615d02fcd2b30fd0756fd7ed350b05d2c99723526763999e5aeed97e93353f3fe26c825b5fa014c6431add30acb392005f177d6938d6d689
7
+ data.tar.gz: 04d285c06be4b0993e27f53b4c80ace24280cf24eed8527e2ddecb70858adf3e0a3a2d6a4e7b5b1ef8c1f8d671df780e35fb4b215d577ba0fb66fb87b0ebc39b
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in desklickrb.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 fukuda minoru
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # desklickrb
2
+
3
+ Flickr から画像ファイルをダウンロードして Mac のデスクトップピクチャ(壁紙)に設定する Ruby スクリプトです。
4
+
5
+ ## 前提
6
+
7
+ 以下がインストールされていることが条件です。
8
+
9
+ - ruby 2.0.0 以上
10
+ - rubygems
11
+
12
+ ## インストール
13
+
14
+ ```
15
+ gem install desklickrb
16
+ ```
17
+
18
+ ## もひとつ準備
19
+
20
+ Flickr の API キーを作ってください。 <https://www.flickr.com/services/apps/create/>
21
+ ここで作った API キーをコマンドライン引数の `-k` で指定するようにしてください。
22
+
23
+ ## 使い方
24
+
25
+ desklickrb -h で下記のヘルプが表示されます。(ロングオプションには未対応)
26
+
27
+ ```
28
+ desklickrb [-v] [-k flickr-api-key] [-o filename] [gallery options]
29
+
30
+ -v: verbose
31
+ -k: API key created on https://www.flickr.com/services/apps/create/
32
+ -u: download picture of user-id
33
+ -o: download picture to filename (default: /tmp/desklickrb.jpg)
34
+
35
+ gallery options:
36
+ -u user-id: gallery of user-id
37
+ -t tag: gallery by tag
38
+ default is choosing from interestingness.
39
+ ```
40
+
41
+ まず、動きをチェックしたい場合は、APIキーを下記のように指定して、実行してみてください。
42
+ デスクトップピクチャが変わると思います。
43
+
44
+ `desklickrb -k "FlickrのAPIキー"`
45
+
46
+ デフォルトでは Flickr の interestingness から画像をランダムで選択してダウンロードします。
47
+ `-u` で指定ユーザのもの、`-t` で指定したタグのものをダウンロードします。
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/desklickrb ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'desklickrb'
4
+
5
+ USAGE =<<EOU
6
+ #$0 [-v] [-k flickr-api-key] [-o filename] [gallery options]
7
+
8
+ -v: verbose
9
+ -k: API key created on https://www.flickr.com/services/apps/create/
10
+ -u: download picture of user-id
11
+ -o: download picture to filename (default: #{@filename})
12
+
13
+ gallery options:
14
+ -u user-id: gallery of user-id
15
+ -t tag: gallery by tag
16
+ default is choosing from interestingness.
17
+ EOU
18
+
19
+ abort USAGE unless params = ARGV.getopts('hk:u:o:t:v')
20
+ abort USAGE if params['h']
21
+
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']
28
+
29
+ abort "no photos" unless size = desklickrb.choose_photo
30
+ desklickrb.write_file(size)
31
+ desklickrb.apply_desktop_picture
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'desklickrb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "desklickrb"
8
+ spec.version = Desklickrb::VERSION
9
+ spec.authors = ["fukuda, minoru"]
10
+ spec.email = ["fukuda@bylo.jp"]
11
+ spec.summary = %q{Mac's Desktop Picture refresher using Flickr pictures}
12
+ spec.description = 'Gem for using Flickr API in Ruby - https://www.flickr.com/services/api/'
13
+ spec.homepage = "http://github.com/moicci/desklickrb"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency('flickr.rb', ['>= 1.1.2'])
25
+ end
@@ -0,0 +1,3 @@
1
+ class Desklickrb
2
+ VERSION = "1.0.0"
3
+ end
data/lib/desklickrb.rb ADDED
@@ -0,0 +1,75 @@
1
+ require "desklickrb/version"
2
+ require 'optparse'
3
+ require 'flickr.rb'
4
+ require 'fileutils'
5
+
6
+ class Desklickrb
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"
15
+
16
+ raise 'API Key must be created at https://www.flickr.com/services/apps/create/' unless api_key
17
+ @flickr = Flickr.new(api_key)
18
+ end
19
+
20
+ def choose_photo
21
+ if @tag
22
+ puts "picking up a photo by a tag #{@tag}" if @verbose
23
+ photos = @flickr.tag(@tag)
24
+ elsif @user_id
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)
27
+ photos = user.photos
28
+ else
29
+ puts "picking up a photo from interestingness" if @verbose
30
+ photos = @flickr.photos_request('interestingness.getList')
31
+ end
32
+
33
+ return nil if photos.size < 1
34
+
35
+ # find photo by random
36
+ index = [*0..(photos.size-1)].sample
37
+ photo = photos[index]
38
+ puts "chosen photo index=#{index} of #{photos.size}" if @verbose
39
+
40
+ # find maximum
41
+ max_size = nil
42
+ photo.sizes.each do |size|
43
+ max_size = size if max_size == nil || max_size['width'].to_i < size['width'].to_i
44
+ end
45
+ puts "chosen photo size is #{max_size['width']} x #{max_size['height']}" if @verbose
46
+ max_size
47
+ end
48
+
49
+ def write_file(size)
50
+ puts "downloading image file to #{@filename}" if @verbose
51
+ file = Net::HTTP.get_response(URI.parse(size['source'])).body
52
+ open(@filename, 'w') do |io|
53
+ io.puts file
54
+ end
55
+ end
56
+
57
+ def apply_desktop_picture
58
+
59
+ puts "applying desktop picture to #{@filename}" if @verbose
60
+
61
+ # set desktop picture with another filename because Dock does not change
62
+ # the picture of the same filename with previous.
63
+ another_file = @filename + ".jpg"
64
+ FileUtils.cp(@filename, another_file)
65
+
66
+ IO.popen("/usr/bin/osascript", "r+") do |io|
67
+ io.puts <<EOS
68
+ tell application "System Events"
69
+ set picture of every desktop to "#{another_file}"
70
+ set picture of every desktop to "#{@filename}"
71
+ end tell
72
+ EOS
73
+ end
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: desklickrb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - fukuda, minoru
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: flickr.rb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.1.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.1.2
55
+ description: Gem for using Flickr API in Ruby - https://www.flickr.com/services/api/
56
+ email:
57
+ - fukuda@bylo.jp
58
+ executables:
59
+ - desklickrb
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/desklickrb
69
+ - desklickrb.gemspec
70
+ - lib/desklickrb.rb
71
+ - lib/desklickrb/version.rb
72
+ homepage: http://github.com/moicci/desklickrb
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Mac's Desktop Picture refresher using Flickr pictures
96
+ test_files: []
97
+ has_rdoc: