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 CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- metadata.gz: ad0060be9db7f626014c7d30193e256b9c714ee9
4
- data.tar.gz: d29d9ae532e354117389fce9dbe728ff8851caf9
5
- SHA512:
6
- metadata.gz: d9190285cc2003325353014fac914d99657492f3e715062355f4a9a7b62dc462f28d90000dfc261a5fd143a91aac55b97eb9b939415276cd3c6cbc1193ebee27
7
- data.tar.gz: b7277aea5c3f1c3b0f853ad538589ff757554a1d6d7db926ee15e719751c8233048b4657362bb3cb5af6b660c4c0cbe3cdde3f86945670e0989f2098c7ee97d1
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
@@ -3,3 +3,4 @@
3
3
  .DS_Store
4
4
  pkg
5
5
  tmp
6
+ .ruby-version
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  Gyazo
2
2
  =====
3
- Upload an image to http://gyazo.com
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
- g = Gyazo::Client.new
24
- g.upload 'my_image.png' #=> "http://gyazo.com/a1b2cdef345"
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
- g.list.each do |image|
31
- image['image_id']
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
- g = Gyazo::Client.new
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
 
@@ -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{Upload an image to Gyazo.com}
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", "~> 1.3"
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
@@ -2,6 +2,7 @@ require 'gyazo/version'
2
2
  require 'gyazo/error'
3
3
  require 'gyazo/client'
4
4
 
5
+ require 'erb' # for httparty bug
5
6
  require 'httparty'
6
7
  require 'httmultiparty'
7
8
  require 'json'
@@ -4,78 +4,48 @@ module Gyazo
4
4
 
5
5
  attr_accessor :id, :user_id, :user_agent, :host
6
6
 
7
- def initialize(user_id=nil)
8
- @user_id = user_id
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 info(image_id)
18
- res = HTTParty.get "#{@host}/api/image/get", {
12
+ def upload(imagefile)
13
+ url = "https://upload.gyazo.com/api/upload"
14
+ res = HTTMultiParty.post url, {
19
15
  :query => {
20
- :image_id => image_id
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
- raise Gyazz::Error, res.body unless res.code == 200
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(page=1, count=100)
32
- url = "#{@host}/api/image/list"
33
- query = {:page => page, :count => count}
34
- if @user_id
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
- raise Gyazz::Error, res.body unless res.code == 200
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
- DEFAULT_UPLOAD_OPTS = {:time => nil, :raw => false}
52
- def upload(imagefile, opts={})
53
- DEFAULT_UPLOAD_OPTS.each do |k,v|
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
- :id => @id,
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
@@ -1,3 +1,3 @@
1
1
  module Gyazo
2
- VERSION = '1.0.0'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -0,0 +1,10 @@
1
+ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
2
+
3
+ require 'gyazo'
4
+
5
+ gyazo = Gyazo::Client.new(ENV['GYAZO_TOKEN'])
6
+
7
+ res = gyazo.list(:page => 1, :per_page => 50)
8
+
9
+ puts res[0]
10
+ puts res[0]['url']
@@ -0,0 +1,10 @@
1
+ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
2
+
3
+ require 'gyazo'
4
+
5
+ gyazo = Gyazo::Client.new(ENV['GYAZO_TOKEN'])
6
+
7
+ img_path = ARGV.shift
8
+
9
+ res = gyazo.upload(img_path)
10
+ puts res['url']
@@ -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
- url = @gyazo.upload @imagefile
13
- assert_equal url, "#{@gyazo.host}/#{@image_id}"
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 test_info
28
- info = @gyazo.info @image_id
29
- assert_equal info.class, Hash
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: 1.0.0
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
- date: 2014-01-05 00:00:00 Z
13
- dependencies:
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
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
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
- requirement: &id002 !ruby/object:Gem::Requirement
28
- requirements:
29
- - &id003
30
- - ">="
31
- - !ruby/object:Gem::Version
32
- version: "0"
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
- requirement: &id004 !ruby/object:Gem::Requirement
39
- requirements:
40
- - *id003
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
- requirement: &id005 !ruby/object:Gem::Requirement
47
- requirements:
48
- - *id003
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
- requirement: &id006 !ruby/object:Gem::Requirement
55
- requirements:
56
- - *id003
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
- requirement: &id007 !ruby/object:Gem::Requirement
63
- requirements:
64
- - *id003
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
- requirement: &id008 !ruby/object:Gem::Requirement
71
- requirements:
72
- - *id003
73
- type: :runtime
74
- version_requirements: *id008
75
- description: Upload an image to Gyazo.com
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
- - *id003
113
- required_rubygems_version: !ruby/object:Gem::Requirement
114
- requirements:
115
- - *id003
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.1.11
141
+ rubygems_version: 2.0.14
120
142
  signing_key:
121
143
  specification_version: 4
122
- summary: Upload an image to Gyazo.com
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