Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding coderwall badges #36

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/assets/stylesheets/application.css.sass
Expand Up @@ -229,6 +229,18 @@ body
.smaller .smaller
font-size: 0.8em font-size: 0.8em


#coderwall
+horizontal-list
+grid-prefix(2,12)
+grid(8,12)
+grid-suffix(2,12)

li
font-size: 12px
img
width: 35px
height: 35px

#search-page #search-page
+grid-prefix(2,12) +grid-prefix(2,12)
+grid(8,12) +grid(8,12)
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/users_controller.rb
@@ -1,8 +1,10 @@
require 'coderwall'
class UsersController < ApplicationController class UsersController < ApplicationController
before_filter :find_user before_filter :find_user
before_filter :authorize_user!, :except => :show before_filter :authorize_user!, :except => :show


def show def show
@coderwall = CoderWall.achievements_of(User.find(params[:id]).github_login)
end end


def edit def edit
Expand Down
5 changes: 5 additions & 0 deletions app/views/users/show.html.haml
Expand Up @@ -26,3 +26,8 @@
%li.interests %li.interests
%label Interests %label Interests
%span.value.lengthy= interest_links %span.value.lengthy= interest_links

%ul#coderwall
- @coderwall.each do |ach|
%li
= image_tag ach.badge
31 changes: 31 additions & 0 deletions lib/coderwall.rb
@@ -0,0 +1,31 @@
# Simple and Stupid Ruby API for Coderwall.com
# Vivien Didelot <vivien@didelot.org>
# https://gist.github.com/1007591

require "open-uri"
require "json"

module CoderWall
class Achievement
attr_reader :name, :badge, :description

def initialize(hashed_badge)
@name, @badge, @description = hashed_badge.values
end
end

module_function

def achievements_of(username)
raise(ArgumentError, "Invalid username") if username.empty?
url = URI.escape("http://coderwall.com/#{username}.json")
begin
response = JSON.load(open(url))
rescue OpenURI::HTTPError
raise(ArgumentError, "Invalid username")
end

response["badges"].map { |badge| Achievement.new(badge) }
end
end