preposterous 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 2
4
+ :patch: 3
5
5
  :build:
@@ -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
@@ -18,32 +18,50 @@ module Preposterous
18
18
 
19
19
  def newpost(fields={}, *files)
20
20
  # create options hash
21
- options = {:fields => fields}
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: write readposts method
30
- def readposts
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
- # TODO: write update method
34
- def updatepost
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
- # TODO: write comment method
38
- def newcomment
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)
@@ -1,7 +1,7 @@
1
1
  module Preposterous
2
2
  class HTTPAuth
3
3
  include HTTParty
4
- format :xml
4
+ format :plain
5
5
 
6
6
  attr_reader :username, :password, :options
7
7
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{preposterous}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ray Hernandez"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ray Hernandez