rubytter 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/friends_timeline.rb +6 -0
- data/lib/rubytter.rb +17 -8
- metadata +1 -1
@@ -12,3 +12,9 @@ client = Rubytter.new(ARGV[0], ARGV[1])
|
|
12
12
|
client.friends_timeline.each do |status|
|
13
13
|
puts "#{status.user.screen_name}: #{status.text}"
|
14
14
|
end
|
15
|
+
|
16
|
+
puts
|
17
|
+
|
18
|
+
client.friends_timeline(:page => 2).each do |status|
|
19
|
+
puts "#{status.user.screen_name}: #{status.text}"
|
20
|
+
end
|
data/lib/rubytter.rb
CHANGED
@@ -10,7 +10,7 @@ class Rubytter
|
|
10
10
|
class APIError < StandardError; end
|
11
11
|
|
12
12
|
APP_NAME = 'Rubytter'
|
13
|
-
VERSION = '0.4.
|
13
|
+
VERSION = '0.4.2'
|
14
14
|
HOMEPAGE = 'http://github.com/jugyo/rubytter'
|
15
15
|
|
16
16
|
def initialize(login, password, options = {})
|
@@ -86,7 +86,7 @@ class Rubytter
|
|
86
86
|
|
87
87
|
def get(path, params = {})
|
88
88
|
path += '.json'
|
89
|
-
param_str = '?' + params
|
89
|
+
param_str = '?' + to_param_str(params)
|
90
90
|
path = path + param_str unless param_str.empty?
|
91
91
|
req = create_request(Net::HTTP::Get.new(path))
|
92
92
|
http_request(req)
|
@@ -94,16 +94,21 @@ class Rubytter
|
|
94
94
|
|
95
95
|
def post(path, params = {})
|
96
96
|
path += '.json'
|
97
|
-
param_str = params
|
97
|
+
param_str = to_param_str(params)
|
98
98
|
req = create_request(Net::HTTP::Post.new(path))
|
99
|
-
http_request(req)
|
99
|
+
http_request(req, param_str)
|
100
100
|
end
|
101
101
|
|
102
102
|
alias delete post
|
103
103
|
|
104
|
-
def http_request(req)
|
105
|
-
|
106
|
-
|
104
|
+
def http_request(req, param_str = nil, host = nil)
|
105
|
+
host ||= @host
|
106
|
+
res = @connection.start(host) do |http|
|
107
|
+
if param_str
|
108
|
+
http.request(req, param_str)
|
109
|
+
else
|
110
|
+
http.request(req)
|
111
|
+
end
|
107
112
|
end
|
108
113
|
struct = json_to_struct(JSON.parse(res.body))
|
109
114
|
case res.code
|
@@ -117,7 +122,7 @@ class Rubytter
|
|
117
122
|
def create_request(req)
|
118
123
|
req.add_field('User-Agent', "#{APP_NAME} #{HOMEPAGE}")
|
119
124
|
req.basic_auth(@login, @password)
|
120
|
-
|
125
|
+
req
|
121
126
|
end
|
122
127
|
|
123
128
|
def json_to_struct(json)
|
@@ -141,4 +146,8 @@ class Rubytter
|
|
141
146
|
json
|
142
147
|
end
|
143
148
|
end
|
149
|
+
|
150
|
+
def to_param_str(hash)
|
151
|
+
hash.to_a.map{|i| i[0].to_s + '=' + CGI.escape(i[1].to_s) }.join('&')
|
152
|
+
end
|
144
153
|
end
|