Class: Ubiquitously::StumbleUpon::Post

Inherits:
Ubiquitously::Service::Post show all
Defined in:
lib/ubiquitously/services/stumble_upon.rb

Instance Attribute Summary

Attributes inherited from Ubiquitously::Service::Post

#captcha, #categories, #description, #downvotes, #extension, #format, #image, #kind, #must_be_unique, #privacy, #rating, #remote, #service_id, #service_url, #slug, #source, #source_url, #state, #status, #tags, #title, #token, #upvotes, #url, #user, #vote

Instance Method Summary collapse

Methods inherited from Ubiquitously::Service::Post

#access_token, #initialize

Methods included from Loggable::Post

included

Methods included from Restful::Post

included

Methods included from Postable::Post

included

Methods included from Ownable::Post

included

Methods inherited from Base

#apply, #debug?

Methods included from SubclassableCallbacks

included, override

Constructor Details

This class inherits a constructor from Ubiquitously::Service::Post

Instance Method Details

#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