Skip to content

Commit 8a1eccc

Browse files
committed
Improve iot client function names
1 parent 990e625 commit 8a1eccc

File tree

11 files changed

+39
-39
lines changed

11 files changed

+39
-39
lines changed

command/device/create.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func Create(params *CreateParams) (string, error) {
5757
}
5858

5959
fmt.Println("Creating a new device on the cloud")
60-
devID, err := iotClient.AddDevice(dev.fqbn, params.Name, dev.serial, dev.dType)
60+
devID, err := iotClient.DeviceCreate(dev.fqbn, params.Name, dev.serial, dev.dType)
6161
if err != nil {
6262
return "", err
6363
}
@@ -71,7 +71,7 @@ func Create(params *CreateParams) (string, error) {
7171
if err != nil {
7272
// TODO: retry to delete the device if it returns an error.
7373
// In alternative: encapsulate also this error.
74-
iotClient.DeleteDevice(devID)
74+
iotClient.DeviceDelete(devID)
7575
err = fmt.Errorf("%s: %w", "cannot provision device", err)
7676
return "", err
7777
}

command/device/delete.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ func Delete(params *DeleteParams) error {
2323
return err
2424
}
2525

26-
return iotClient.DeleteDevice(params.ID)
26+
return iotClient.DeviceDelete(params.ID)
2727
}

command/device/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func List() ([]DeviceInfo, error) {
2727
return nil, err
2828
}
2929

30-
foundDevices, err := iotClient.ListDevices()
30+
foundDevices, err := iotClient.DeviceList()
3131
if err != nil {
3232
return nil, err
3333
}

command/device/provision.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (p provision) configDev() error {
7878
if err != nil {
7979
return err
8080
}
81-
cert, err := p.AddCertificate(p.id, string(csr))
81+
cert, err := p.CertificateCreate(p.id, string(csr))
8282
if err != nil {
8383
return err
8484
}

command/thing/bind.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func Bind(params *BindParams) error {
3131
DeviceId: params.DeviceID,
3232
}
3333

34-
err = iotClient.UpdateThing(params.ID, thing, true)
34+
err = iotClient.ThingUpdate(params.ID, thing, true)
3535
if err != nil {
3636
return err
3737
}

command/thing/clone.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func Clone(params *CloneParams) (string, error) {
3434

3535
thing.Name = params.Name
3636
force := true
37-
thingID, err := iotClient.AddThing(thing, force)
37+
thingID, err := iotClient.ThingCreate(thing, force)
3838
if err != nil {
3939
return "", err
4040
}
@@ -43,7 +43,7 @@ func Clone(params *CloneParams) (string, error) {
4343
}
4444

4545
func retrieve(client iot.Client, thingID string) (*iotclient.Thing, error) {
46-
clone, err := client.GetThing(thingID)
46+
clone, err := client.ThingShow(thingID)
4747
if err != nil {
4848
return nil, fmt.Errorf("%s: %w", "retrieving the thing to be cloned", err)
4949
}

command/thing/create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func Create(params *CreateParams) (string, error) {
4646
}
4747

4848
force := true
49-
thingID, err := iotClient.AddThing(thing, force)
49+
thingID, err := iotClient.ThingCreate(thing, force)
5050
if err != nil {
5151
return "", err
5252
}

command/thing/delete.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ func Delete(params *DeleteParams) error {
2323
return err
2424
}
2525

26-
return iotClient.DeleteThing(params.ID)
26+
return iotClient.ThingDelete(params.ID)
2727
}

command/thing/extract.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func Extract(params *ExtractParams) error {
3131
return err
3232
}
3333

34-
thing, err := iotClient.GetThing(params.ID)
34+
thing, err := iotClient.ThingShow(params.ID)
3535
if err != nil {
3636
err = fmt.Errorf("%s: %w", "cannot extract thing: ", err)
3737
return err

command/thing/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func List(params *ListParams) ([]ThingInfo, error) {
3737
return nil, err
3838
}
3939

40-
foundThings, err := iotClient.ListThings(params.IDs, params.DeviceID, params.Variables)
40+
foundThings, err := iotClient.ThingList(params.IDs, params.DeviceID, params.Variables)
4141
if err != nil {
4242
return nil, err
4343
}

internal/iot/client.go

+27-27
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import (
1010

1111
// Client can be used to perform actions on Arduino IoT Cloud.
1212
type Client interface {
13-
AddDevice(fqbn, name, serial, devType string) (string, error)
14-
DeleteDevice(id string) error
15-
ListDevices() ([]iotclient.ArduinoDevicev2, error)
16-
AddCertificate(id, csr string) (*iotclient.ArduinoCompressedv2, error)
17-
AddThing(thing *iotclient.Thing, force bool) (string, error)
18-
UpdateThing(id string, thing *iotclient.Thing, force bool) error
19-
DeleteThing(id string) error
20-
GetThing(id string) (*iotclient.ArduinoThing, error)
21-
ListThings(ids []string, device *string, props bool) ([]iotclient.ArduinoThing, error)
13+
DeviceCreate(fqbn, name, serial, devType string) (string, error)
14+
DeviceDelete(id string) error
15+
DeviceList() ([]iotclient.ArduinoDevicev2, error)
16+
CertificateCreate(id, csr string) (*iotclient.ArduinoCompressedv2, error)
17+
ThingCreate(thing *iotclient.Thing, force bool) (string, error)
18+
ThingUpdate(id string, thing *iotclient.Thing, force bool) error
19+
ThingDelete(id string) error
20+
ThingShow(id string) (*iotclient.ArduinoThing, error)
21+
ThingList(ids []string, device *string, props bool) ([]iotclient.ArduinoThing, error)
2222
}
2323

2424
type client struct {
@@ -38,9 +38,9 @@ func NewClient(clientID, secretID string) (Client, error) {
3838
return cl, nil
3939
}
4040

41-
// AddDevice allows to create a new device on Arduino IoT Cloud.
41+
// DeviceCreate allows to create a new device on Arduino IoT Cloud.
4242
// It returns the ID associated to the new device, and an error.
43-
func (cl *client) AddDevice(fqbn, name, serial, dType string) (string, error) {
43+
func (cl *client) DeviceCreate(fqbn, name, serial, dType string) (string, error) {
4444
payload := iotclient.CreateDevicesV2Payload{
4545
Fqbn: fqbn,
4646
Name: name,
@@ -55,9 +55,9 @@ func (cl *client) AddDevice(fqbn, name, serial, dType string) (string, error) {
5555
return dev.Id, nil
5656
}
5757

58-
// DeleteDevice deletes the device corresponding to the passed ID
58+
// DeviceDelete deletes the device corresponding to the passed ID
5959
// from Arduino IoT Cloud.
60-
func (cl *client) DeleteDevice(id string) error {
60+
func (cl *client) DeviceDelete(id string) error {
6161
_, err := cl.api.DevicesV2Api.DevicesV2Delete(cl.ctx, id)
6262
if err != nil {
6363
err = fmt.Errorf("deleting device: %w", errorDetail(err))
@@ -66,9 +66,9 @@ func (cl *client) DeleteDevice(id string) error {
6666
return nil
6767
}
6868

69-
// ListDevices retrieves and returns a list of all Arduino IoT Cloud devices
69+
// DeviceList retrieves and returns a list of all Arduino IoT Cloud devices
7070
// belonging to the user performing the request.
71-
func (cl *client) ListDevices() ([]iotclient.ArduinoDevicev2, error) {
71+
func (cl *client) DeviceList() ([]iotclient.ArduinoDevicev2, error) {
7272
devices, _, err := cl.api.DevicesV2Api.DevicesV2List(cl.ctx, nil)
7373
if err != nil {
7474
err = fmt.Errorf("listing devices: %w", errorDetail(err))
@@ -77,9 +77,9 @@ func (cl *client) ListDevices() ([]iotclient.ArduinoDevicev2, error) {
7777
return devices, nil
7878
}
7979

80-
// AddCertifcate allows to upload a certificate on Arduino IoT Cloud.
80+
// CertificateCreate allows to upload a certificate on Arduino IoT Cloud.
8181
// It returns the certificate parameters populated by the cloud.
82-
func (cl *client) AddCertificate(id, csr string) (*iotclient.ArduinoCompressedv2, error) {
82+
func (cl *client) CertificateCreate(id, csr string) (*iotclient.ArduinoCompressedv2, error) {
8383
cert := iotclient.CreateDevicesV2CertsPayload{
8484
Ca: "Arduino",
8585
Csr: csr,
@@ -95,8 +95,8 @@ func (cl *client) AddCertificate(id, csr string) (*iotclient.ArduinoCompressedv2
9595
return &newCert.Compressed, nil
9696
}
9797

98-
// AddThing adds a new thing on Arduino IoT Cloud.
99-
func (cl *client) AddThing(thing *iotclient.Thing, force bool) (string, error) {
98+
// ThingCreate adds a new thing on Arduino IoT Cloud.
99+
func (cl *client) ThingCreate(thing *iotclient.Thing, force bool) (string, error) {
100100
opt := &iotclient.ThingsV2CreateOpts{Force: optional.NewBool(force)}
101101
newThing, _, err := cl.api.ThingsV2Api.ThingsV2Create(cl.ctx, *thing, opt)
102102
if err != nil {
@@ -105,8 +105,8 @@ func (cl *client) AddThing(thing *iotclient.Thing, force bool) (string, error) {
105105
return newThing.Id, nil
106106
}
107107

108-
// AddThing updates a thing on Arduino IoT Cloud.
109-
func (cl *client) UpdateThing(id string, thing *iotclient.Thing, force bool) error {
108+
// ThingUpdate updates a thing on Arduino IoT Cloud.
109+
func (cl *client) ThingUpdate(id string, thing *iotclient.Thing, force bool) error {
110110
opt := &iotclient.ThingsV2UpdateOpts{Force: optional.NewBool(force)}
111111
_, _, err := cl.api.ThingsV2Api.ThingsV2Update(cl.ctx, id, *thing, opt)
112112
if err != nil {
@@ -115,8 +115,8 @@ func (cl *client) UpdateThing(id string, thing *iotclient.Thing, force bool) err
115115
return nil
116116
}
117117

118-
// DeleteThing deletes a thing from Arduino IoT Cloud.
119-
func (cl *client) DeleteThing(id string) error {
118+
// ThingDelete deletes a thing from Arduino IoT Cloud.
119+
func (cl *client) ThingDelete(id string) error {
120120
_, err := cl.api.ThingsV2Api.ThingsV2Delete(cl.ctx, id, nil)
121121
if err != nil {
122122
err = fmt.Errorf("deleting thing: %w", errorDetail(err))
@@ -125,9 +125,9 @@ func (cl *client) DeleteThing(id string) error {
125125
return nil
126126
}
127127

128-
// GetThing allows to retrieve a specific thing, given its id,
128+
// ThingShow allows to retrieve a specific thing, given its id,
129129
// from Arduino IoT Cloud.
130-
func (cl *client) GetThing(id string) (*iotclient.ArduinoThing, error) {
130+
func (cl *client) ThingShow(id string) (*iotclient.ArduinoThing, error) {
131131
thing, _, err := cl.api.ThingsV2Api.ThingsV2Show(cl.ctx, id, nil)
132132
if err != nil {
133133
err = fmt.Errorf("retrieving thing, %w", errorDetail(err))
@@ -136,8 +136,8 @@ func (cl *client) GetThing(id string) (*iotclient.ArduinoThing, error) {
136136
return &thing, nil
137137
}
138138

139-
// ListThings returns a list of things on Arduino IoT Cloud.
140-
func (cl *client) ListThings(ids []string, device *string, props bool) ([]iotclient.ArduinoThing, error) {
139+
// ThingList returns a list of things on Arduino IoT Cloud.
140+
func (cl *client) ThingList(ids []string, device *string, props bool) ([]iotclient.ArduinoThing, error) {
141141
opts := &iotclient.ThingsV2ListOpts{}
142142
opts.ShowProperties = optional.NewBool(props)
143143

0 commit comments

Comments
 (0)