<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gravatar &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/gravatar/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Mon, 22 Mar 2021 20:37:16 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Using Gravatar in Web, Desktop &#038; iOS Applications</title>
		<link>https://blog.xojo.com/2021/03/15/using-gravatar-in-web-desktop-ios-applications/</link>
		
		<dc:creator><![CDATA[Wayne Golding]]></dc:creator>
		<pubDate>Mon, 15 Mar 2021 10:00:00 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Guest Post]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Gravatar]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=7902</guid>

					<description><![CDATA[Learn to build a reusable Gravatar Connection class for web, desktop and iOS apps using the Gravatar API.]]></description>
										<content:encoded><![CDATA[
<p>Your Gravatar is an image and public profile that follows you from site to site, appearing beside your name when you do things like comment or post. Gravatars help identify your posts on blogs and web forums, so why not a web application?</p>



<p>It turns out that adding Gravatars to your application is very simple using the Gravatar API.*</p>



<h3 class="wp-block-heading">Build a Reusable Gravatar Connection</h3>



<p>First, create a new project in Xojo. You can choose any type of project and there are examples available on my <a href="https://github.com/axisdirectnz/Gravatar">GitHub</a> for Desktop, Web and iOS projects.</p>



<p>Click on the Insert button and select Class to add a new class to your project. Call the class “GravatarConnection” and make its super URLConnection.</p>



<p>Next, add a private function to generate the hash required to lookup a Gravatar:</p>



<pre class="wp-block-code"><code>Private Function GenerateGravatarHash(email As String) As String
      // Generate Gravatar Hash
      Var hash As String = Crypto.Hash(email.Lowercase.Trim, Crypto.HashAlgorithms.MD5)
      hash = EncodeHex(hash).Lowercase
      
      Return hash
      
    End Function
</code></pre>



<p>As you can see, this function takes the email address, creates an MD5 checksum, encodes that checksum as hex converting it to a lower case string and returning it to the calling method.</p>



<p>Now add a method to get the Profile Data:</p>



<pre class="wp-block-code"><code>Public Sub GetProfile(email As String)
  Me.ClearRequestHeaders
  Me.RequestHeader("User-Agent") = "*"
  Send("GET", "HTTPS://www.gravatar.com/" + GenerateGravatarHash(email) + ".json")
End Sub
</code></pre>



<p>Again, this method takes the email address and requests the profile in JSON format from&nbsp;<a href="http://www.gravatar.com/">www.gravatar.com</a>.</p>



<p>Next we’ll add three event definitions:</p>



<pre class="wp-block-code"><code>Event Avatar(Value As Picture)
Event Found(FullName As String, Location As String, AvatarURL As String)
Event NotFound()
</code></pre>



<p>These events will be raised based on the result of our request.</p>



<p>Now we need to handle the ContentReceived Event with:</p>



<pre class="wp-block-code"><code>Sub ContentReceived(URL As String, HTTPStatus As Integer, content As String) Handles ContentReceived
  If HTTPStatus = 404 Then
    RaiseEvent NotFound
    Return
  End If
  
  If URL.BeginsWith("HTTPS://www.gravatar.com/avatar/") Then
    Var pic As Picture = Picture.FromData(content)
    RaiseEvent Avatar(pic)
  Else
    Var d As Dictionary = ParseJSON(content)
    Var v() As Variant = d.value("entry")
    Var entry As Dictionary = v(0)
    Var names As Dictionary = entry.Value("name")
    v = entry.Value("photos")
    Var Avatar As Dictionary = v(0)
    RaiseEvent Found(names.Lookup("formatted", ""), entry.Lookup("currentLocation", ""), _
      Avatar.Lookup("value", ""))
  End If
End Sub</code></pre>



<p>Here we either raise the NotFound event or either the Gravatar or Found events, depending on the URL.</p>



<p>This class is freely available at <a href="https://github.com/axisdirectnz/Gravatar">https://github.com/axisdirectnz/Gravatar</a> and there are example projects for Desktop, Web &amp; iOS that show how to use the class.</p>



<h3 class="wp-block-heading">*UPDATE  3/22/21 &#8211; Per community feedback,  this post has been updated.  </h3>



<p>Thanks Jeannot and Thom! I would recommend anyone who has downloaded from Git before March  22, 2021, to do so again.</p>



<p><em>Wayne Golding has been a Xojo developer since 2005 and is a Xojo MVP. He operates the IT Company <a href="http://www.axisdirect.nz">Axis Direct Ltd </a>which primarily develops applications using Xojo that integrate with Xero www.xero.com. Wayne’s hobby is robotics where he uses Xojo to build applications for his Raspberry Pi, often implementing IoT for remote control.</em></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
