Sha256: f2b4282cd24ab9e6f265f22908b1e364257e1a228d39c4e42cc3e30b776e5849
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
require "coder_wally/version" require "open-uri" require "json" # All code in the gem is namespaced under this module. module CoderWally # The URL of API we'll use. Url = "https://coderwall.com/%s.json" class Badge attr_reader :name, :badge, :description, :created def initialize(hashed_badge) @name = hashed_badge.fetch("name") @badge = hashed_badge.fetch("badge") @description = hashed_badge.fetch("description") @created = hashed_badge.fetch("created") end end def CoderWally.get_badges_for username raise(ArgumentError, "Plesae provide a username") if username.empty? url = URI.parse(Url % username) begin request = open(url) rescue OpenURI::HTTPError => error raise UserNotFoundError, "User not found" if error.io.status[0] == "404" raise ServerError, "Server error" if error.io.status[0] == "500" end response = JSON.load(request) response["badges"].map { |badge| Badge.new(badge) } # end end class UserNotFoundError < StandardError end class ServerError < StandardError end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
coder_wally-0.0.3 | lib/coder_wally.rb |