Module: Delicious::Bookmarks::Methods::Create

Extended by:
ActiveSupport::Concern
Included in:
Api
Defined in:
lib/delicious/bookmarks/methods/create.rb

Instance Method Summary collapse

Instance Method Details

#create(attrs) ⇒ Post

Create new bookmark

Examples:

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

Parameters:

  • attrs (Hash)

    Bookmark attributes

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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