Search code examples
rubydelicious-api

How to add Delicious post with multiple tags in ruby


How can I add a post with more than one tag?

I'm doing this. The post is added to my Delicious collection but without tags.

require 'www/delicious'

d_api = WWW::Delicious.new('username', 'password')

d_api.posts_add(:tags=> "tools,ruby,online",:url => 'http://rubular.com/', :title => 'Rubular', :notes=>'a Ruby regular expression editor')

I'm currently using www/Delicious gem but I'm open to other suggestion.

I also try the

:tags=> ["tools","ruby","online"]

or event use the constructor

tag = WWW::Delicious::Tag.new(:name => "tools")

but the result is the same the tags are mixted in oneDelicious screenshot of the tag

thanks


Solution

  • Inspired by Delicious API with HTTParty Gem code I create a class like this

    require 'rubygems'
    require 'httparty'
    
    class Delicious
      include HTTParty
      base_uri 'https://api.del.icio.us/v1'
    
      def initialize(auth)
        @auth = auth
      end
    
      # query params that filter the posts are:
      #   url      = (required) the url of the item.
      #   description= (required) the description of the item. 
      #   extended     = (optional) notes for the item.
      #   tags         = (optional) tags for the item (comma delimited).
      #   dt       = {CCYY-MM-DDThh:mm:ssZ}(optional) datestamp of the item (format "CCYY-MM-DDThh:mm:ssZ").
      #   replace  = no(optional) don't replace post if given url has already been posted. 
      #   shared   = no(optional) make the item private
      def add(options={}))
        options.merge!({:basic_auth => @auth})
        self.class.get('/posts/add', options)
      end
    end
    

    Then I can call it like this:

    delicious = Delicious.new( :username => 'myUsername', :password => 'myPassword' )
    puts delicious.add(:query => {:url => 'http://rubular.com/', :description => 'Rubular', :tags => "tools,ruby,online"})