TwitRuby 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +11 -0
  3. data/LICENSE.txt +674 -0
  4. data/README.md +29 -0
  5. data/Rakefile +1 -0
  6. data/doc/README_rdoc.html +185 -0
  7. data/doc/TwitRuby.html +1189 -0
  8. data/doc/created.rid +2 -0
  9. data/doc/images/add.png +0 -0
  10. data/doc/images/arrow_up.png +0 -0
  11. data/doc/images/brick.png +0 -0
  12. data/doc/images/brick_link.png +0 -0
  13. data/doc/images/bug.png +0 -0
  14. data/doc/images/bullet_black.png +0 -0
  15. data/doc/images/bullet_toggle_minus.png +0 -0
  16. data/doc/images/bullet_toggle_plus.png +0 -0
  17. data/doc/images/date.png +0 -0
  18. data/doc/images/delete.png +0 -0
  19. data/doc/images/find.png +0 -0
  20. data/doc/images/loadingAnimation.gif +0 -0
  21. data/doc/images/macFFBgHack.png +0 -0
  22. data/doc/images/package.png +0 -0
  23. data/doc/images/page_green.png +0 -0
  24. data/doc/images/page_white_text.png +0 -0
  25. data/doc/images/page_white_width.png +0 -0
  26. data/doc/images/plugin.png +0 -0
  27. data/doc/images/ruby.png +0 -0
  28. data/doc/images/tag_blue.png +0 -0
  29. data/doc/images/tag_green.png +0 -0
  30. data/doc/images/transparent.png +0 -0
  31. data/doc/images/wrench.png +0 -0
  32. data/doc/images/wrench_orange.png +0 -0
  33. data/doc/images/zoom.png +0 -0
  34. data/doc/index.html +71 -0
  35. data/doc/js/darkfish.js +155 -0
  36. data/doc/js/jquery.js +18 -0
  37. data/doc/js/navigation.js +142 -0
  38. data/doc/js/search.js +94 -0
  39. data/doc/js/search_index.js +1 -0
  40. data/doc/js/searcher.js +228 -0
  41. data/doc/rdoc.css +595 -0
  42. data/doc/table_of_contents.html +94 -0
  43. data/lib/func_sample.rb +34 -0
  44. data/lib/twitruby/version.rb +4 -0
  45. data/lib/twitruby/version.rb~ +2 -0
  46. data/lib/twitruby.rb +370 -0
  47. data/lib/twitruby.rb~ +371 -0
  48. data/twitruby.gemspec +23 -0
  49. metadata +119 -0
data/lib/twitruby.rb~ ADDED
@@ -0,0 +1,371 @@
1
+ # encoding: utf-8
2
+ require "twitruby/version"
3
+
4
+ ########################################################################
5
+ # ==TwitRuby== #
6
+ # Copyright (C) alphaKAI @alpha_kai_NET 2013 http://alpha-kai-net.info #
7
+ # GPLv3 LICENSE #
8
+ # #
9
+ # Version:0.0.1_alpha FIX05 #
10
+ # This is one of the Twitter Library #
11
+ # inspired by https://gist.github.com/pnlybubbles/5476370 #
12
+ # This is development version. #
13
+ # So very unstable. #
14
+ # You must accept it when you use this. #
15
+ ########################################################################
16
+ class TwitRuby
17
+ def initalize_connection(consumer_keys)
18
+ ak_exist=true
19
+ #デフォ状態での引数にアクセストークン系があるかないか 初期になかった場合は処理中にfalseに変更
20
+ if consumer_keys.size !=4 then
21
+ puts "error"
22
+ puts "wrong number of arguments"
23
+ puts "arguments array is require 4 element"
24
+ exit
25
+ end
26
+ consumer_key = consumer_keys[0]
27
+ consumer_secret = consumer_keys[1]
28
+ access_token = consumer_keys[2]
29
+ access_token_secret = consumer_keys[3]
30
+
31
+ @consumer = OAuth::Consumer.new(
32
+ consumer_key,
33
+ consumer_secret,
34
+ :site => "http://api.twitter.com/"
35
+ )
36
+
37
+ if access_token == nil || access_token == "" || access_token_secret == nil || access_token_secret == ""
38
+ puts "アクセストークンが設定されていないため、アクセストークンを取得します"
39
+ oauth_array = oauth_init
40
+ access_token = oauth_array[0]
41
+ access_token_secret = oauth_array[1]
42
+ ak_exist = false
43
+ end
44
+
45
+ #puts access_token
46
+ #puts access_token_secret
47
+
48
+ @access_token = OAuth::AccessToken.new(
49
+ @consumer,
50
+ access_token,
51
+ access_token_secret
52
+ )
53
+ end#end of function
54
+
55
+ def oauth_init
56
+ begin
57
+ request_token = @consumer.get_request_token
58
+
59
+ # require "Win32API"
60
+
61
+ # shellexecute = Win32API.new("shell32.dll","ShellExecuteA",%w(p p p p p i),"i")
62
+ # shellexecute.call(0, "open", "#{request_token.authorize_url}", 0, 0, 1)
63
+
64
+ puts("Access here: #{request_token.authorize_url}\nand...")
65
+ print("Please input pin:=>")
66
+ pin = STDIN.gets.chomp
67
+ puts ""#改行
68
+
69
+ access_token = request_token.get_access_token(
70
+ :oauth_token => request_token.token,
71
+ :oauth_verifier => pin
72
+ )
73
+
74
+ access_tokens = []
75
+ access_tokens << access_token.token.to_s
76
+ access_tokens << access_token.secret.to_s
77
+
78
+ return access_tokens
79
+ end#end of begin
80
+ end#end of function oauth_init
81
+
82
+ ##########################################################################
83
+ #Generate api parameters function
84
+ def gen_parms(api,parms)
85
+ hash_str="?"
86
+ parms.each{|key,value|
87
+ hash_str+=key.to_s+"="+value.to_s+"&"
88
+ }
89
+ hash_str[hash_str.size-1]=""
90
+ return hash_str.chomp
91
+ end
92
+ ##########################################################################
93
+
94
+ #POST statuses/update
95
+ def update(str, id="")
96
+ if (id.empty?) then
97
+ @access_token.post("/1.1/statuses/update.json",
98
+ "status" => str)
99
+ else
100
+ p @access_token.post("/1.1/statuses/update.json",
101
+ "status" => str,
102
+ "in_reply_to_status_id" => id)
103
+ end
104
+ end
105
+
106
+ #POST favorites/create
107
+ def favorite(id)
108
+ @access_token.post("/1.1/favorites/create.json",
109
+ "id" => id.to_s)
110
+ end
111
+
112
+ #POST favorites/destroy
113
+ def unfavorite(id)
114
+ @access_token.post("/1.1/favorites/destroy.json",
115
+ "id" => id.to_s)
116
+ end
117
+
118
+ #POST statuses/retweet
119
+ def retweet(id)
120
+ @access_token.post("/1.1/statuses/retweet/#{id}.json")
121
+ end
122
+
123
+ #POST statuses/destroy
124
+ def post_delete(id)
125
+ @access_token.post("/1.1/statuses/destroy/#{id}.json")
126
+ end
127
+
128
+ #GET account/verify_credentials
129
+ def verify_credentials
130
+ return JSON.parse(@access_token.get("/1.1/account/verify_credentials.json").body)
131
+ end
132
+
133
+ #POST friendships/create
134
+ def follow(screen_name="",user_id="")
135
+ @access_token.post("/1.1/friendships/create.json",
136
+ "screen_name" => screen_name,
137
+ "user_id" => user_id,
138
+ "follow" => true)
139
+ end
140
+
141
+ #POST friendships/destroy
142
+ def remove(screen_name="",user_id="")
143
+ @access_token.post("/1.1/friendships/destroy.json",
144
+ "screen_name" => screen_name,
145
+ "user_id" => user_id)
146
+ end
147
+
148
+ #GET statuses/mentions_timeline
149
+ def mentions_timeline(count="",since_id="",max_id="",trim_user="",contributor_details="",include_entities="")
150
+ return JSON.parse((@access_token.get("/1.1/statuses/mentions_timeline.json",
151
+ "count" => count,
152
+ "since_id" => since_id,
153
+ "max_id" => max_id,
154
+ "trim_user" => trim_user,
155
+ "contributor_details" =>contributor_details,
156
+ "include_entities" =>include_entities)
157
+ ).body)
158
+ end
159
+
160
+ #GET statuses/home_timeline
161
+ def home_timeline(count,since_id="",max_id="",trim_user="",include_entities="",include_user_entities="")
162
+ return JSON.parse(@access_token.get("/1.1/statuses/home_timeline.json",
163
+ "count" =>count,
164
+ "since_id" => since_id,
165
+ "max_id" => max_id,
166
+ "trim_user" => trim_user,
167
+ "include_entities" => include_entities,
168
+ "include_user_entities" => include_user_entities
169
+ ).body)
170
+ end
171
+
172
+ #GET statuses/user_timeline
173
+ def user_timeline(user_id="",screen_name="",since_id="",count="",max_id="",trim_user="",exclude_replies="",contributor_details="",include_rts="")
174
+ return JSON.parse(@access_token.get("/1.1/statuses/user_timeline.json",
175
+ "user_id" => user_id,
176
+ "screen_name" => screen_name,
177
+ "since_id" => since_id,
178
+ "count" => count,
179
+ "max_id" => max_id,
180
+ "trim_user" => trim_user,
181
+ "exclude_replies" => exclude_replies,
182
+ "contributor_details" => contributor_details,
183
+ "include_rts" => include_rts
184
+ ).body)
185
+ end
186
+
187
+ #GET statuses/retweets_of_me
188
+ def get_rom(count,since_id="",max_id="",trim_user="",include_entities="",include_user_entities="")
189
+ return JSON.parse(@access_token.get("/1.1/statuses/retweets_of_me.json",
190
+ "count" =>count,
191
+ "since_id" => since_id,
192
+ "max_id" => max_id,
193
+ "trim_user" => trim_user,
194
+ "include_entities" => include_entities,
195
+ "include_user_entities" => include_user_entities
196
+ ).body)
197
+ end
198
+
199
+ ##########################################################################
200
+
201
+ #POST direct_messages/new
202
+ def dm_send(user_id="",screen_name="",text)
203
+ if user_id.empty? then
204
+ return "Error. user_id => empty"
205
+ end
206
+ @access_token.get("/1.1/direct_messages/new.json",
207
+ "user_id" => user_id,
208
+ "screen_name" => screen_name,
209
+ "text" => text)
210
+ end
211
+
212
+ #GET direct_messages/sent
213
+ def get_sent_dm(since_id="",max_id="",count="",page="",include_entities="")
214
+ if since_id.empty? || max_id.empty? || count.empty? || page.empty? || include_entities.empty? then
215
+ return "Error. same parms is empty"
216
+ end
217
+
218
+ return JSON.parse(@access_token.get("/1.1/direct_messages/sent.json",
219
+ "since_id" => since_id,
220
+ "max_id" => max_id,
221
+ "count" => count,
222
+ "page" => page,
223
+ "include_entities" => include_entities,
224
+ ).body)
225
+ end
226
+
227
+ #GET direct_messages
228
+ def dm_msgs(since_id="",max_id="",count="",include_entities="",skip_status="")
229
+ return JSON.parse(@access_token.get("/1.1/direct_messages.json",
230
+ "since_id" => since_id,
231
+ "max_id" => max_id,
232
+ "count" => count,
233
+ "include_entities" => include_entities,
234
+ "skip_status" => skip_status
235
+ ).body)
236
+ end
237
+
238
+ #POST direct_messages/destroy
239
+ def post_dm_destory(id,include_entities="")
240
+ @access_token.post("/1.1/direct_messages/destroy.json",
241
+ "id" => id,
242
+ "include_entities" => include_entities)
243
+ end
244
+
245
+ ##########################################################################
246
+
247
+ #GET followers/ids
248
+ def follower_ids(user_id="",screen_name="",cursor="",stringify_ids="",count="")
249
+ return JSON.parse(@access_token.get("/1.1/followers/ids.json",
250
+ "user_id" => user_id,
251
+ "screen_name" => screen_name,
252
+ "cursor" => cursor,
253
+ "stringify_ids" => stringify_ids,
254
+ "count" => count
255
+ ).body)
256
+ end
257
+
258
+ #GET username_available?
259
+ #存在確認なので真偽値は逆となる trueなら使用可(IDとして新規作成時に)
260
+ def user_ava?(user_name)
261
+
262
+ #for https
263
+ https = Net::HTTP.new("twitter.com",443)
264
+ https.use_ssl = true
265
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
266
+
267
+ #get and parse
268
+ get_torf = JSON.parse(https.get("/users/username_available",
269
+ "user_name" => user_name).body)["valid"]
270
+
271
+ if get_torf == false
272
+ return true#存在する
273
+ elsif get_torf == true
274
+ return false#存在しない
275
+ end
276
+ end
277
+
278
+ #GET account/rate_limit_status
279
+ def get_rate_limit
280
+ return JSON.parse((@access_token.get("/1.1/application/rate_limit_status.json")).body)
281
+ end
282
+
283
+ #GET friendships/show
284
+ def friendships?(source_id="",source_screen_name="",target_id="",target_screen_name="")
285
+
286
+ #Convert and Build
287
+ if source_id.empty? == true && source_screen_name.empty? == false
288
+ source_ = "source_screen_name"
289
+ source=source_screen_name
290
+ elsif source_id.empty? == false && source_screen_name.empty? == true
291
+ source_ = "source_id"
292
+ source = source_id
293
+ else
294
+ return "ERROR"
295
+ end
296
+
297
+ if target_id.empty? ==true && target_screen_name.empty? == false
298
+ target_ = "target_screen_name"
299
+ target = target_screen_name
300
+ elsif target_id.empty? ==false && target_screen_name.empty? == true
301
+ target_ = "target_id"
302
+ target = target_id
303
+ else
304
+ return "ERROR"
305
+ end
306
+
307
+ return JSON.parse(@access_token.get("/1.1/friendships/show.json?#{source_}=#{source}&#{target_}=#{target}").body)
308
+ end
309
+
310
+ ##########################################################################
311
+ #Streaming APIs
312
+ #Usage:Call from block
313
+
314
+ #UserStream
315
+ def user_stream(&block)
316
+ uri = URI.parse("https://userstream.twitter.com/1.1/user.json")
317
+ https = Net::HTTP.new(uri.host, uri.port)
318
+ https.use_ssl = true
319
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
320
+
321
+ https.start do |https|
322
+ request = Net::HTTP::Get.new(uri.request_uri)
323
+ request.oauth!(https, @consumer, @access_token)
324
+ buf = ""
325
+ https.request(request) do |response|
326
+ response.read_body do |chunk|
327
+ buf << chunk
328
+ while(line = buf[/.*(\r\n)+/m])
329
+ begin
330
+ buf.sub!(line,"")
331
+ line.strip!
332
+ status = JSON.parse(line)
333
+ rescue
334
+ break
335
+ end
336
+ yield status
337
+ end
338
+ end
339
+ end
340
+ end
341
+ end
342
+
343
+ #Public Sample
344
+ def public_sample(&block)
345
+ uri = URI.parse("https://stream.twitter.com/1.1/statuses/sample.json")
346
+ https = Net::HTTP.new(uri.host, uri.port)
347
+ https.use_ssl = true
348
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
349
+ https.start do |https|
350
+ request = Net::HTTP::Get.new(uri.request_uri+"track=twitter")
351
+ request.oauth!(https, @consumer, @access_token)
352
+ buf = ""
353
+ https.request(request) do |response|
354
+ response.read_body do |chunk|
355
+ buf << chunk
356
+ while(line = buf[/.*(\r\n)+/m])
357
+ begin
358
+ buf.sub!(line,"")
359
+ line.strip!
360
+ status = JSON.parse(line)
361
+ rescue
362
+ break
363
+ end
364
+ yield status
365
+ end
366
+ end
367
+ end
368
+ end
369
+ end
370
+ end#End of Class TwitRuby
371
+ end#nd of Module TwitRuby
data/twitruby.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'twitruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "TwitRuby"
8
+ spec.version = TwitRuby::VERSION
9
+ spec.authors = ["alphaKAI"]
10
+ spec.email = ["alpha.kai.net@alpha-kai-net.info"]
11
+ spec.description = %q{This is one of the Twitter Libraries.}
12
+ spec.summary = %q{This is one of the Twitter Libraries.}
13
+ spec.homepage = "http://alpha-kai-net.info"
14
+ spec.license = "GPLv3"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: TwitRuby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - alphaKAI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This is one of the Twitter Libraries.
42
+ email:
43
+ - alpha.kai.net@alpha-kai-net.info
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - LICENSE.txt
50
+ - README.md
51
+ - Rakefile
52
+ - doc/README_rdoc.html
53
+ - doc/TwitRuby.html
54
+ - doc/created.rid
55
+ - doc/images/add.png
56
+ - doc/images/arrow_up.png
57
+ - doc/images/brick.png
58
+ - doc/images/brick_link.png
59
+ - doc/images/bug.png
60
+ - doc/images/bullet_black.png
61
+ - doc/images/bullet_toggle_minus.png
62
+ - doc/images/bullet_toggle_plus.png
63
+ - doc/images/date.png
64
+ - doc/images/delete.png
65
+ - doc/images/find.png
66
+ - doc/images/loadingAnimation.gif
67
+ - doc/images/macFFBgHack.png
68
+ - doc/images/package.png
69
+ - doc/images/page_green.png
70
+ - doc/images/page_white_text.png
71
+ - doc/images/page_white_width.png
72
+ - doc/images/plugin.png
73
+ - doc/images/ruby.png
74
+ - doc/images/tag_blue.png
75
+ - doc/images/tag_green.png
76
+ - doc/images/transparent.png
77
+ - doc/images/wrench.png
78
+ - doc/images/wrench_orange.png
79
+ - doc/images/zoom.png
80
+ - doc/index.html
81
+ - doc/js/darkfish.js
82
+ - doc/js/jquery.js
83
+ - doc/js/navigation.js
84
+ - doc/js/search.js
85
+ - doc/js/search_index.js
86
+ - doc/js/searcher.js
87
+ - doc/rdoc.css
88
+ - doc/table_of_contents.html
89
+ - lib/func_sample.rb
90
+ - lib/twitruby.rb
91
+ - lib/twitruby.rb~
92
+ - lib/twitruby/version.rb
93
+ - lib/twitruby/version.rb~
94
+ - twitruby.gemspec
95
+ homepage: http://alpha-kai-net.info
96
+ licenses:
97
+ - GPLv3
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.0.3
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: This is one of the Twitter Libraries.
119
+ test_files: []