Skip to content

Working with non-restful entities #12

Open

Description

@SteveRedka

Let's assume we have an API that returns a list of entities. But list is paginated; so it has several helpful fields, and entity data itself is stored in separate key, say, results. It could look like this:

{
  "next": null,
  "previous": null,
  "total": 3,
  "per_page": 100,
  "results": [
    {
      "entity_id": 1,
      "datetime_stored": "2020-01-16T14:48:46.897379Z"
    },
    {
      "entity_id": 2,
      "datetime_stored": "2020-01-16T15:02:30.430281Z"
    },
    {
      "entity_id": 3,
      "datetime_stored": "2020-01-16T15:03:15.315064Z"
    }
  ]
}

What is the proper way for writing index for this?

Activity

  1. SteveRedka commented on Jan 17, 2020

    @SteveRedka
    Author

    Currently I do it like this:

      class EntityClient < ApiStruct::Client
        rest_api 'entities'
    
        def index
          response = get(path: 'entities/', headers: SimpleAuthenticationHeader.call)
          response.fmap { |i| i[:results] }
        end
      end

    However, README.md didn't say anything that I am supposed to know anything about monads. Either I do it wrong or it should be mentioned in docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions