Class: Hatena::Bookmark

Inherits:
Object
  • Object
show all
Defined in:
lib/hatena-bookmark.rb

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Bookmark

Hatena::Bookmark.new(

:consumer_key => "",
:consumer_secret => "",
:request_token => "",
:request_secret => ""
)


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hatena-bookmark.rb', line 13

def initialize(params)
  consumer = OAuth::Consumer.new(
    params[:consumer_key],
    params[:consumer_secret]
  )

  @access_token = OAuth::AccessToken.new(
    consumer,
    params[:request_token],
    params[:request_secret]
  )
end

Instance Method Details

#create(params) ⇒ Object

PostURI

hatebu.create(:url => “www.exapmle.com/”, :comment => “test”)



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hatena-bookmark.rb', line 33

def create(params)

xml =<<XML
<entry xmlns="http://purl.org/atom/ns#">
  <title>#{params[:title]}</title>
  <link rel="related" type="text/html" href="#{params[:url]}" />
  <summary type="text/plain">#{params[:comment]}</summary>
</entry>
XML

  post('/post', xml)
end

#delete_edit(params, options = {}) ⇒ Object

DELETE /atom/edit/XXXX



64
65
66
# File 'lib/hatena-bookmark.rb', line 64

def delete_edit(params,options={})
  delete("/edit/#{params[:eid]}",options)
end

#feedObject

FeedURI



69
70
71
# File 'lib/hatena-bookmark.rb', line 69

def feed
  get('/feed')
end

#get_edit(options) ⇒ Object

GET /atom/edit/XXXX



47
48
49
# File 'lib/hatena-bookmark.rb', line 47

def get_edit(options)
  get("/edit/#{options[:eid]}",options)
end

#ok?Boolean

# HTTP/1.1 201 hatebu.ok? #=> true

Returns:

  • (Boolean)


75
76
77
# File 'lib/hatena-bookmark.rb', line 75

def ok? 
  @response.is_a? Net::HTTPOK
end

#pingObject

Root Atom Endpoint



27
28
29
# File 'lib/hatena-bookmark.rb', line 27

def ping
  get('')
end

#put_edit(params) ⇒ Object

PUT /atom/edit/XXXX



52
53
54
55
56
57
58
59
60
61
# File 'lib/hatena-bookmark.rb', line 52

def put_edit(params)

xml =<<XML
<entry xmlns="http://purl.org/atom/ns#">
  <title>#{params[:title]}</title>
  <summary type="text/plain">#{params[:comment]}</summary>
</entry>
XML
  put("/edit/#{params[:eid]}",xml)
end