Class: Ubiquitously::Snipt::Post

Inherits:
Ubiquitously::Service::Post show all
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

#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



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").options.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