Class: Strobe::Addons::Social::Twitter

Inherits:
Object
  • Object
show all
Defined in:
lib/strobe/addons/social/twitter.rb

Defined Under Namespace

Classes: NotFoundError, ServerError

Constant Summary collapse

"twitter_access_token"
REQUEST_TOKEN_SECRETS =
{}
ACCESS_TOKEN_SECRETS =
{}

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Twitter

Returns a new instance of Twitter.



19
20
21
22
23
24
25
# File 'lib/strobe/addons/social/twitter.rb', line 19

def initialize(settings)
  @settings        = settings
  @consumer_key    = settings["social.twitter.consumer_key"]
  @consumer_secret = settings["social.twitter.consumer_secret"]
  @url             = settings["social.twitter.url"] || "http://api.twitter.com"
  @consumer        = OAuth::Consumer.new(@consumer_key, @consumer_secret, :site => @url)
end

Instance Method Details

#_call(env) ⇒ Object

Raises:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/strobe/addons/social/twitter.rb', line 33

def _call(env)
  @request = Rack::Request.new(env)
  @response = Rack::Response.new

  raise ServerError, "Social addon requires `social.twitter.consumer_key` configuration" unless @consumer_key
  raise ServerError, "Social addon requires `social.twitter.consumer_secret` configuration"unless @consumer_secret

  case @request.path_info
  when "/authentication"
    env['REQUEST_METHOD'] == 'DELETE' ? unauthenticate : authenticate
  when "/callback"
    callback
  else
    proxy
  end

  @response.finish
end

#call(env) ⇒ Object



27
28
29
30
31
# File 'lib/strobe/addons/social/twitter.rb', line 27

def call(env)
  dup._call(env)
rescue ServerError, NotFoundError => error
  Rack::Response.new("#{error.message}\n", error.code, "Content-Type" => "text/plain").finish
end