rubytter 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -2
- data/lib/rubytter.rb +22 -12
- data/spec/rubytter_spec.rb +3 -3
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -8,7 +8,7 @@ Rubytter is simple twitter library.
|
|
8
8
|
|
9
9
|
== FEATURES/PROBLEMS:
|
10
10
|
|
11
|
-
implemented methods:
|
11
|
+
implemented API methods:
|
12
12
|
|
13
13
|
- /statuses/update
|
14
14
|
- /statuses/destroy/id
|
@@ -73,7 +73,6 @@ or
|
|
73
73
|
== TODO:
|
74
74
|
|
75
75
|
- search
|
76
|
-
- favorite
|
77
76
|
|
78
77
|
== LICENSE:
|
79
78
|
|
data/lib/rubytter.rb
CHANGED
@@ -6,8 +6,11 @@ require 'cgi'
|
|
6
6
|
require 'rubytter/connection'
|
7
7
|
|
8
8
|
class Rubytter
|
9
|
+
|
10
|
+
class APIError < StandardError; end
|
11
|
+
|
9
12
|
APP_NAME = 'Rubytter'
|
10
|
-
VERSION = '0.4.
|
13
|
+
VERSION = '0.4.1'
|
11
14
|
HOMEPAGE = 'http://github.com/jugyo/rubytter'
|
12
15
|
|
13
16
|
def initialize(login, password, options = {})
|
@@ -85,26 +88,33 @@ class Rubytter
|
|
85
88
|
path += '.json'
|
86
89
|
param_str = '?' + params.to_a.map{|i| i[0].to_s + '=' + CGI.escape(i[1].to_s) }.join('&')
|
87
90
|
path = path + param_str unless param_str.empty?
|
88
|
-
req =
|
89
|
-
|
90
|
-
http.request(req).body
|
91
|
-
end
|
92
|
-
json_to_struct(JSON.parse(res_body))
|
91
|
+
req = create_request(Net::HTTP::Get.new(path))
|
92
|
+
http_request(req)
|
93
93
|
end
|
94
94
|
|
95
95
|
def post(path, params = {})
|
96
96
|
path += '.json'
|
97
97
|
param_str = params.to_a.map{|i| i[0].to_s + '=' + CGI.escape(i[1].to_s) }.join('&')
|
98
|
-
req =
|
99
|
-
|
100
|
-
http.request(req, param_str).body
|
101
|
-
end
|
102
|
-
json_to_struct(JSON.parse(res_body))
|
98
|
+
req = create_request(Net::HTTP::Post.new(path))
|
99
|
+
http_request(req)
|
103
100
|
end
|
104
101
|
|
105
102
|
alias delete post
|
106
103
|
|
107
|
-
def
|
104
|
+
def http_request(req)
|
105
|
+
res = @connection.start(@host) do |http|
|
106
|
+
http.request(req)
|
107
|
+
end
|
108
|
+
struct = json_to_struct(JSON.parse(res.body))
|
109
|
+
case res.code
|
110
|
+
when "200"
|
111
|
+
struct
|
112
|
+
else
|
113
|
+
raise APIError, struct.error
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def create_request(req)
|
108
118
|
req.add_field('User-Agent', "#{APP_NAME} #{HOMEPAGE}")
|
109
119
|
req.basic_auth(@login, @password)
|
110
120
|
return req
|
data/spec/rubytter_spec.rb
CHANGED
@@ -77,14 +77,14 @@ class Rubytter
|
|
77
77
|
|
78
78
|
# friendship
|
79
79
|
|
80
|
-
it 'should respond to
|
80
|
+
it 'should respond to follow' do
|
81
81
|
@rubytter.should_receive(:post).with('/friendships/create/test', {})
|
82
82
|
@rubytter.follow('test')
|
83
83
|
end
|
84
84
|
|
85
|
-
it 'should respond to
|
85
|
+
it 'should respond to leave' do
|
86
86
|
@rubytter.should_receive(:delete).with('/friendships/destroy/test', {})
|
87
|
-
@rubytter.
|
87
|
+
@rubytter.leave('test')
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'should respond to friendship_exists' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubytter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jugyo
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-15 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|