[Eiffel-Loop News] Update on Amazon Instant Access API

11 views
Skip to first unread message

Finnian Reilly

unread,
Dec 7, 2017, 6:05:54 AM12/7/17
to Eiffel Users
Amazon Instant Access API
Amazon Instant Access (AIA) is a fulfilment technology for digital content that is purchased on the Amazon website and is delivered by a third party vendor.

Motivation
My motivation for developing this API is so I can advertise my software on the thousands of books sold by Amazon relevant to the software. But do this I need to become a vendor. It could be worth it despite the 30% cut Amazon take on the software.

Progress Update
Work on this API is now substantially finished although I have yet to test against a live server.  I have inserted links to the integration guide in the class descriptions. I have not bothered to implement the subscription activation part of the API since I have my own software subscription system. But will be happy to implement it for anyone who requests it. There is very little in it.

Test Suite
The code for the test suite can be found here.

New Reflective Classes
It's a fairly simple API and the reason it has been taking so long is I have been using it as a test ground for some new Eiffel-Loop classes that provide some powerful reflective capabilities. If you examine the AIA code you will find many classes are curiously absent of code that does anything. For example you won't find any JSON related strings, and you won't find any code to translate between the JSON camel case and the Eiffel snake case naming conventions, and you won't find any code that defines object equality by attribute comparison. All the heavy lifting is done by the reflective parent. Here is the reflective class hierarchy as pertaining to the AIA api.

EL_REFLECTION
   EL_STATUS_CODE_REFLECTION* [N -> {NUMERIC, HASHABLE}]
      AIA_RESPONSE_CODE
      AIA_REASON_CODE
   EL_REFLECTIVELY_SETTABLE* [S -> STRING_GENERAL create make_empty end]
      EL_STORABLE*
         AIA_CREDENTIAL
      EL_REFLECTIVELY_JSON_SETTABLE*
         AIA_REQUEST*
            AIA_GET_USER_ID_REQUEST
            AIA_PURCHASE_REQUEST
               AIA_REVOKE_REQUEST
         AIA_RESPONSE
            AIA_GET_USER_ID_RESPONSE
            AIA_PURCHASE_RESPONSE
               AIA_REVOKE_RESPONSE
      AIA_AUTHORIZATION_HEADER
      EL_REFLECTIVELY_SETTABLE_STRINGS* [S -> STRING_GENERAL create make_empty end]
         AIA_CREDENTIAL_ID
      FCGI_REQUEST_PARAMETERS
      FCGI_HTTP_HEADERS

Source Code
The code is not yet part of an Eiffel-Loop release but is available by cloning or checking out the github repository.

The AIA code is located here


Finnian Reilly

unread,
Dec 7, 2017, 6:39:56 AM12/7/17
to Eiffel Users
Reflection Notes

I forgot to mention about one cool new feature of the template substitution class  EL_SUBSTITUTION_TEMPLATE that is demonstrated in class AIA_AUTHORIZATION_HEADER. You can use `set_variables_from_object' to reflectively set the variables in the template from an object that implements EL_REFLECTIVELY_SETTABLE.

feature -- Access

   as_string: STRING
      local
         template: like Signed_string_template
      do
         template := Signed_string_template
         template.wipe_out_variables
         template.set_variables_from_object (Current)
         template.set_variables_from_object (credential)
         Result := template.substituted
      end

feature {NONE} -- Constants

   Signed_string_template: EL_SUBSTITUTION_TEMPLATE [STRING]
      once
         create Result.make ("$algorithm SignedHeaders=$signed_headers, Credential=$key/$date, Signature=$signature")
      end

A Note on Efficiency

It is worth pointing out that class EL_REFLECTIVELY_SETTABLE removes a major source of inefficiency from the underlying Eiffel reflection API. I am referring to calls to {REFLECTED_OBJECT}.field_name which creates a new string every time it's called. Class EL_REFLECTIVELY_SETTABLE caches field names in a table `field_index_table' which is generated only once per each reflectively settable type.

Reply all
Reply to author
Forward
0 new messages