Class: Tumblr::API::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/tumblr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http, email, password, generator) ⇒ Writer

Returns a new instance of Writer.



330
331
332
333
334
335
# File 'lib/tumblr.rb', line 330

def initialize(http, email, password, generator)
  @http = http
  @email = email
  @password = password
  @generator = generator
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



328
329
330
# File 'lib/tumblr.rb', line 328

def email
  @email
end

#generatorObject

Returns the value of attribute generator.



328
329
330
# File 'lib/tumblr.rb', line 328

def generator
  @generator
end

#httpObject

Returns the value of attribute http.



328
329
330
# File 'lib/tumblr.rb', line 328

def http
  @http
end

#passwordObject

Returns the value of attribute password.



328
329
330
# File 'lib/tumblr.rb', line 328

def password
  @password
end

Instance Method Details

#conversation(conversation, title = nil) ⇒ Object



353
354
355
# File 'lib/tumblr.rb', line 353

def conversation(conversation, title=nil)
  post("type" => "conversation", "title" => title, "conversation" => conversation)
end


349
350
351
# File 'lib/tumblr.rb', line 349

def link(url, name=nil, description=nil)
  post("type" => "link", "name" => name, "url" => url, "description" => description)
end

#photo(source, caption = nil) ⇒ Object



345
346
347
# File 'lib/tumblr.rb', line 345

def photo(source, caption=nil)
  post("type" => "photo", "caption" => caption, "source" => source)
end

#post(data) ⇒ Object



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/tumblr.rb', line 361

def post(data)
  req = Net::HTTP::Post.new "/api/write"
  req.set_form_data({
    "email" => @email,
    "password" => @password,
    "generator" => @generator
  }.merge(data))
  res = @http.request req
  case res.code
  when '201'
    return res.body.chomp
  when '403'
    raise AuthError.new
  when '400'
    raise BadRequestError.new(res.body)
  else
    raise ResponseError.new(res)
  end
end

#quote(text, source = nil) ⇒ Object



341
342
343
# File 'lib/tumblr.rb', line 341

def quote(text, source=nil)
  post("type" => "quote", "quote" => text, "source" => source)
end

#regular(body, title = nil) ⇒ Object



337
338
339
# File 'lib/tumblr.rb', line 337

def regular(body, title=nil)
  post("type" => "regular", "title" => title, "body" => body)
end

#video(embed, caption = nil) ⇒ Object



357
358
359
# File 'lib/tumblr.rb', line 357

def video(embed, caption=nil)
  post("type" => "video", "embed" => embed, "caption" => caption)
end