Skip to content

Loading…

Adding coderwall badges #36

Closed
wants to merge 2 commits into from

2 participants

@rubygeek

Adding coderwall.com badges to profile, need suggestion on where to put the tests and stylesheet placement of badges

@lenary

Put Specs in spec/lib/coderwall_spec.rb - stylesheets i have no idea

@rubygeek rubygeek closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 12, 2011
Commits on Sep 21, 2011
  1. displaying users coderwalls badgese

    Nola Stowe committed
View
12 app/assets/stylesheets/application.css.sass
@@ -229,6 +229,18 @@ body
.smaller
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
+grid-prefix(2,12)
+grid(8,12)
View
2 app/controllers/users_controller.rb
@@ -1,8 +1,10 @@
+require 'coderwall'
class UsersController < ApplicationController
before_filter :find_user
before_filter :authorize_user!, :except => :show
def show
+ @coderwall = CoderWall.achievements_of(User.find(params[:id]).github_login)
end
def edit
View
5 app/views/users/show.html.haml
@@ -26,3 +26,8 @@
%li.interests
%label Interests
%span.value.lengthy= interest_links
+
+%ul#coderwall
+ - @coderwall.each do |ach|
+ %li
+ = image_tag ach.badge
View
31 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
+
Something went wrong with that request. Please try again.