Sha256: 5dc760f944febc616710f799fa2c0536f5bdb2ef7f89aa70ea72b065525628b4

Contents?: true

Size: 782 Bytes

Versions: 1

Compression:

Stored size: 782 Bytes

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)
    response = JSON.load(open(url))      

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coder_wally-0.0.2 lib/coder_wally.rb