# frozen_string_literal: true #-- # gravaty # rubocop:disable Style/AsciiComments # © 2013 Marco Bresciani # rubocop:enable Style/AsciiComments # # This file is part of gravaty. # # gravaty is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation, either version 3 of the License, or (at your # option) any later version. # # gravaty is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License # along with gravaty. If not, see . # # SPDX-FileCopyrightText: 2013 Marco Bresciani # # SPDX-License-Identifier: GPL-3.0-or-later #++ require_relative '../lib/gravaty' require 'open-uri' i = 0 def internet_connection? true if URI.open('http://secure.gravatar.com') rescue StandardError false end # Creates the Gravaty object with an (example) email puts '==========================================' puts "AVATAR '#{i}': Creates the Gravaty object with an (example) email." puts "irb(main):001:0> a_gravaty = Gravaty::gravatize 'user@example.com'" a_gravaty = Gravaty.gravatize 'user@example.com' puts '------------------------------------------' puts i += 1 # Prints the secure URL for avatar retrieval, with no frills # (https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af) puts '==========================================' puts "AVATAR '#{i}': Prints the secure URL for avatar retrieval, with no frills (https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af)." puts 'irb(main):001:0> a_gravaty.avatar' puts a_gravaty.avatar puts '------------------------------------------' puts i += 1 # Prints the basic URL for avatar retrieval, with no frills # (http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af) puts '==========================================' puts "AVATAR '#{i}': Prints the basic URL for avatar retrieval, with no frills (http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af)." puts 'irb(main):001:0> a_gravaty.avatar secure: false' puts a_gravaty.avatar secure: false puts '------------------------------------------' puts i += 1 # Prints the secure URL for avatar retrieval, with specified image file # extension # (https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.jpg) puts '==========================================' puts "AVATAR '#{i}': Prints the secure URL for avatar retrieval, with specified image file extension (https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.jpg)." puts "irb(main):001:0> a_gravaty.avatar type: 'JPG'" puts a_gravaty.avatar type: 'JPG' puts '------------------------------------------' puts i += 1 # Retrieves the latest saved operation (email address, if none saved) # (user@example.com) puts '==========================================' puts "AVATAR '#{i}': Retrieves the latest saved operation (email address, if none saved) (user@example.com)." puts 'irb(main):001:0> puts a_gravaty' puts a_gravaty puts '------------------------------------------' puts i += 1 # Prints and saves the secure URL for avatar and later retrieval, with # specified image file extension # (https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.jpg) puts '==========================================' # rubocop:disable Layout/LineLength puts "AVATAR '#{i}': Prints and saves the secure URL for avatar and later retrieval, with specified image file extension (https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.jpg)." # rubocop:enable Layout/LineLength puts "irb(main):001:0> a_gravaty.avatar! type: 'JPG'" puts a_gravaty.avatar! type: 'JPG' puts '------------------------------------------' puts i += 1 # Prints the basic URL for avatar retrieval, with specified image file # extension # (http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.gif) puts '==========================================' puts "AVATAR '#{i}': Prints the basic URL for avatar retrieval, with specified image file extension (http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.gif)." puts "irb(main):001:0> a_gravaty.avatar type: 'GIF', secure: false" puts a_gravaty.avatar type: 'GIF', secure: false puts '------------------------------------------' puts i += 1 # Retrieves and prints the latest saved operation # (https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.jpg) puts '==========================================' puts "AVATAR '#{i}': Retrieves and prints the latest saved operation. (https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.jpg)" puts 'irb(main):001:0> puts a_gravaty' puts a_gravaty puts '------------------------------------------' puts i += 1 # Prints the basic URL for avatar retrieval, with specified image size # (in pixels) and specified image file extension # (http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?s=42) puts '==========================================' # rubocop:disable Layout/LineLength puts "AVATAR '#{i}': Prints the basic URL for avatar retrieval, with specified image size (in pixels) and specified image file extension (http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?s=42)." # rubocop:enable Layout/LineLength puts "irb(main):001:0> a_gravaty.avatar type: 'png', pixelsize: 42, secure: false" puts a_gravaty.avatar type: 'png', pixelsize: 42, secure: false puts '------------------------------------------' puts i += 1 # Prints and saves the basic URL for avatar retrieval, with specified # image size (in pixels), specified image file extension and type # (http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?s=42&d=monsterid) puts '==========================================' # rubocop:disable Layout/LineLength puts "AVATAR '#{i}': Prints and saves the basic URL for avatar retrieval, with specified image size (in pixels), specified image file extension and type (http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?s=42&d=robohash)." # rubocop:enable Layout/LineLength puts "irb(main):001:0> a_gravaty.avatar! type: 'png', default: 'robohash', pixelsize: 42, secure: false" puts a_gravaty.avatar! type: 'png', default: 'robohash', pixelsize: 42, secure: false puts '------------------------------------------' puts i += 1 # Downloads the previously saved gravaty configuration with the default # name of the file according to saved URI # (saves b58996c504c5638798eb6b511e6f49af.png file) puts '==========================================' # rubocop:disable Layout/LineLength puts "AVATAR '#{i}': Downloads the previously saved gravaty configuration with the default name of the file according to saved URI. (saves b58996c504c5638798eb6b511e6f49af.png file)" # rubocop:enable Layout/LineLength puts 'irb(main):001:0> a_gravaty.download' a_gravaty.download if internet_connection? && !ENV['SSL_CERT_FILE'].nil? File.delete('b58996c504c5638798eb6b511e6f49af.png') if File.exist?('b58996c504c5638798eb6b511e6f49af.png') puts '------------------------------------------' puts i += 1 # Prints and saves the basic URL for avatar retrieval, with specified # image default # (https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.jpg?d=identicon) puts '==========================================' puts "AVATAR '#{i}': Prints and saves the basic URL for avatar retrieval, with specified image default (https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.jpg?d=identicon)." puts "irb(main):001:0> a_gravaty.avatar default: 'identicon', type: 'jpg'" puts a_gravaty.avatar! default: 'identicon', type: 'jpg' puts '------------------------------------------' puts i += 1 # Downloads the previously saved gravaty configuration with the default # name of the file according to saved URI # (saves b58996c504c5638798eb6b511e6f49af.jpg file) puts '==========================================' # rubocop:disable Layout/LineLength puts "AVATAR '#{i}': Downloads the previously saved gravaty configuration with the default name of the file according to saved URI. (saves b58996c504c5638798eb6b511e6f49af.jpg file)" # rubocop:enable Layout/LineLength puts 'irb(main):001:0> a_gravaty.download' a_gravaty.download if internet_connection? && !ENV['SSL_CERT_FILE'].nil? File.delete('b58996c504c5638798eb6b511e6f49af.jpg') if File.exist?('b58996c504c5638798eb6b511e6f49af.jpg') puts '------------------------------------------' puts