spotify.cr icon indicating copy to clipboard operation
spotify.cr copied to clipboard

Abstractions

Open marceloboeira opened this issue 8 years ago • 0 comments

Currently we have shitty abstractions for the resource, the request and the API setup.

Basically we have to improve this parts of the code: https://github.com/marceloboeira/spotify.cr/blob/master/src/spotify/resource.cr

I'm not sure currently what is the best way to do this, @gabrielalmir10 @bronzdoc any suggestions?

Desired 'DSL':

module Spotify
  class Albums < Resource
    resource_for("albums")
    attributes({
       id:   String,
       name: String,
       genres: { type: Array(String), default: [], nilable: true } 
     })
  end
end

Where: resource_for is a macro that registers and identify the resource attributes is a macro for the JSON.mapping

Some available methods, coming from the resource inheritance:

  • find(id)
  • from_json(String | JSON::Any)
  • to_json

marceloboeira avatar Mar 17 '16 01:03 marceloboeira