em-http-request 0.2.9 → 0.3.0

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.
@@ -1,50 +1,50 @@
1
- # Courtesy of Darcy Laycock:
2
- # http://gist.github.com/265261
3
- #
4
-
5
- require 'rubygems'
6
-
7
- require 'em-http'
8
- require 'oauth'
9
-
10
- # At a minimum, require 'oauth/request_proxy/em_http_request'
11
- # for this example, we'll use Net::HTTP like support.
12
- require 'oauth/client/em_http'
13
-
14
- # You need two things: an oauth consumer and an access token.
15
- # You need to generate an access token, I suggest looking elsewhere how to do that or wait for a full tutorial.
16
- # For a consumer key / consumer secret, signup for an app at:
17
- # http://twitter.com/apps/new
18
-
19
- # Edit in your details.
20
- CONSUMER_KEY = ""
21
- CONSUMER_SECRET = ""
22
- ACCESS_TOKEN = ""
23
- ACCESS_TOKEN_SECRET = ""
24
-
25
- def twitter_oauth_consumer
26
- @twitter_oauth_consumer ||= OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site => "http://twitter.com")
27
- end
28
-
29
- def twitter_oauth_access_token
30
- @twitter_oauth_access_token ||= OAuth::AccessToken.new(twitter_oauth_consumer, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
31
- end
32
-
33
- EM.run do
34
-
35
- request = EventMachine::HttpRequest.new('http://twitter.com/statuses/update.json')
36
- http = request.post(:body => {'status' => 'Hello Twitter from em-http-request with OAuth'}, :head => {"Content-Type" => "application/x-www-form-urlencoded"}) do |client|
37
- twitter_oauth_consumer.sign!(client, twitter_oauth_access_token)
38
- end
39
-
40
- http.callback do
41
- puts "Response: #{http.response} (Code: #{http.response_header.status})"
42
- EM.stop_event_loop
43
- end
44
-
45
- http.errback do
46
- puts "Failed to post"
47
- EM.stop_event_loop
48
- end
49
-
1
+ # Courtesy of Darcy Laycock:
2
+ # http://gist.github.com/265261
3
+ #
4
+
5
+ require 'rubygems'
6
+
7
+ require 'em-http'
8
+ require 'oauth'
9
+
10
+ # At a minimum, require 'oauth/request_proxy/em_http_request'
11
+ # for this example, we'll use Net::HTTP like support.
12
+ require 'oauth/client/em_http'
13
+
14
+ # You need two things: an oauth consumer and an access token.
15
+ # You need to generate an access token, I suggest looking elsewhere how to do that or wait for a full tutorial.
16
+ # For a consumer key / consumer secret, signup for an app at:
17
+ # http://twitter.com/apps/new
18
+
19
+ # Edit in your details.
20
+ CONSUMER_KEY = ""
21
+ CONSUMER_SECRET = ""
22
+ ACCESS_TOKEN = ""
23
+ ACCESS_TOKEN_SECRET = ""
24
+
25
+ def twitter_oauth_consumer
26
+ @twitter_oauth_consumer ||= OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site => "http://twitter.com")
27
+ end
28
+
29
+ def twitter_oauth_access_token
30
+ @twitter_oauth_access_token ||= OAuth::AccessToken.new(twitter_oauth_consumer, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
31
+ end
32
+
33
+ EM.run do
34
+
35
+ request = EventMachine::HttpRequest.new('http://twitter.com/statuses/update.json')
36
+ http = request.post(:body => {'status' => 'Hello Twitter from em-http-request with OAuth'}, :head => {"Content-Type" => "application/x-www-form-urlencoded"}) do |client|
37
+ twitter_oauth_consumer.sign!(client, twitter_oauth_access_token)
38
+ end
39
+
40
+ http.callback do
41
+ puts "Response: #{http.response} (Code: #{http.response_header.status})"
42
+ EM.stop_event_loop
43
+ end
44
+
45
+ http.errback do
46
+ puts "Failed to post"
47
+ EM.stop_event_loop
48
+ end
49
+
50
50
  end
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'eventmachine'
3
+ require '../lib/em-http'
4
+
5
+ EM.run do
6
+ # Establish a SOCKS5 tunnel via SSH
7
+ # ssh -D 8000 some_remote_machine
8
+
9
+ # http = EM::HttpRequest.new('http://whatismyip.org/').get({
10
+ http = EM::HttpRequest.new('http://igvita.com/').get({
11
+ :proxy => {:host => '127.0.0.1', :port => 8000, :type => :socks},
12
+ :redirects => 2
13
+ })
14
+
15
+ http.callback {
16
+ puts "#{http.response_header.status} - #{http.response.length} bytes\n"
17
+ puts http.response
18
+ EM.stop
19
+ }
20
+
21
+ http.errback {
22
+ puts "Error: " + http.error
23
+ puts http.inspect
24
+ EM.stop
25
+ }
26
+ end
@@ -1,28 +1,28 @@
1
- require 'rubygems'
2
- require 'lib/em-http'
3
-
4
- module KBHandler
5
- include EM::Protocols::LineText2
6
-
7
- def receive_line(data)
8
- p "Want to send: #{data}"
9
- p "Error status: #{$http.error?}"
10
- $http.send(data)
11
- p "After send"
12
- end
13
- end
14
-
15
- EventMachine.run {
16
- $http = EventMachine::HttpRequest.new("ws://localhost:8080/").get :timeout => 0
17
-
18
- $http.disconnect { puts 'oops' }
19
- $http.callback {
20
- puts "WebSocket connected!"
21
- }
22
-
23
- $http.stream { |msg|
24
- puts "Recieved: #{msg}"
25
- }
26
-
27
- EM.open_keyboard(KBHandler)
28
- }
1
+ require 'rubygems'
2
+ require 'lib/em-http'
3
+
4
+ module KBHandler
5
+ include EM::Protocols::LineText2
6
+
7
+ def receive_line(data)
8
+ p "Want to send: #{data}"
9
+ p "Error status: #{$http.error?}"
10
+ $http.send(data)
11
+ p "After send"
12
+ end
13
+ end
14
+
15
+ EventMachine.run {
16
+ $http = EventMachine::HttpRequest.new("ws://localhost:8080/").get :timeout => 0
17
+
18
+ $http.disconnect { puts 'oops' }
19
+ $http.callback {
20
+ puts "WebSocket connected!"
21
+ }
22
+
23
+ $http.stream { |msg|
24
+ puts "Recieved: #{msg}"
25
+ }
26
+
27
+ EM.open_keyboard(KBHandler)
28
+ }
@@ -1,8 +1,8 @@
1
- require 'rubygems'
2
- require 'em-websocket'
3
-
4
- EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080) do |ws|
5
- ws.onopen { ws.send "Hello Client!"}
6
- ws.onmessage { |msg| p "got: #{msg}"; ws.send "Pong: #{msg}" }
7
- ws.onclose { puts "WebSocket closed" }
8
- end
1
+ require 'rubygems'
2
+ require 'em-websocket'
3
+
4
+ EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080) do |ws|
5
+ ws.onopen { ws.send "Hello Client!"}
6
+ ws.onmessage { |msg| p "got: #{msg}"; ws.send "Pong: #{msg}" }
7
+ ws.onclose { puts "WebSocket closed" }
8
+ end