Last active
August 29, 2015 14:05
-
-
Save stakes/34fbb70f9788b3a7239e to your computer and use it in GitHub Desktop.
Social aggregation POC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+VINE_LOGIN: '' | |
+VINE_PASSWORD: '' | |
+ | |
+INSTAGRAM_ID: '' | |
+INSTAGRAM_SECRET: '' | |
+INSTAGRAM_TOKEN: '' | |
+ | |
+TWITTER_KEY: '' | |
+TWITTER_SECRET: '' | |
+ | |
+FACEBOOK_ID: '' | |
+FACEBOOK_SECRET: '' | |
+ | |
+ | |
+# here are the social accounts for the user, ex Shane Dawson below | |
+ | |
+VINE_USERNAME: '911813020152369152' | |
+INSTAGRAM_USERNAME: 'shanedawson' | |
+TWITTER_USERNAME: 'shanedawson' | |
+FACEBOOK_USERNAME: 'shanedawsonfans' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Api::BaseController < ApplicationController | |
respond_to :json | |
def bad_request | |
render json: {errors: 'bad request'}, status: :bad_request, :formats => :json | |
end | |
def unauthorized | |
render json: {errors: 'unauthorized'}, status: :unauthorized, :formats => :json | |
end | |
def validate_content_type(parameters) | |
content_type = parameters.content_type | |
unless content_type.in? ['image/jpeg', 'image/gif', 'image/png'] | |
raise "Invalid content type for image upload" | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
ruby '2.0.0' | |
gem 'rails', '4.0.4' | |
gem 'sass-rails', '~> 4.0.2' | |
gem 'uglifier', '>= 1.3.0' | |
gem 'coffee-rails', '~> 4.0.0' | |
gem 'jquery-rails' | |
gem 'turbolinks' | |
gem 'jbuilder', '~> 1.2' | |
gem 'bootstrap-sass' | |
gem 'figaro' | |
gem 'haml-rails' | |
gem 'thin' | |
gem 'mongoid', github: 'mongoid/mongoid' | |
gem 'redvine' | |
gem 'twitter' | |
gem 'instagram' | |
gem 'koala' | |
group :development do | |
gem 'better_errors' | |
gem 'binding_of_caller', :platforms=>[:mri_19, :mri_20, :mri_21, :rbx] | |
gem 'guard-bundler' | |
gem 'guard-rails' | |
gem 'guard-rspec' | |
gem 'html2haml' | |
gem 'quiet_assets' | |
gem 'rails_layout' | |
gem 'rb-fchange', :require=>false | |
gem 'rb-fsevent', :require=>false | |
gem 'rb-inotify', :require=>false | |
end | |
group :development, :test do | |
gem 'factory_girl_rails' | |
gem 'rspec-rails' | |
end | |
group :test do | |
gem 'database_cleaner', '1.0.1' | |
gem 'email_spec' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Item | |
include Mongoid::Document | |
field :provider, type: String | |
field :image, type: String | |
field :content, type: String | |
field :media_url, type: String | |
field :provider_username, type: String | |
def self.create_from(service, data) | |
o = {provider: service} | |
case service | |
when 'vine' | |
o.merge!( | |
image: data.thumbnailUrl, | |
content: data.description, | |
media_url: data.permalinkUrl, | |
provider_username: data.userId | |
) | |
when 'instagram' | |
o.merge!(image: data.images.standard_resolution.url) | |
o.merge!(content: data.caption.text) | |
o.merge!(media_url: data.link) | |
o.merge!(provider_username: data.user.username) | |
when 'twitter' | |
o.merge!(image: data.media) unless data.media.blank? | |
o.merge!(content: data.text) | |
o.merge!(media_url: data.source) | |
o.merge!(provider_username: data.user.screen_name) | |
when 'facebook' | |
o.merge!(image: data['picture']) unless data['picture'].blank? | |
o.merge!(content: data['message']) | |
o.merge!(media_url: data['link']) | |
o.merge!(provider_username: data['from']['name']) | |
end | |
o | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Api::ItemsController < Api::BaseController | |
# | |
# GET REQUESTS | |
# | |
def index | |
# VINE | |
vine_client = Redvine.new | |
vine_client.connect(:email => ENV['VINE_LOGIN'], :password => ENV['VINE_PASSWORD']) | |
vines = vine_client.user_timeline(ENV['VINE_USERNAME']) | |
Instagram.configure do |config| | |
config.client_id = ENV['INSTAGRAM_ID'] | |
config.client_secret = ENV['INSTAGRAM_SECRET'] | |
end | |
user = Instagram.user_search(ENV['INSTAGRAM_USERNAME']) | |
instagrams = Instagram.user_recent_media(user[0].id) | |
twitter_client = Twitter::REST::Client.new do |config| | |
config.consumer_key = ENV['TWITTER_KEY'] | |
config.consumer_secret = ENV['TWITTER_SECRET'] | |
end | |
tweets = twitter_client.user_timeline(ENV['TWITTER_USERNAME'], {:count => 10, :include_rts => false}) | |
oauth = Koala::Facebook::OAuth.new(ENV['FACEBOOK_ID'], ENV['FACEBOOK_SECRET']) | |
token = oauth.get_app_access_token | |
graph = Koala::Facebook::API.new(token) | |
fbposts = graph.get_connections(ENV['FACEBOOK_USERNAME'], 'feed') | |
# mix em up | |
items = vines.map {|vine| Item.create_from('vine', vine)} | |
items = items | instagrams.map {|insta| Item.create_from('instagram', insta)} | |
items = items | tweets.map {|tweet| Item.create_from('twitter', tweet)} | |
items = items | fbposts.map {|post| Item.create_from('facebook', post)} | |
render json: items.shuffle! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment