Class: SelfSDK::RestClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, app_id, app_key, env) ⇒ RestClient

RestClient initializer

Parameters:

  • url (string)

    self-messaging url

  • token (string)

    jwt token identifying the authenticated user



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

def initialize(url, app_id, app_key, env)
  SelfSDK.logger.info "client setup with #{url}"
  @self_url = url
  @env = env
  @jwt = SelfSDK::JwtService.new(app_id, app_key)
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



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

def env
  @env
end

#jwtObject (readonly)

Returns the value of attribute jwt.



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

def jwt
  @jwt
end

#self_urlObject (readonly)

Returns the value of attribute self_url.



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

def self_url
  @self_url
end

Instance Method Details

#app(id) ⇒ Object

Get app details

Parameters:

  • id (string)

    app self_id.



30
31
32
# File 'lib/client.rb', line 30

def app(id)
  get_identity "/v1/apps/#{id}"
end

#devices(id) ⇒ Object

Lists all devices assigned to the given identity

Parameters:

  • id (string)

    identity id



49
50
51
52
53
54
55
56
57
# File 'lib/client.rb', line 49

def devices(id)
  res = get "/v1/identities/#{id}/devices"
  body = JSON.parse(res.body, symbolize_names: true)
  if res.code != 200
    SelfSDK.logger.error "identity response : #{body[:message]}"
    raise "you need connection permissions"
  end
  body
end

#entity(id) ⇒ Object

Get app/identity details

Parameters:

  • id (string)

    app/identity self_id.



37
38
39
40
41
42
43
44
# File 'lib/client.rb', line 37

def entity(id)
  #TODO : Consider a better check for this conditional
  if id.length == 11
    return identity(id)
  else
    return app(id)
  end
end

#identity(id) ⇒ Object

Get identity details

Parameters:

  • id (string)

    identity self_id.



23
24
25
# File 'lib/client.rb', line 23

def identity(id)
  get_identity "/v1/identities/#{id}"
end

#public_key(id, kid) ⇒ Object

Lists all public keys stored on self for the given ID

Parameters:

  • id (string)

    identity id



71
72
73
74
75
# File 'lib/client.rb', line 71

def public_key(id, kid)
  i = entity(id)
  sg = SelfSDK::SignatureGraph.new(i[:history])
  sg.key_by_id(kid)
end

#public_keys(id) ⇒ Object

Lists all public keys stored on self for the given ID

DEPRECATED

Parameters:

  • id (string)

    identity id



63
64
65
66
# File 'lib/client.rb', line 63

def public_keys(id)
  i = entity(id)
  i[:public_keys]
end