Class: Ubiquitously::Snipt::Post
- Inherits:
-
Ubiquitously::Service::Post
- Object
- Base
- Ubiquitously::Service::Post
- Ubiquitously::Snipt::Post
- Defined in:
- lib/ubiquitously/services/snipt.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
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
Instance Method Details
#create ⇒ Object
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 |
# File 'lib/ubiquitously/services/snipt.rb', line 17 def create page = agent.get("http://snipt.net/#{user.username_for(self)}") form = page.forms.detect { |form| form.form_node["id"] == "snippet-form" } form["description"] = token[:title] form["code"] = token[:description] form["tags"] = token[:tags] form.field_with(:name => "lexer")..each do |option| option.select if (format == option.value || format == option.text.to_s.downcase) end form["public"] = public? ? "True" : "False" form["id"] = "0" # trailing slash matters form.action = "/save/" headers = { "X-Requested-With" => "XMLHttpRequest", "Accept" => "application/json, text/javascript, */*", "Content-Type" => "application/x-www-form-urlencoded; charset=UTF-8", "Pragma" => "no-cache", "Cache-Control" => "no-cache", "Accept-Encoding" => "gzip,deflate" } page = form.submit(nil, headers) url = JSON.parse(page.body)["slug"] rescue nil true end |