
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
badges is a Ruby gem that allows you to connect to different API's to retrieve your earned badges and profile information.
Add this line to your application's Gemfile:
gem 'badges'
And then execute:
$ bundle
Or install it yourself as:
$ gem install badges
Both Badges::CodeSchool and Badges::Treehouse are a subclass of Request. Because of this, they share the same methods and variables, and function in exactly the same way. Examples following the first will be considerably shorter.
Create a new instance of a CodeSchool badge request.
codeschool = Badges::CodeSchool.new('username')
Badges gem knows the proper url for the request. If the base url for the request happens to change one day, you can optionally pass in a different base url and the gem will use that instead.
codeschool = Badges::CodeSchool.new('username', 'http://www.codeschool.com/users/')
CodeSchool is a subclass of Request, so it inherits these useful methods and variables pertaining to your api request.
codeschool.user_id
=> "user"
codeschool.profile_url
=> "http://www.codeschool.com/users/username"
codeschool.valid?
=> true
codeschool.code
=> 200
codeschool.message
=> "OK"
Any error in the request will yield a message in the console or log.
Retrieved JSON is stored as a plain Ruby object inside the variable codeschool.body. Here's an example of proper usage:
codeschool.body.user.avatar
=> "http://example.com/avatar.jpg"
codeschool.body.courses.completed.count
=> 11
codeschool.body.courses.completed[0].title
=> "Rails for Zombies"
You can view all the attributes of the JSON request online in a nice tree view gui by using the Json Editor Online.
treehouse = Badges::Treehouse.new('username')
Create a new instance of a badge request in the controller.
class BadgesController < ApplicationController
def index
@codeschool = Badges::CodeSchool.new('keilmillerjr')
@treehouse = Badges::Treehouse.new('keilmillerjr')
end
end
Inside your view, use the list_badges view helper to create a list of badges. Params left out are assumed to be false. You can also use class methods and variables inside the view.
<h1>Badges#index</h1>
<p>Find me in app/views/badges/index.html.erb</p>
<%= image_tag @codeschool.body.user.avatar %>
<%= list_badges @codeschool, codeschool_badges: {image: true, link: true, text: true}, id: 'codeschool_badges', class: 'badges' %>
<%= list_badges @codeschool, codeschool_courses_completed: {image: true, link: true, text: true}, id: 'codeschool_courses_completed', class: 'badges' %>
<%= list_badges @codeschool, codeschool_courses_in_progress: {image: true, link: true, text: true}, id: 'codeschool_courses_in_progress', class: 'badges' %>
<%= image_tag @treehouse.body.gravatar_url %>
<%= list_badges @treehouse, treehouse_badges: {image: true, link: true, text: true}, id: 'treehouse_badges', class: 'badges' %>
Tip: Use css/sass afterwards to style this list appropriately.
list_badges will render nothing if there is an error in the request. Check the console or log for an error message.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that badges demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.