Class: EventMachine::Twitter::Client
- Inherits:
-
Object
- Object
- EventMachine::Twitter::Client
show all
- Defined in:
- lib/em-twitter/client.rb
Constant Summary
collapse
- CALLBACKS =
[
:each_item_callback,
:error_callback,
:unauthorized_callback,
:forbidden_callback,
:not_found_callback,
:not_acceptable_callback,
:too_long_callback,
:range_unacceptable_callback,
:enhance_your_calm_callback,
:reconnect_callback,
:max_reconnects_callback,
:close_callback,
:no_data_callback,
:service_unavailable_callback
].freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/em-twitter/client.rb', line 34
def initialize(options = {})
@options = DEFAULT_CONNECTION_OPTIONS.merge(options)
validate_client
@host = @options[:host]
@port = @options[:port]
if @options[:proxy] && @options[:proxy][:uri]
proxy_uri = URI.parse(@options[:proxy][:uri])
@host = proxy_uri.host
@port = proxy_uri.port
end
@connection = nil
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Delegate to EM::Twitter::Connection
112
113
114
115
|
# File 'lib/em-twitter/client.rb', line 112
def method_missing(method, *args, &block)
return super unless @connection.respond_to?(method)
@connection.send(method, *args, &block)
end
|
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
24
25
26
|
# File 'lib/em-twitter/client.rb', line 24
def connection
@connection
end
|
#host ⇒ Object
Returns the value of attribute host.
24
25
26
|
# File 'lib/em-twitter/client.rb', line 24
def host
@host
end
|
#options ⇒ Object
Returns the value of attribute options.
24
25
26
|
# File 'lib/em-twitter/client.rb', line 24
def options
@options
end
|
#port ⇒ Object
Returns the value of attribute port.
24
25
26
|
# File 'lib/em-twitter/client.rb', line 24
def port
@port
end
|
Class Method Details
.connect(options = {}) ⇒ Object
A convenience method for creating and connecting.
28
29
30
31
32
|
# File 'lib/em-twitter/client.rb', line 28
def self.connect(options = {})
new(options).tap do |client|
client.connect
end
end
|
Instance Method Details
#connect ⇒ Object
50
51
52
|
# File 'lib/em-twitter/client.rb', line 50
def connect
@connection = EM.connect(@host, @port, Connection, self, @host, @port)
end
|
#each(&block) ⇒ Object
54
55
56
|
# File 'lib/em-twitter/client.rb', line 54
def each(&block)
@each_item_callback = block
end
|
#on_close(&block) ⇒ Object
103
104
105
|
# File 'lib/em-twitter/client.rb', line 103
def on_close(&block)
@close_callback = block
end
|
#on_enhance_your_calm(&block) ⇒ Object
Also known as:
on_rate_limited
86
87
88
|
# File 'lib/em-twitter/client.rb', line 86
def on_enhance_your_calm(&block)
@enhance_your_calm_callback = block
end
|
#on_error(&block) ⇒ Object
58
59
60
|
# File 'lib/em-twitter/client.rb', line 58
def on_error(&block)
@error_callback = block
end
|
#on_forbidden(&block) ⇒ Object
66
67
68
|
# File 'lib/em-twitter/client.rb', line 66
def on_forbidden(&block)
@forbidden_callback = block
end
|
#on_max_reconnects(&block) ⇒ Object
99
100
101
|
# File 'lib/em-twitter/client.rb', line 99
def on_max_reconnects(&block)
@max_reconnects_callback = block
end
|
#on_no_data_received(&block) ⇒ Object
107
108
109
|
# File 'lib/em-twitter/client.rb', line 107
def on_no_data_received(&block)
@no_data_callback = block
end
|
#on_not_acceptable(&block) ⇒ Object
74
75
76
|
# File 'lib/em-twitter/client.rb', line 74
def on_not_acceptable(&block)
@not_acceptable_callback = block
end
|
#on_not_found(&block) ⇒ Object
70
71
72
|
# File 'lib/em-twitter/client.rb', line 70
def on_not_found(&block)
@not_found_callback = block
end
|
#on_range_unacceptable(&block) ⇒ Object
82
83
84
|
# File 'lib/em-twitter/client.rb', line 82
def on_range_unacceptable(&block)
@range_unacceptable_callback = block
end
|
#on_reconnect(&block) ⇒ Object
95
96
97
|
# File 'lib/em-twitter/client.rb', line 95
def on_reconnect(&block)
@reconnect_callback = block
end
|
#on_service_unavailable(&block) ⇒ Object
91
92
93
|
# File 'lib/em-twitter/client.rb', line 91
def on_service_unavailable(&block)
@service_unavailable_callback = block
end
|
#on_too_long(&block) ⇒ Object
78
79
80
|
# File 'lib/em-twitter/client.rb', line 78
def on_too_long(&block)
@too_long_callback = block
end
|
#on_unauthorized(&block) ⇒ Object
62
63
64
|
# File 'lib/em-twitter/client.rb', line 62
def on_unauthorized(&block)
@unauthorized_callback = block
end
|
#respond_to?(method, include_all = false) ⇒ Boolean
117
118
119
|
# File 'lib/em-twitter/client.rb', line 117
def respond_to?(method, include_all=false)
@connection.respond_to?(method, include_all) || super(method, include_all)
end
|