gyazo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of gyazo might be problematic. Click here for more details.
- data/.gemtest +0 -0
- data/History.txt +4 -0
- data/Manifest.txt +11 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +42 -0
- data/Rakefile +26 -0
- data/lib/gyazo.rb +74 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_gyazo.rb +14 -0
- data/test/test_helper.rb +3 -0
- metadata +126 -0
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
= gyazo
|
2
|
+
|
3
|
+
* http://github.com/masui/gyazo-ruby
|
4
|
+
|
5
|
+
== REQUIREMENTS:
|
6
|
+
|
7
|
+
* Works only for Mac
|
8
|
+
|
9
|
+
== DESCRIPTION:
|
10
|
+
|
11
|
+
* Upload an image to Gyazo.com
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
require 'gyazo'
|
16
|
+
g = Gyazo.new('/Applications/Gyazo.app')
|
17
|
+
url = g.upload('/Users/masui/junk.png')
|
18
|
+
|
19
|
+
== LICENSE:
|
20
|
+
|
21
|
+
(The MIT License)
|
22
|
+
|
23
|
+
Copyright (c) 2012 Toshiyuki Masui
|
24
|
+
|
25
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
26
|
+
a copy of this software and associated documentation files (the
|
27
|
+
'Software'), to deal in the Software without restriction, including
|
28
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
29
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
30
|
+
permit persons to whom the Software is furnished to do so, subject to
|
31
|
+
the following conditions:
|
32
|
+
|
33
|
+
The above copyright notice and this permission notice shall be
|
34
|
+
included in all copies or substantial portions of the Software.
|
35
|
+
|
36
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
37
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
38
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
39
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
40
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
41
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
42
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/gyazo'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
# Hoe.plugin :website
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
10
|
+
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
$hoe = Hoe.spec 'gyazo' do
|
14
|
+
self.developer 'Toshiyuki Masui', 'masui@pitecan.com'
|
15
|
+
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
|
+
self.rubyforge_name = self.name # TODO this is default value
|
17
|
+
# self.extra_deps = [['activesupport','>= 2.0.2']]
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'newgem/tasks'
|
22
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
23
|
+
|
24
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
25
|
+
# remove_task :default
|
26
|
+
# task :default => [:spec, :features]
|
data/lib/gyazo.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
3
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
4
|
+
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
class Gyazo
|
8
|
+
VERSION = '0.0.1'
|
9
|
+
|
10
|
+
def initialize(app = '/Applications/Gyazo.app')
|
11
|
+
@user = IO.popen("whoami", "r+").gets.chomp
|
12
|
+
@program = app
|
13
|
+
@idfile = "/Users/#{@user}/Library/Gyazo/id"
|
14
|
+
@old_idfile = File.dirname(@program) + "/gyazo.app/Contents/Resources/id"
|
15
|
+
@id = ''
|
16
|
+
if File.exist?(@idfile) then
|
17
|
+
@id = File.read(@idfile).chomp
|
18
|
+
elsif File.exist?(@old_idfile) then
|
19
|
+
@id = File.read(@old_idfile).chomp
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def upload(imagefile)
|
24
|
+
tmpfile = "/tmp/image_upload#{$$}.png"
|
25
|
+
if imagefile && File.exist?(imagefile) then
|
26
|
+
system "sips -s format png \"#{imagefile}\" --out \"#{tmpfile}\""
|
27
|
+
end
|
28
|
+
imagedata = File.read(tmpfile)
|
29
|
+
File.delete(tmpfile)
|
30
|
+
|
31
|
+
boundary = '----BOUNDARYBOUNDARY----'
|
32
|
+
@host = 'gyazo.com'
|
33
|
+
@cgi = '/upload.cgi'
|
34
|
+
@ua = 'Gyazo/1.0'
|
35
|
+
data = <<EOF
|
36
|
+
--#{boundary}\r
|
37
|
+
content-disposition: form-data; name="id"\r
|
38
|
+
\r
|
39
|
+
#{@id}\r
|
40
|
+
--#{boundary}\r
|
41
|
+
content-disposition: form-data; name="imagedata"; filename="gyazo.com"\r
|
42
|
+
\r
|
43
|
+
#{imagedata}\r
|
44
|
+
--#{boundary}--\r
|
45
|
+
EOF
|
46
|
+
header ={
|
47
|
+
'Content-Length' => data.length.to_s,
|
48
|
+
'Content-type' => "multipart/form-data; boundary=#{boundary}",
|
49
|
+
'User-Agent' => @ua
|
50
|
+
}
|
51
|
+
res = Net::HTTP.start(@host,80){|http|
|
52
|
+
http.post(@cgi,data,header)
|
53
|
+
}
|
54
|
+
|
55
|
+
@url = res.read_body
|
56
|
+
|
57
|
+
# save id
|
58
|
+
newid = res['X-Gyazo-Id']
|
59
|
+
if newid and newid != "" then
|
60
|
+
if !File.exist?(File.dirname(@idfile)) then
|
61
|
+
Dir.mkdir(File.dirname(@idfile))
|
62
|
+
end
|
63
|
+
if File.exist?(@idfile) then
|
64
|
+
File.rename(@idfile, @idfile+Time.new.strftime("_%Y%m%d%H%M%S.bak"))
|
65
|
+
end
|
66
|
+
File.open(@idfile,"w").print(newid)
|
67
|
+
if File.exist?(@old_idfile) then
|
68
|
+
File.delete(@old_idfile)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
@url
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/gyazo.rb'}"
|
9
|
+
puts "Loading gyazo gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/test/test_gyazo.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestGyazo < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_upload
|
9
|
+
imagefile = File.dirname(__FILE__) + '/test.png'
|
10
|
+
g = Gyazo.new
|
11
|
+
url = g.upload(imagefile)
|
12
|
+
assert_equal(url,'http://gyazo.com/a2a2a8154340bd33e9cd5eeea1efd832.png')
|
13
|
+
end
|
14
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gyazo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Toshiyuki Masui
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-03-10 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rdoc
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 19
|
29
|
+
segments:
|
30
|
+
- 3
|
31
|
+
- 10
|
32
|
+
version: "3.10"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: newgem
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 5
|
44
|
+
segments:
|
45
|
+
- 1
|
46
|
+
- 5
|
47
|
+
- 3
|
48
|
+
version: 1.5.3
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: hoe
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 27
|
60
|
+
segments:
|
61
|
+
- 2
|
62
|
+
- 12
|
63
|
+
version: "2.12"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
description: "* Upload an image to Gyazo.com"
|
67
|
+
email:
|
68
|
+
- masui@pitecan.com
|
69
|
+
executables: []
|
70
|
+
|
71
|
+
extensions: []
|
72
|
+
|
73
|
+
extra_rdoc_files:
|
74
|
+
- History.txt
|
75
|
+
- Manifest.txt
|
76
|
+
- PostInstall.txt
|
77
|
+
files:
|
78
|
+
- History.txt
|
79
|
+
- Manifest.txt
|
80
|
+
- PostInstall.txt
|
81
|
+
- README.rdoc
|
82
|
+
- Rakefile
|
83
|
+
- lib/gyazo.rb
|
84
|
+
- script/console
|
85
|
+
- script/destroy
|
86
|
+
- script/generate
|
87
|
+
- test/test_gyazo.rb
|
88
|
+
- test/test_helper.rb
|
89
|
+
- .gemtest
|
90
|
+
homepage: http://github.com/masui/gyazo-ruby
|
91
|
+
licenses: []
|
92
|
+
|
93
|
+
post_install_message: PostInstall.txt
|
94
|
+
rdoc_options:
|
95
|
+
- --main
|
96
|
+
- README.rdoc
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
requirements: []
|
118
|
+
|
119
|
+
rubyforge_project: gyazo
|
120
|
+
rubygems_version: 1.7.2
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: "* Upload an image to Gyazo.com"
|
124
|
+
test_files:
|
125
|
+
- test/test_gyazo.rb
|
126
|
+
- test/test_helper.rb
|