Class: Ubiquitously::Snipplr::Post

Inherits:
Ubiquitously::Service::Post show all
Defined in:
lib/ubiquitously/services/snipplr.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



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/snipplr.rb', line 24

def create
  page = agent.get("http://snipplr.com/new/")
  form = page.form_with(:action => "/new/")
  
  form["title"] = token[:title]
  form["url"] = token[:title].downcase.strip.gsub(/[^a-z0-9]/, "-").squeeze("-")
  form["source"] = token[:description]
  form["tags"] = token[:tags]
  form.field_with(:name => "lang").options.each do |option|
    if option.text.to_s.downcase.strip == format
      option.select
      break
    end
  end
  form["private"] = 1 if private?
  
  # captcha
  iframe_url = page.parser.css("noscript 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
  
  form["recaptcha_challenge_field"] = captcha_response
  form["recaptcha_response_field"] = captcha_says
  form["btnsubmit"] = "POST"
  
  page = form.submit
  
  true
end

#tokenizeObject



20
21
22
# File 'lib/ubiquitously/services/snipplr.rb', line 20

def tokenize
  super.merge(:tags => tags.taggify(" ", " "))
end