Class: Ubiquitously::YahooBuzz::Post

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

Instance Attribute Summary

Attributes inherited from 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 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

yahoo has 4 ajax forms on one page, but they make it look like it’s 2 steps



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
# File 'lib/ubiquitously/services/yahoo_buzz.rb', line 18

def create
  page = agent.get("http://buzz.yahoo.com/submit")
  
  headers = {
    "X-Requested-With" => "XMLHttpRequest",
    "Content-Type" => "application/x-www-form-urlencoded; charset=UTF-8"
  }
  
  # url form
  form = page.form_with(:name => "urlsubmissionform")
  if page.body =~ /YAHOO\.Buzz\.Submit\.QueryDataUrl \= \"\\\/submit\\\/get\;_ylt=([^\"]+)\"/i
    form.action = "http://buzz.yahoo.com/submit/get;_ylt=#{$1}"
  end

  form["url"] = token[:url]
  result = form.submit(nil, headers)
  
  # description form
  if description
    form = page.forms.detect do |form|
      form.form_node["class"] == "inline-edit-form" &&
        !form.form_node.css("input[value=submitSummary]").first.blank?
    end
    form["fieldvalue"] = description
    form.submit(nil, headers)
  end
  
  # category form
  form = page.forms.detect do |form|
    form.form_node["class"] == "inline-edit-form" &&
      !form.form_node.css("input[value=submitCategory]").first.blank?
  end
  # form.field_with(:name => "fieldvalue")
  
  # captcha
  form = page.form_with(:name => "submissiondataform")
  captcha_image = form.form_node.css(".captcha-image img").first["src"]
  
  system("open", captcha_image)
  # enter captcha response in terminal
  captcha_says = ask("Enter Captcha from Browser Image:  ") { |q| q.echo = true }
  form["submitCaptcha"] = captcha_says
  result = form.submit(nil, headers)
end