0

如何添加具有多个标签的帖子?

我正在做这个。该帖子已添加到我的 Delicious 收藏中,但没有标签。

需要'www/delicious'

d_api = WWW::Delicious.new('用户名', '密码')

d_api.posts_add(:tags=> "tools,ruby,online",:url => ' http://rubular.com/ ', :title => 'Rubular', :notes=>'一个 Ruby 正则表达式编辑器' )

我目前正在使用www/Delicious gem,但我愿意接受其他建议。

我也尝试

:tags=> ["工具","ruby","在线"]

或事件使用构造函数

标签 = WWW::Delicious::Tag.new(:name => "工具")

但结果是一样的,标签混合在一起美味的标签截图

谢谢

4

5 回答 5

1

受到带有 HTTParty Gem代码的 Delicious API 的启发,我创建了一个这样的类

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

然后我可以这样称呼它:

delicious = Delicious.new( :username => 'myUsername', :password => 'myPassword' )
puts delicious.add(:query => {:url => 'http://rubular.com/', :description => 'Rubular', :tags => "tools,ruby,online"})
于 2012-01-30T20:23:03.017 回答
0

如果您查看WWW::Delicious::Post的 API ,标签是一个实例属性。我的猜测是它是一个数组。尝试:

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

它可能是一个 Tag 对象的数组,所以要尝试的另一件事是:

my_tags = ["tools","ruby","online"].map {|t| WWW::Delicious::Tag.new(t)}
d_api.posts_add(:tags => my_tags,:url => 'http://rubular.com/', :title => 'Rubular', :notes=>'a Ruby regular expression editor')
于 2012-01-30T13:49:18.190 回答
0

奇怪的是,有效的是:

delicious.posts_add(
  :url   => 'http://www.test2.com',
  :title => 'test',
  :tags => ['test1, test2']
)

具有单个条目的数组是逗号分隔的标记列表。

于 2012-02-21T14:29:02.287 回答
0

我创建了美味的 gem,它是Delicious oAuth API的 ruby​​ 包装器。您可以轻松添加书签:

client = Delicious::Client.new do |c|
  c.access_token = 'your-access-token'
end

client.bookmarks.create tags: 'tools,ruby,online',
                        url: 'http://rubular.com/',
                        description: 'Rubular',
                        extended: 'a Ruby regular expression editor'
于 2014-06-20T18:17:23.643 回答
0

作为替代方案,Temboo SDK(包含 Ruby 以及其他几种语言)除了 100 多个其他公共 API 之外,还包括 Delicious API 的方法。AddBookmark 方法支持多个标签:只需提供一个逗号分隔的列表作为输入值。

看看https://www.temboo.com/library/Library/Delicious/AddBookmark/

(全面披露:我在 Temboo 工作)

于 2013-04-16T22:38:51.903 回答