littlebits / cloud-client-api-http

Lightweight wrapper for littleBits Cloud HTTP API
GNU General Public License v3.0
32 stars 10 forks source link

New interface #18

Open jasonkuhrt opened 8 years ago

jasonkuhrt commented 8 years ago

The following sketches the core necessary actions and their types.

-- Devices Actions

devicesGet :: AccessToken -> Promise (List Device)

-- Device Actions

devicePost     :: AccessToken -> DeviceSpec -> Promise Device
deviceSettings :: AccessToken -> DeviceID -> SettingsSpec -> Promise Device
deviceGet      :: AccessToken -> DeviceID -> Promise Device
deviceDelete   :: AccessToken -> DeviceID -> Promise Device

-- Device Input Actions

deviceInputGet :: AccessToken -> DeviceID -> ReadSemantics -> Promise InputEvent

-- Device Output Actions

deviceOutputPost :: AccessToken -> DeviceID -> Promise ()

-- Relation Actions

relationPost         :: AccessToken -> RelationSpec -> Promise Relation
relationGet          :: AccessToken -> EdgeIdent -> Promise Relation
relationGetSubjects  :: AccessToken -> VertexID -> Promise (List Relation)
relationGetObservers :: AccessToken -> VertexID -> Promise (List Relation)
relationDelete       :: AccessToken -> EdgeIdent -> Promise Relation

Sugar for AccessToken

There should be an easy way for the user to get an API that has the first argument AccessToken applied. For example the following could return whole API with AccessToken partially applied to each action:

littleBitsCloud
  .withUser('83hs026fbn2pqw=27qbs91571k')
  // deviceSettings :: DeviceID -> SettingsSpec -> Promise Device
  // deviceGet      :: DeviceID -> Promise Device
  // etc.

Sugar for DeviceID

There should be an easy way for the user to get an API to work with a specific device wherein the second argument DeviceID is applied. For example:

littleBitsCloud
  .withUser('83hs026fbn2pqw=27qbs91571k')
  .withDevice('71d1hoa610')
  // deviceSettings :: SettingsSpec -> Promise Device
  // deviceGet      :: Promise Device
  // etc.

The returned API function names should have aliases that drop the device prefix given that it is redundant in this chaining context. So for example these two would be the same:

littleBitsCloud
  .withUser('83hs026fbn2pqw=27qbs91571k')
  .withDevice('71d1hoa610')
  .deviceSettings({ input_interval_ms: 50 })
  // ...
littleBitsCloud
  .withUser('83hs026fbn2pqw=27qbs91571k')
  .withDevice('71d1hoa610')
  .settings({ input_interval_ms: 50 })
  // ...