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
15 16 17 18 19 20 |
# File 'lib/client.rb', line 15 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.
9 10 11 |
# File 'lib/client.rb', line 9 def env @env end |
permalink #jwt ⇒ Object (readonly)
Returns the value of attribute jwt.
9 10 11 |
# File 'lib/client.rb', line 9 def jwt @jwt end |
permalink #self_url ⇒ Object (readonly)
Returns the value of attribute self_url.
9 10 11 |
# File 'lib/client.rb', line 9 def self_url @self_url end |
Instance Method Details
permalink #app(id) ⇒ Object
Get app details
32 33 34 |
# File 'lib/client.rb', line 32 def app(id) get_identity "/v1/apps/#{id}" end |
permalink #device_public_key(id, did) ⇒ Object
Get the active public key for a device
110 111 112 113 114 |
# File 'lib/client.rb', line 110 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
51 52 53 54 55 56 57 58 59 |
# File 'lib/client.rb', line 51 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
39 40 41 42 43 44 45 46 |
# File 'lib/client.rb', line 39 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]
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/client.rb', line 85 def get(endpoint) res = nil loop do res = HTTParty.get("#{@self_url}#{endpoint}", headers: { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{@jwt.auth_token}" }) break if res.code != 503 sleep 2 end return res end |
permalink #identity(id) ⇒ Object
Get identity details
25 26 27 |
# File 'lib/client.rb', line 25 def identity(id) get_identity "/v1/identities/#{id}" end |
permalink #post(endpoint, body) ⇒ Object
[View source]
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/client.rb', line 70 def post(endpoint, body) res = nil loop do res = HTTParty.post("#{@self_url}#{endpoint}", headers: { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{@jwt.auth_token}" }, body: body) break if res.code != 503 sleep 2 end return res end |
permalink #public_key(id, kid) ⇒ Object
Lists all public keys stored on self for the given ID
101 102 103 104 105 |
# File 'lib/client.rb', line 101 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
65 66 67 68 |
# File 'lib/client.rb', line 65 def public_keys(id) i = entity(id) i[:public_keys] end |