Class: SelfSDK::RestClient
- Inherits:
-
Object
- Object
- SelfSDK::RestClient
- Defined in:
- lib/client.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#jwt ⇒ Object
readonly
Returns the value of attribute jwt.
-
#self_url ⇒ Object
readonly
Returns the value of attribute self_url.
Instance Method Summary collapse
-
#app(id) ⇒ Object
Get app details.
-
#devices(id) ⇒ Object
Lists all devices assigned to the given identity.
-
#entity(id) ⇒ Object
Get app/identity details.
-
#identity(id) ⇒ Object
Get identity details.
-
#initialize(url, app_id, app_key, env) ⇒ RestClient
constructor
RestClient initializer.
-
#public_key(id, kid) ⇒ Object
Lists all public keys stored on self for the given ID.
-
#public_keys(id) ⇒ Object
Lists all public keys stored on self for the given ID.
Constructor Details
#initialize(url, app_id, app_key, env) ⇒ RestClient
RestClient initializer
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
#env ⇒ Object (readonly)
Returns the value of attribute env.
7 8 9 |
# File 'lib/client.rb', line 7 def env @env end |
#jwt ⇒ Object (readonly)
Returns the value of attribute jwt.
7 8 9 |
# File 'lib/client.rb', line 7 def jwt @jwt end |
#self_url ⇒ Object (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
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
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
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
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
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
63 64 65 66 |
# File 'lib/client.rb', line 63 def public_keys(id) i = entity(id) i[:public_keys] end |