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.
-
#device_public_key(id, did) ⇒ Object
Get the active public key for a device.
-
#devices(id) ⇒ Object
Lists all devices assigned to the given identity.
-
#entity(id) ⇒ Object
Get app/identity details.
- #get(endpoint) ⇒ Object
-
#identity(id) ⇒ Object
Get identity details.
-
#initialize(url, app_id, app_key, env) ⇒ RestClient
constructor
RestClient initializer.
- #post(endpoint, body) ⇒ Object
-
#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
permalink #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
permalink #env ⇒ Object (readonly)
Returns the value of attribute env.
7 8 9 |
# File 'lib/client.rb', line 7 def env @env end |
permalink #jwt ⇒ Object (readonly)
Returns the value of attribute jwt.
7 8 9 |
# File 'lib/client.rb', line 7 def jwt @jwt end |
permalink #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
permalink #app(id) ⇒ Object
Get app details
30 31 32 |
# File 'lib/client.rb', line 30 def app(id) get_identity "/v1/apps/#{id}" end |
permalink #device_public_key(id, did) ⇒ Object
Get the active public key for a device
96 97 98 99 100 |
# File 'lib/client.rb', line 96 def device_public_key(id, did) i = entity(id) sg = SelfSDK::SignatureGraph.new(i[:history]) sg.key_by_device(did) end |
permalink #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 |
permalink #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 |
permalink #get(endpoint) ⇒ Object
[View source]
77 78 79 80 81 82 |
# File 'lib/client.rb', line 77 def get(endpoint) HTTParty.get("#{@self_url}#{endpoint}", headers: { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{@jwt.auth_token}" }) end |
permalink #identity(id) ⇒ Object
Get identity details
23 24 25 |
# File 'lib/client.rb', line 23 def identity(id) get_identity "/v1/identities/#{id}" end |
permalink #post(endpoint, body) ⇒ Object
[View source]
68 69 70 71 72 73 74 75 |
# File 'lib/client.rb', line 68 def post(endpoint, body) p HTTParty.post("#{@self_url}#{endpoint}", headers: { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{@jwt.auth_token}" }, body: body) end |
permalink #public_key(id, kid) ⇒ Object
Lists all public keys stored on self for the given ID
87 88 89 90 91 |
# File 'lib/client.rb', line 87 def public_key(id, kid) i = entity(id) sg = SelfSDK::SignatureGraph.new(i[:history]) sg.key_by_id(kid) end |
permalink #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 |