Closed MakersF closed 9 years ago
When I initially built Orianna, which Cass is in a lot of ways a new version of, I made the API an object instead of a static resource. In the second version of Ori and in Cass I switched to a static resource based on the following analysis:
1) One important goal of these libraries is to help enforce best practice when accessing the API. As the use of multiple API keys for the same project is forbidden by Riot, this helps enforce that policy
2) It more closely models the "real world" construct that the wrapper represents. This goes along with why API values for Core objects are immutable. The REST API that's being accessed itself is a single static resource, and the data it serves can't be modified.
3) Since the API key should be the same across all API instances in this setup, synchronization of the underlying rate limiters can become cumbersome, especially if the rate limits for several instances are being changed long after creation.
4) The static resource setup allows for "singleton-esque" accessibility of the API anywhere in the application where the rate limit synchronization is handled painlessly.
5) The encapsulation and accessibility control of the methods/data is the part of making this a class which is actually desirable for the wrapper. A module or an abstract class (Java) handles those nicely without bringing along instantiability, inheritence, polymorphism, and the rest of the fixings of classes that don't really serve a purpose in this case.
6) On the flip side, the benefit I see for breaking these out into classes is that you can subdivide your rate limit among multiple tasks and that flipping between calls to different regions is easier.
All things considered, I think the cons of the static resource approach are significantly outweighed. There are alternative solutions to get the same functionality without losing the valuable aspects of the static resources.
That makes sense! I agree with you.
Made some changes to the structure of the code. Now you have a class which exposes all the api functions as members. Moreover you can have multiple of this class, which can share any of the key, region, rate limiter and so on.
You can find the changes here. Let me know if you are interested into them (at the moment core doesn't work, as it hasn't been translated to the new pattern)
Prints
Examples with summoners, but you can use it for any function in the api