Class: Ubiquitously::Propeller::Post

Inherits:
Base::Post show all
Defined in:
lib/ubiquitously/propeller.rb

Instance Attribute Summary

Attributes inherited from Base::Post

#categories, #description, #service_url, #tags, #title, #url, #user

Instance Method Summary collapse

Methods inherited from Base::Post

#agent, create

Methods included from Resourceful

included

Instance Method Details

#saveObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ubiquitously/propeller.rb', line 27

def save
  return false unless valid?
  
  user.

  # url
  page        = agent.get("http://www.propeller.com/story/submit/")
  form        = page.forms.detect {|form| form.form_node["method"].downcase == "post"}
  form["url"] = url
  puts "SUBMIT FORM"
  # details
  # http://www.propeller.com/story/submit/content/
  page        = form.submit
  form        = page.forms.detect {|form| form.form_node["method"].downcase == "post"}
  puts "DETAILS"
  form.radiobuttons_with(:name => "title_multi").each do |button|
    button.check if button.value == "-1"
  end
  
  form["title_multi_text"] = title
  form["description"]      = description
  # separate by space, multi words are underscored
  form["user_tags"]        = tags.map {|tag| tag.underscore.gsub(/[\s|-]+/, "_")}.join(" ")
  
  form.radiobuttons_with(:name => "category").each do |button|
    button.check if button.value.to_s == "18"
  end
  
  # http://www.propeller.com/story/submit/preview/
  page = form.submit
  puts "SUBMIT DETAILS"
  # approve
  page.forms[1].submit
  
  unless options[:debug] == true
    page = form.submit
  end

  true
end