Class: InstLtiTwitter::ApiController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#set_default_headers

Instance Method Details

#embedObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/inst_lti_twitter/api_controller.rb', line 46

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

#health_checkObject



25
26
27
# File 'app/controllers/inst_lti_twitter/api_controller.rb', line 25

def health_check
  head 200
end

#tweetsObject



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

def tweets
  client = Twitter::REST::Client.new do |config|
    config.consumer_key        = ENV["INST_LTI_TWITTER_CONSUMER_KEY"]
    config.consumer_secret     = ENV["INST_LTI_TWITTER_CONSUMER_SECRET"]
    config.access_token        = ENV["INST_LTI_TWITTER_ACCESS_TOKEN"]
    config.access_token_secret = ENV["INST_LTI_TWITTER_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

#xml_configObject



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

def xml_config
  host = "#{request.protocol}#{request.host_with_port}"
  url = "#{host}#{root_path}"
  title = "Twitter"
  tool_id = "twitter_lti"
  tc = IMS::LTI::ToolConfig.new(:title => title, :launch_url => url)
  tc.extend IMS::LTI::Extensions::Canvas::ToolConfig
  tc.description = "Embed a Twitter stream"
  tc.canvas_privacy_anonymous!
  tc.canvas_domain!(request.host)
  tc.canvas_icon_url!("#{host}/assets/inst_lti_twitter/icon.png")
  tc.canvas_text!(title)
  tc.set_ext_param('canvas.instructure.com', :tool_id, tool_id)
  tc.canvas_editor_button!(enabled: true)
  tc.canvas_resource_selection!(enabled: true)
  render xml: tc.to_xml
end