Class: Gyazo::Client
- Inherits:
-
Object
- Object
- Gyazo::Client
- Defined in:
- lib/gyazo/client.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#id ⇒ Object
Returns the value of attribute id.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Instance Method Summary collapse
- #delete(image_id) ⇒ Object
-
#initialize(access_token = nil) ⇒ Client
constructor
A new instance of Client.
- #list(query = {}) ⇒ Object
- #upload(imagefile, params = {}) ⇒ Object
Constructor Details
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/gyazo/client.rb', line 6 def host @host end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/gyazo/client.rb', line 6 def id @id end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
6 7 8 |
# File 'lib/gyazo/client.rb', line 6 def user_agent @user_agent end |
#user_id ⇒ Object
Returns the value of attribute user_id.
6 7 8 |
# File 'lib/gyazo/client.rb', line 6 def user_id @user_id end |
Instance Method Details
#delete(image_id) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gyazo/client.rb', line 46 def delete(image_id) url = "https://api.gyazo.com/api/images/#{image_id}" res = HTTParty.delete url, { :query => { :access_token => @access_token } } raise Gyazo::Error, res.body unless res.code == 200 return JSON.parse res.body end |
#list(query = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gyazo/client.rb', line 33 def list(query = {}) url = "https://api.gyazo.com/api/images" query[:access_token] = @access_token res = HTTParty.get url, { :query => query, :header => { 'User-Agent' => @user_agent } } raise Gyazo::Error, res.body unless res.code == 200 return JSON.parse res.body end |
#upload(imagefile, params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gyazo/client.rb', line 13 def upload(imagefile,params={}) url = "https://upload.gyazo.com/api/upload" time = params[:time] || params[:created_at] || Time.now res = HTTMultiParty.post url, { :query => { :access_token => @access_token, :imagedata => File.open(imagefile), :created_at => time.to_i, :referer_url => params[:referer_url] || params[:url] || '', :title => params[:title] || '', :desc => params[:desc] || '' }, :header => { 'User-Agent' => @user_agent } } raise Gyazo::Error, res.body unless res.code == 200 return JSON.parse res.body end |