module Delicious::Bookmarks::Methods::Create
Public Instance Methods
create(attrs)
click to toggle source
Create
new bookmark
@example
client.bookmarks.create url: 'http://example.com', description: 'Example website', extended: 'Extended information', tags: %w(tag1 tag2), dt: '2014-04-15T10:20:00Z', shared: true, replace: false
@param attrs [Hash] Bookmark attributes @return [Post]
# File lib/delicious/bookmarks/methods/create.rb, line 23 def create(attrs) post = Delicious::Post.new url: attrs[:url], description: attrs[:description], extended: attrs[:extended], tags: attrs[:tags], dt: attrs[:dt], shared: attrs[:shared] if post.valid? response = @client.connection.post '/v1/posts/add', post_attrs(post, attrs[:replace]) code = response.body['result']['code'] fail Delicious::Error, code unless 'done' == code post.persisted = true post.delicious_client = @client end post end
Private Instance Methods
post_attrs(post, replace = false)
click to toggle source
# File lib/delicious/bookmarks/methods/create.rb, line 44 def post_attrs(post, replace = false) { url: post.url, description: post.description, extended: post.extended, tags: post.tags.join(','), dt: post.dt, shared: post.shared ? 'yes' : 'no', replace: replace ? 'yes' : 'no' } end