Sha256: 0c0ec3e34d53852a4c27f6b0e43ac10a0f170280a385097a559cd10657343104

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

module Ubiquitously
  module Delicious
    class Account < Ubiquitously::Service::Account
      def login
        true
      end
    end
    
    class Post < Ubiquitously::Service::Post
      include HTTParty
      base_uri 'https://api.del.icio.us/v1'
      submit_to "http://del.icio.us/post/?url=:url&title=:title&notes=:description&tags=:tags"
      
      def tokenize
        super.merge(:tags => tags.taggify("-", " "))
      end
      
      def create
        puts "CREATE #{@auth.inspect}"
        res = self.class.get(
          "/posts/add",
          :query => {
            :url => url,
            :description => title,
            :extended => description,
            :tags => tags.map { |tag| tag.downcase.gsub(/[^a-z0-9]/, "-").squeeze("-") }.join(" ")
          },
          :basic_auth => @auth
        )
        puts "RESPONSE: #{res.inspect}"
        true
      end
      
      def remote(options = {})
        return nil
        raise "what url to do want" if self.url.nil?
        @remote ||= self.class.find(options.merge(
          :query => {
            :url => CGI.escape(self.url)
          },
          :basic_auth => @auth
        ))
      end
      
      class << self
        def find(options = {})
          options[:result] = options.delete(:count) unless options[:count].nil?
          raise "enter ':basic_auth => {:username => x, :password => y}'" unless options[:basic_auth]
          self.get('/posts/get', options)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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