Project

api_smash

0.0
No commit activity in last 3 years
No release in over 3 years
An enhanced Hash useful for API clients. Extracted from API Smith, and extends Hashie::Dash.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
~> 2.0

Runtime

~> 1.0
 Project Readme

ApiSmash - A Smarter Hash

The ApiSmash class is a 'smarter' (or, alternatively, structured) hash. Built on top of Hashie::Dash, ApiSmash adds several features that make it useful for making objects that represent an external api response. On top of the base Hashie::Dash feature set, ApiSmash adds:

Configuration of alternative names for fields

A feature useful for dealing with apis where they may have a fullName field in their api response but you want to use full_name. Configurable by a simple :from option on property declarations.

This importantly lets you deal with one format internally whilst automatically taking care of normalising external data sources. More importantly, it also provides simple methods you can override to handle a wide range of external schemes (e.g. always underscoring the field name).

Configurable transformers

Essentially, any object (e.g. a lambda, a class or something else) that responds to #call can be used to transform incoming data into a useable format. More importantly, your api_smash classes will also respond to #call meaning they can intelligently be used as transformers for other classes, making complex / nested objects simple and declarative.

Using it on a property is as simple as passing a :transformer option with the #call-able object as the value.

A well defined (and documented) api

Making it possible for you to hook in at multiple stages to further specialise your ApiSmash objects for specific API use cases.

Contributors

API Smith was written by Darcy Laycock, and Steve Webb from The Frontier Group, as part of a bigger project with Filter Squad.

This 'ApiSmash' library was extracted from it.

Contributing

We encourage all community contributions. Keeping this in mind, please follow these general guidelines when contributing:

  • Fork the project
  • Create a topic branch for what you’re working on (git checkout -b awesome_feature)
  • Commit away, push that up (git push your_remote awesome_feature)
  • Create a new GitHub Issue with the commit, asking for review. Alternatively, send a pull request with details of what you added.
  • Once it’s accepted, if you want access to the core repository feel free to ask! Otherwise, you can continue to hack away in your own fork.

Other than that, our guidelines very closely match the GemCutter guidelines here.

(Thanks to GemCutter for the contribution guide)

License

API Smith is released under the MIT License (see the license file) and is copyright Filter Squad, 2011. Therefore so is 'ApiSmash'.