Class: Melaya::PhoneAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/melaya/phone.rb

Overview

Phone API — pair and control Android devices connected to the Melaya runner.

Agents use these endpoints to drive a paired phone (tap, type, read screen state, launch apps) via the Melaya APK.

Maps to /api/v1/private/phone/*.

Examples:

result = melaya.phone.pair
puts "Pairing code: #{result["code"]}"
# User enters code in the Melaya APK on the phone

devices = melaya.phone.list_devices
tree = melaya.phone.screen_tree

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ PhoneAPI

Returns a new instance of PhoneAPI.



19
20
21
# File 'lib/melaya/phone.rb', line 19

def initialize(http)
  @http = http
end

Instance Method Details

#list_appsObject

GET /api/v1/private/phone/apps List installed apps on the paired phone.



50
51
52
# File 'lib/melaya/phone.rb', line 50

def list_apps
  @http.get("/api/v1/private/phone/apps").dig("result", "apps") || []
end

#list_devicesObject

GET /api/v1/private/phone/devices List all paired phone devices for the authenticated user.



31
32
33
# File 'lib/melaya/phone.rb', line 31

def list_devices
  @http.get("/api/v1/private/phone/devices").fetch("devices", [])
end

#pairObject

POST /api/v1/private/phone/pair Start phone device pairing — generates a pairing code for the Melaya APK.



25
26
27
# File 'lib/melaya/phone.rb', line 25

def pair
  @http.post("/api/v1/private/phone/pair")
end

#register_active_run(run_id) ⇒ Object

POST /api/v1/private/phone/active-run Register the currently active pipeline run on the phone (used by agents).

Parameters:

  • run_id (String)


65
66
67
# File 'lib/melaya/phone.rb', line 65

def register_active_run(run_id)
  @http.post("/api/v1/private/phone/active-run", "runId" => run_id)
end

#revoke_device(device_id) ⇒ Object

DELETE /api/v1/private/phone/devices/:deviceId Revoke a paired phone device by ID.

Parameters:

  • device_id (String)


38
39
40
# File 'lib/melaya/phone.rb', line 38

def revoke_device(device_id)
  @http.delete("/api/v1/private/phone/devices/#{enc(device_id)}")
end

#screen_treeObject

GET /api/v1/private/phone/screen-tree Get the current accessibility tree from the paired phone's screen.



44
45
46
# File 'lib/melaya/phone.rb', line 44

def screen_tree
  @http.get("/api/v1/private/phone/screen-tree")
end

#set_allowed_apps(package_names) ⇒ Object

PUT /api/v1/private/phone/apps/allowed Set the allowlist of apps that agents are permitted to interact with.

Parameters:

  • package_names (Array<String>)


57
58
59
60
# File 'lib/melaya/phone.rb', line 57

def set_allowed_apps(package_names)
  apps = package_names.map { |package| { "package" => package } }
  @http.put("/api/v1/private/phone/apps/allowed", "apps" => apps)
end