Method: Ubiquitously::StumbleUpon::Post#create

Defined in:
lib/ubiquitously/services/stumble_upon.rb

#createObject



18
19
20
21
22
23
24
25
26
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
# File 'lib/ubiquitously/services/stumble_upon.rb', line 18

def create
  page = agent.get("http://www.stumbleupon.com/favorites/")
  action    = "http://www.stumbleupon.com/ajax/edit/comment"

  form = page.forms.detect do |form|
    !form.form_node.css("textarea#review").first.blank?
  end
  
  headers = {
    "X-Requested-With" => "XMLHttpRequest",
    "Accept" => "application/json, text/javascript, */*"
  }
  
  # get key properties
  key = page.parser.css("div#wrapperContent").first["class"]
  var = page.parser.css("li.listLi var").first
  comment_id = var["id"].blank? ? 0 : var["id"]
  public_id   = var["class"].blank? ? "" : var["class"]
  
  # post to hidden api
  params = {
    "url"           => token[:url],
    "title"         => token[:title],
    "review"        => token[:description],
    "tags"          => token[:tags],
    "token"         => key,
    "sticky_post"   => "0",
    "publicid"      => "",
    "syndicate_fb"  =>"syndicate_fb",
    "syndicate_tw"  => "syndicate_tw",
    "commentid"     => 0,
    "new_post"      => 1,
    "blog_post"     => 0,
    "keep_date"     => 0
  }
  
  form.action = action
  form.method = "POST"
  
  params.each do |k, v|
    form[k] = v
  end
  
  page   = form.submit(nil, headers)
  
  true
end