lib/tumblr4r.rb in tumblr4r-0.8.0 vs lib/tumblr4r.rb in tumblr4r-0.8.1
- old
+ new
@@ -1,21 +1,20 @@
# -*- coding: utf-8 -*-
+require "tumblr4r/version"
require 'net/http'
-require 'rubygems'
require 'rexml/document'
-begin
- require 'active_support/core_ext'
- require 'active_support/core_ext'
-rescue
- require 'activesupport'
-end
+begin
+ require 'active_support/core_ext'
+ require 'active_support/core_ext'
+rescue
+ require 'activesupport'
+end
require 'logger'
require 'cgi'
module Tumblr4r
- VERSION = '0.8.0'
class TumblrError < StandardError
attr_accessor :attachment
def initialize(msg, attachment=nil)
super(msg)
@attachment = attachment
@@ -28,10 +27,11 @@
QUOTE = "quote"
LINK = "link"
CHAT = "conversation"
AUDIO = "audio"
VIDEO = "video"
+ ANSWER = "answer"
end
# ConnectionオブジェクトとParserオブジェクトを組み合わせて、
# TumblrAPIとRubyオブジェクトの相互変換を行う
# TODO: private な post だけを取得する API が無いのだなぁ
@@ -360,10 +360,18 @@
"title" => @title,
"caption" => @video_caption})
end
end
+ class Answer < Post
+ attr_accessor :answer, :question
+
+ def params
+ super.merge!({"question" => @question, "answer" => @answer})
+ end
+ end
+
# Tumblr XML API への薄いラッパー。
# Rubyオブジェクトからの変換やRubyオブジェクトへの変換などは
# Parserクラスで行う。Parserクラスへの依存関係は一切持たない。
class XMLConnection
attr_accessor :logger, :group, :authenticated
@@ -527,10 +535,12 @@
post = self.chat(Chat.new, rexml_post)
when POST_TYPE::AUDIO
post = self.audio(Audio.new, rexml_post)
when POST_TYPE::VIDEO
post = self.video(Video.new, rexml_post)
+ when POST_TYPE::ANSWER
+ post = self.answer(Answer.new, rexml_post)
else
raise TumblrError.new("unknown post type #{post_type}")
end
posts << post
end
@@ -610,9 +620,16 @@
def video(post, rexml_post)
post = self.post(post, rexml_post)
post.video_caption = rexml_post.elements["video-caption"].try(:text) || ""
post.video_source = rexml_post.elements["video-source"].try(:text) || ""
post.video_player = rexml_post.elements["video-player"].try(:text) || ""
+ post
+ end
+
+ def answer(post, rexml_post)
+ post = self.post(post, rexml_post)
+ post.question = rexml_post.elements["question"].try(:text) || ""
+ post.answer = rexml_post.elements["answer"].try(:text) || ""
post
end
end