class AvatarsIO

Public Class Methods

access_token=(access_token) click to toggle source
# File lib/avatars.io.rb, line 18
def self.access_token=(access_token)
  @@access_token = access_token
end
auto_url(key, services = []) click to toggle source
# File lib/avatars.io.rb, line 66
def self.auto_url(key, services = [])
  if services.size.eql? 0
    "http://avatars.io/auto/#{ key }"
  else
    "http://avatars.io/auto/#{ key }?services=#{ services.join ',' }"
  end
end
avatar_url(service = 'twitter', key) click to toggle source
# File lib/avatars.io.rb, line 62
def self.avatar_url(service = 'twitter', key)
  "http://avatars.io/#{ service }/#{ key }"
end
client_id=(client_id) click to toggle source
# File lib/avatars.io.rb, line 14
def self.client_id=(client_id)
  @@client_id = client_id
end
upload(filename, identifier = '') click to toggle source
# File lib/avatars.io.rb, line 22
def self.upload(filename, identifier = '')
  file = File.read filename
  response = post '/v1/token', {
    :headers => {
      'x-client_id' => @@client_id,
      'Authorization' => "OAuth #{ @@access_token }",
      'Content-Type' => 'application/json'
    }, :body => {
      :data => {
        :filename => filename,
        :md5 => Digest::MD5::hexdigest(file),
        :size => File.size(filename),
        :path => identifier
      }
    }.to_json
  }
  
  return response["data"]["url"] if !response["data"]["upload_info"]
  
  info = response["data"]["upload_info"]
  AvatarsIOFile.put info["upload_url"].gsub('http://s3.amazonaws.com', ''), {
    :headers => {
      'Authorization' => info["signature"],
      'Date' => info["date"],
      'Content-Type' => info["content_type"],
      'x-amz-acl' => 'public-read'
    },
    :body => file
  }
  
  response = post "/v1/token/#{ response["data"]["id"] }/complete", {
    :headers => {
      'x-client_id' => @@client_id,
      'Authorization' => "OAuth #{ @@access_token }"
    },
    :body => ''
  }
  response["data"]
end