Class: Faces::Providers::Highrise

Inherits:
Object
  • Object
show all
Defined in:
lib/providers/highrise.rb

Overview

Highrise class handles all Highrise based avatar methods Default required methods for providers are url and/or html, exists? All other methods are at the discretion of the developer Check the provider creation guide for more details: nickpellant.com/open-source/faces/ruby/developing-providers

Instance Method Summary collapse

Instance Method Details

#exists?(contact_id, configuration = {}) ⇒ Boolean

Checks Avatar exists

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
# File 'lib/providers/highrise.rb', line 31

def exists?(contact_id, configuration = {})
  url = URI.parse(url(contact_id, configuration))
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = (url.scheme == 'https')
  request = Net::HTTP::Get.new(url.path)
  response = http.request(request)
  response.code == '200' ? true : false
end

#html(contact_id, configuration = {}) ⇒ Object

Constructs HTML <img /> tag for Highrise avatar



24
25
26
27
# File 'lib/providers/highrise.rb', line 24

def html(contact_id, configuration = {})
  m_configuration = Faces::Common.merge_configurations([Faces::Configuration::HIGHRISE, configuration])
  Faces::Public.generate_html(url(contact_id, configuration), m_configuration)
end

#ssl?Boolean

Supports SSL

Returns:

  • (Boolean)


29
# File 'lib/providers/highrise.rb', line 29

def ssl?; true; end

#url(contact_id, configuration = {}) ⇒ Object

Constructs Highrise url from contact_id/configuration



19
20
21
22
# File 'lib/providers/highrise.rb', line 19

def url(contact_id, configuration = {})
  m_configuration =  Faces::Common.merge_configurations([Faces::Configuration::HIGHRISE, configuration])
  hostname(m_configuration) + contact_id[0..3] + '/' + contact_id[4..-1] + '-' + size(m_configuration) + '.png'
end