Class: Richpresence::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/richpresence-client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client_id) ⇒ Client

Returns a new instance of Client.



7
8
9
10
# File 'lib/richpresence-client.rb', line 7

def initialize(client_id)
  @client_id = client_id.to_s
  @ipc = Richpresence::Ipc.new
end

Instance Method Details

#activity=(params) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/richpresence-client.rb', line 21

def activity=(params)
  payload = {
    cmd: 'SET_ACTIVITY',
    args: {
      activity: params,
      pid: Process.pid
    }
  }

  run 'Setting activity...'
  response = JSON.parse @ipc.send(Richpresence::Opcode::FRAME, payload)[1]

  # If there is an error
  code = response['data']['code']
  if code
    error = Richpresence::Errors.parse_error_code(code)
    bad "An error occured: #{error}"
    exit code
  end

  good 'Activity setted'
end

#loginObject



12
13
14
15
16
17
18
19
# File 'lib/richpresence-client.rb', line 12

def 
  payload = {
    v: 1,
    client_id: @client_id
  }

  @ipc.send(Richpresence::Opcode::HANDSHAKE, payload)
end