gyazo 2.1.2 → 3.1.1

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
1
  ---
2
- SHA1:
3
- metadata.gz: 73172604e611a854e2191a013b9e4e3367a72ec7
4
- data.tar.gz: 055ea0cca4ad119bd3c65163c39179f5f200ef93
2
+ SHA256:
3
+ metadata.gz: 26d22e358a2f7ad15e819b689f39ceb3399a2b1b1071b61dff3975943cc5b94b
4
+ data.tar.gz: 4f43bafa5994680a5ce030e48d041d2b8bbaa1abd8e15ca3fc2c21f680173d9a
5
5
  SHA512:
6
- metadata.gz: a6d592e7a2155d0421a5e1279a4caa85f1764b456702ef8f8d943f4d46de0e45e1aa5708951a26df747cfe97f1912222ec91675078d01c7c83b86a72bddd1675
7
- data.tar.gz: c7cdc51eca52d3ec370cc8cca78b8c6c8e59c1228a3ea5d07281ffa573e4ddc8562a78b896195c0a6ff8b6182efdfbba5440c00144c942ec9d8e1c439e5b411b
6
+ metadata.gz: 9b461bc154522c72909a14addfc49ac5ab9c6accb5c8d0836a55141895eae3985ebb97cdf5c0e2762555e326335b0b6d4832c52f3e83cf2821675b40515e540a
7
+ data.tar.gz: d93f554481d7744d054d452fab529c2d5d7bfe0977d5cfc89b65ffb913ffba849272c63dae58ca182b14e273cd716885fe635c4734b61bf12a3b0ab513cbd372
data/.travis.yml CHANGED
@@ -1,5 +1,8 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
- - 2.1.2
4
+ - 2.2.3
4
5
  env:
5
6
  secure: SKTPKUXfgOehDNdgdMxKykef1m7XswYKA72qANyqHQ3/P/9c7RcRfTSVD86wj4riT8BX5YTbNhKKQFa79HozioezF7tT5A6xF5qiJOt1sjjtMfhc0d3zqN3RVJNRpx+1+hgNpv9OQ6RrTdw3At1TjzvgdMAiJI4X8lqZ904Gu60=
7
+ install: bundle install
8
+ script: bundle exec rake test
data/README.md CHANGED
@@ -2,59 +2,69 @@ Gyazo
2
2
  =====
3
3
  [Gyazo API](https://gyazo.com/api/docs) wrapper for Ruby
4
4
 
5
- [![Build Status](https://travis-ci.org/masui/gyazo-ruby.svg?branch=master)](https://travis-ci.org/masui/gyazo-ruby)
6
-
7
- - http://github.com/masui/gyazo-ruby
5
+ - http://github.com/gyazo/gyazo-ruby
8
6
  - https://rubygems.org/gems/gyazo
9
7
 
10
8
 
11
9
  # Install
12
10
 
13
-
14
11
  % gem install gyazo
15
12
 
16
-
17
13
  # Usage
18
14
 
19
15
  Register new application and get [ACCESS TOKEN](https://gyazo.com/oauth/applications), then
20
16
 
21
- ### Upload
17
+ ## Upload
22
18
 
23
19
  ```ruby
24
20
  require 'gyazo'
25
-
26
- gyazo = Gyazo::Client.new 'your-access-token'
27
- res = gyazo.upload 'my_image.png'
28
- puts res['permalink_url'] # => "http://gyazo.com/a1b2cdef345"
21
+ gyazo = Gyazo::Client.new access_token: 'your-access-token'
22
+ res = gyazo.upload imagefile: 'my_image.png'
23
+ puts res #=> {:type=>"png", :thumb_url=>"https://thumb.gyazo.com/thumb/...", :created_at=>"2019-05-03T11:57:35+0000", :image_id=>"...", :permalink_url=>"https://gyazo.com/...", :url=>"https://i.gyazo.com/....png"}
29
24
  ```
30
- #### Upload with metadata
25
+
26
+ ### passing filename
27
+ if you give io for `imagefile:`, you need `filename:`.
31
28
 
32
29
  ```ruby
33
- require 'gyazo'
30
+ gyazo.upload imagefile: File.open(image), filename: 'image.png'
31
+ ```
34
32
 
35
- gyazo = Gyazo::Client.new 'your-access-token'
36
- res = gyazo.upload 'my_image.png',
37
- { :time => Time.now, :url => 'http://example.com/' }
38
- puts res['permalink_url']
33
+ ### Upload with metadata
34
+ Following attributes can be set
35
+
36
+ * created_at(default: `Time.now`)
37
+ * referer_url(default: '')
38
+ * title(default: '')
39
+ * desc(default: '')
40
+ * collection_id(default: '')
41
+
42
+ ```ruby
43
+ res = gyazo.upload imagefile: 'my_image.png', created_at: Time.now, referer_url: 'https://example.com/'
39
44
  ```
40
45
 
41
- ### List
46
+ ## List
42
47
 
43
48
  ```ruby
44
- gyazo.list.each do |image|
45
- puts image['url']
49
+ gyazo.list[:images].each do |image|
50
+ puts image[:url]
46
51
  end
47
52
  ```
48
53
 
49
- ### Delete
54
+ ## image detail
55
+
56
+ ```ruby
57
+ gyazo.image image_id: image_id
58
+ ```
59
+
60
+ ## Delete
50
61
 
51
62
  ```ruby
52
- gyazo.delete image_id
63
+ gyazo.delete image_id: image_id
53
64
  ```
54
65
 
55
66
 
56
- Test
57
- ----
67
+ # Test
58
68
 
59
69
  setup
60
70
 
data/gyazo.gemspec CHANGED
@@ -6,11 +6,11 @@ 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", "Sho Hashimoto"]
9
+ spec.authors = ["Toshiyuki Masui", "Sho Hashimoto", "Nana Kugayama"]
10
10
  spec.email = ["masui@pitecan.com"]
11
11
  spec.description = %q{Gyazo.com API Wrapper}
12
12
  spec.summary = spec.description
13
- spec.homepage = "http://github.com/masui/gyazo-ruby"
13
+ spec.homepage = "http://github.com/gyazo/gyazo-ruby"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/).reject{|i| i=="Gemfile.lock" }
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "minitest"
24
24
 
25
- spec.add_dependency "json"
26
- spec.add_dependency "httparty"
27
- spec.add_dependency "httmultiparty"
25
+ spec.add_dependency "faraday", '< 2.0.0'
26
+ spec.add_dependency "multipart-post"
27
+ spec.add_dependency "mime-types"
28
28
  end
data/lib/gyazo/client.rb CHANGED
@@ -1,57 +1,98 @@
1
1
  # coding: utf-8
2
- module Gyazo
2
+ require 'json'
3
+ require 'faraday'
4
+ require 'mime/types'
3
5
 
6
+ module Gyazo
4
7
  class Client
8
+ UploadURI = 'https://upload.gyazo.com/api/upload'
9
+ APIHost = 'https://api.gyazo.com'
10
+ attr_accessor :access_token, :user_agent
5
11
 
6
- attr_accessor :id, :user_id, :user_agent, :host
7
-
8
- def initialize(access_token = nil)
12
+ def initialize(access_token:, user_agent: nil)
9
13
  @access_token = access_token
10
- @user_agent = "GyazoRubyGem/#{Gyazo::VERSION}"
14
+ @user_agent = user_agent || "GyazoRubyGem/#{Gyazo::VERSION}"
15
+ @conn = ::Faraday.new(url: APIHost) do |f|
16
+ f.request :url_encoded
17
+ f.adapter ::Faraday.default_adapter
18
+ end
11
19
  end
12
-
13
- def upload(imagefile,params={})
14
- url = "https://upload.gyazo.com/api/upload"
15
- time = params[:time] || params[:created_at] || Time.now
16
- res = HTTMultiParty.post url, {
17
- :query => {
18
- :access_token => @access_token,
19
- :imagedata => File.open(imagefile),
20
- :created_at => time.to_i,
21
- :referer_url => params[:referer_url] || params[:url] || '',
22
- :title => params[:title] || '',
23
- :desc => params[:desc] || ''
24
- },
25
- :header => {
26
- 'User-Agent' => @user_agent
20
+
21
+ def upload(imagefile:, filename: nil, created_at: ::Time.now, referer_url: '', title: '', desc: '', collection_id: '')
22
+ ensure_io_or_file_exists imagefile, filename
23
+
24
+ conn = ::Faraday.new do |f|
25
+ f.request :multipart
26
+ f.request :url_encoded
27
+ f.adapter ::Faraday.default_adapter
28
+ end
29
+ type = ::MIME::Types.type_for(filename || imagefile)[0].to_s
30
+ res = conn.post UploadURI do |req|
31
+ req.body = {
32
+ access_token: @access_token,
33
+ imagedata: ::Faraday::UploadIO.new(imagefile, type, filename),
34
+ created_at: created_at.to_i,
35
+ referer_url: referer_url.to_s,
36
+ title: title.to_s,
37
+ desc: desc.to_s,
38
+ collection_id: collection_id.to_s,
27
39
  }
28
- }
29
- raise Gyazo::Error, res.body unless res.code == 200
30
- return JSON.parse res.body
40
+ req.headers['User-Agent'] = @user_agent
41
+ end
42
+ raise Gyazo::Error, res.body unless res.status == 200
43
+ return ::JSON.parse res.body, symbolize_names: true
31
44
  end
32
45
 
33
- def list(query = {})
34
- url = "https://api.gyazo.com/api/images"
35
- query[:access_token] = @access_token
36
- res = HTTParty.get url, {
37
- :query => query,
38
- :header => {
39
- 'User-Agent' => @user_agent
40
- }
46
+ def list(page: 1, per_page: 20)
47
+ path = '/api/images'
48
+ res = @conn.get path do |req|
49
+ req.params[:access_token] = @access_token
50
+ req.params[:page] = page
51
+ req.params[:per_page] = per_page
52
+ req.headers['User-Agent'] = @user_agent
53
+ end
54
+ raise Gyazo::Error, res.body unless res.status == 200
55
+ json = ::JSON.parse res.body, symbolize_names: true
56
+ {
57
+ total_count: res.headers['X-Total-Count'],
58
+ current_page: res.headers['X-Current-Page'],
59
+ per_page: res.headers['X-Per-Page'],
60
+ user_type: res.headers['X-User-Type'],
61
+ images: json
41
62
  }
42
- raise Gyazo::Error, res.body unless res.code == 200
43
- return JSON.parse res.body
44
63
  end
45
64
 
46
- def delete(image_id)
47
- url = "https://api.gyazo.com/api/images/#{image_id}"
48
- res = HTTParty.delete url, {
49
- :query => {
50
- :access_token => @access_token
51
- }
52
- }
53
- raise Gyazo::Error, res.body unless res.code == 200
54
- return JSON.parse res.body
65
+ def image(image_id:)
66
+ path = "/api/images/#{image_id}"
67
+ res = @conn.get path do |req|
68
+ req.params[:access_token] = @access_token
69
+ req.headers['User-Agent'] = @user_agent
70
+ end
71
+ raise Gyazo::Error, res.body unless res.status == 200
72
+ return ::JSON.parse res.body, symbolize_names: true
73
+ end
74
+
75
+ def delete(image_id:)
76
+ path = "/api/images/#{image_id}"
77
+ res = @conn.delete path do |req|
78
+ req.params[:access_token] = @access_token
79
+ req.headers['User-Agent'] = @user_agent
80
+ end
81
+ raise Gyazo::Error, res.body unless res.status == 200
82
+ return ::JSON.parse res.body, symbolize_names: true
83
+ end
84
+
85
+ private
86
+
87
+ def ensure_io_or_file_exists(file, name)
88
+ if file.respond_to?(:read) && file.respond_to?(:rewind)
89
+ if name.nil?
90
+ raise ArgumentError, "need filename: when file is io"
91
+ end
92
+ return
93
+ end
94
+ return if ::File.file? file
95
+ raise ArgumentError, "cannot find file #{file}"
55
96
  end
56
97
  end
57
98
  end
data/lib/gyazo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gyazo
2
- VERSION = '2.1.2'
2
+ VERSION = '3.1.1'
3
3
  end
data/lib/gyazo.rb CHANGED
@@ -1,8 +1,3 @@
1
1
  require 'gyazo/version'
2
2
  require 'gyazo/error'
3
3
  require 'gyazo/client'
4
-
5
- require 'httparty'
6
- require 'httmultiparty'
7
- require 'json'
8
- require 'kconv'
data/test/test_gyazo.rb CHANGED
@@ -1,30 +1,43 @@
1
1
  require File.expand_path 'test_helper', File.dirname(__FILE__)
2
2
 
3
3
  class TestGyazo < MiniTest::Test
4
+ GYAZO_REGEXP = %r{^https://gyazo\.com/[a-z\d]{32}$}
4
5
 
5
6
  def setup
6
- @gyazo = Gyazo::Client.new ENV['GYAZO_TOKEN']
7
+ @gyazo = Gyazo::Client.new access_token: ENV['GYAZO_TOKEN']
7
8
  @imagefile = File.expand_path 'test.png', File.dirname(__FILE__)
8
9
  end
9
10
 
10
11
  def test_upload_filepath
11
- res = @gyazo.upload @imagefile
12
- assert res['permalink_url'].match /^https?:\/\/gyazo.com\/[a-z\d]{32}$/i
12
+ res = @gyazo.upload imagefile: @imagefile
13
+ assert res[:permalink_url].match GYAZO_REGEXP
13
14
  end
14
15
 
15
16
  def test_upload_file
16
- res = @gyazo.upload File.open(@imagefile)
17
- assert res['permalink_url'].match /^https?:\/\/gyazo.com\/[a-z\d]{32}$/i
17
+ res = @gyazo.upload imagefile: File.open(@imagefile), filename: 'test.png'
18
+ assert res[:permalink_url].match GYAZO_REGEXP
19
+ end
20
+
21
+ def test_upload_with_collection_id
22
+ res = @gyazo.upload imagefile: @imagefile, collection_id: ENV['GYAZO_COLLECTION_ID']
23
+ assert res[:permalink_url].match GYAZO_REGEXP
18
24
  end
19
25
 
20
26
  def test_list
21
- assert_equal @gyazo.list.class, Array
27
+ list = @gyazo.list
28
+ assert_instance_of Hash, list
29
+ assert_instance_of Array, list[:images]
22
30
  end
23
31
 
24
32
  def test_delete
25
- res_up = @gyazo.upload @imagefile
26
- res_del = @gyazo.delete res_up['image_id']
27
- assert_equal res_del['image_id'], res_up['image_id']
33
+ res_up = @gyazo.upload imagefile: @imagefile
34
+ res_del = @gyazo.delete image_id: res_up[:image_id]
35
+ assert_equal res_del[:image_id], res_up[:image_id]
28
36
  end
29
37
 
38
+ def test_image
39
+ res_up = @gyazo.upload imagefile: @imagefile
40
+ res = @gyazo.image image_id: res_up[:image_id]
41
+ assert_equal res[:image_id], res_up[:image_id]
42
+ end
30
43
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gyazo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshiyuki Masui
8
8
  - Sho Hashimoto
9
- autorequire:
9
+ - Nana Kugayama
10
+ autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2015-12-23 00:00:00.000000000 Z
13
+ date: 2022-01-04 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: bundler
@@ -54,21 +55,21 @@ dependencies:
54
55
  - !ruby/object:Gem::Version
55
56
  version: '0'
56
57
  - !ruby/object:Gem::Dependency
57
- name: json
58
+ name: faraday
58
59
  requirement: !ruby/object:Gem::Requirement
59
60
  requirements:
60
- - - ">="
61
+ - - "<"
61
62
  - !ruby/object:Gem::Version
62
- version: '0'
63
+ version: 2.0.0
63
64
  type: :runtime
64
65
  prerelease: false
65
66
  version_requirements: !ruby/object:Gem::Requirement
66
67
  requirements:
67
- - - ">="
68
+ - - "<"
68
69
  - !ruby/object:Gem::Version
69
- version: '0'
70
+ version: 2.0.0
70
71
  - !ruby/object:Gem::Dependency
71
- name: httparty
72
+ name: multipart-post
72
73
  requirement: !ruby/object:Gem::Requirement
73
74
  requirements:
74
75
  - - ">="
@@ -82,7 +83,7 @@ dependencies:
82
83
  - !ruby/object:Gem::Version
83
84
  version: '0'
84
85
  - !ruby/object:Gem::Dependency
85
- name: httmultiparty
86
+ name: mime-types
86
87
  requirement: !ruby/object:Gem::Requirement
87
88
  requirements:
88
89
  - - ">="
@@ -119,11 +120,11 @@ files:
119
120
  - test/test.png
120
121
  - test/test_gyazo.rb
121
122
  - test/test_helper.rb
122
- homepage: http://github.com/masui/gyazo-ruby
123
+ homepage: http://github.com/gyazo/gyazo-ruby
123
124
  licenses:
124
125
  - MIT
125
126
  metadata: {}
126
- post_install_message:
127
+ post_install_message:
127
128
  rdoc_options: []
128
129
  require_paths:
129
130
  - lib
@@ -138,9 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
139
  - !ruby/object:Gem::Version
139
140
  version: '0'
140
141
  requirements: []
141
- rubyforge_project:
142
- rubygems_version: 2.2.2
143
- signing_key:
142
+ rubygems_version: 3.2.32
143
+ signing_key:
144
144
  specification_version: 4
145
145
  summary: Gyazo.com API Wrapper
146
146
  test_files: