jugyo-rubytter 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -2
- data/examples/friends_timeline.rb +14 -0
- data/examples/update_status.rb +12 -0
- data/lib/rubytter.rb +8 -42
- data/lib/rubytter/connection.rb +37 -0
- metadata +4 -1
data/README.rdoc
CHANGED
@@ -32,7 +32,17 @@ implemented methods:
|
|
32
32
|
|
33
33
|
== SYNOPSIS:
|
34
34
|
|
35
|
-
|
35
|
+
update status
|
36
|
+
|
37
|
+
client = Rubytter.new(user_id, password)
|
38
|
+
client.update('hello twitter!!')
|
39
|
+
|
40
|
+
get friends timeline
|
41
|
+
|
42
|
+
client = Rubytter.new(user_id, password)
|
43
|
+
client.friends_timeline().each do |status|
|
44
|
+
puts "#{status['user']['screen_name']}: #{status['text']}"
|
45
|
+
end
|
36
46
|
|
37
47
|
== REQUIREMENTS:
|
38
48
|
|
@@ -40,7 +50,8 @@ TODO
|
|
40
50
|
|
41
51
|
== INSTALL:
|
42
52
|
|
43
|
-
|
53
|
+
gem source -a http://gems.github.com
|
54
|
+
sudo gem install jugyo-rubytter
|
44
55
|
|
45
56
|
== TODO:
|
46
57
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rubytter'
|
5
|
+
|
6
|
+
if ARGV.size < 2
|
7
|
+
puts "Usage: ruby #{File.basename(__FILE__)} user_id password"
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
|
+
client = Rubytter.new(ARGV[0], ARGV[1])
|
12
|
+
client.friends_timeline().each do |status|
|
13
|
+
puts "#{status['user']['screen_name']}: #{status['text']}"
|
14
|
+
end
|
data/lib/rubytter.rb
CHANGED
@@ -3,6 +3,8 @@ require 'json'
|
|
3
3
|
require 'net/https'
|
4
4
|
require 'cgi'
|
5
5
|
|
6
|
+
require 'rubytter/connection'
|
7
|
+
|
6
8
|
class Rubytter
|
7
9
|
APP_NAME = self.to_s
|
8
10
|
|
@@ -70,10 +72,7 @@ class Rubytter
|
|
70
72
|
path += '.json'
|
71
73
|
param_str = '?' + params.to_a.map{|i| i[0].to_s + '=' + CGI.escape(i[1]) }.join('&')
|
72
74
|
path = path + param_str unless param_str.empty?
|
73
|
-
|
74
|
-
req = Net::HTTP::Get.new(path)
|
75
|
-
req.add_field('User-Agent', 'Rubytter http://github.com/jugyo/rubytter')
|
76
|
-
req.basic_auth(@login, @password)
|
75
|
+
req = prepare_request(Net::HTTP::Get.new(path))
|
77
76
|
res_text = @connection.start(@host) do |http|
|
78
77
|
http.request(req).body
|
79
78
|
end
|
@@ -83,10 +82,7 @@ class Rubytter
|
|
83
82
|
def post(path, params = {})
|
84
83
|
path += '.json'
|
85
84
|
param_str = params.to_a.map{|i| i[0].to_s + '=' + CGI.escape(i[1]) }.join('&')
|
86
|
-
|
87
|
-
req = Net::HTTP::Post.new(path)
|
88
|
-
req.add_field('User-Agent', 'Rubytter http://github.com/jugyo/rubytter')
|
89
|
-
req.basic_auth(@login, @password)
|
85
|
+
req = prepare_request(Net::HTTP::Post.new(path))
|
90
86
|
@connection.start(@host) do |http|
|
91
87
|
http.request(req, param_str).body
|
92
88
|
end
|
@@ -96,39 +92,9 @@ class Rubytter
|
|
96
92
|
post(path, params)
|
97
93
|
end
|
98
94
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
@proxy_host = options[:proxy_host]
|
104
|
-
@proxy_port = options[:proxy_port]
|
105
|
-
@proxy_user = options[:proxy_user_name]
|
106
|
-
@proxy_password = options[:proxy_password]
|
107
|
-
@proxy_uri = nil
|
108
|
-
@enable_ssl = options[:enable_ssl]
|
109
|
-
|
110
|
-
if @proxy_host
|
111
|
-
@http_class = Net::HTTP::Proxy(@proxy_host, @proxy_port,
|
112
|
-
@proxy_user, @proxy_password)
|
113
|
-
@proxy_uri = "http://" + @proxy_host + ":" + @proxy_port + "/"
|
114
|
-
else
|
115
|
-
@http_class = Net::HTTP
|
116
|
-
end
|
117
|
-
|
118
|
-
if @enable_ssl
|
119
|
-
@protocol = "https"
|
120
|
-
@port = 443
|
121
|
-
else
|
122
|
-
@protocol = "http"
|
123
|
-
@port = 80
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def start(host, port = nil, &block)
|
128
|
-
http = @http_class.new(host, port || @port)
|
129
|
-
http.use_ssl = @enable_ssl
|
130
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
|
131
|
-
http.start(&block)
|
132
|
-
end
|
95
|
+
def prepare_request(req)
|
96
|
+
req.add_field('User-Agent', 'Rubytter http://github.com/jugyo/rubytter')
|
97
|
+
req.basic_auth(@login, @password)
|
98
|
+
return req
|
133
99
|
end
|
134
100
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Rubytter
|
2
|
+
class Connection
|
3
|
+
attr_reader :protocol, :port, :proxy_uri
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
@proxy_host = options[:proxy_host]
|
7
|
+
@proxy_port = options[:proxy_port]
|
8
|
+
@proxy_user = options[:proxy_user_name]
|
9
|
+
@proxy_password = options[:proxy_password]
|
10
|
+
@proxy_uri = nil
|
11
|
+
@enable_ssl = options[:enable_ssl]
|
12
|
+
|
13
|
+
if @proxy_host
|
14
|
+
@http_class = Net::HTTP::Proxy(@proxy_host, @proxy_port,
|
15
|
+
@proxy_user, @proxy_password)
|
16
|
+
@proxy_uri = "http://" + @proxy_host + ":" + @proxy_port.to_s + "/"
|
17
|
+
else
|
18
|
+
@http_class = Net::HTTP
|
19
|
+
end
|
20
|
+
|
21
|
+
if @enable_ssl
|
22
|
+
@protocol = "https"
|
23
|
+
@port = 443
|
24
|
+
else
|
25
|
+
@protocol = "http"
|
26
|
+
@port = 80
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def start(host, port = nil, &block)
|
31
|
+
http = @http_class.new(host, port || @port)
|
32
|
+
http.use_ssl = @enable_ssl
|
33
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
|
34
|
+
http.start(&block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jugyo-rubytter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jugyo
|
@@ -32,6 +32,9 @@ extra_rdoc_files:
|
|
32
32
|
- History.txt
|
33
33
|
files:
|
34
34
|
- lib/rubytter.rb
|
35
|
+
- lib/rubytter/connection.rb
|
36
|
+
- examples/friends_timeline.rb
|
37
|
+
- examples/update_status.rb
|
35
38
|
- spec/rubytter_spec.rb
|
36
39
|
- spec/spec_helper.rb
|
37
40
|
- README.rdoc
|