gyazo 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/.gitignore +1 -0
- data/README.md +17 -9
- data/gyazo.gemspec +3 -4
- data/lib/gyazo.rb +1 -0
- data/lib/gyazo/client.rb +20 -50
- data/lib/gyazo/version.rb +1 -1
- data/samples/list.rb +10 -0
- data/samples/upload.rb +10 -0
- data/test/test_gyazo.rb +7 -14
- metadata +99 -77
- data/bin/gyazo +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e65dd6e3ffb8646a0c6581c36a9f98a8da2633bc
|
4
|
+
data.tar.gz: 15812ea2cd6b802a72f872c7d80523fe9d1debab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ae89aeaf000a410af3db162e4f457c182aaa1788bd1547ee106765c8222c439261e15697b85c798455d8acb3d992975d6d1263bef3599f1afce0f9dd2af0864a
|
7
|
+
data.tar.gz: fe2488f428a5cacb59547d56752bfbb75b66308a7c53ab049c12c4f41e4dde91b58bebf2508fb05b20a5db664cccd8a46b6737bfb1a010f93ef9a544909cf46e
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gyazo
|
2
2
|
=====
|
3
|
-
|
3
|
+
[Gyazo API](https://gyazo.com/api/docs) wrapper for Ruby
|
4
4
|
|
5
5
|
- http://github.com/masui/gyazo-ruby
|
6
6
|
- https://rubygems.org/gems/gyazo
|
@@ -15,36 +15,44 @@ Installation
|
|
15
15
|
Usage
|
16
16
|
-----
|
17
17
|
|
18
|
+
Register new application and get [ACCESS TOKEN](https://gyazo.com/oauth/applications), then
|
19
|
+
|
18
20
|
### Upload
|
19
21
|
|
20
22
|
```ruby
|
21
23
|
require 'gyazo'
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
gyazo = Gyazo::Client.new 'your-access-token'
|
26
|
+
res = gyazo.upload 'my_image.png'
|
27
|
+
puts res['permalink_url'] # => "http://gyazo.com/a1b2cdef345"
|
25
28
|
```
|
26
29
|
|
27
30
|
### List
|
28
31
|
|
29
32
|
```ruby
|
30
|
-
|
31
|
-
|
33
|
+
gyazo.list.each do |image|
|
34
|
+
image['image_id']
|
32
35
|
end
|
33
36
|
```
|
34
37
|
|
38
|
+
### Delete
|
35
39
|
|
36
|
-
### Upload to http://your-private-gyazo.com
|
37
40
|
```ruby
|
38
|
-
|
39
|
-
g.host = 'http://your-private-gyazo.com'
|
40
|
-
g.upload 'my_image.png'
|
41
|
+
gyazo.delete image_id
|
41
42
|
```
|
42
43
|
|
44
|
+
|
43
45
|
Test
|
44
46
|
----
|
45
47
|
|
48
|
+
setup
|
49
|
+
|
46
50
|
% gem install bundler
|
47
51
|
% bundle install
|
52
|
+
% export GYAZO_TOKEN=a1b2cdef3456 ## set your API Token
|
53
|
+
|
54
|
+
run test
|
55
|
+
|
48
56
|
% bundle exec rake test
|
49
57
|
|
50
58
|
|
data/gyazo.gemspec
CHANGED
@@ -6,9 +6,9 @@ require 'gyazo/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "gyazo"
|
8
8
|
spec.version = Gyazo::VERSION
|
9
|
-
spec.authors = ["Toshiyuki Masui"]
|
9
|
+
spec.authors = ["Toshiyuki Masui", "Sho Hashimoto"]
|
10
10
|
spec.email = ["masui@pitecan.com"]
|
11
|
-
spec.description = %q{
|
11
|
+
spec.description = %q{Gyazo.com API Wrapper}
|
12
12
|
spec.summary = spec.description
|
13
13
|
spec.homepage = "http://github.com/masui/gyazo-ruby"
|
14
14
|
spec.license = "MIT"
|
@@ -18,12 +18,11 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler"
|
21
|
+
spec.add_development_dependency "bundler"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "minitest"
|
24
24
|
|
25
25
|
spec.add_dependency "json"
|
26
26
|
spec.add_dependency "httparty"
|
27
27
|
spec.add_dependency "httmultiparty"
|
28
|
-
spec.add_dependency "launchy"
|
29
28
|
end
|
data/lib/gyazo.rb
CHANGED
data/lib/gyazo/client.rb
CHANGED
@@ -4,78 +4,48 @@ module Gyazo
|
|
4
4
|
|
5
5
|
attr_accessor :id, :user_id, :user_agent, :host
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
9
|
-
@user = ENV['USER']
|
10
|
-
@idfile = "#{ENV['HOME']}/Library/Gyazo/id"
|
11
|
-
@id = nil
|
12
|
-
@id = File.read(@idfile).strip if File.exist? @idfile
|
7
|
+
def initialize(access_token = null)
|
8
|
+
@access_token = access_token
|
13
9
|
@user_agent = "GyazoRubyGem/#{Gyazo::VERSION}"
|
14
|
-
@host = 'http://gyazo.com'
|
15
10
|
end
|
16
11
|
|
17
|
-
def
|
18
|
-
|
12
|
+
def upload(imagefile)
|
13
|
+
url = "https://upload.gyazo.com/api/upload"
|
14
|
+
res = HTTMultiParty.post url, {
|
19
15
|
:query => {
|
20
|
-
:
|
16
|
+
:access_token => @access_token,
|
17
|
+
:imagedata => File.open(imagefile)
|
21
18
|
},
|
22
19
|
:header => {
|
23
20
|
'User-Agent' => @user_agent
|
24
21
|
}
|
25
22
|
}
|
26
|
-
|
27
|
-
|
28
|
-
JSON.parse(res.body)
|
23
|
+
raise Gyazo::Error, res.body unless res.code == 200
|
24
|
+
return JSON.parse res.body
|
29
25
|
end
|
30
26
|
|
31
|
-
def list(
|
32
|
-
url = "
|
33
|
-
query =
|
34
|
-
|
35
|
-
query[:user_id] = @user_id
|
36
|
-
else
|
37
|
-
query[:device_id] = @id
|
38
|
-
end
|
39
|
-
|
40
|
-
res = HTTParty.get "#{@host}/api/image/list", {
|
27
|
+
def list(query = {})
|
28
|
+
url = "https://api.gyazo.com/api/images"
|
29
|
+
query[:access_token] = @access_token
|
30
|
+
res = HTTParty.get url, {
|
41
31
|
:query => query,
|
42
32
|
:header => {
|
43
33
|
'User-Agent' => @user_agent
|
44
34
|
}
|
45
35
|
}
|
46
|
-
|
47
|
-
|
48
|
-
JSON.parse(res.body)['images']
|
36
|
+
raise Gyazo::Error, res.body unless res.code == 200
|
37
|
+
return JSON.parse res.body
|
49
38
|
end
|
50
39
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
opts[k] = v unless opts.include? k
|
55
|
-
end
|
56
|
-
|
57
|
-
unless opts[:raw]
|
58
|
-
tmpfile = "/tmp/gyazo_upload_#{Time.now.to_i}_#{Time.now.usec}.png"
|
59
|
-
if File.exist? imagefile
|
60
|
-
system "sips -s format png \"#{imagefile}\" --out \"#{tmpfile}\" > /dev/null"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
res = HTTMultiParty.post "#{@host}/upload.cgi", {
|
40
|
+
def delete(image_id)
|
41
|
+
url = "https://api.gyazo.com/api/images/#{image_id}"
|
42
|
+
res = HTTParty.delete url, {
|
65
43
|
:query => {
|
66
|
-
:
|
67
|
-
:imagedata => File.new(imagefile)
|
68
|
-
},
|
69
|
-
:header => {
|
70
|
-
'User-Agent' => @user_agent
|
44
|
+
:access_token => @access_token
|
71
45
|
}
|
72
46
|
}
|
73
|
-
|
74
|
-
File.delete(tmpfile) if tmpfile and File.exists? tmpfile
|
75
|
-
|
76
47
|
raise Gyazo::Error, res.body unless res.code == 200
|
77
|
-
res.body
|
48
|
+
return JSON.parse res.body
|
78
49
|
end
|
79
|
-
|
80
50
|
end
|
81
51
|
end
|
data/lib/gyazo/version.rb
CHANGED
data/samples/list.rb
ADDED
data/samples/upload.rb
ADDED
data/test/test_gyazo.rb
CHANGED
@@ -3,30 +3,23 @@ require File.expand_path 'test_helper', File.dirname(__FILE__)
|
|
3
3
|
class TestGyazo < MiniTest::Test
|
4
4
|
|
5
5
|
def setup
|
6
|
-
@gyazo = Gyazo::Client.new
|
6
|
+
@gyazo = Gyazo::Client.new ENV['GYAZO_TOKEN']
|
7
7
|
@imagefile = File.expand_path 'test.png', File.dirname(__FILE__)
|
8
|
-
@image_id = "a2a2a8154340bd33e9cd5eeea1efd832"
|
9
8
|
end
|
10
9
|
|
11
10
|
def test_upload
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_id
|
17
|
-
@gyazo = Gyazo::Client.new
|
18
|
-
assert @gyazo.id =~ /^[0-9a-f]+$/
|
19
|
-
@gyazo.id = '12345'
|
20
|
-
assert_equal @gyazo.id, '12345'
|
11
|
+
res = @gyazo.upload @imagefile
|
12
|
+
assert res['permalink_url'].match /^https?:\/\/gyazo.com\/[a-z\d]{32}$/i
|
21
13
|
end
|
22
14
|
|
23
15
|
def test_list
|
24
16
|
assert_equal @gyazo.list.class, Array
|
25
17
|
end
|
26
18
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
19
|
+
def test_delete
|
20
|
+
res_up = @gyazo.upload @imagefile
|
21
|
+
res_del = @gyazo.delete res_up['image_id']
|
22
|
+
assert_equal res_del['image_id'], res_up['image_id']
|
30
23
|
end
|
31
24
|
|
32
25
|
end
|
metadata
CHANGED
@@ -1,126 +1,148 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: gyazo
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Toshiyuki Masui
|
8
|
+
- Sho Hashimoto
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2015-05-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
version: "1.3"
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
22
21
|
type: :development
|
23
|
-
version_requirements: *id001
|
24
|
-
- !ruby/object:Gem::Dependency
|
25
|
-
name: rake
|
26
22
|
prerelease: false
|
27
|
-
|
28
|
-
requirements:
|
29
|
-
-
|
30
|
-
-
|
31
|
-
|
32
|
-
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
33
35
|
type: :development
|
34
|
-
version_requirements: *id002
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: minitest
|
37
36
|
prerelease: false
|
38
|
-
|
39
|
-
requirements:
|
40
|
-
-
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: minitest
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
41
49
|
type: :development
|
42
|
-
version_requirements: *id004
|
43
|
-
- !ruby/object:Gem::Dependency
|
44
|
-
name: json
|
45
50
|
prerelease: false
|
46
|
-
|
47
|
-
requirements:
|
48
|
-
-
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: json
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
49
63
|
type: :runtime
|
50
|
-
version_requirements: *id005
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
|
-
name: httparty
|
53
64
|
prerelease: false
|
54
|
-
|
55
|
-
requirements:
|
56
|
-
-
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: httparty
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
57
77
|
type: :runtime
|
58
|
-
version_requirements: *id006
|
59
|
-
- !ruby/object:Gem::Dependency
|
60
|
-
name: httmultiparty
|
61
78
|
prerelease: false
|
62
|
-
|
63
|
-
requirements:
|
64
|
-
-
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: httmultiparty
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
65
91
|
type: :runtime
|
66
|
-
version_requirements: *id007
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
|
-
name: launchy
|
69
92
|
prerelease: false
|
70
|
-
|
71
|
-
requirements:
|
72
|
-
-
|
73
|
-
|
74
|
-
|
75
|
-
description:
|
76
|
-
email:
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
description: Gyazo.com API Wrapper
|
99
|
+
email:
|
77
100
|
- masui@pitecan.com
|
78
|
-
executables:
|
79
|
-
- gyazo
|
101
|
+
executables: []
|
80
102
|
extensions: []
|
81
|
-
|
82
103
|
extra_rdoc_files: []
|
83
|
-
|
84
|
-
files:
|
104
|
+
files:
|
85
105
|
- .gitignore
|
86
106
|
- Gemfile
|
87
107
|
- LICENSE.txt
|
88
108
|
- Makefile
|
89
109
|
- README.md
|
90
110
|
- Rakefile
|
91
|
-
- bin/gyazo
|
92
111
|
- gyazo.gemspec
|
93
112
|
- lib/gyazo.rb
|
94
113
|
- lib/gyazo/client.rb
|
95
114
|
- lib/gyazo/error.rb
|
96
115
|
- lib/gyazo/version.rb
|
116
|
+
- samples/list.rb
|
117
|
+
- samples/upload.rb
|
97
118
|
- test/test.png
|
98
119
|
- test/test_gyazo.rb
|
99
120
|
- test/test_helper.rb
|
100
121
|
homepage: http://github.com/masui/gyazo-ruby
|
101
|
-
licenses:
|
122
|
+
licenses:
|
102
123
|
- MIT
|
103
124
|
metadata: {}
|
104
|
-
|
105
125
|
post_install_message:
|
106
126
|
rdoc_options: []
|
107
|
-
|
108
|
-
require_paths:
|
127
|
+
require_paths:
|
109
128
|
- lib
|
110
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
-
requirements:
|
112
|
-
-
|
113
|
-
|
114
|
-
|
115
|
-
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
116
139
|
requirements: []
|
117
|
-
|
118
140
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.0.14
|
120
142
|
signing_key:
|
121
143
|
specification_version: 4
|
122
|
-
summary:
|
123
|
-
test_files:
|
144
|
+
summary: Gyazo.com API Wrapper
|
145
|
+
test_files:
|
124
146
|
- test/test.png
|
125
147
|
- test/test_gyazo.rb
|
126
148
|
- test/test_helper.rb
|
data/bin/gyazo
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'gyazo'
|
6
|
-
require 'launchy'
|
7
|
-
|
8
|
-
raw = ARGV.include? "-raw"
|
9
|
-
upload_files = ARGV.reject{|arg| arg =~ /^\-+raw$/ }
|
10
|
-
|
11
|
-
if upload_files.empty?
|
12
|
-
STDERR.puts "gyazo [file1, file2 ...]"
|
13
|
-
STDERR.puts "gyazo -raw [file1, file2 ...] # raw upload"
|
14
|
-
exit 1
|
15
|
-
end
|
16
|
-
|
17
|
-
g = Gyazo::Client.new
|
18
|
-
|
19
|
-
|
20
|
-
upload_files.each do |file|
|
21
|
-
next unless File.exists? file
|
22
|
-
url = g.upload file, :raw => raw
|
23
|
-
puts url
|
24
|
-
Launchy.open url
|
25
|
-
sleep 1
|
26
|
-
end
|