Class: Tuiter::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/tuiter/utils.rb

Instance Method Summary collapse

Constructor Details

#initialize(authentication_type, options) ⇒ Request

if :basic => options = :password if :oauth => options = consumer_secret, token, secret



7
8
9
10
11
12
13
14
# File 'lib/tuiter/utils.rb', line 7

def initialize(authentication_type, options)
  if [:basic, :oauth].include?(authentication_type)
    @authentication_type = authentication_type
  else
    raise StandardError, "Type of Authentication not informed (must be :basic or :oauth)."
  end
  @config = options
end

Instance Method Details

#authorize(token, secret) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/tuiter/utils.rb', line 20

def authorize(token, secret)
  if @authentication_type == :oauth
    request_token = OAuth::RequestToken.new(oauth_consumer, token, secret)
    @access_token = request_token.get_access_token
    @config[:token] = @access_token.token
    @config[:secret] = @access_token.secret
    @access_token
  end
end

#delete(path, headers = {}) ⇒ Object



46
47
48
# File 'lib/tuiter/utils.rb', line 46

def delete(path, headers = {})
  request(:delete, path, headers)
end

#get(path, headers = {}) ⇒ Object



34
35
36
# File 'lib/tuiter/utils.rb', line 34

def get(path, headers = {})
  request(:get, path, headers)
end

#is_basic?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/tuiter/utils.rb', line 50

def is_basic?
  return (@authentication_type == :basic)
end

#is_oauth?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/tuiter/utils.rb', line 54

def is_oauth?
  return (@authentication_type == :oauth)
end

#post(path, body = '', headers = {}) ⇒ Object



38
39
40
# File 'lib/tuiter/utils.rb', line 38

def post(path, body = '', headers = {})
  request(:post, path, body, headers)
end

#put(path, body = '', headers = {}) ⇒ Object



42
43
44
# File 'lib/tuiter/utils.rb', line 42

def put(path, body = '', headers = {})
  request(:post, path, body, headers)
end

#request(http_method, path, *arguments) ⇒ Object



30
31
32
# File 'lib/tuiter/utils.rb', line 30

def request(http_method, path, *arguments)
  send(("#{@authentication_type.to_s}_request").to_sym, http_method, path, *arguments)
end

#request_tokenObject



16
17
18
# File 'lib/tuiter/utils.rb', line 16

def request_token
  oauth_consumer.get_request_token if @authentication_type == :oauth
end