Socket
Book a DemoInstallSign in
Socket

social-avatar-proxy

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

social-avatar-proxy

2.0.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

SocialAvatarProxy

This gem acts as a proxy for avatars on Twitter & Facebook.

Build Status Code Climate

Installation

Add this line to your application's Gemfile:

gem "social-avatar-proxy"

And then execute:

$ bundle

Or install it yourself as:

$ gem install social-avatar-proxy

Usage

Rails

In your config/routes.rb file:

mount SocialAvatarProxy::Engine, at: "/avatars"

The engine is basically a proxy for the Rack app, it also adds the path helpers below:

In your views:

# for a Twitter user, by username:
image_tag(twitter_avatar_path("username"))
# by ID:
image_tag(twitter_avatar_path(12345))

# for a Facebook user, by username:
image_tag(facebook_avatar_path("username"))
# by ID:
image_tag(facebook_avatar_path(12345))

You might wish to configure a default image which will be rendered if an avatar could not be found, or if the remote service has an error (e.g. times out or has a redirect loop), this is simple with an initializer:

# choose our image
image_path = Rails.root.join(*%W(app assets images default_avatar.jpg))
# set the config
SocialAvatarProxy.configure do
  default_image(image_path)
end

HTTP caching can be configured as below:

SocialAvatarProxy.configure do
  http_cache do
    expires 10.minutes
    cache_control({
      max_age: 5.days,
      max_stale: 1.day,
      public: true
    })
  end
end

Files can be cached in either or both of Memcached and the file system, here is the configuration options:

SocialAvatarProxy.configure do
  file_cache do
    directory "/path/to/folder"
  end
  
  memcache do
    enable # only required if you don't set either of the following options
    host "192.168.1.2:11211" # defaults to "localhost:11211"
    namespace "something:" # defaults to "sap/"
  end
end

Rack

The Rack app is available at: SocialAvatarProxy::App.

Both the class and an instance respond to call so either can be mounted.

use SocialAvatarProxy::App
# or
use SocialAvatarProxy::App.new

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

FAQs

Package last updated on 07 Nov 2012

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.