Ruminations of an addled mind

Random ramblings about my thoughts

  • Meta

  • RSS DelphiFeeds.com

    • Less Checking – More QA! November 22, 2017
      Julia Atlygina and developer Alexander Ivkin came by our TestRail stand at the Atlasssian Conference. Imagine our surprise when we learned they had created a mobile application that enables users to view, execute and get reports on their tests from a linked TestRail instance!  As you’ll know ...
      blog.gurock.com (Simon Knight)
    • check if network connection is permanent November 22, 2017
      Thanks Uwe for the below code! I was in a situation of a batch file running from a Task Scheduler that got broken because the user suddenly turned on persistent network connections. So I needed to check if a shared drive-letter was indeed persistent or not and act accordingly. The below code helped ...
      The Wiert Corner (jpluimers)
    • Delphi history: No, dynamic arrays do not support a non-zero lower bound, but what if you want them? – via Stack Overflow November 21, 2017
      A post of some older Delphi stuff I did in the past just in case need it again. David Heffernan found the documentation for this: [WayBack] Structured Types (Delphi): Dynamic Arrays – RAD Studio Since I needed a dynamic array structure supporting a non-zero lower bound, I was glad he also ...
      The Wiert Corner (jpluimers)
    • New on Embarcadero Academy: CodeRage Replays and my New Course and Bundle November 20, 2017
      Embarcadero Academy is an independent online training site available at https://www.embarcaderoacademy.com/. The site has an overall agreement with Embarcadero as a key destination for online training for the company development tools products. The academy site co-hosted the CodeRage XII ...
      Marco's Tech Blog (marcocantu)
    • 30% discount on EurekaLog November 20, 2017
      We are pleased to announce Black Friday and Cyber Monday 30% discount on any of our EurekaLog products using the coupon code found below. The sale starts on Black Friday (24 November) and ends at end of Cyber Monday (27 November). Enter this code when paying for the item on our web site: BFCM2017 ...
      EurekaLog Blog (Александр Алексеев)
    • Testing Tools in Python November 17, 2017
      Python offers several robust testing libraries, from unit testing and mocking for integration tests to security, load, and UI testing. We have reviewed several libraries and have chosen to share these for their ease of implementation, ease of use, and community contribution/active maintenance over ...
      blog.gurock.com (Simon Knight)
    • Explaining Tasks in Delphi Parallel Library... by Creating too Many Tasks November 16, 2017
      Recently, I wrote some new demo for Delphi PPL (Parallel Programming Library), while doing some research for an online class -- which is available since last week on the Embarcadero Academy site ("Anonymous Methods in Delphi"), along with a new overall bundle of my classes ("Master Modern Delphi ...
      Marco's Tech Blog (marcocantu)
    • Hi! how to hide a property in object inspector? i have my custom components … November 16, 2017
      For my link archive: [WayBack] How to hide a property in object inspector? i have my custom components … [WayBack] delphi – Custom component and tab order – Stack Overflow Some quotes Jeroen Wiert Pluimers You cannot undo things that are inherited. What you can do is not make ...
      The Wiert Corner (jpluimers)
    • FastMM4 + Delphi – Recompiling application with 10.2.1 causes memory leaks? November 15, 2017
      This is why you should always test your Delphi apps with FastMM4 and FullDebugMode enabled: [WayBack] Delphi – Recompiling application with 10.2.1 causes memory leaks? A workaround is to add the below code in either of these places: end of your .dpr file right before the end. in the ...
      The Wiert Corner (jpluimers)
    • How I Learned to Build a Test Suite November 15, 2017
      I learned to build a UI automation suite through a lot of trial and error. This article would be the guide of how to teach yourself to design a suite from the ground up: resources for learning specific skills, reasons for selecting languages (Python or Ruby are lightweight choices and easier to ...
      blog.gurock.com (Simon Knight)

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!

Advertisements

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 | 2 Comments »

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 »