Giter Club home page Giter Club logo

ex_castor_edc's Introduction

Hi there ๐Ÿ‘‹

ex_castor_edc's People

Contributors

basbl avatar zoni avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

zoni

ex_castor_edc's Issues

Refactor `CastorEDC.Client`

There's likely to be more additions in the future that end-users might want to set (timeouts, for example). It could be nice to make that possible through an interface like:

def new(client_id, client_secret, opts \\ [])

Where opts is a keyword list that accepts :endpoint, :user_agent, :connect_timeout, :read_timeout etc.

This would be a breaking change though (unless you add a new/5 like def new(client_id, client_secret, endpoint, opts \\ []) but that starts getting unwieldy, especially as the same opts parameter needs to be made available on access_token()), so I didn't want to go there yet without some discussion.

On that note, another perhaps elegant way to model this is:

def new(credentials, opts \\ [])

# or:

def new(credentials, endpoint, opts \\ [])

Where credentials can be given as %{"client_id" => "...", "client_secret" => "..."} or %{"access_token" => "..."}. Then you could do away with the separate access_token/1 and access_token/2 functions.

Originally posted by @zoni in #18 (comment)

Error handling patterns

At the moment, the success/error API for this library uses a pattern of {<http_response_code>, <data>, <maybe more data>}.
For example:

{200, list_of_studies, _} = CastorEDC.Common.Studies.list(client)

This requires people to know what status code is expected from the api (are there cases where we get 201 instead of 200?) and it makes it a little less ergonomic to incorporate into with statements or approaches advocated by the OK library.

Furthermore, calls may generate an exception, for example on networking errors, due to the use of exception-raising Tesla methods. For example:

|> Tesla.get!(url(client, url), query: params)

I have not explored how much effort it would be to actually adjust this, but I believe we may be able to make error-handling patterns more friendly to end-users if the following conventions were adopted:

  1. Regular API calls will only ever return {:ok, data} or {:error, reason} tuples.
  2. (Optional) ! methods are provided to do automatic unpacking/raise-on-error behavior. (list_of_studies = CastorEDC.Common.Studies.list!(client) in the example above)

What are your thoughts on such a design?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.