Skip to content

Commit

Permalink
Add twitter and dotenv-rails gems, update member model to get twitter…
Browse files Browse the repository at this point in the history
… images, and change rake task reference to Member
  • Loading branch information
gringocl authored and zenspider committed Apr 23, 2014
1 parent 03725de commit f772767
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ log
db/*.sqlite3
db/data.yml
config/memcache.conf
.env
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ gem "httparty", "~> 0.8.0"
gem "rails_admin", "~> 0.4.9"
gem "devise", "~> 2.1.0"
gem "strong_parameters", "~> 0.2.3"
gem "twitter", "~> 5.0.0"
gem "dotenv-rails"

group :production do
gem "pg", "~> 0.12.0"
Expand Down
30 changes: 30 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ GEM
multi_json (~> 1.0)
addressable (2.2.6)
arel (3.0.3)
atomic (1.1.16)
autotest-rails (4.1.2)
ZenTest (~> 4.5)
bcrypt-ruby (3.0.1)
bootstrap-sass (2.3.2.2)
sass (~> 3.2)
buftok (0.1)
builder (3.0.4)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
Expand All @@ -44,13 +46,20 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.7.0)
descendants_tracker (0.0.3)
devise (2.1.2)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
railties (~> 3.1)
warden (~> 1.2.1)
dotenv (0.10.0)
dotenv-rails (0.10.0)
dotenv (= 0.10.0)
equalizer (0.0.9)
erubis (2.7.0)
execjs (2.0.2)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
font-awesome-rails (3.2.1.3)
railties (>= 3.2, < 5.0)
haml (4.0.5)
Expand All @@ -61,6 +70,9 @@ GEM
rubyzip
term-ansicolor (~> 1.0.5)
hike (1.2.3)
http (0.5.0)
http_parser.rb
http_parser.rb (0.5.3)
httparty (0.8.3)
multi_json (~> 1.0)
multi_xml
Expand All @@ -81,6 +93,8 @@ GEM
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
memoizable (0.2.0)
thread_safe (~> 0.1.3)
mime-types (1.25.1)
mini_portile (0.5.3)
minitest (4.3.2)
Expand All @@ -89,6 +103,7 @@ GEM
rails (~> 3.0)
multi_json (1.9.2)
multi_xml (0.5.1)
multipart-post (2.0.0)
nested_form (0.3.2)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
Expand Down Expand Up @@ -148,6 +163,7 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
simple_oauth (0.2.0)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
Expand All @@ -161,10 +177,22 @@ GEM
railties (~> 3.0)
term-ansicolor (1.0.7)
thor (0.19.1)
thread_safe (0.1.3)
atomic
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
twitter (5.0.0)
buftok (~> 0.1.0)
descendants_tracker (~> 0.0.1)
equalizer (~> 0.0.7)
faraday (>= 0.8, < 0.10)
http (~> 0.5.0)
http_parser.rb (~> 0.5.0)
json (~> 1.8)
memoizable (~> 0.2.0)
simple_oauth (~> 0.2.0)
tzinfo (0.3.39)
uglifier (1.2.3)
execjs (>= 0.3.0)
Expand All @@ -179,6 +207,7 @@ DEPENDENCIES
ZenTest (~> 4.9)
autotest-rails (~> 4.1.2)
devise (~> 2.1.0)
dotenv-rails
heroku (~> 2.19)
httparty (~> 0.8.0)
jquery-rails (~> 3.1.0)
Expand All @@ -189,4 +218,5 @@ DEPENDENCIES
rake (~> 0.9.0)
sqlite3 (~> 1.3.0)
strong_parameters (~> 0.2.3)
twitter (~> 5.0.0)
uglifier (~> 1.2.0)
20 changes: 11 additions & 9 deletions app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def update_avatar!

def set_avatar
if missing_image?
twitter_response = get_twitter_info if twitter
twitter_response = get_twitter_image_url if twitter
image_url = if twitter_response
twitter_response["profile_image_url"].gsub(/normal/i, "bigger")
twitter_response.to_s
else
"missing_image.png"
end
Expand All @@ -36,15 +36,17 @@ def set_avatar
end

def missing_image?
image_url.blank? || image_url == "missing_image.png"
image_url.blank? || image_url == "missing_image.png" || HTTParty.get(self.image_url).code != 200
end

def get_twitter_info
response = HTTParty.get("https://api.twitter.com/1/users/show.json?screen_name=#{self.twitter}")
if response.code == 200
response.parsed_response
else
false
def get_twitter_image_url
client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
config.access_token = ENV['TWITTER_ACCESS_TOKEN']
config.access_token_secret = ENV['TWITTER_ACCESS_TOKEN_SECRET']
end

client.user(self.twitter).profile_image_uri_https(:bigger).to_s
end
end
23 changes: 11 additions & 12 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20140403033350) do
ActiveRecord::Schema.define(:version => 20140402025519) do

create_table "admins", :force => true do |t|
t.string "email", :default => "", :null => false
Expand All @@ -24,8 +24,8 @@
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
Expand All @@ -51,22 +51,21 @@
t.string "email"
t.text "bio", :limit => 255
t.string "website"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "ruby_gems_id"
t.boolean "featured", :default => false
t.string "twitter"
t.string "github"
t.string "image_url"
t.boolean "verified"
end

create_table "projects", :force => true do |t|
t.string "name"
t.string "url"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

create_table "rails_admin_histories", :force => true do |t|
Expand All @@ -76,16 +75,16 @@
t.string "table"
t.integer "month", :limit => 2
t.integer "year", :limit => 5
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

add_index "rails_admin_histories", ["item", "table", "month", "year"], :name => "index_rails_admin_histories"

create_table "suggestions", :force => true do |t|
t.string "title"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "suggester"
end

Expand Down
5 changes: 3 additions & 2 deletions lib/tasks/update.rake
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
namespace :twitter do
task :update_avatars do
Rake::Task[:environment].invoke
people = Dude.scoped
people = Member.scoped
people.each do |person|
puts "Updating #{person.name}..."
person.update_avatar!
puts person.image_url
end
end

task :update_handle do
Rake::Task[:environment].invoke
people_and_handles = [["Aaron Patterson", "tenderlove"], ["Damon Danieli", "damondanieli"], ["Dave Myron", "orngchkn"], ["Eric Hodel", "drbrain"], ["Eric Wong", "the_eric_wong"], ["Evan Phoenix", "evanphx"], ["Jack Danger Canty", "jackdanger"], ["John Barnette", "jbarnette"], ["Mike Mondragon", "monde"], ["Phil Hagelberg", "technomancy"], ["Wilson Bilkovich", "defiler"], ["Alex Vollmer", "alexvollmer"], ["Geoffrey Grosenbach", "topfunky"], ["Pete Higgins", "pete_higgins"]]
people_and_handles.each do |name, handle|
Dude.where(name: name).first.update_attributes(twitter: handle)
Member.where(name: name).first.update_attributes(twitter: handle)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/models/member_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_missing_image
:image_url => "missing_image.png")
regular = Member.create!( :name => "regular",
:ruby_gems_id => "x",
:image_url => "test.png")
:image_url => "http://placekitten.com/50/50")

assert no_img.missing_image?
assert missing_img.missing_image?
Expand Down

0 comments on commit f772767

Please sign in to comment.