Skip to content

Commit 9bba58b

Browse files
committed
first commit
0 parents  commit 9bba58b

14 files changed

+294
-0
lines changed

Gemfile

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
source "https://rubygems.org"
2+
ruby '2.1.1'
3+
4+
gem 'sinatra'
5+
gem 'rack' #for static site
6+
gem 'rack-contrib'
7+
8+
gem 'pry'
9+
# gem 'pry-debugger' #add step, next
10+
gem 'airbrake'
11+
gem 'sucker_punch'
12+
13+
gem 'mongoid', "~> 3.1.2"
14+
gem 'bson_ext'
15+
16+
gem 'redis'
17+
# gem 'nokogiri'
18+
19+
# for loading the .env file locally
20+
gem 'dotenv', :groups => [:development, :test]
21+
22+
# gem "geocoder"
23+
gem 'faraday'
24+
gem 'faraday_middleware'
25+
gem 'simple_oauth'
26+
27+
# needed because open-uri won't allow to redirect from http to https and vice versa. needed to get base url
28+
gem 'open_uri_redirections'
29+
30+
group :test do
31+
# gem 'spinach'
32+
gem "rack-test"
33+
gem "factory_girl"
34+
gem 'rspec'
35+
end

Gemfile.lock

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
activemodel (3.2.15)
5+
activesupport (= 3.2.15)
6+
builder (~> 3.0.0)
7+
activesupport (3.2.15)
8+
i18n (~> 0.6, >= 0.6.4)
9+
multi_json (~> 1.0)
10+
airbrake (4.1.0)
11+
builder
12+
multi_json
13+
bson (1.9.2)
14+
bson_ext (1.9.2)
15+
bson (~> 1.9.2)
16+
builder (3.0.4)
17+
celluloid (0.15.2)
18+
timers (~> 1.1.0)
19+
coderay (1.1.0)
20+
diff-lcs (1.2.5)
21+
dotenv (0.9.0)
22+
factory_girl (4.3.0)
23+
activesupport (>= 3.0.0)
24+
faraday (0.8.8)
25+
multipart-post (~> 1.2.0)
26+
faraday_middleware (0.9.0)
27+
faraday (>= 0.7.4, < 0.9)
28+
i18n (0.6.5)
29+
method_source (0.8.2)
30+
mongoid (3.1.5)
31+
activemodel (~> 3.2)
32+
moped (~> 1.4)
33+
origin (~> 1.0)
34+
tzinfo (~> 0.3.29)
35+
moped (1.5.1)
36+
multi_json (1.8.2)
37+
multipart-post (1.2.0)
38+
open_uri_redirections (0.1.4)
39+
origin (1.1.0)
40+
pry (0.9.12.3)
41+
coderay (~> 1.0)
42+
method_source (~> 0.8)
43+
slop (~> 3.4)
44+
rack (1.5.2)
45+
rack-contrib (1.1.0)
46+
rack (>= 0.9.1)
47+
rack-protection (1.5.1)
48+
rack
49+
rack-test (0.6.2)
50+
rack (>= 1.0)
51+
redis (3.1.0)
52+
rspec (2.14.1)
53+
rspec-core (~> 2.14.0)
54+
rspec-expectations (~> 2.14.0)
55+
rspec-mocks (~> 2.14.0)
56+
rspec-core (2.14.7)
57+
rspec-expectations (2.14.4)
58+
diff-lcs (>= 1.1.3, < 2.0)
59+
rspec-mocks (2.14.4)
60+
simple_oauth (0.2.0)
61+
sinatra (1.4.4)
62+
rack (~> 1.4)
63+
rack-protection (~> 1.4)
64+
tilt (~> 1.3, >= 1.3.4)
65+
slop (3.4.7)
66+
sucker_punch (1.1)
67+
celluloid (~> 0.15.2)
68+
tilt (1.4.1)
69+
timers (1.1.0)
70+
tzinfo (0.3.38)
71+
72+
PLATFORMS
73+
ruby
74+
75+
DEPENDENCIES
76+
airbrake
77+
bson_ext
78+
dotenv
79+
factory_girl
80+
faraday
81+
faraday_middleware
82+
mongoid (~> 3.1.2)
83+
open_uri_redirections
84+
pry
85+
rack
86+
rack-contrib
87+
rack-test
88+
redis
89+
rspec
90+
simple_oauth
91+
sinatra
92+
sucker_punch

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: bundle exec rackup config.ru -p $PORT

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Template: add description of what this app does
2+
3+
Use as console:
4+
bundle exec ruby console.rb

app.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'sinatra'
2+
require './config/initializer'
3+
4+
before do
5+
content_type :json
6+
end

config.ru

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'rubygems'
2+
Bundler.require
3+
4+
require './app'
5+
6+
run Rack::URLMap.new \
7+
"/" => Sinatra::Application

config/initializer.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'rubygems'
2+
require 'pry'
3+
require 'json'
4+
require 'faraday'
5+
6+
# for Twitter.base_uri
7+
require 'open-uri'
8+
require 'open_uri_redirections'
9+
10+
# # require 'newrelic_rpm'
11+
12+
if ENV['RACK_ENV'] != "production"
13+
require 'dotenv'
14+
Dotenv.load
15+
end
16+
17+
Dir['./config/initializers/*.rb'].each{ |f| require f }
18+
Dir['./models/*.rb'].each{ |f| require f }
19+
Dir['./lib/*.rb'].each{ |f| require f }

config/initializers/airbrake.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'airbrake'
2+
3+
Airbrake.configure do |config|
4+
config.api_key = ENV['AIRBRAKE_KEY']
5+
config.async = true
6+
end

config/initializers/mongo.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require 'mongoid'
2+
# mongolab password is same as aws account key
3+
4+
Mongoid.load!('./config/mongoid.yml')

config/initializers/redis.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require 'redis'
2+
3+
# use a different database if only this app will need it. use 0 where everything will be shared.
4+
REDIS = Redis.new(:host => ENV['REDIS_HOST'], :port => ENV['REDIS_PORT'], :password => ENV['REDIS_AUTH'], :db => 0)

config/mongoid.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
development:
2+
sessions:
3+
default:
4+
uri: <%= ENV['MONGOHQ_URL'] %>
5+
6+
production:
7+
sessions:
8+
default:
9+
uri: <%= ENV['MONGOHQ_URL'] %>
10+
11+
test:
12+
sessions:
13+
default:
14+
database: jetsam-test
15+
hosts:
16+
- localhost:27017

console.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require './config/initializer.rb'
2+
3+
binding.pry

lib/redis_key.rb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class RedisKey
2+
3+
attr_accessor :registry
4+
5+
def initialize(prefix)
6+
@prefix = prefix
7+
@registry = {
8+
"default" => {
9+
:name => "example",
10+
:data_type => "string",
11+
:desc => "stores example data"
12+
}
13+
}
14+
end
15+
16+
def get(name, arg = {})
17+
if @registry[name]
18+
str = "#{@prefix}:#{name}"
19+
20+
if !arg.empty?
21+
str += ":#{arg}"
22+
end
23+
return str
24+
else
25+
raise NotFound
26+
end
27+
end
28+
29+
class NotFound < StandardError; end
30+
end

models/link.rb

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
class Link
2+
3+
def self.ignore_list
4+
keyword_file = File.join(Dir.pwd, "lib/ignore.yml")
5+
YAML::load( File.open( keyword_file ) )
6+
end
7+
8+
def self.aggregate_across_list(list_owner, list_name)
9+
ignore = ignore_list
10+
domains = {}
11+
puts ignore.inspect
12+
members = Twitter.list_members(list_owner, list_name)
13+
members.each do |screen_name, twid|
14+
Link.new(screen_name, {:ignore => ignore }).from_twitter(domains)
15+
end
16+
domains
17+
end
18+
19+
def initialize(screen_name, options = {})
20+
@screen_name = screen_name
21+
if options[:ignore]
22+
@ignore = options[:ignore]
23+
end
24+
end
25+
26+
def from_twitter(domains = {})
27+
puts "screen_name: #{@screen_name}"
28+
res = Twitter.timeline(@screen_name)
29+
res.each do |tweet|
30+
if !tweet['entities']['urls'].empty?
31+
tweet['entities']['urls'].each do |obj|
32+
begin
33+
shared = obj['expanded_url']
34+
link = Link.base_uri(shared)
35+
url = URI.parse(link)
36+
domain = PublicSuffix.parse(url.host).domain
37+
puts domain
38+
next if @ignore && @ignore.include?(domain)
39+
40+
if domains[domain]
41+
domains[domain] += 1
42+
else
43+
domains[domain] = 1
44+
end
45+
rescue => e
46+
puts "LINK problem: #{e.message}"
47+
end
48+
end
49+
end
50+
end
51+
puts "__________________________________"
52+
domains
53+
end
54+
55+
def self.base_uri(url)
56+
begin
57+
Timeout.timeout(3) do
58+
open(url,:allow_redirections => :safe) do |res|
59+
res.base_uri.to_s
60+
end
61+
end
62+
rescue => e
63+
puts "TIMEOUT for #{url}"
64+
url
65+
end
66+
end
67+
end

0 commit comments

Comments
 (0)