# 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' def internet_connection? true if URI.open('http://secure.gravatar.com') rescue StandardError false end i = 0 # Creates the Gravaty object with an (example) email puts '==========================================' puts "PROFILE '#{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 basic URL for profile retrieval, with no frills # (https://www.gravatar.com/b58996c504c5638798eb6b511e6f49af) puts '==========================================' puts "PROFILE '#{i}': Prints the basic URL for profile retrieval, with no frills (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af)." puts 'irb(main):001:0> a_gravaty.profile' puts a_gravaty.profile puts '------------------------------------------' puts i += 1 # Prints the basic URL for profile retrieval, with no frills, in json # format through json-specific method # (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af.json) puts '==========================================' # rubocop:disable Layout/LineLength puts "PROFILE '#{i}': Prints the basic URL for profile retrieval, with no frills, in json format through json-specific method (http://www.gravatar.com/b58996c504c5638798eb6b511e6f49af.json)." # rubocop:enable Layout/LineLength puts 'irb(main):001:0> a_gravaty.json' puts a_gravaty.json puts '------------------------------------------' puts i += 1 # Prints the basic URL for profile retrieval, in JSON format, with # callback string # (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af.json?callback=my_callback) puts '==========================================' puts "PROFILE '#{i}': Prints the basic URL for profile retrieval, in JSON format, with callback string (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af.json?callback=my_callback)." puts "irb(main):001:0> a_gravaty.json callback: 'my_callback'" puts a_gravaty.json callback: 'my_callback' puts '------------------------------------------' puts i += 1 # Prints the basic URL for profile retrieval, in PHP format # (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af.php) puts '==========================================' puts "PROFILE '#{i}': Prints the basic URL for profile retrieval, in PHP format (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af.php)." puts "irb(main):001:0> a_gravaty.profile format: 'php'" puts a_gravaty.profile format: 'php' puts '------------------------------------------' puts i += 1 # Prints the basic URL for profile retrieval, with no frills, in QR code # format through QR code-specific method # (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af.qr) puts '==========================================' # rubocop:disable Layout/LineLength puts "PROFILE '#{i}': Prints the basic URL for profile retrieval, with no frills, in QR code format through QR code-specific method (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af.qr)." # rubocop:enable Layout/LineLength puts 'irb(main):001:0> a_gravaty.qrcode' puts a_gravaty.qrcode puts '------------------------------------------' puts i += 1 # Prints and saves the basic URL for profile retrieval, with no frills, # in QR code format # (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af.qr) puts '==========================================' puts "PROFILE '#{i}': Prints and saves the basic URL for profile retrieval, with no frills, in QR code format (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af.qr)." puts "irb(main):001:0> a_gravaty.profile! format: 'qr'" puts a_gravaty.profile! format: 'qr' puts '------------------------------------------' puts i += 1 # Retrieves the latest saved operation (email address, if none saved) # (user@example.com) puts '==========================================' puts "PROFILE '#{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 save the basic URL for profile and later retrieval, in QR # code format # (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af.qr) puts '==========================================' puts "PROFILE '#{i}': Prints and save the basic URL for profile and later retrieval, in QR code format (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af.qr)." puts "irb(main):001:0> a_gravaty.profile! format: 'qr'" puts a_gravaty.profile! format: 'qr' puts '------------------------------------------' puts # Downloads the previously saved gravaty configuration with the default # name of the file according to saved URI # (saves b58996c504c5638798eb6b511e6f49af.qr file via HTTPS) puts '==========================================' # rubocop:disable Layout/LineLength puts "PROFILE '#{i}': Downloads the previously saved gravaty configuration with the default name of the file according to saved URI. (saves b58996c504c5638798eb6b511e6f49af.qr file via HTTPS)" # 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.qr') if File.exist?('bb58996c504c5638798eb6b511e6f49af.qr') puts '------------------------------------------' puts i += 1 # Prints the basic URL for profile retrieval in QR code format # (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af.qr) puts '==========================================' puts "Profile: '#{i}'a. Prints the basic URL for profile retrieval in QR code format (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af.qr)." puts 'irb(main):001:0> a_gravaty.qrcode' puts a_gravaty.qrcode puts '------------------------------------------' puts # Prints the unsecure URL for profile retrieval in QR code format with # specified image size (in pixels) # (http://www.gravatar.com/b58996c504c5638798eb6b511e6f49af.qr?s=42) puts '==========================================' # rubocop:disable Layout/LineLength puts "Profile: '#{i}'b. prints the unsecure URL for profile retrieval in QR code format with specified image size (in pixels) (http://www.gravatar.com/b58996c504c5638798eb6b511e6f49af.qr?s=42)." # rubocop:enable Layout/LineLength puts 'irb(main):001:0> a_gravaty.qrcode pixelsize: 42, secure: false' puts a_gravaty.qrcode! pixelsize: 42, secure: false puts '------------------------------------------' puts i += 1 # Retrieves the latest saved operation (email address, if none saved) # (user@example.com) puts '==========================================' puts "PROFILE '#{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 unsecure URL for profile retrieval, in VFC/vCard # format (http://www.gravatar.com/b58996c504c5638798eb6b511e6f49af.vcf) puts '==========================================' puts "PROFILE '#{i}': Prints and saves the unsecure URL for profile retrieval, in VFC/vCard format (http://www.gravatar.com/b58996c504c5638798eb6b511e6f49af.vcf)." puts "irb(main):001:0> a_gravaty.profile format: 'vcf', secure: false" puts a_gravaty.profile! format: 'vcf', 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.vcf file via HTTP) puts '==========================================' # rubocop:disable Layout/LineLength puts "PROFILE '#{i}': Downloads the previously saved gravaty configuration with the default name of the file according to saved URI. (saves b58996c504c5638798eb6b511e6f49af.vcf file via HTTP)" # 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.vcf') if File.exist?('b58996c504c5638798eb6b511e6f49af.vcf') puts '------------------------------------------' puts i += 1 # Prints the basic URL for profile retrieval, in XML format # (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af.xml) puts '==========================================' puts "PROFILE '#{i}': Prints the basic URL for profile retrieval, in XML format (https://secure.gravatar.com/b58996c504c5638798eb6b511e6f49af.xml)." puts "irb(main):001:0> a_gravaty.profile format: 'xml'" puts a_gravaty.profile format: 'xml' puts '------------------------------------------' puts