Sha256: acc56cd85a96c1f9646b414167a5208faba0e64ae38ab4619063771c9134aa0f

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

module Ubiquitously
  module Snipt
    class Account < Ubiquitously::Service::Account
      def login
        page = agent.get("http://snipt.net/login")
        form = page.form_with(:name => "fauth")
        form["username"] = username
        form["password"] = password
        form["blogin"] = "Login"
        page = form.submit
        
        authorize!(page.uri != "http://snipt.net/login")
      end
    end
    
    class Post < Ubiquitously::Service::Post      
      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ubiquitously-0.1.0 lib/ubiquitously/services/snipt.rb