Class: Twitter::RESTClient

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter/rest_api.rb

Constant Summary collapse

API_ADDRESS =
'twitter.com'

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ RESTClient

Returns a new instance of RESTClient.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/twitter/rest_api.rb', line 9

def initialize(options = {})
  @login   = options[:login]
  @password   = options[:password]

  @port       = options[:port] || 80
  @ssl_port   = options[:ssl_port] || 443
  @proxy_addr = options[:proxy_addr]
  @proxy_port = options[:proxy_port]
  @proxy_user = options[:proxy_user]
  @proxy_pass = options[:proxy_pass]

  @header = {'User-Agent' => "twitter-ruby/#{Twitter::VERSION}"}
  @header.merge! options[:header] if options[:header]
end

Instance Method Details

#delete(path, params = {}, require_auth = true) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/twitter/rest_api.rb', line 46

def delete(path, params = {}, require_auth = true)
  path += '.json'

  params_str = Util.to_params_str(params)
  path += "?#{params_str}" if params_str

  req = Net::HTTP::Post.new(path, @header)
  req.basic_auth @login, @password if require_auth

  http_request(req, require_auth)
end

#get(path, params = {}, require_auth = true) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/twitter/rest_api.rb', line 24

def get(path, params = {}, require_auth = true)
  path += '.json'

  params_str = Util.to_params_str(params)
  path += "?#{params_str}" if params_str

  req = Net::HTTP::Get.new(path, @header)
  req.basic_auth @login, @password if require_auth

  http_request(req, require_auth)
end

#post(path, params = {}, require_auth = true) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/twitter/rest_api.rb', line 36

def post(path, params = {}, require_auth = true)
  path += '.json'

  req = Net::HTTP::Post.new(path, @header)
  req.body = Util.to_params_str(params)
  req.basic_auth @login, @password if require_auth

  http_request(req, require_auth)
end