• Stars
    star
    120
  • Rank 295,983 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 14 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A gem for interfacing with the entire Gravatar API: not just images, but the XML-RPC API too!

gravatar-ultimate <img src=“https://secure.travis-ci.org/sinisterchipmunk/gravatar.png” /> <img src=“https://codeclimate.com/github/sinisterchipmunk/gravatar.png” /> <img src=“https://coveralls.io/repos/sinisterchipmunk/gravatar/badge.png” alt=“Coverage Status” />

The Ultimate Gravatar Gem!

This gem is used to interface with the entire Gravatar API: it’s not just for generating image URLs, but for connecting to and communicating with the XML-RPC API too! Additionally, it can be used to download the Gravatar image data itself, rather than just a URL to that data. This saves you the extra step of having to do so.

Installation

Only Ruby 2.0 is officially supported. Rails itself is optional, but if used, only versions 3.1, 3.2, and 4.0+ are supported. For older versions of Ruby and/or Rails, see v1.x of this gem.

In your Gemfile:

gem 'gravatar-ultimate'

Usage

Using the gem is actually pretty simple. Let’s say you want the Gravatar image URL for “[email protected]”:

url = Gravatar.new("[email protected]").image_url

Cool, huh? Let’s take it a step further and grab the actual image data so that we can render it on the screen:

data = Gravatar.new("[email protected]").image_data

Fine, but how about the rest of the API as advertised at en.gravatar.com/site/implement/xmlrpc? Well, for that you need either the user’s Gravatar password, or their API key:

api = Gravatar.new("[email protected]", :password => "helloworld")
api = Gravatar.new("[email protected]", :api_key => "AbCdEfG1234")

After you have that, things get a lot easier:

api.exists?                                   #=> true or false, depending on whether this user has an account.
api.addresses                                 #=> a list of email addresses and their corresponding images
api.save_data!(rating, image_data)            #=> saves an image to this user's account and returns a handle to it
api.use_user_image!(handle, an_email_address) #=> uses the specified image handle for the specified email address(es)
api.exists?("[email protected]")            #=> true or false, depending on whether the specified email exists.

Caching

As you can see this is quite powerful. But it gets better. Gravatar Ultimate even manages caching of API responses for you! That way, if an error occurs, (such as the Gravatar site being offline), your code won’t break. It’ll instead gracefully fall back to the cached copy! By default, if you are using Rails, it’ll use the Rails cache. Otherwise, it’ll use whatever cache you’re using with Gravatar (by default an instance of ActiveSupport::Cache::FileStore).

This has obvious benefits when used for the API calls that do not result in changing the user’s profile, but what you might not have thought of yet is that it also caches #image_data, so you can hook your application up to that method without fear of what might happen to all those Gravatar images if the Gravatar server should be unavailable!

To customize exactly which cache is used, see the next section…

Configuration

To see settings and options you can give for a particular Gravatar instance, check out the Gravatar class documentation. There are a few things you can set for Gravatar on a system-wide basis, and that’s what we’ll go over next.

For a non-Rails project, simply set these options before you start using Gravatar. For a Rails project, you should set them within an Initializer in config/initializers/any_filename.rb in order to ensure that the settings are applied (A) after Gravatar has been included into the project, and (B) before it is actually used by Rails.

# You can set the default cache for Gravatar to use:
Gravatar.cache = ActiveSupport::Cache::SynchronizedMemoryStore.new

# You can also set the length of time an item in the Gravatar cache is valid. Default is 24.hours
Gravatar.duration = 20.minutes

# You can also change the logger used by default. It's worth mentioning that, once again, Gravatar will use
# the Rails logger if it's available. Otherwise, the default is $stdout.
grav_log = ""
Gravatar.logger = StringIO.new(grav_log) # logs Gravatar output to a String

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Don’t update the version number. (If you want to have your own version, that’s fine but bump version in a commit by itself I can ignore when I pull.)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010-2012 Colin MacKenzie IV. See LICENSE for details.

Contributors

github.com/sinisterchipmunk/gravatar/contributors

Also:

abitdodgy (Mohamad El-Husseini) for github.com/sinisterchipmunk/gravatar/pull/7

More Repositories

1

rspec-prof

Integrates ruby-prof with RSpec, allowing you to easily profile your RSpec examples.
Ruby
136
star
2

bitcoin-client

Provides a Ruby library to the complete Bitcoin JSON-RPC API. Implements all methods listed at https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list .
Ruby
124
star
3

jax

Framework for creating rich WebGL-enabled applications using JavaScript and Ruby
CoffeeScript
94
star
4

bot-away

Silently, unobtrusively masks Rails-generated forms in order to filter out spambot submissions.
Ruby
62
star
5

eve

A Ruby library for interfacing with all aspects of the EVE Online MMO. It is designed for use within a Ruby on Rails project, but does not require Rails as a dependency. That means there‘s nothing preventing you from writing a stand-alone application or script using this library.
Ruby
31
star
6

node.rb

Embeds a Ruby interpreter into Node.js, so you can execute Ruby code from within your Node-based JavaScript
Ruby
20
star
7

genspec

An RSpec-based library for concisely and efficiently testing Rails generators
Ruby
19
star
8

bitpool

a Ruby-based bitcoin mining pool
Ruby
18
star
9

vulkan-ruby

Vulkan bindings for Ruby
Ruby
15
star
10

redis-orm

Easy-to-use object relational mapping for Redis.
Ruby
14
star
11

xmlsec

C
14
star
12

webgl-compat

Standards-compliant WebGL compatability layer using Canvas2D
JavaScript
14
star
13

webgl

Home to my various tests and demos using WebGL; see them in action at http://webgldemos.thoughtsincomputation.com
JavaScript
11
star
14

bvh

A library for loading, modifying and saving BVH motion capture files.
Ruby
11
star
15

normal-map

normal-map
Ruby
9
star
16

acts_as_awesome

This gem does absolutely nothing. It's part of my response to http://stackoverflow.com/questions/4018469/rails3-gem-acts-as-something
Ruby
9
star
17

sinisterchipmunk.github.com

Live demos of the Jax WebGL framework
JavaScript
8
star
18

active-gist

ActiveModel-based wrapper around the Gist API. Because I can.
Ruby
7
star
19

shader-script

Generate shaders with CoffeeScript, and unit test it using the simulator!
JavaScript
7
star
20

sc2sim

Attempts to simulate StarCraft 2 mechanics, primarily to test the timing of build orders.
Ruby
6
star
21

rails-webgl

A WebGL framework for Ruby on Rails
JavaScript
6
star
22

md2

A Ruby library for loading MD2 3D model files.
Ruby
4
star
23

sc-ansi

Handles every aspect (that I could think of) of dealing with ANSI escape sequences.
Ruby
4
star
24

rink

Makes interactive consoles awesome.
Ruby
4
star
25

cglm-ruby

Ruby bindings for CGLM (https://github.com/recp/cglm), a high performance math library for OpenGL.
C
4
star
26

google-blogsearch-pings

Utilizes the Google Blog Search Pinging Service API in order to notify Google of updates to your blog so that it can be reindexed more quickly. See also: http://www.google.com/help/blogsearch/pinging_API.html
Ruby
4
star
27

rubyjs

Generates JavaScript classes from Ruby code; works fine on its own but is designed for Rails
Ruby
4
star
28

nuklear-ruby

Nuklear GUI bindings for Ruby
C
3
star
29

test-spec

The test-spec framework with added global before and after hooks
Ruby
3
star
30

eve-dump

ActiveResource models, migrations and seeds for reproducing the EVE database.
Ruby
3
star
31

rpm

Builds RPMs out of RubyGems or Rails projects
Ruby
3
star
32

jax-coldet

A fast collision detection library for Jax
JavaScript
3
star
33

jax-guides-getting-started

The Jax "Getting Started" guide, committed step-by-step, for your reference.
Ruby
2
star
34

tiny_gltf-ruby

Provides a Ruby extension for TinyGLTF, a C++ glTF 2.0 library.
C++
2
star
35

sparkly-auth

Rails authentication with Sparkles!
Ruby
2
star
36

mist

a git-powered, gist-backed blogging engine for Rails 3
Ruby
2
star
37

sizes

A very simple gem that exposes the C *sizeof* keyword to Ruby.
Ruby
2
star
38

testbeds

Manages multiple testbeds within which to test your gems (or other code)
Ruby
2
star
39

divinity

A new kind of game engine. Check back when the project has something worthwhile in it, because right now it's just a place for me to put stuff.
Ruby
2
star
40

tomato

Leverages Google's V8 JavaScript library to interface Ruby code with JavaScript code.
C++
2
star
41

authgen

Configures a Rails application for use with the authlogic and declarative_authorization gems, and generates all code (migrations, models, controller methods, routes, roles, seeds, etc.) required.
Ruby
2
star
42

ambrosia

coming soon
CoffeeScript
1
star
43

tinyobj-ruby

Provides a Ruby interface around TinyOBJ.
C++
1
star
44

core-ext

A collection of Ruby core extensions that I've built up over time. They rely on ActiveSupport.
Ruby
1
star
45

swarm

Ruby
1
star
46

sample_app_three

Ruby
1
star
47

voidrepublic

Void republic issues tracking
1
star
48

blog

A blog engine that I'm writing, mostly 'cause I can.
Ruby
1
star
49

jax-blender-models

a Jax plugin adding support for models built in Blender. Includes model importers and exporters for Blender.
Python
1
star
50

tiny_mce

This plugin adapts the TinyMCE JavaScript library from Moxiecode Systems to a Ruby on Rails application. The TinyMCE version bundled with this plugin is Version 3.2.7 (2009-09-22).
Ruby
1
star
51

jax-fractals

Fractal textures and terrain for Jax!
Ruby
1
star
52

jax-dungeon

A dungeon demo built using the Jax WebGL framework.
JavaScript
1
star
53

pingbacks

Git repo to track the progress of my Coding Gems for Rails 3 tutorial series. See tags to jump to the snapshot for a specific segment.
Ruby
1
star
54

widgets

widget, n : a device that is very useful for a particular job
Ruby
1
star
55

sdl2_vulkan

Exposes the Vulkan functions in SDL2 to Ruby
Ruby
1
star
56

spirv-cross-ruby

Ruby bindings for SPIRV-Cross to provide reflection of SPIR-V shaders.
C++
1
star
57

dock

Documentation generator for multi-language projects
JavaScript
1
star
58

rubytastic

Part of my answer on stack overflow: http://stackoverflow.com/questions/11383048/serious-stuck-on-validations-not-triggered-for-nested-resource-with-fields-for/11495512#11495512
Ruby
1
star
59

c4

Toy SPA framework, highly experimental. Probably wouldn't work in the real world. You've been warned.
JavaScript
1
star