hatena-bookmark 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hatena-bookmark}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["kkosuge"]
@@ -1,9 +1,15 @@
1
1
  require 'oauth'
2
2
  require 'crack'
3
3
 
4
- module Hatena
4
+ module Hatena #:nodoc:
5
5
  class Bookmark
6
6
 
7
+ # Hatena::Bookmark.new(
8
+ # :consumer_key => "",
9
+ # :consumer_secret => "",
10
+ # :request_token => "",
11
+ # :request_secret => ""
12
+ # )
7
13
  def initialize(params)
8
14
  consumer = OAuth::Consumer.new(
9
15
  params[:consumer_key],
@@ -17,41 +23,13 @@ module Hatena
17
23
  )
18
24
  end
19
25
 
20
- def get(path,options={})
21
- @response = @access_token.get("http://b.hatena.ne.jp/atom#{path}#{query_params(options)}")
22
- Crack::XML.parse(@response.body)
23
- end
24
-
25
- def query_params(params={})
26
- query = ""
27
- params.each do |key,value|
28
- query.empty? ? query = "?#{key}=#{value}" : query = "#{query}&#{key}=#{value}"
29
- end
30
- query
31
- end
32
-
33
- def post(path,xml)
34
- @response = @access_token.post("http://b.hatena.ne.jp/atom#{path}", xml, {'Content-Type' => 'application/x.atom+xml'})
35
- Crack::XML.parse(@response.body)
36
- end
37
-
38
- def put(path,xml)
39
- @response = @access_token.put("http://b.hatena.ne.jp/atom#{path}", xml, {'Content-Type' => 'application/x.atom+xml'})
40
- Crack::XML.parse(@response.body)
41
- end
42
-
43
- def delete(path,options={})
44
- @response = @access_token.delete("http://b.hatena.ne.jp/atom#{path}#{query_params(options)}")
45
- end
46
-
47
- def ok?
48
- @response.is_a? Net::HTTPOK
49
- end
50
-
26
+ # == Root Atom Endpoint
51
27
  def ping
52
28
  get('')
53
29
  end
54
30
 
31
+ # == PostURI
32
+ # hatebu.create(:url => "http://www.exapmle.com/", :comment => "test")
55
33
  def create(params)
56
34
 
57
35
  xml =<<XML
@@ -65,10 +43,12 @@ XML
65
43
  post('/post', xml)
66
44
  end
67
45
 
46
+ # == GET /atom/edit/XXXX
68
47
  def get_edit(options)
69
48
  get("/edit/#{options[:eid]}",options)
70
49
  end
71
50
 
51
+ # == PUT /atom/edit/XXXX
72
52
  def put_edit(params)
73
53
 
74
54
  xml =<<XML
@@ -80,13 +60,50 @@ XML
80
60
  put("/edit/#{params[:eid]}",xml)
81
61
  end
82
62
 
63
+ # == DELETE /atom/edit/XXXX
83
64
  def delete_edit(params,options={})
84
65
  delete("/edit/#{params[:eid]}",options)
85
66
  end
86
67
 
68
+ # == FeedURI
87
69
  def feed
88
70
  get('/feed')
89
71
  end
90
72
 
73
+ # # HTTP/1.1 201
74
+ # hatebu.ok? #=> true
75
+ def ok?
76
+ @response.is_a? Net::HTTPOK
77
+ end
78
+
79
+ private
80
+
81
+ def get(path,options={})
82
+ @response = @access_token.get("http://b.hatena.ne.jp/atom#{path}#{query_params(options)}")
83
+ Crack::XML.parse(@response.body)
84
+ end
85
+
86
+ def query_params(params={})
87
+ query = ""
88
+ params.each do |key,value|
89
+ query.empty? ? query = "?#{key}=#{value}" : query = "#{query}&#{key}=#{value}"
90
+ end
91
+ query
92
+ end
93
+
94
+ def post(path,xml)
95
+ @response = @access_token.post("http://b.hatena.ne.jp/atom#{path}", xml, {'Content-Type' => 'application/x.atom+xml'})
96
+ Crack::XML.parse(@response.body)
97
+ end
98
+
99
+ def put(path,xml)
100
+ @response = @access_token.put("http://b.hatena.ne.jp/atom#{path}", xml, {'Content-Type' => 'application/x.atom+xml'})
101
+ Crack::XML.parse(@response.body)
102
+ end
103
+
104
+ def delete(path,options={})
105
+ @response = @access_token.delete("http://b.hatena.ne.jp/atom#{path}#{query_params(options)}")
106
+ end
107
+
91
108
  end
92
109
  end
@@ -14,7 +14,7 @@ describe Hatena::Bookmark do
14
14
  @eid = ""
15
15
  end
16
16
 
17
- it "must recieeeeeeeeeeeeeve" do
17
+ it "must recieve response" do
18
18
  @hatebu.ping.should be_kind_of Hash
19
19
  @hatebu.ok?.should be_true
20
20
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hatena-bookmark
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - kkosuge
@@ -114,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- hash: 2280648175901441462
117
+ hash: 3098500840430533807
118
118
  segments:
119
119
  - 0
120
120
  version: "0"