Class: Tumblr::API::Writer
- Inherits:
-
Object
- Object
- Tumblr::API::Writer
- Defined in:
- lib/tumblr.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#generator ⇒ Object
Returns the value of attribute generator.
-
#http ⇒ Object
Returns the value of attribute http.
-
#password ⇒ Object
Returns the value of attribute password.
Instance Method Summary collapse
- #conversation(conversation, title = nil) ⇒ Object
-
#initialize(http, email, password, generator) ⇒ Writer
constructor
A new instance of Writer.
- #link(url, name = nil, description = nil) ⇒ Object
- #photo(source, caption = nil) ⇒ Object
- #post(data) ⇒ Object
- #quote(text, source = nil) ⇒ Object
- #regular(body, title = nil) ⇒ Object
- #video(embed, caption = nil) ⇒ Object
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
#email ⇒ Object
Returns the value of attribute email.
328 329 330 |
# File 'lib/tumblr.rb', line 328 def email @email end |
#generator ⇒ Object
Returns the value of attribute generator.
328 329 330 |
# File 'lib/tumblr.rb', line 328 def generator @generator end |
#http ⇒ Object
Returns the value of attribute http.
328 329 330 |
# File 'lib/tumblr.rb', line 328 def http @http end |
#password ⇒ Object
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 |
#link(url, name = nil, description = nil) ⇒ Object
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, =nil) post("type" => "photo", "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(, =nil) post("type" => "video", "embed" => , "caption" => ) end |