Class: Ubiquitously::Mixx::Post
- Inherits:
-
Service::Post
- Object
- Base
- Service::Post
- Ubiquitously::Mixx::Post
- Defined in:
- lib/ubiquitously/services/mixx.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
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Service::Post
Methods included from Loggable::Post
Methods included from Restful::Post
Methods included from Postable::Post
Methods included from Ownable::Post
Methods inherited from Base
Methods included from SubclassableCallbacks
Constructor Details
This class inherits a constructor from Ubiquitously::Service::Post
Class Method Details
.find(options = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ubiquitously/services/mixx.rb', line 66 def find( = {}) records = [] user = [:user] user_url = "http://www.mixx.com/feeds/users/#{user.username_for(self)}" xml = Nokogiri::XML(open(user_url).read) urls = url_permutations([:url]) xml.css("item").each do |node| title = node.css("title").first.text url = node.xpath("mixx:source", {"mixx" => "http://www.mixx.com/mixxrss/"}).first.text description = node.css("description").first.text service_url = node.css("link").first.text record = new( :title => title, :url => url, :description => description, :service_url => service_url, :user => user ) return record if urls.include?(record.url) records << record end [:url] ? nil : records end |
Instance Method Details
#create ⇒ Object
16 17 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 |
# File 'lib/ubiquitously/services/mixx.rb', line 16 def create page = agent.get("http://www.mixx.com/submit") form = page.form_with(:action => "http://www.mixx.com/submit/step2") form["thingy[page_url]"] = token[:url] page = form.submit already_submitted = page.parser.css(".flash.notice").first.text rescue "" if (already_submitted =~ /already submitted/i) form = page.forms.detect { |form| form.form_node["class"] =~ /vote-for/ } form.submit form = page.forms.detect { |form| form.form_node["id"] == "thingy_comment_form" } form["comment[body]"] = token[:description] form.submit else # 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]"] = token[:title] form["thingy[description]"] = token[:description] form["thingy[new_tags]"] = token[:tags] form["recaptcha_challenge_field"] = captcha_response form["recaptcha_response_field"] = captcha_says form.submit end true end |