ruby-tumblr 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,8 +5,9 @@ require "uri"
5
5
  require "rexml/document"
6
6
  require "tzinfo"
7
7
  require "time"
8
+ require "tumblr/version"
8
9
 
9
- class Tumblr
10
+ module Tumblr
10
11
  class Data
11
12
  attr_accessor :tumblelog, :posts
12
13
 
@@ -18,14 +19,7 @@ class Tumblr
18
19
  end
19
20
 
20
21
  def self.load(path)
21
- xml.each do |post|
22
- case post.attributes["type"]
23
- when "regular"
24
- Regular.new()
25
- when "quote"
26
- Quote.new(post)
27
- end
28
- end
22
+ new(REXML::Document.new(File.read(path)))
29
23
  end
30
24
 
31
25
  def save(path)
@@ -40,7 +34,7 @@ class Tumblr
40
34
 
41
35
  def <<(other)
42
36
  @tumblelog = other.tumblelog unless @tumblelog
43
- @posts ? @posts << other.posts : @posts = other.posts
37
+ @posts ? @posts.push(*other.posts) : @posts = other.posts
44
38
  end
45
39
 
46
40
  class Tumblelog
@@ -51,7 +45,7 @@ class Tumblr
51
45
  @timezone = TZInfo::Timezone.get(elt.attributes["timezone"])
52
46
  @cname = elt.attributes["cname"]
53
47
  @title = elt.attributes["title"]
54
- @description = elt.attributes["description"]
48
+ @description = elt.text
55
49
  end
56
50
 
57
51
  def to_xml
@@ -60,7 +54,7 @@ class Tumblr
60
54
  elt.attributes["timezone"] = @timezone.name
61
55
  elt.attributes["cname"] = @cname
62
56
  elt.attributes["title"] = @title
63
- elt.text = description
57
+ elt.text = @description
64
58
  return elt
65
59
  end
66
60
  end
@@ -109,9 +103,9 @@ class Tumblr
109
103
 
110
104
  def to_xml
111
105
  elt = REXML::Element.new("post")
112
- elt.attributes["postid"] = @postid
106
+ elt.attributes["id"] = @postid
113
107
  elt.attributes["date"] = @date.strftime("%a, %d %b %Y %X")
114
- elt.attributes["bookmarklet"] = "true" if @bookmark
108
+ elt.attributes["bookmarklet"] = "true" if @bookmarklet
115
109
  elt.attributes["url"] = @url
116
110
  return elt
117
111
  end
@@ -122,16 +116,23 @@ class Tumblr
122
116
 
123
117
  def initialize(elt, tz)
124
118
  super
125
- @title = elt.elements["regular-title"].text if elt.elements["regular-title"]
126
- @body = elt.elements["regular-body"].text if elt.elements["regular-body"]
119
+ if elt.elements["regular-title"]
120
+ @title = elt.elements["regular-title"].text
121
+ end
122
+ if elt.elements["regular-body"]
123
+ @body = elt.elements["regular-body"].text
124
+ end
127
125
  end
128
126
 
129
127
  def to_xml
130
128
  elt = super
131
- title = elt.add_element("regular-title")
132
- title.text = @title
133
- body = elt.add_element("regular-body")
134
- body.text = @body
129
+ elt.attributes["type"] = "regular"
130
+ if @title
131
+ (elt.add_element("regular-title")).text = @title
132
+ end
133
+ if @body
134
+ (elt.add_element("regular-body")).text = @body
135
+ end
135
136
  return elt
136
137
  end
137
138
  end
@@ -142,15 +143,19 @@ class Tumblr
142
143
  def initialize(elt, tz)
143
144
  super
144
145
  @text = elt.elements["quote-text"].text
145
- @source = elt.elements["quote-source"].text
146
+ if elt.elements["quote-source"]
147
+ @source = elt.elements["quote-source"].text
148
+ end
146
149
  end
147
150
 
148
151
  def to_xml
149
152
  elt = super
153
+ elt.attributes["type"] = "quote"
150
154
  et = elt.add_element("quote-text")
151
155
  et.text = @text
152
- es = elt.add_element("quote-source")
153
- es.text = @source
156
+ if @source
157
+ (elt.add_element("quote-source")).text = @source
158
+ end
154
159
  return elt
155
160
  end
156
161
  end
@@ -160,7 +165,9 @@ class Tumblr
160
165
 
161
166
  def initialize(elt, tz)
162
167
  super
163
- @caption = elt.elements["photo-caption"].text
168
+ if elt.elements["photo-caption"]
169
+ @caption = elt.elements["photo-caption"].text
170
+ end
164
171
  @urls = Hash.new
165
172
  elt.elements.each("photo-url") do |url|
166
173
  @urls[url.attributes["max-width"].to_i] = url.text
@@ -169,8 +176,10 @@ class Tumblr
169
176
 
170
177
  def to_xml
171
178
  elt = super
172
- caption = elt.add_element "photo-caption"
173
- caption.text = @caption
179
+ elt.attributes["type"] = "photo"
180
+ if @caption
181
+ (elt.add_element "photo-caption").text = @caption
182
+ end
174
183
  @urls.each do |width, url|
175
184
  e = elt.add_element "photo-url", {"max-width" => width}
176
185
  e.text = url
@@ -191,6 +200,7 @@ class Tumblr
191
200
 
192
201
  def to_xml
193
202
  elt = super
203
+ elt.attributes["type"] = "link"
194
204
  name = elt.add_element "link-text"
195
205
  name.text = @text
196
206
  url = elt.add_element "link-url"
@@ -206,10 +216,12 @@ class Tumblr
206
216
 
207
217
  def initialize(elt, tz)
208
218
  super
209
- @title = elt.elements["conversation-title"].text
219
+ if elt.elements["conversation-title"]
220
+ @title = elt.elements["conversation-title"]
221
+ end
210
222
  @text = elt.elements["conversation-text"].text
211
223
  @lines = []
212
- elt.each("conversation-line") do |line|
224
+ elt.elements.each("conversation-line") do |line|
213
225
  name = line.attributes["name"]
214
226
  label = line.attributes["label"]
215
227
  @lines << [name, label, line.text]
@@ -218,8 +230,10 @@ class Tumblr
218
230
 
219
231
  def to_xml
220
232
  elt = super
221
- title = elt.add_element "conversation-title"
222
- title.text = @title
233
+ elt.attributes["type"] = "conversation"
234
+ if @title
235
+ (elt.add_element "conversation-title").text = @title
236
+ end
223
237
  text = elt.add_element "conversation-text"
224
238
  text.text = @text
225
239
  @lines.each do |line|
@@ -235,11 +249,12 @@ class Tumblr
235
249
  super
236
250
  @caption = elt.elements["video-caption"].text
237
251
  @source = elt.elements["video-source"].text
238
- @player = elt.attributes["video-player"]
252
+ @player = elt.elements["video-player"].text
239
253
  end
240
254
 
241
255
  def to_xml
242
256
  elt = super
257
+ elt.attributes["type"] = "video"
243
258
  caption = elt.add_element "video-caption"
244
259
  caption.text = @caption
245
260
  player = elt.add_element "video-player"
@@ -2,7 +2,7 @@ module Tumblr #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -43,7 +43,10 @@
43
43
  <h2>Installing</h2>
44
44
 
45
45
  <pre syntax="ruby">sudo gem install ruby-tumblr</pre>
46
- <h2>The basics</h2>
46
+ <h2>API Document</h2>
47
+
48
+ <p><a href="http://ruby-tumblr.rubyforge.org/doc/">http://ruby-tumblr.rubyforge.org/doc/</a></p>
49
+
47
50
 
48
51
  <h2>Demonstration of usage</h2>
49
52
 
@@ -8,15 +8,15 @@ h2. Installing
8
8
 
9
9
  <pre syntax="ruby">sudo gem install ruby-tumblr</pre>
10
10
 
11
- h2. The basics
11
+ h2. API Document
12
12
 
13
+ http://ruby-tumblr.rubyforge.org/doc/
13
14
 
14
15
  h2. Demonstration of usage
15
16
 
16
17
  h3. read
17
18
 
18
- <pre><code>require "tumblr"
19
-
19
+ <pre><code>
20
20
  Tumblr::API.read("tumblr.dynamic-semantics.com") do |pager|
21
21
  data = pager.page(0)
22
22
  p data.tumblelog
@@ -28,8 +28,7 @@ end
28
28
 
29
29
  h3. write
30
30
 
31
- <pre><code>require "tumblr"
32
-
31
+ <pre><code>
33
32
  Tumblr::API.write($email, $password) do
34
33
  regular("test body", "test title")
35
34
  quote("test quote", "test source")
@@ -37,6 +36,19 @@ Tumblr::API.write($email, $password) do
37
36
  end
38
37
  </code></pre>
39
38
 
39
+ h3. backup
40
+
41
+ <pre><code>
42
+ Tumblr::API.read("tumblr.dynamic-semantics.com") do |pager|
43
+ data = Tumblr::Data.new
44
+ 0.upto(pager.last_page) do |n|
45
+ puts "get #{n}/#{pager.last_page}"
46
+ data << pager.page(n)
47
+ end
48
+ data.save(File.join(ENV["HOME"], "backup.xml"))
49
+ end
50
+ </code></pre>
51
+
40
52
  h2. Forum
41
53
 
42
54
  "http://groups.google.com/group/ruby-tumblr":http://groups.google.com/group/ruby-tumblr
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: ruby-tumblr
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-08-20 00:00:00 +09:00
6
+ version: 0.0.2
7
+ date: 2007-08-21 00:00:00 +09:00
8
8
  summary: ruby-tumblr is a library for tumblr API.
9
9
  require_paths:
10
10
  - lib