preposterous 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/examples/post.rb +26 -0
- data/lib/preposterous/base.rb +28 -10
- data/lib/preposterous/httpauth.rb +1 -1
- data/preposterous.gemspec +1 -1
- metadata +2 -2
data/VERSION.yml
CHANGED
data/examples/post.rb
CHANGED
@@ -52,3 +52,29 @@ fields = {
|
|
52
52
|
|
53
53
|
# perform the actual post
|
54
54
|
posterous.newpost(fields, *files)
|
55
|
+
|
56
|
+
#
|
57
|
+
# update post w/files
|
58
|
+
#
|
59
|
+
|
60
|
+
# initialize array of files
|
61
|
+
files = [
|
62
|
+
File.open("examples/three.png"),
|
63
|
+
File.open("examples/four.png")
|
64
|
+
]
|
65
|
+
|
66
|
+
# initialize fields
|
67
|
+
fields = {
|
68
|
+
:post_id => 12345678,
|
69
|
+
:title => "Autogenerated post from Preposterous Gem [#{Time.now}]",
|
70
|
+
:body => "This is some new text for my autogenerated post."
|
71
|
+
}
|
72
|
+
|
73
|
+
# perform the update
|
74
|
+
posterous.updatepost(fields, *files)
|
75
|
+
|
76
|
+
#
|
77
|
+
# fetch the tags from your site
|
78
|
+
#
|
79
|
+
|
80
|
+
puts posterous.gettags
|
data/lib/preposterous/base.rb
CHANGED
@@ -18,32 +18,50 @@ module Preposterous
|
|
18
18
|
|
19
19
|
def newpost(fields={}, *files)
|
20
20
|
# create options hash
|
21
|
-
options =
|
22
|
-
options = build_multipart_bodies(*files).merge(options) if files
|
23
|
-
|
21
|
+
options = generate_post_options(fields, *files)
|
24
22
|
response = perform_post("/api/newpost", options)
|
25
23
|
# return post attrs
|
26
24
|
response["post"] if not response.nil?
|
27
25
|
end
|
28
26
|
|
29
|
-
# TODO:
|
30
|
-
def
|
27
|
+
# TODO: refactor this and the newpost method
|
28
|
+
def updatepost(fields={}, *files)
|
29
|
+
# create options hash
|
30
|
+
options = generate_post_options(fields, *files)
|
31
|
+
response = perform_post("/api/updatepost", options)
|
32
|
+
# return post attrs
|
33
|
+
response["post"] if not response.nil?
|
31
34
|
end
|
32
35
|
|
33
|
-
#
|
34
|
-
|
36
|
+
# this is BROKEN
|
37
|
+
# for some reason the XML will not parse
|
38
|
+
# the CDATA fields are throwing off the parser
|
39
|
+
def readposts(options={})
|
40
|
+
response = perform_get("/api/readposts")
|
41
|
+
response["post"] if not response.nil?
|
35
42
|
end
|
36
43
|
|
37
|
-
#
|
38
|
-
|
44
|
+
# for some reason posterous does not recognize the post_id
|
45
|
+
# i think there maybe something wrong with their API
|
46
|
+
# at least I hope it isn't me
|
47
|
+
def newcomment(options={})
|
48
|
+
response = perform_post("/api/newcomment")
|
49
|
+
response["comment"] if not response.nil?
|
39
50
|
end
|
40
51
|
|
41
|
-
# TODO: write gettags method
|
42
52
|
def gettags
|
53
|
+
response = perform_get("/api/gettags")
|
54
|
+
response["tag"] if not response.nil?
|
43
55
|
end
|
44
56
|
|
45
57
|
protected
|
46
58
|
|
59
|
+
def generate_post_options(fields, *files)
|
60
|
+
# create options hash
|
61
|
+
options = {:fields => fields}
|
62
|
+
options = build_multipart_bodies(*files).merge(options) if files
|
63
|
+
end
|
64
|
+
|
47
65
|
CRLF = "\r\n"
|
48
66
|
def build_multipart_bodies(*files)
|
49
67
|
boundary = Time.now.to_i.to_s(16)
|
data/preposterous.gemspec
CHANGED