cycle method added to auto cycle through tweets and exception handling is modified to capture all errors that raise from twitter

This commit is contained in:
AnithaPal 2016-07-27 17:02:40 -04:00
parent f29a15b8e4
commit 881518f1f3
10 changed files with 73 additions and 56 deletions

View file

@ -57,6 +57,11 @@ There are a couple of environment variables you can set to configure OSEM.
We use [Stripe](https://stripe.com) for accepting your ticket payments securely over the web. We use [Stripe](https://stripe.com) for accepting your ticket payments securely over the web.
Our application uses iFrame for accepting your user's payment details without storing them, making the application PCI SAQ-A Compliant. Our application uses iFrame for accepting your user's payment details without storing them, making the application PCI SAQ-A Compliant.
Please refer to [PAYMENTS](PAYMENTS.md) documentation file for setting up your stripe account and start accepting payments from your users. Please refer to [PAYMENTS](PAYMENTS.md) documentation file for setting up your stripe account and start accepting payments from your users.
| CLOUDINARY_URL | *string* | Configure your cloudinary.com cloud name and api key/secret
| OSEM_TWITTER_CONSUMER_KEY | *string* | To embed tweets about the conference in the conference wide page
| OSEM_TWITTER_CONSUMER_SECRET | *string* | To embed tweets about the conference in the conference wide page
| OSEM_TWITTER_ACCESS_TOKEN | *string* | To embed tweets about the conference in the conference wide page
| OSEM_TWITTER_ACCESS_TOKEN_SECRET | *string* | To embed tweets about the conference in the conference wide page
## Dependencies ## Dependencies

View file

@ -1,6 +1,17 @@
$(document).ready(function() { $(document).ready(function() {
// will call refreshCurrentEvents every 15 minutes // will call refreshCurrentEvents every 15 minutes
setInterval(refreshCurrentEvents, 900000) setInterval(refreshCurrentEvents, 900000)
// To cycle through tweets
var tweets = $('div[id^="tweet"]').hide();
var i = 0;
(function cycle() {
tweets.eq(i).show(0)
.delay(5000)
.hide(0, cycle);
i = ++i % tweets.length;
})();
}); });
function refreshCurrentEvents(){ function refreshCurrentEvents(){

View file

@ -174,20 +174,21 @@ module Admin
end end
def conference_wide_screen def conference_wide_screen
#To display sponsors in the conference wide information page # To display sponsors in the conference wide information page
@conference = Conference.find_by(short_title: params[:id]) @conference = Conference.find_by(short_title: params[:id])
@sponsors = @conference.sponsors @sponsors = @conference.sponsors
@program = @conference.program @program = @conference.program
@current_events = @conference.program.events.confirmed.select{ |event| event.is_current?} @current_events = @conference.program.events.confirmed.select(&:current?)
@tweets = twitter_client.search_tweets(3, @conference.contact.social_tag) @tweets = twitter_client.search_tweets(15, @conference.contact.social_tag)
respond_to do |format| respond_to do |format|
format.html{render layout: "conference_wide_screen"} format.html{render layout: 'conference_wide_screen'}
format.js {render :action=> "conference_wide_screen.js.haml"} format.js {render action: 'conference_wide_screen.js.haml'}
end end
end end
private private
# To create a twitter client # To create a twitter client
def twitter_client def twitter_client
@twitter_client ||= TwitterWrapper.new @twitter_client ||= TwitterWrapper.new

View file

@ -41,8 +41,6 @@ class Event < ActiveRecord::Base
scope :canceled, -> { where(state: 'canceled') } scope :canceled, -> { where(state: 'canceled') }
scope :withdrawn, -> { where(state: 'withdrawn') } scope :withdrawn, -> { where(state: 'withdrawn') }
scope :highlighted, -> { where(is_highlight: true) } scope :highlighted, -> { where(is_highlight: true) }
state_machine initial: :new do state_machine initial: :new do
state :new state :new
@ -250,10 +248,10 @@ class Event < ActiveRecord::Base
end end
## ##
#Compares event start_time, end_with with current time to predict current events # Compares event start_time, end_with with current time to predict current events
# #
def is_current? def current?
Time.current >= self.start_time && Time.current <= end_time Time.current >= self.start_time && Time.current <= self.end_time
end end
private private
@ -305,10 +303,10 @@ class Event < ActiveRecord::Base
end end
## ##
#Compares event start_time, end_with with current time to predict current events # Compares event start_time, end_with with current time to predict current events
# #
def is_current? def current?
Time.current >= self.start_time && Time.current <= end_time Time.current >= self.start_time && Time.current <= self.end_time
end end
end end

View file

@ -3,23 +3,19 @@ class TwitterWrapper
def initialize def initialize
@client = Twitter::REST::Client.new do |config| @client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV["OSEM_TWITTER_CONSUMER_KEY"] config.consumer_key = ENV['OSEM_TWITTER_CONSUMER_KEY']
config.consumer_secret = ENV["OSEM_TWITTER_CONSUMER_SECRET"] config.consumer_secret = ENV['OSEM_TWITTER_CONSUMER_SECRET']
config.access_token = ENV["OSEM_TWITTER_ACCESS_TOKEN"] config.access_token = ENV['OSEM_TWITTER_ACCESS_TOKEN']
config.access_token_secret = ENV["OSEM_TWITTER_ACCESS_TOKEN_SECRET"] config.access_token_secret = ENV['OSEM_TWITTER_ACCESS_TOKEN_SECRET']
end end
end end
## ##
#Fetches tweets from twitter api based on search_term and no_of_tweets # Fetches tweets from twitter api based on search_term and no_of_tweets
# #
def search_tweets(no_of_tweets, search_term) def search_tweets(no_of_tweets, search_term)
begin @client.search(search_term, result_type: 'recent').take(no_of_tweets).collect
@client.search(search_term, result_type: "recent").take(no_of_tweets).collect rescue
rescue Twitter::Error::TooManyRequests => error nil
sleep error.rate_limit.reset_in + 1
retry
end
end end
end end

View file

@ -1,21 +1,16 @@
#main-display - if @conference.present?
- if @conference.present? .row
%section#main-heading .col-md-12.text-center
.container %h1
.row = @conference.title
.col-md-12.text-center - if @conference.description.present?
%h1 %h3
= @conference.title = @conference.description
- if @conference.description.present?
%h3
= @conference.description
- if @program.present? - if @program.present?
%section#event-display .row
= render 'current_events' = render 'current_events'
- if @conference.contact.social_tag.present? - if @conference.contact.social_tag.present? && @tweets.present?
%section#tweets-display .row
- if @tweets.present? = render 'conference_tweets'
= render 'conference_tweets'
- if @sponsors.any? - if @sponsors.any?
%section#sponsor-display = render 'sponsors'
= render 'sponsors'

View file

@ -54,6 +54,13 @@ production:
facebook_key: '' facebook_key: ''
facebook_secret: '' facebook_secret: ''
# Register your application with Twitter from
# https://apps.twitter.com/
twitter_consumer_key: ''
twitter_consumer_secret: ''
twitter_access_token: ''
twitter_access_token_secret: ''
# Developers do not need to register their application for suse account to # Developers do not need to register their application for suse account to
# work. You must, however, add some sample value to the variables, for the # work. You must, however, add some sample value to the variables, for the
# login option to appear. For example: # login option to appear. For example:

View file

@ -57,3 +57,9 @@ OSEM_SMTP_DOMAIN=""
# Enable the usage of the devise ichain plugin # Enable the usage of the devise ichain plugin
OSEM_ICHAIN_ENABLED=false OSEM_ICHAIN_ENABLED=false
# To embed tweets about the conference in the conference wide screen
OSEM_TWITTER_CONSUMER_KEY=""
OSEM_TWITTER_CONSUMER_SECRET=""
OSEM_TWITTER_ACCESS_TOKEN=""
OSEM_TWITTER_ACCESS_TOKEN_SECRET=""

View file

@ -296,8 +296,8 @@ describe Admin::ConferencesController do
describe 'GET #conference_wide_screen' do describe 'GET #conference_wide_screen' do
it 'requires organizer privileges' do it 'requires organizer privileges' do
get :conference_wide_screen, id: conference.short_title, get :conference_wide_screen, id: conference.short_title,
conference: attributes_for(:conference, conference: attributes_for(:conference,
short_title: 'ExCon') short_title: 'ExCon')
expect(response).to redirect_to(send(path)) expect(response).to redirect_to(send(path))
if message if message
expect(flash[:alert]).to match(/#{message}/) expect(flash[:alert]).to match(/#{message}/)
@ -306,7 +306,6 @@ describe Admin::ConferencesController do
end end
end end
describe 'participant access' do describe 'participant access' do
before(:each) do before(:each) do
sign_in(participant) sign_in(participant)

View file

@ -328,27 +328,26 @@ describe Event do
end end
end end
describe 'current?' do
describe 'is_current?' do
let(:past_event) { create(:event, program: conference.program) } let(:past_event) { create(:event, program: conference.program) }
let(:future_event) { create(:event, program: conference.program) } let(:future_event) { create(:event, program: conference.program) }
before do before do
event.update_attributes(start_time: "#{Time.current}") event.update_attributes(start_time: Time.current.to_s)
past_event.update_attributes(start_time: "#{Time.current - 2.days}") past_event.update_attributes(start_time: (Time.current - 2.days).to_s)
future_event.update_attributes(start_time: "#{Time.current + 2.days}") future_event.update_attributes(start_time: (Time.current + 2.days).to_s)
end end
it 'returns false for a completed event' do it 'returns false for a completed event' do
expect(past_event.is_current?).to be_falsey expect(past_event.current?).to be_falsey
end end
it 'returns false for a future event' do it 'returns false for a future event' do
expect(future_event.is_current?).to be_falsey expect(future_event.current?).to be_falsey
end end
it 'returns true for a current event' do it 'returns true for a current event' do
expect(event.is_current?).to be_truthy expect(event.current?).to be_truthy
end end
end end