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:
parent
f29a15b8e4
commit
881518f1f3
10 changed files with 73 additions and 56 deletions
|
|
@ -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.
|
||||
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.
|
||||
| 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
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,17 @@
|
|||
$(document).ready(function() {
|
||||
// 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(){
|
||||
|
|
|
|||
|
|
@ -174,20 +174,21 @@ module Admin
|
|||
end
|
||||
|
||||
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])
|
||||
@sponsors = @conference.sponsors
|
||||
@program = @conference.program
|
||||
@current_events = @conference.program.events.confirmed.select{ |event| event.is_current?}
|
||||
@tweets = twitter_client.search_tweets(3, @conference.contact.social_tag)
|
||||
@current_events = @conference.program.events.confirmed.select(&:current?)
|
||||
@tweets = twitter_client.search_tweets(15, @conference.contact.social_tag)
|
||||
|
||||
respond_to do |format|
|
||||
format.html{render layout: "conference_wide_screen"}
|
||||
format.js {render :action=> "conference_wide_screen.js.haml"}
|
||||
format.html{render layout: 'conference_wide_screen'}
|
||||
format.js {render action: 'conference_wide_screen.js.haml'}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# To create a twitter client
|
||||
def twitter_client
|
||||
@twitter_client ||= TwitterWrapper.new
|
||||
|
|
|
|||
|
|
@ -42,8 +42,6 @@ class Event < ActiveRecord::Base
|
|||
scope :withdrawn, -> { where(state: 'withdrawn') }
|
||||
scope :highlighted, -> { where(is_highlight: true) }
|
||||
|
||||
|
||||
|
||||
state_machine initial: :new do
|
||||
state :new
|
||||
state :withdrawn
|
||||
|
|
@ -250,10 +248,10 @@ class Event < ActiveRecord::Base
|
|||
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?
|
||||
Time.current >= self.start_time && Time.current <= end_time
|
||||
def current?
|
||||
Time.current >= self.start_time && Time.current <= self.end_time
|
||||
end
|
||||
|
||||
private
|
||||
|
|
@ -305,10 +303,10 @@ class Event < ActiveRecord::Base
|
|||
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?
|
||||
Time.current >= self.start_time && Time.current <= end_time
|
||||
def current?
|
||||
Time.current >= self.start_time && Time.current <= self.end_time
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,23 +3,19 @@ class TwitterWrapper
|
|||
|
||||
def initialize
|
||||
@client = Twitter::REST::Client.new do |config|
|
||||
config.consumer_key = ENV["OSEM_TWITTER_CONSUMER_KEY"]
|
||||
config.consumer_secret = ENV["OSEM_TWITTER_CONSUMER_SECRET"]
|
||||
config.access_token = ENV["OSEM_TWITTER_ACCESS_TOKEN"]
|
||||
config.access_token_secret = ENV["OSEM_TWITTER_ACCESS_TOKEN_SECRET"]
|
||||
config.consumer_key = ENV['OSEM_TWITTER_CONSUMER_KEY']
|
||||
config.consumer_secret = ENV['OSEM_TWITTER_CONSUMER_SECRET']
|
||||
config.access_token = ENV['OSEM_TWITTER_ACCESS_TOKEN']
|
||||
config.access_token_secret = ENV['OSEM_TWITTER_ACCESS_TOKEN_SECRET']
|
||||
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)
|
||||
begin
|
||||
@client.search(search_term, result_type: "recent").take(no_of_tweets).collect
|
||||
rescue Twitter::Error::TooManyRequests => error
|
||||
sleep error.rate_limit.reset_in + 1
|
||||
retry
|
||||
end
|
||||
@client.search(search_term, result_type: 'recent').take(no_of_tweets).collect
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,21 +1,16 @@
|
|||
#main-display
|
||||
- if @conference.present?
|
||||
%section#main-heading
|
||||
.container
|
||||
.row
|
||||
.col-md-12.text-center
|
||||
%h1
|
||||
= @conference.title
|
||||
- if @conference.description.present?
|
||||
%h3
|
||||
= @conference.description
|
||||
- if @conference.present?
|
||||
.row
|
||||
.col-md-12.text-center
|
||||
%h1
|
||||
= @conference.title
|
||||
- if @conference.description.present?
|
||||
%h3
|
||||
= @conference.description
|
||||
- if @program.present?
|
||||
%section#event-display
|
||||
.row
|
||||
= render 'current_events'
|
||||
- if @conference.contact.social_tag.present?
|
||||
%section#tweets-display
|
||||
- if @tweets.present?
|
||||
= render 'conference_tweets'
|
||||
- if @conference.contact.social_tag.present? && @tweets.present?
|
||||
.row
|
||||
= render 'conference_tweets'
|
||||
- if @sponsors.any?
|
||||
%section#sponsor-display
|
||||
= render 'sponsors'
|
||||
= render 'sponsors'
|
||||
|
|
|
|||
|
|
@ -54,6 +54,13 @@ production:
|
|||
facebook_key: ''
|
||||
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
|
||||
# work. You must, however, add some sample value to the variables, for the
|
||||
# login option to appear. For example:
|
||||
|
|
|
|||
|
|
@ -57,3 +57,9 @@ OSEM_SMTP_DOMAIN=""
|
|||
|
||||
# Enable the usage of the devise ichain plugin
|
||||
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=""
|
||||
|
|
|
|||
|
|
@ -296,8 +296,8 @@ describe Admin::ConferencesController do
|
|||
describe 'GET #conference_wide_screen' do
|
||||
it 'requires organizer privileges' do
|
||||
get :conference_wide_screen, id: conference.short_title,
|
||||
conference: attributes_for(:conference,
|
||||
short_title: 'ExCon')
|
||||
conference: attributes_for(:conference,
|
||||
short_title: 'ExCon')
|
||||
expect(response).to redirect_to(send(path))
|
||||
if message
|
||||
expect(flash[:alert]).to match(/#{message}/)
|
||||
|
|
@ -306,7 +306,6 @@ describe Admin::ConferencesController do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'participant access' do
|
||||
before(:each) do
|
||||
sign_in(participant)
|
||||
|
|
|
|||
|
|
@ -328,27 +328,26 @@ describe Event do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'is_current?' do
|
||||
describe 'current?' do
|
||||
let(:past_event) { create(:event, program: conference.program) }
|
||||
let(:future_event) { create(:event, program: conference.program) }
|
||||
|
||||
before do
|
||||
event.update_attributes(start_time: "#{Time.current}")
|
||||
past_event.update_attributes(start_time: "#{Time.current - 2.days}")
|
||||
future_event.update_attributes(start_time: "#{Time.current + 2.days}")
|
||||
event.update_attributes(start_time: Time.current.to_s)
|
||||
past_event.update_attributes(start_time: (Time.current - 2.days).to_s)
|
||||
future_event.update_attributes(start_time: (Time.current + 2.days).to_s)
|
||||
end
|
||||
|
||||
it 'returns false for a completed event' do
|
||||
expect(past_event.is_current?).to be_falsey
|
||||
expect(past_event.current?).to be_falsey
|
||||
end
|
||||
|
||||
it 'returns false for a future event' do
|
||||
expect(future_event.is_current?).to be_falsey
|
||||
expect(future_event.current?).to be_falsey
|
||||
end
|
||||
|
||||
it 'returns true for a current event' do
|
||||
expect(event.is_current?).to be_truthy
|
||||
expect(event.current?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue