Sha256: ca3a7b476775568c57bd4d99727d3624eeca285d0da6dfaedf704e449551253c

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

module Ubiquitously
  module Gist
    class Account < Ubiquitously::Service::Account
      def login
        page = agent.get("https://gist.github.com/login")
        form = page.form_with(:action => "/session")
        form["login"] = username
        form["password"] = password
        page = form.submit
        
        authorize!(page.uri != "https://gist.github.com/session")
      end
    end
    
    class Post < Ubiquitously::Service::Post
      validates_presence_of :format, :extension
      
      def tokenize
        super.merge(
          # make sure we have the extension
          :title => self.title.gsub(/(?:\.#{self.extension})?$/, ".#{self.extension}")
        )
      end
      
      def create
        page = agent.get("http://gist.github.com/")
        form = page.form_with(:action => "/gists")
        
        form.field_with(:name => "file_ext[gistfile1]").options.each do |option|
          if format == extension || format == option.text.to_s.downcase.strip
            option.select
            break
          end
        end
        
        form["file_name[gistfile1]"] = token[:title]
        form["file_contents[gistfile1]"] = token[:description]
        
        if public?
          button = form.buttons.last
        else
          form["action_button"] = "private"
          button = form.buttons.first
        end
        
        page = form.submit(button)
        
        true
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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