Class: Ubiquitously::Mixx::Post

Inherits:
Base::Post show all
Defined in:
lib/ubiquitously/mixx.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



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
# File 'lib/ubiquitously/mixx.rb', line 24

def save
  return false unless valid?
  
  user.
  
  page = agent.get("http://www.mixx.com/submit")
  form = page.form_with(:action => "http://www.mixx.com/submit/step2")
  form["thingy[page_url]"] = url
  page = form.submit

  # last page
  form = page.form_with(:action => "http://www.mixx.com/submit/save")

  # captcha
  iframe_url = page.parser.css("li.captcha iframe").first["src"]
  params     = iframe_url.split("?").last
  captcha_iframe = agent.click(page.iframes.first)
  captcha_form = captcha_iframe.forms.first
  captcha_image = captcha_iframe.parser.css("img").first["src"]
  # open browser with captcha image
  system("open", "http://api.recaptcha.net/#{captcha_image}")
  # enter captcha response in terminal
  captcha_says = ask("Enter Captcha from Browser Image:  ") { |q| q.echo = true }
  captcha_form["recaptcha_response_field"] = captcha_says
  # submit captcha
  captcha_form.action = "http://www.google.com/recaptcha/api/noscript?#{params}"
  captcha_response = captcha_form.submit
  # grab secret
  captcha_response = captcha_response.parser.css("textarea").first.text

  # submit post
  form = page.form_with(:action => "http://www.mixx.com/submit/save")
  form["thingy[title]"] = title
  form["thingy[description]"] = description if description
  form["thingy[new_tags]"] = tags if tags
  form["recaptcha_challenge_field"] = captcha_response
  form["recaptcha_response_field"] = captcha_says
  
  form.submit
end