Class: OpenWFE::Extras::AtomPubParticipant

Inherits:
Object
  • Object
show all
Includes:
LocalParticipant
Defined in:
lib/openwfe/extras/participants/atompub_participants.rb

Overview

This participants posts (as in HTTP POST) a workitem to an AtomPub enabled resource.

target_uri = "https://openwferu.wordpress.com/wp-app.php/posts"

params = {}
params[:username] = 'jmettraux'
params[:password] = ENV['WORDPRESS_PASSWORD']
params[:categories] = 'openwferu, test'

engine.register_participant(
    "app", OpenWFE::Extras::AtomPubParticipant.new target_uri, params)

This base implementation dumps workitem as YAML in the entry content.

See BlogParticipant for a human-oriented blog posting participant.

Direct Known Subclasses

BlogParticipant

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_uri, params) ⇒ AtomPubParticipant

Returns a new instance of AtomPubParticipant.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/openwfe/extras/participants/atompub_participants.rb', line 89

def initialize (target_uri, params)

    @target_uri = target_uri

    @username = params[:username]
    @password = params[:password]

    @author_name = \
        params[:author_name] || self.class.name
    @author_uri = \
        params[:author_uri] || "http://openwferu.rubyforge.org"


    @categories = params[:categories] || []
    @categories = @categories.split(",") if @categories.is_a?(String)
    @categories = Array(@categories)
end

Instance Attribute Details

#author_nameObject

Returns the value of attribute author_name.



86
87
88
# File 'lib/openwfe/extras/participants/atompub_participants.rb', line 86

def author_name
  @author_name
end

#author_uriObject

Returns the value of attribute author_uri.



86
87
88
# File 'lib/openwfe/extras/participants/atompub_participants.rb', line 86

def author_uri
  @author_uri
end

#target_uriObject

The URI to post to



84
85
86
# File 'lib/openwfe/extras/participants/atompub_participants.rb', line 84

def target_uri
  @target_uri
end

Instance Method Details

#consume(workitem) ⇒ Object

The incoming workitem will generate an atom entry that will get posted to the target URI.

This consume() method returns the URI (as a String) where the just uploaded post can be edited.



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/openwfe/extras/participants/atompub_participants.rb', line 114

def consume (workitem)

    entry = Atom::Entry.new
    entry.updated! # set updated time to now

    render_author entry, workitem
    render_categories entry, workitem
    render_content entry, workitem

    h = Atom::HTTP.new
    h.user = @username
    h.pass = @password
    h.always_auth = :basic
    
    res = Atom::Collection.new(@target_uri, h).post!(entry)

    # initial implementation
    # don't catch an error, let the process fail

    #res.read_body
    extract_new_link res
end