Ruminations of an addled mind

Random ramblings about my thoughts

  • Meta

  • RSS DelphiFeeds.com

    • The Observer Design Pattern in Delphi – Pull November 8, 2009
      As mentioned in the previous article The Observer Design Pattern in Delphi – Push I intended to do a “Pull” article to show, what I think is, a significant “feature” of this pattern and one that I thought was underplayed in the Head First Design Patterns book that I’m learning from. I wrote code ...
      TDelphiHobbyist (TDelphiHobbyist)
    • Delphi Events – Verona – Stuttgart November 8, 2009
      On Tuesday i travel to verona to the IT Devcon the Italian Delphi Conference form 11-12 November. On this conference i will speak about: Delphi and Subversion Removing BDE from Delphi Projects Interbase 2009 the Vault But there are also many Speakers and Friends talking in a lot of sessions ...
      Daniel Magin's Weblog (dmagin)
    • Chad “Kudzu” Hower arrested and needs your help! November 7, 2009
      Hi, typically I am not blogging here about any non Development related things. Well there’s something that needs to be spread this way now: The famous and well-known Delphi Developer Chad “Kudzu” Hower had been arrested in Bulgaria on False Charges. Yes, Kudzu – the one ...
      Arvid's Blog (Arvid)
    • Do we need DelphiOverflow.com? November 6, 2009
      Today I was interviewed for the greatest Delphi podcast of them all and Jim asked me a question I didn’t know how to answer: “Do you think there should be Delphi equivalent of StackOverflow.com?” I’m afraid my answer was somewhere along: “Hmph. Yes. Very good question. Very good. Let’s talk about ...
      The Delphi Geek (gabr)
    • Your data, how you want it, where you want it, with DataSnap 2010 November 6, 2009
      You can use Embarcadero Technologies' RAD Studio 2010, Delphi 2010, C++Builder 2010, and Delphi Prism 2010 to build lightning-fast, rich native Windows, .NET, Web, and database applications.  You can also decide to use the new DataSnap 2010 technology to build distributed applications with separate ...
      Sip from the Firehose
    • The Anti-Case campaign November 6, 2009
      windwings
      Wings of Wind (Wings of Wind)
    • Use an Icon for a Glyph on a TBitBtn Delphi control with the help of TImageList November 6, 2009
      in Delphi TIPS :: The TBitBtn Delphi control is a button control that can include a bitmap on its face. The Glyph property specifies the bitmap that appears on the bitmap button. By design, the Glyph property can only display BMP (Windows Bitmap) images. Read the full article to learn how to Use ...
      About Delphi Programming
    • Casting lists using LINQ #2 November 5, 2009
      In my previous post I showed the LINQ way to cast List to List. Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->IEnumerable baseObjects = ...
      Delphi Power Unleashed (Roland Beenhakker)
    • Tell Cary a Birthday Story November 5, 2009
      Today is Cary Jensen’s birthday, and all he wants is your Unicode migration stories.  He is putting together a white paper on Unicode migration, and he needs your stories: both success and horror stories.  He hopes to capture what the migration was like in the real world, to help others who ...
      The PodCast at Delphi.org (Jim McKeeth)
    • Call for Unicode Migration Stories (by Cary Jensen) November 5, 2009
      As he blogged on http://caryjensen.blogspot.com/2009/10/share-your-unicode-migration-story.html, my friend Cary Jensen is looking for experiences in migrating Delphi projects to Unicode. He is looking for "real-life stories from developers".  The deadline for submitting ideas and material is ...
      Marco's Tech Blog (marcocantu)

Always double-check your itinerary

Posted by chuckbeasley on May 19, 2009

I spent the last few days attending a conference in San Francisco.  The conference was Friday through Sunday.  I knew when I purchased my airline ticket the dates of the conference.  Imagine my surprise when I received an email, shortly after midnight Saturday morning, informing me that it was time to check-in for my flight.  I knew this couldn’t be correct because my flight wasn’t scheduled to leave until 12:35 a.m. May 18 or so I thought.  After a conversation with the airline’s customer service department, just before 1 a.m., I realized that I had purchased the ticket for the wrong date.  Now, I’m not going to sit here and blame the website or anything else.  I bought the ticket and failed to verify the date of the return trip.  So, learn from me to always double-check your itinerary before you click the purchase button.  Otherwise, have fun booking a one-way ticket back home!

Posted in Travel | Leave a Comment »

Using OAUTH for Delphi

Posted by chuckbeasley on April 29, 2009

Before attempting to use OAUTH, you must obtain a developer key and secret from the service provider.  In the sample code provided in this article, I have removed my developer key and secret.  No other code modifications have been made.

Step 1 – Request request token (step A in diagram)

procedure TForm1.RqsBtnClick(Sender: TObject);
var
URL: string;
endpos: integer;
begin
Key := ‘http://www.myspace.com/developerkey’;
Secret := ‘developersecret’;
URL := ‘http://api.myspace.com/request_token’;
// Create all objects
Consumer := TOAuthConsumer.Create(Key, Secret);
HMAC := TOAuthSignatureMethod_HMAC_SHA1.Create;

ARequest := TOAuthRequest.Create(URL);

ARequest := ARequest.FromConsumerAndToken(Consumer, nil, URL);
ARequest.Sign_Request(HMAC, Consumer, nil);
HTTPStream := TStringStream.Create(”);
URL := URL + ‘?’ + ARequest.GetString;
Response := idHTTP1.Get(URL);

endpos := AnsiPos(‘&oauth_token_secret=’, Response);
oauth_token := ”;
oauth_token := Copy(Response, 13, endpos-13);
Response := Copy(Response, endpos, Length(Response));

oauth_token_secret := Copy(Response, 21, Length(Response));
Token := TOAuthToken.Create(oauth_token, oauth_token_secret);
end;

The service provider responds by sending a token and token secret, which is parsed from the Response variable.

Step 2 – Authorize (Step C in diagram)

procedure TForm1.AuthBtnClick(Sender: TObject);
var
Callback_URL, URL :string;
begin
URL := ‘http://api.myspace.com/authorize’;
Callback_URL := ‘http://www.chuckbeasley.com’;
URL := URL + ‘?’ + ‘oauth_token=’ + oauth_token + ‘&’ + ‘oauth_token_secret=’ + oauth_token_secret +
‘&oauth_callback=’ + TOAuthUtil.urlEncodeRFC3986(Callback_URL);
EmbeddedWB1.Navigate(URL);
end;

The token, token secret, and call back URL are appended to the URL.  The service provider obtains user authorization and directs the consumer to the call back URL.

Step 3 – Request access token (Step E in diagram)

procedure TForm1.AccBtnClick(Sender: TObject);
var
endpos: integer;
URL: string;
begin
URL := ‘http://api.myspace.com/access_token’;
Consumer := nil;
Consumer := TOAuthConsumer.Create(Key, Secret, ‘http://www.chuckbeasley.com’);
ARequest.HTTPURL := URL;
ARequest := ARequest.FromConsumerAndToken(Consumer, Token, URL);
ARequest.Sign_Request(HMAC, Consumer, Token);
URL := URL + ‘?’ + ARequest.GetString;
Response := idHTTP1.Get(URL);
endpos := AnsiPos(‘&oauth_token_secret=’, Response);
oauth_token := ”;
oauth_token := Copy(Response, 13, endpos-13);
Response := Copy(Response, endpos, Length(Response));

oauth_token_secret := Copy(Response, 21, Length(Response));
Token := TOAuthToken.Create(oauth_token, oauth_token_secret);
end;

The service provider responds by sending an access token and token secret, which is parsed from the Response variable.

Step 4 – Access protected resources (Step G on diagram)

procedure TForm1.AccRscClick(Sender: TObject);

procedure process(o: ISuperObject);
var
f: TSuperObjectIter;
i: Integer;
begin
case ObjectGetType(o) of
stObject:
begin
Memo1.Lines.Add(‘{‘);
if ObjectFindFirst(o, f) then
repeat
keypair := f.key;
process(f.val)
until not ObjectFindNext(f);
ObjectFindClose(f);
Memo1.Lines.Add(‘}’);
end;
stArray:
begin
Memo1.Lines.Add(‘[');
for i := 0 to o.AsArray.Length - 1 do
process(o.AsArray.O[i]);
Memo1.Lines.Add(‘]’);
end;
stString:
begin
keypair := keypair + ‘:’ +(UTF8Decode(o.AsString));
Memo1.Lines.Add(keypair);
end;
stNull:
Memo1.Lines.add(‘nil’);
else
Memo1.Lines.add(o.AsString);
end;
end;
var
json: ISuperObject;
StringList: TStringList;
URL: string;
begin
URL := ‘http://api.myspace.com/v2/people/40250975/@friends?count=10000&format=json’;
Consumer := nil;
Consumer := TOAuthConsumer.Create(Key, Secret, ‘http://www.chuckbeasley.com’);
ARequest.HTTPURL := URL;
ARequest := ARequest.FromConsumerAndToken(Consumer, Token, URL);
ARequest.Sign_Request(HMAC, Consumer, Token);
URL := URL + ‘&’ + ARequest.GetString;
Response := idHTTP1.Get(URL);

StringList := TStringList.Create;
StringList.Add(Response);

json := TSuperObject.Create(stObject);
json.Merge(Response);
json := json.O['entry'];
Memo1.Lines.Clear;
process(json);
end;

This step assumes that the profile owner has authorized the application to access its protected data.  That can be performed by adding the application to the profile.

OAUTH for Delphi is available via SVN:   http://oauthdelphi.svn.sourceforge.net/.

Posted in Delphi | Leave a Comment »

Catching up with technology

Posted by chuckbeasley on March 25, 2009

So, I’ve finally decided to write an entry in my blog.  In less than 2 weeks, I’ve join Twitter and begun blogging.  I’m not exactly sure what I’ll find to write about, but I’ll make it interesting.  Check back from time to time to see what things I find on the ‘net.

Posted in Uncategorized | Leave a Comment »