Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 20 Next »

The SHELL adapter library is just intended to something you copy and rename and make it into a real adapter for a real system. It has all the boiler plate you need. I made it because I wanted to try to build a few adapters to Solve the calendar management problem.

I took the Slack Notifier Adapter and hollowed it out to make this empty adapter. Should help me write a few adapters fast (remove bottlenecks )

The shell adapter ships with Iguana just add the Shell Example - see Create a Component .

So how do we use it say to create an Atlassian adapter.

 The Goal - A good adapter will have very little code and be easy for the user to extend

It’s better to have a simple ‘incomplete’ adapter that is easily understood and altered by the user than an over elaborate one.

Iguana X is a open system which is intended to allow our customers and do anything. Overly elaborate adapters means that the code is a what we call a Code dump which makes it difficult for other people to adapt and use the code to their own purposes.

This is problem with a lot of Open Source projects.

Sure you have access to the code but that isn’t helpful if it takes months of study to understand it and it the code has many many design flaws that you cannot solve without with years of commitment.

Less is more.

 Import the SHELL library and associate it with a new repo

Let’s say git@bitbucket.org:interfaceware/atlassian

 Rename the folder and all the files in it to a new prefix

For instance:

 Create a new git repo for your new Library

Use ‘View Remote’ for the now named ATTL library

image-20240319-145410.png

… and specify new REPOSITORY name for this Library to be associated with

image-20240319-145629.png
 Search and replace SHELL for ATTL in the project

This gets all the prefixes consistent.

 Make sure the ATTLclient function gets the parameters needed to authenticate
function ATTLclient(T)
   local S= {}
   setmetatable(S, MT)
   S.key = T.key
   return S
end

So in the case of Atlassian we need:

  • user - I.e. fred.smith@acme.com

  • space - i.e. ABC for a Confluence space that has this ID

  • key - A unique personal API key for a confluence user

  • organization - to construct base URL to our Confluence space, e.g. https://acme.atalassian.net

This adheres with Naming convention for table parameters in Iguana.

These should just be passed through in the table arguments. So the code becomes:

function ATTLclient(T)
   local S= {}
   setmetatable(S, MT)
   S.key           = T.key
   S.space         = T.space
   S.user          = T.user
   S.organization  = T.organization
   return S
end
 Implement a good custom method

The custom method should do most the guts of the adapter. Most web APIs have some magic sauce that you have to make an API call. The custom method does this and should make it easy to call methods on the API which have not been wrapped explicitly.

Let’s call our new Custom method ATTLdescendants. We can rename ATTLhello into ATTLdescendants and to rewrite its content.

 Implement a good API method

Let’s call our new API method ATTLgetDescendants. We can rename ATTLcustom into ATTLgetDescendants and to rewrite its content.

This method will returns all pages in a space.

 More about API methods

Sometimes an API method would require a parameter which can be discovered only programmatically. In our example of Confluence Adapter this is Confluence Space Id parameter, which isn’t the same as a Space Key above. The API method ATTLgetSpaceId will help us to discover this value. Let’s create new Lua file, name it ATTLgetSpaceId and write its content.

 Update Client Constructor

Append to Client’s meta table the three newly added methods

 Not to forget the Help files

Add Help files to explain what parameters your custom methods expect. Other users will appreciate this!

 Time to put all of this to good work.

First we discover the Confluence Space ID. Next we prepare for paginated API call and require only 2 calls to be executed. This will save the test time. And finally, we request and get a listing of descendants for 50 pages.

 Share a little of 'what is next'?

So, we can query Atlassian API for Confluence! What it is good for? We can query documents, we can edit documents, we can modify/export/add/delete content in any manner we imagine. The complete documentation for this API is available here.

Just create more API methods and more Custom methods.

Custom methods are very helpful to keep API methods true to API documentation. Custom methods will help to create your specific parameters combination, and to massage the responses. Custom methods are the interface, between your code, to clean and true API methods.

  • No labels