Class: InstLtiTwitter::ApiController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- InstLtiTwitter::ApiController
- Defined in:
- app/controllers/inst_lti_twitter/api_controller.rb
Instance Method Summary collapse
Methods inherited from ApplicationController
Instance Method Details
#embed ⇒ Object
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 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_check ⇒ Object
25 26 27 |
# File 'app/controllers/inst_lti_twitter/api_controller.rb', line 25 def health_check head 200 end |
#tweets ⇒ Object
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_config ⇒ Object
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.(enabled: true) tc.canvas_resource_selection!(enabled: true) render xml: tc.to_xml end |