Class: ProveKeybase::KeybaseAdapter
- Inherits:
-
Object
- Object
- ProveKeybase::KeybaseAdapter
- Defined in:
- lib/prove_keybase/keybase_adapter.rb
Instance Method Summary collapse
- #badge_url ⇒ Object
-
#initialize(proof) ⇒ KeybaseAdapter
constructor
A new instance of KeybaseAdapter.
- #keybase_avatar_url ⇒ Object
- #keybase_live? ⇒ Boolean
- #keybase_valid? ⇒ Boolean
- #on_success_path(kb_ua) ⇒ Object
- #profile_url ⇒ Object
- #proof_url ⇒ Object
- #refresh ⇒ Object
- #refresh! ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(proof) ⇒ KeybaseAdapter
Returns a new instance of KeybaseAdapter.
4 5 6 7 8 |
# File 'lib/prove_keybase/keybase_adapter.rb', line 4 def initialize(proof) @proof = proof @domain = ProveKeybase.configuration.domain @base_url = ProveKeybase.configuration.keybase_base_url end |
Instance Method Details
#badge_url ⇒ Object
60 61 62 |
# File 'lib/prove_keybase/keybase_adapter.rb', line 60 def badge_url File.join(@base_url, "#{@proof.kb_username}/proof_badge/#{@proof.token}?username=#{@proof.username}&domain=#{@domain}") end |
#keybase_avatar_url ⇒ Object
48 49 50 |
# File 'lib/prove_keybase/keybase_adapter.rb', line 48 def keybase_avatar_url client.pic_url end |
#keybase_live? ⇒ Boolean
38 39 40 |
# File 'lib/prove_keybase/keybase_adapter.rb', line 38 def keybase_live? client.proof_live? end |
#keybase_valid? ⇒ Boolean
34 35 36 |
# File 'lib/prove_keybase/keybase_adapter.rb', line 34 def keybase_valid? client.proof_valid? end |
#on_success_path(kb_ua) ⇒ Object
42 43 44 45 46 |
# File 'lib/prove_keybase/keybase_adapter.rb', line 42 def on_success_path(kb_ua) uri = URI.parse(File.join(@base_url, '/_/proof_creation_success')) uri.query = URI.encode_www_form(proof_params.merge(kb_ua: kb_ua || 'unknown')) uri.to_s end |
#profile_url ⇒ Object
56 57 58 |
# File 'lib/prove_keybase/keybase_adapter.rb', line 56 def profile_url File.join(@base_url, @proof.kb_username) end |
#proof_url ⇒ Object
52 53 54 |
# File 'lib/prove_keybase/keybase_adapter.rb', line 52 def proof_url File.join(@base_url, "#{@proof.kb_username}/sigchain\##{@proof.token}") end |
#refresh ⇒ Object
18 19 20 |
# File 'lib/prove_keybase/keybase_adapter.rb', line 18 def refresh ProveKeybase::UpdateFromKeybaseJob.perform_later(@proof.id) end |
#refresh! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/prove_keybase/keybase_adapter.rb', line 22 def refresh! status = client.remote_status # if Keybase thinks the proof is valid but not live, yet the proof exists locally, # then this is very likely during the creation flow, and Keybase just hasn't # fetched the proof through the API yet. Throw this specific error so we know to # retry. raise ProveKeybase::ExpectedProofLiveError if status[:proof_valid] && !status[:proof_live] @proof.update!(status.slice(:proof_valid, :proof_live)) end |
#validate! ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/prove_keybase/keybase_adapter.rb', line 10 def validate! if keybase_valid? @proof.proof_valid = true else @proof.errors.add(:base, 'token not valid for user combo in keybase') end end |