Class: TwitterLti::ApiController

Inherits:
ApplicationController show all
Defined in:
app/controllers/twitter_lti/api_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#set_default_headers

Instance Method Details

#embedObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/twitter_lti/api_controller.rb', line 25

def embed
  tp = IMS::LTI::ToolProvider.new(nil, nil, params[:launch_params])
  tp.extend IMS::LTI::Extensions::Content::ToolProvider

  title, url = generate_url(params)
  width = 500
  height = 530
  redirect_url = build_url(tp, title, url, width, height)

  if redirect_url.present?
    render json: { redirectUrl: redirect_url }
  else
    render json: {
      url: url,
      title: title,
      width: width,
      height: height
    }
  end
end

#tweetsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/twitter_lti/api_controller.rb', line 8

def tweets
  client = Twitter::REST::Client.new do |config|
    config.consumer_key        = ENV["CONSUMER_KEY"]
    config.consumer_secret     = ENV["CONSUMER_SECRET"]
    config.access_token        = ENV["ACCESS_TOKEN"]
    config.access_token_secret = ENV["ACCESS_TOKEN_SECRET"]
  end
  max = params[:max] || 10
  tweets = []
  if params[:hashtag].present?
    tweets = client.search("##{params[:hashtag]}", count: max, result_type: "recent")
  elsif params[:username].present?
    tweets = client.user_timeline(params[:username], count: max, result_type: "recent")
  end
  render json: tweets
end