Class: Stocktwits::Dispatcher::Plain
- Inherits:
-
Object
- Object
- Stocktwits::Dispatcher::Plain
show all
- Includes:
- Shared
- Defined in:
- lib/stocktwits/dispatcher/plain.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Shared
#append_extension_to, #handle_response
Constructor Details
#initialize(user) ⇒ Plain
Returns a new instance of Plain.
10
11
12
13
|
# File 'lib/stocktwits/dispatcher/plain.rb', line 10
def initialize(user)
raise Stocktwits::Error, 'Dispatcher must be initialized with a User.' unless user.is_a?(Stocktwits::PlainUser)
self.user = user
end
|
Instance Attribute Details
#user ⇒ Object
Returns the value of attribute user.
8
9
10
|
# File 'lib/stocktwits/dispatcher/plain.rb', line 8
def user
@user
end
|
Instance Method Details
#delete(path, *arguments) ⇒ Object
39
40
41
|
# File 'lib/stocktwits/dispatcher/plain.rb', line 39
def delete(path, *arguments)
request(:delete, path, *arguments)
end
|
#get(path, *arguments) ⇒ Object
27
28
29
|
# File 'lib/stocktwits/dispatcher/plain.rb', line 27
def get(path, *arguments)
request(:get, path, *arguments)
end
|
#post(path, body = '', *arguments) ⇒ Object
31
32
33
|
# File 'lib/stocktwits/dispatcher/plain.rb', line 31
def post(path, body='', *arguments)
request(:post, path, body, *arguments)
end
|
#put(path, body = '', *arguments) ⇒ Object
35
36
37
|
# File 'lib/stocktwits/dispatcher/plain.rb', line 35
def put(path, body='', *arguments)
request(:put, path, body, *arguments)
end
|
#request(http_method, path, body = nil, *arguments) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/stocktwits/dispatcher/plain.rb', line 15
def request(http_method, path, body=nil, *arguments)
path = Stocktwits.path_prefix + path
path = append_extension_to(path)
response = Stocktwits.net.start{ |http|
req = "Net::HTTP::#{http_method.to_s.capitalize}".constantize.new(path, *arguments)
req.set_form_data(body) unless body.nil?
http.request(req)
}
handle_response(response)
end
|