RTwitter 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/RTwitter/version.rb +1 -1
- metadata +1 -3
- data/README.md~ +0 -29
- data/lib/RTwitter.rb~ +0 -265
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a94e520bd5913c6e511b140238bcf81a36ff6b1
|
4
|
+
data.tar.gz: ebafd81e914a2382bfb5dbf70885eceb0044ab1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ea02c69bbdab970cf0c9a5cf50fc3ccc13b9e145cb0106eb86d420890c63a2f7e80f2dc5082da925eb5b4e2d7192cb22585845cc53e1d4cfddb9ba39b415770
|
7
|
+
data.tar.gz: 8ce9c139d4930e1ff224a392bda434f69cc8e93e2c020c3118bf70922f3c947a07aaa83c0b457db83817dcf50b57171944b66d5225aae0b00a5a4de467ffe48c
|
data/lib/RTwitter/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RTwitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seurix
|
@@ -49,11 +49,9 @@ files:
|
|
49
49
|
- Gemfile
|
50
50
|
- LICENSE.txt
|
51
51
|
- README.md
|
52
|
-
- README.md~
|
53
52
|
- RTwitter.gemspec
|
54
53
|
- Rakefile
|
55
54
|
- lib/RTwitter.rb
|
56
|
-
- lib/RTwitter.rb~
|
57
55
|
- lib/RTwitter/version.rb
|
58
56
|
- lib/RTwitter/version.rb~
|
59
57
|
homepage: ''
|
data/README.md~
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# RTwitter
|
2
|
-
|
3
|
-
TODO: Write a gem description
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'RTwitter'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install RTwitter
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Contributing
|
24
|
-
|
25
|
-
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
data/lib/RTwitter.rb~
DELETED
@@ -1,265 +0,0 @@
|
|
1
|
-
require "RTwitter/version"
|
2
|
-
|
3
|
-
require'base64'
|
4
|
-
require'openssl'
|
5
|
-
require'uri'
|
6
|
-
require'json'
|
7
|
-
require'net/http'
|
8
|
-
|
9
|
-
module RTwitter
|
10
|
-
class OAuth
|
11
|
-
|
12
|
-
attr_reader :consumer_key,:consumer_key_secret,:access_token,:access_token_secret,:user_id,:screen_name
|
13
|
-
attr_accessor :userAgent
|
14
|
-
def initialize(ck ,cks ,at = nil ,ats = nil)
|
15
|
-
@consumer_key = ck
|
16
|
-
@consumer_key_secret = cks
|
17
|
-
@access_token = at
|
18
|
-
@access_token_secret = ats
|
19
|
-
@userAgent = 'RTwitter'
|
20
|
-
end
|
21
|
-
def request_token
|
22
|
-
|
23
|
-
oauth_params = oauth
|
24
|
-
oauth_params.delete('oauth_token')
|
25
|
-
oauth_params['oauth_callback'] = 'oob'
|
26
|
-
base_params = Hash[oauth_params.sort]
|
27
|
-
query = build_query(base_params)
|
28
|
-
url = 'https://api.twitter.com/oauth/request_token'
|
29
|
-
base = 'POST&' + escape(url) + '&' + escape(query)
|
30
|
-
key = @consumer_key_secret + '&'
|
31
|
-
oauth_params['oauth_signature'] = Base64.encode64(OpenSSL::HMAC.digest("sha1",key, base)).chomp
|
32
|
-
header = {'Authorization' => 'OAuth ' + build_header(oauth_params),'User-Agent' => @userAgent}
|
33
|
-
response = post_request(url,'',header)
|
34
|
-
|
35
|
-
items = response.body.split('&')
|
36
|
-
@request_token = items[0].split('=')[1]
|
37
|
-
@request_token_secret = items[1].split('=')[1]
|
38
|
-
return "https://api.twitter.com/oauth/authenticate?oauth_token=#{@request_token}"
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
def access_token(pin)
|
43
|
-
|
44
|
-
oauth_params = oauth
|
45
|
-
oauth_params.delete('oauth_token')
|
46
|
-
oauth_params['oauth_verifier'] = pin.chomp
|
47
|
-
oauth_params['oauth_token'] = @request_token
|
48
|
-
base_params = Hash[oauth_params.sort]
|
49
|
-
query = build_query(base_params)
|
50
|
-
url = 'https://api.twitter.com/oauth/access_token'
|
51
|
-
base = 'POST&' + escape(url) + '&' + escape(query)
|
52
|
-
key = @consumer_key_secret + '&' + @request_token_secret
|
53
|
-
oauth_params['oauth_signature'] = Base64.encode64(OpenSSL::HMAC.digest("sha1",key, base)).chomp
|
54
|
-
header = {'Authorization' => 'OAuth ' + build_header(oauth_params),'User-Agent' => @userAgent}
|
55
|
-
body = ''
|
56
|
-
response = post_request(url,body,header)
|
57
|
-
|
58
|
-
access_tokens = response.body.split('&')
|
59
|
-
@access_token = access_tokens[0].split('=')[1]
|
60
|
-
@access_token_secret = access_tokens[1].split('=')[1]
|
61
|
-
@user_id = access_tokens[2].split('=')[1]
|
62
|
-
@screen_name = access_tokens[3].split('=')[1]
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
def post(endpoint,additional_params = Hash.new)
|
67
|
-
|
68
|
-
url = url(endpoint)
|
69
|
-
header = signature('POST',url,additional_params)
|
70
|
-
body = build_body(additional_params)
|
71
|
-
response = post_request(url,body,header)
|
72
|
-
return decode(response)
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
def get(endpoint,additional_params = Hash.new)
|
77
|
-
|
78
|
-
url = url(endpoint)
|
79
|
-
header = signature('GET',url,additional_params)
|
80
|
-
body = build_body(additional_params)
|
81
|
-
response = get_request(url,body,header)
|
82
|
-
return decode(response)
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
def streaming(endpoint,additional_params = Hash.new)
|
87
|
-
|
88
|
-
url = url(endpoint)
|
89
|
-
header = signature('GET',url,additional_params)
|
90
|
-
body = build_body(additional_params)
|
91
|
-
buffer = ''
|
92
|
-
streaming_request(url,body,header){|chunk|
|
93
|
-
if buffer != ''
|
94
|
-
chunk = buffer + chunk
|
95
|
-
buffer = ''
|
96
|
-
end
|
97
|
-
begin
|
98
|
-
status = JSON.parse(chunk)
|
99
|
-
rescue
|
100
|
-
buffer << chunk
|
101
|
-
next
|
102
|
-
end
|
103
|
-
|
104
|
-
yield status
|
105
|
-
}
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
private
|
110
|
-
def signature(method,url,additional_params)
|
111
|
-
oauth_params = oauth
|
112
|
-
base_params = oauth_params.merge(additional_params)
|
113
|
-
base_params = Hash[base_params.sort]
|
114
|
-
query = build_query(base_params)
|
115
|
-
base = method + '&' + escape(url) + '&' + escape(query)
|
116
|
-
key = @consumer_key_secret + '&' + @access_token_secret
|
117
|
-
oauth_params['oauth_signature'] = Base64.encode64(OpenSSL::HMAC.digest("sha1",key, base)).chomp
|
118
|
-
header = {'Authorization' => 'OAuth ' + build_header(oauth_params),'User-Agent' => @userAgent}
|
119
|
-
return header
|
120
|
-
end
|
121
|
-
|
122
|
-
def oauth
|
123
|
-
{
|
124
|
-
'oauth_consumer_key' => @consumer_key,
|
125
|
-
'oauth_signature_method' => 'HMAC-SHA1',
|
126
|
-
'oauth_timestamp' => Time.now.to_i.to_s,
|
127
|
-
'oauth_version' => '1.0',
|
128
|
-
'oauth_nonce' => Random.new_seed.to_s,
|
129
|
-
'oauth_token' => @access_token
|
130
|
-
}
|
131
|
-
end
|
132
|
-
|
133
|
-
def decode(response)
|
134
|
-
if response.body == nil
|
135
|
-
raise RTwitterException,'Failed to receive response.'
|
136
|
-
end
|
137
|
-
if response.body == ''
|
138
|
-
raise RTwitterException,'Empty response.'
|
139
|
-
end
|
140
|
-
begin
|
141
|
-
obj = JSON.parse(response.body)
|
142
|
-
rescue
|
143
|
-
return response.body
|
144
|
-
end
|
145
|
-
if obj.include?('error')
|
146
|
-
raise RTwitterException,obj['error']
|
147
|
-
end
|
148
|
-
if obj.include?('errors')
|
149
|
-
if obj['errors'].kind_of?(String)
|
150
|
-
raise RTwitterException,obj['errors']
|
151
|
-
else
|
152
|
-
messages = []
|
153
|
-
obj['errors'].each{|errors|
|
154
|
-
messages << errors['message']
|
155
|
-
}
|
156
|
-
raise RTwitterException,messages.join("\n")
|
157
|
-
end
|
158
|
-
end
|
159
|
-
return obj
|
160
|
-
end
|
161
|
-
|
162
|
-
|
163
|
-
def escape(value)
|
164
|
-
|
165
|
-
URI.escape(value.to_s,/[^a-zA-Z0-9\-\.\_\~]/)
|
166
|
-
|
167
|
-
end
|
168
|
-
|
169
|
-
def post_request(url,body,header)
|
170
|
-
|
171
|
-
uri = URI.parse(url)
|
172
|
-
https = Net::HTTP.new(uri.host, uri.port)
|
173
|
-
if uri.port == 443
|
174
|
-
https.use_ssl = true
|
175
|
-
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
176
|
-
end
|
177
|
-
response = https.start{|https|
|
178
|
-
https.post(uri.request_uri,body,header)
|
179
|
-
}
|
180
|
-
return response
|
181
|
-
|
182
|
-
end
|
183
|
-
|
184
|
-
def get_request(url,body,header)
|
185
|
-
|
186
|
-
uri = URI.parse(url)
|
187
|
-
https = Net::HTTP.new(uri.host, uri.port)
|
188
|
-
if uri.port == 443
|
189
|
-
https.use_ssl = true
|
190
|
-
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
191
|
-
end
|
192
|
-
response = https.start{|https|
|
193
|
-
https.get(uri.request_uri + '?' + body, header)
|
194
|
-
}
|
195
|
-
return response
|
196
|
-
|
197
|
-
end
|
198
|
-
|
199
|
-
def streaming_request(url,body,header)
|
200
|
-
|
201
|
-
uri = URI.parse(url)
|
202
|
-
https = Net::HTTP.new(uri.host, uri.port)
|
203
|
-
if uri.port == 443
|
204
|
-
https.use_ssl = true
|
205
|
-
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
206
|
-
end
|
207
|
-
request = Net::HTTP::Get.new(uri.request_uri + '?' + body,header)
|
208
|
-
https.request(request){|response|
|
209
|
-
response.read_body{|chunk|
|
210
|
-
yield chunk
|
211
|
-
}
|
212
|
-
}
|
213
|
-
|
214
|
-
end
|
215
|
-
|
216
|
-
def url(endpoint)
|
217
|
-
if /https:\/\// =~ endpoint
|
218
|
-
return endpoint
|
219
|
-
end
|
220
|
-
list = {
|
221
|
-
'media/upload' => 'https://upload.twitter.com/1.1/media/upload.json',
|
222
|
-
'statuses/filter' => 'https://stream.twitter.com/1.1/statuses/filter.json',
|
223
|
-
'statuses/sample' => 'https://stream.twitter.com/1.1/statuses/sample.json',
|
224
|
-
'user' => 'https://userstream.twitter.com/1.1/user.json',
|
225
|
-
'site' => 'https://sitestream.twitter.com/1.1/site.json'
|
226
|
-
}
|
227
|
-
if list.include?(endpoint)
|
228
|
-
return list[endpoint]
|
229
|
-
else
|
230
|
-
return "https://api.twitter.com/1.1/#{endpoint}.json"
|
231
|
-
end
|
232
|
-
|
233
|
-
end
|
234
|
-
|
235
|
-
def build_query(params)
|
236
|
-
|
237
|
-
query = params.map{|key,value|
|
238
|
-
"#{escape(key)}=#{escape(value)}"
|
239
|
-
}.join('&')
|
240
|
-
return query
|
241
|
-
|
242
|
-
end
|
243
|
-
|
244
|
-
def build_header(params)
|
245
|
-
|
246
|
-
header = params.map{|key,value|
|
247
|
-
"#{escape(key)}=\"#{escape(value)}\""
|
248
|
-
}.join(',')
|
249
|
-
return header
|
250
|
-
|
251
|
-
end
|
252
|
-
|
253
|
-
def build_body(params)
|
254
|
-
|
255
|
-
body = params.map{|key,value|
|
256
|
-
"#{escape(key)}=#{escape(value)}"
|
257
|
-
}.join('&')
|
258
|
-
return body
|
259
|
-
|
260
|
-
end
|
261
|
-
|
262
|
-
class RTwitterException < RuntimeError; end
|
263
|
-
end
|
264
|
-
|
265
|
-
end
|