Module: T::Requestable

Constant Summary collapse

DEFAULT_HOST =
'api.twitter.com'
DEFAULT_PROTOCOL =
'https'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/t/requestable.rb', line 8

def self.included(base)

private

  def base_url
    "#{protocol}://#{host}"
  end

  def client
    return @client if @client
    @rcfile.path = parent_options['profile'] if parent_options['profile']
    @client = Twitter::Client.new(
      :endpoint => base_url,
      :consumer_key => @rcfile.default_consumer_key,
      :consumer_secret => @rcfile.default_consumer_secret,
      :oauth_token => @rcfile.default_token,
      :oauth_token_secret  => @rcfile.default_secret
    )
  end

  def host
    parent_options['host'] || DEFAULT_HOST
  end

  def protocol
    parent_options['no_ssl'] ? 'http' : DEFAULT_PROTOCOL
  end
end

Instance Method Details

#base_urlObject



12
13
14
# File 'lib/t/requestable.rb', line 12

def base_url
  "#{protocol}://#{host}"
end

#clientObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/t/requestable.rb', line 16

def client
  return @client if @client
  @rcfile.path = parent_options['profile'] if parent_options['profile']
  @client = Twitter::Client.new(
    :endpoint => base_url,
    :consumer_key => @rcfile.default_consumer_key,
    :consumer_secret => @rcfile.default_consumer_secret,
    :oauth_token => @rcfile.default_token,
    :oauth_token_secret  => @rcfile.default_secret
  )
end

#hostObject



28
29
30
# File 'lib/t/requestable.rb', line 28

def host
  parent_options['host'] || DEFAULT_HOST
end

#protocolObject



32
33
34
# File 'lib/t/requestable.rb', line 32

def protocol
  parent_options['no_ssl'] ? 'http' : DEFAULT_PROTOCOL
end