|
1 | 1 | package api |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "net/http" |
| 5 | + |
4 | 6 | "github.com/danielpaulus/go-ios/ios" |
5 | 7 | "github.com/danielpaulus/go-ios/ios/instruments" |
6 | 8 | "github.com/danielpaulus/go-ios/ios/screenshotr" |
| 9 | + "github.com/danielpaulus/go-ios/ios/simlocation" |
7 | 10 | "github.com/gin-gonic/gin" |
8 | 11 | log "github.com/sirupsen/logrus" |
9 | | - "net/http" |
10 | 12 | ) |
11 | 13 |
|
12 | 14 | // Info gets device info |
@@ -64,3 +66,54 @@ func Screenshot(c *gin.Context) { |
64 | 66 | c.Header("Content-Type", "image/png") |
65 | 67 | c.Data(http.StatusOK, "application/octet-stream", b) |
66 | 68 | } |
| 69 | + |
| 70 | +// Change the current device location |
| 71 | +// @Summary Change the current device location |
| 72 | +// @Description Change the current device location to provided latitude and longtitude |
| 73 | +// @Tags general_device_specific |
| 74 | +// @Produce json |
| 75 | +// @Param latitude query string true "Location latitude" |
| 76 | +// @Param longtitude query string true "Location longtitude" |
| 77 | +// @Success 200 {object} GenericResponse |
| 78 | +// @Failure 422 {object} GenericResponse |
| 79 | +// @Failure 500 {object} GenericResponse |
| 80 | +// @Router /device/{udid}/setlocation [post] |
| 81 | +func SetLocation(c *gin.Context) { |
| 82 | + device := c.MustGet(IOS_KEY).(ios.DeviceEntry) |
| 83 | + latitude := c.Query("latitude") |
| 84 | + if latitude == "" { |
| 85 | + c.JSON(http.StatusUnprocessableEntity, GenericResponse{Error: "latitude query param is missing"}) |
| 86 | + return |
| 87 | + } |
| 88 | + |
| 89 | + longtitude := c.Query("longtitude") |
| 90 | + if longtitude == "" { |
| 91 | + c.JSON(http.StatusUnprocessableEntity, GenericResponse{Error: "longtitude query param is missing"}) |
| 92 | + return |
| 93 | + } |
| 94 | + |
| 95 | + err := simlocation.SetLocation(device, latitude, longtitude) |
| 96 | + if err != nil { |
| 97 | + c.JSON(http.StatusInternalServerError, GenericResponse{Error: err.Error()}) |
| 98 | + return |
| 99 | + } |
| 100 | + c.JSON(http.StatusOK, GenericResponse{Message: "Device location set to latitude=" + latitude + ", longtitude=" + longtitude}) |
| 101 | +} |
| 102 | + |
| 103 | +// Reset to the actual device location |
| 104 | +// @Summary Reset the changed device location |
| 105 | +// @Description Reset the changed device location to the actual one |
| 106 | +// @Tags general_device_specific |
| 107 | +// @Produce json |
| 108 | +// @Success 200 |
| 109 | +// @Failure 500 {object} GenericResponse |
| 110 | +// @Router /device/{udid}/resetlocation [post] |
| 111 | +func ResetLocation(c *gin.Context) { |
| 112 | + device := c.MustGet(IOS_KEY).(ios.DeviceEntry) |
| 113 | + err := simlocation.ResetLocation(device) |
| 114 | + if err != nil { |
| 115 | + c.JSON(http.StatusInternalServerError, GenericResponse{Error: err.Error()}) |
| 116 | + return |
| 117 | + } |
| 118 | + c.JSON(http.StatusOK, GenericResponse{Message: "Device location reset"}) |
| 119 | +} |
0 commit comments