0xffffff 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'chunky_png'
4
+ gem 'flickraw-cached'
5
+
6
+ group :development do
7
+ gem "rspec", "~> 2.8.0"
8
+ gem "jeweler", "~> 1.8.3"
9
+ end
@@ -0,0 +1,35 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ chunky_png (1.2.5)
5
+ diff-lcs (1.1.3)
6
+ flickraw (0.9.5)
7
+ flickraw-cached (20110920)
8
+ flickraw (>= 0.9)
9
+ git (1.2.5)
10
+ jeweler (1.8.3)
11
+ bundler (~> 1.0)
12
+ git (>= 1.2.5)
13
+ rake
14
+ rdoc
15
+ json (1.6.5)
16
+ rake (0.9.2.2)
17
+ rdoc (3.12)
18
+ json (~> 1.4)
19
+ rspec (2.8.0)
20
+ rspec-core (~> 2.8.0)
21
+ rspec-expectations (~> 2.8.0)
22
+ rspec-mocks (~> 2.8.0)
23
+ rspec-core (2.8.0)
24
+ rspec-expectations (2.8.0)
25
+ diff-lcs (~> 1.1.2)
26
+ rspec-mocks (2.8.0)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ chunky_png
33
+ flickraw-cached
34
+ jeweler (~> 1.8.3)
35
+ rspec (~> 2.8.0)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 youpy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = 0xffffff
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to 0xffffff
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 youpy. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "0xffffff"
18
+ gem.homepage = "http://github.com/youpy/0xffffff"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A Tool to Upload Images}
21
+ gem.description = %Q{A Tool to Upload 0xffffff Images to Flickr}
22
+ gem.email = "youpy@buycheapviagraonlinenow.com"
23
+ gem.authors = ["youpy"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'pathname'
4
+ require 'pit'
5
+ require '0xffffff'
6
+
7
+ def get_access_token
8
+ token = flickr.get_request_token
9
+ auth_url = flickr.get_authorize_url(token['oauth_token'], :perms => 'delete')
10
+
11
+ puts "Open this url in your process to complete the authication process:"
12
+ puts auth_url
13
+ puts "Copy here the number given when you complete the process."
14
+ verify = gets.strip
15
+
16
+ begin
17
+ flickr.get_access_token(token['oauth_token'], token['oauth_token_secret'], verify)
18
+ login = flickr.test.login
19
+ puts "You are now authenticated as #{login.username} with token #{flickr.access_token} and secret #{flickr.access_secret}"
20
+
21
+ [flickr.access_token, flickr.access_secret]
22
+ rescue FlickRaw::FailedResponse => e
23
+ puts "Authentication failed : #{e.msg}"
24
+ end
25
+ end
26
+
27
+ def main
28
+ config = Pit.get("flickr.com")
29
+ token = config['color_uploader_access_token']
30
+ secret = config['color_uploader_access_secret']
31
+
32
+ unless token && secret
33
+ token, secret = get_access_token
34
+
35
+ Pit.set("flickr.com", :data => {
36
+ "color_uploader_access_token" => token,
37
+ "color_uploader_access_secret" => secret
38
+ })
39
+ end
40
+
41
+ flickr.access_token = token
42
+ flickr.access_secret = secret
43
+
44
+ FFFFFF::Runner.new(Pathname('~/.0xffffff').expand_path).run
45
+ end
46
+
47
+ main
@@ -0,0 +1,104 @@
1
+ require 'pathname'
2
+ require 'tempfile'
3
+ require 'flickraw'
4
+ require 'chunky_png'
5
+ require 'logger'
6
+
7
+ $stdout.sync = true
8
+
9
+ FlickRaw.api_key = 'accf136891b91047e61bd08ca84a4ee6'
10
+ FlickRaw.shared_secret = 'cdc468e584605aea'
11
+
12
+ module FFFFFF
13
+ IMAGE_WIDTH = 640
14
+ IMAGE_HEIGHT = 480
15
+
16
+ class Counter
17
+ def initialize(path)
18
+ @path = Pathname(path)
19
+ end
20
+
21
+ def count_up
22
+ count = read
23
+ count += 1
24
+
25
+ yield count
26
+
27
+ write(count)
28
+ end
29
+
30
+ private
31
+
32
+ def read
33
+ if @path.exist?
34
+ @path.read.chomp.to_i
35
+ else
36
+ 0
37
+ end
38
+ end
39
+
40
+ def write(count)
41
+ open(@path, 'w') do |f|
42
+ f.write count.to_s
43
+ end
44
+ end
45
+ end
46
+
47
+ class Util
48
+ class << self
49
+ def wait(sec)
50
+ sleep(sec)
51
+ end
52
+
53
+ def create_image(width, height, color)
54
+ png = ChunkyPNG::Image.new(width, height)
55
+ color = ChunkyPNG::Color.from_hex('#' + color.to_s(16).rjust(6, '0'))
56
+
57
+ width.times do |w|
58
+ height.times do |h|
59
+ png[w, h] = color
60
+ end
61
+ end
62
+
63
+ tempfile = Tempfile.new("image")
64
+ png.save(tempfile.path)
65
+
66
+ yield tempfile
67
+
68
+ tempfile.unlink
69
+ end
70
+ end
71
+ end
72
+
73
+ class Uploader
74
+ def upload(path)
75
+ flickr.upload_photo path, :title => 'image'
76
+ end
77
+ end
78
+
79
+ class Runner
80
+ def initialize(path)
81
+ @logger = Logger.new(STDOUT)
82
+ @path = path
83
+ end
84
+
85
+ def run
86
+ counter = Counter.new(@path)
87
+ uploader = Uploader.new
88
+
89
+ loop do
90
+ counter.count_up do |count|
91
+ raise "finish!" if count > 0xffffff
92
+
93
+ Util.create_image(IMAGE_WIDTH, IMAGE_HEIGHT, count) do |path|
94
+ uploader.upload(path)
95
+ end
96
+
97
+ @logger.info('upload #%s' % count.to_s(16).rjust(6, '0'))
98
+ end
99
+
100
+ Util.wait(1)
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,46 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Counter do
4
+ before do
5
+ @path = Pathname('/tmp/count.txt')
6
+ end
7
+
8
+ after do
9
+ @path.unlink if @path.exist?
10
+ end
11
+
12
+ describe '#count_up' do
13
+ it 'should count up' do
14
+ open(@path, 'w') do |f|
15
+ f.write(123)
16
+ end
17
+
18
+ x = 0;
19
+
20
+ counter = Counter.new(@path.to_s)
21
+
22
+ counter.count_up do |count|
23
+ x = count
24
+ end
25
+
26
+ x.should eql(124)
27
+
28
+ counter.count_up do |count|
29
+ x = count
30
+ end
31
+
32
+ x.should eql(125)
33
+ end
34
+
35
+ it 'should count up even if file does not exist' do
36
+ x = 0;
37
+
38
+ counter = Counter.new(@path.to_s)
39
+ counter.count_up do |count|
40
+ x = count
41
+ end
42
+
43
+ x.should eql(1)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Runner do
4
+ before do
5
+ @path = Pathname('/tmp/count.txt')
6
+ end
7
+
8
+ after do
9
+ @path.unlink if @path.exist?
10
+ end
11
+
12
+ describe '#run' do
13
+ it 'should run' do
14
+ open(@path, 'w') do |f|
15
+ f.write(123)
16
+ end
17
+
18
+ Uploader.should_receive(:new).and_return(uploader = mock)
19
+ uploader.should_receive(:upload) do |*args|
20
+ Pathname(args[0].path).should be_exist
21
+ end
22
+
23
+ Util.should_receive(:wait).with(1).and_raise('break')
24
+
25
+ lambda {
26
+ Runner.new(@path.to_s).run
27
+ }.should raise_error('break')
28
+
29
+ @path.read.chomp.should eql('124')
30
+ end
31
+
32
+ it 'should raise if count exceeds the max colors' do
33
+ open(@path, 'w') do |f|
34
+ f.write(0xffffff)
35
+ end
36
+
37
+ Uploader.should_receive(:new).and_return(uploader = mock)
38
+ uploader.should_not_receive(:upload)
39
+
40
+ lambda {
41
+ Runner.new(@path.to_s).run
42
+ }.should raise_error('finish!')
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'pathname'
5
+ require '0xffffff'
6
+
7
+ include FFFFFF
8
+
9
+ # Requires supporting files with custom matchers and macros, etc,
10
+ # in ./support/ and its subdirectories.
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+ end
15
+
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Uploader do
4
+ describe '#upload' do
5
+ it 'should upload image to flickr' do
6
+ flickr.should_receive(:upload_photo).with('/path/to/file', :title => 'image')
7
+
8
+ uploader = Uploader.new
9
+ uploader.upload('/path/to/file')
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Util do
4
+ describe '.create_image' do
5
+ it 'should create image' do
6
+ proc_is_called = false
7
+ path = nil
8
+
9
+ Util.create_image(100, 200, 0x00ff00) do |file|
10
+ proc_is_called = true
11
+ path = file.path
12
+ png = ChunkyPNG::Image.from_file(file.path)
13
+ png.should be_a_kind_of(ChunkyPNG::Image)
14
+ png[0, 0].should eql(0x00ff00ff)
15
+ png[99, 199].should eql(0x00ff00ff)
16
+
17
+ lambda {
18
+ png[99, 200]
19
+ }.should raise_error(ChunkyPNG::OutOfBounds)
20
+ end
21
+
22
+ proc_is_called.should be_true
23
+ Pathname(path).should_not be_exist
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: '0xffffff'
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - youpy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: chunky_png
16
+ requirement: &70191937603200 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70191937603200
25
+ - !ruby/object:Gem::Dependency
26
+ name: flickraw-cached
27
+ requirement: &70191937618460 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70191937618460
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70191937616300 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.8.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70191937616300
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &70191937614760 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.3
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70191937614760
58
+ description: A Tool to Upload 0xffffff Images to Flickr
59
+ email: youpy@buycheapviagraonlinenow.com
60
+ executables:
61
+ - '0xffffff'
62
+ extensions: []
63
+ extra_rdoc_files:
64
+ - LICENSE.txt
65
+ - README.rdoc
66
+ files:
67
+ - .document
68
+ - .rspec
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - LICENSE.txt
72
+ - README.rdoc
73
+ - Rakefile
74
+ - VERSION
75
+ - bin/0xffffff
76
+ - lib/0xffffff.rb
77
+ - spec/counter_spec.rb
78
+ - spec/runner_spec.rb
79
+ - spec/spec_helper.rb
80
+ - spec/uploader_spec.rb
81
+ - spec/util_spec.rb
82
+ homepage: http://github.com/youpy/0xffffff
83
+ licenses:
84
+ - MIT
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ segments:
96
+ - 0
97
+ hash: -4373781767294178785
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.10
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: A Tool to Upload Images
110
+ test_files: []