Class: Atmosfire::Session
- Inherits:
-
Object
- Object
- Atmosfire::Session
- Extended by:
- T::Sig
- Includes:
- RequestUtils
- Defined in:
- lib/atmosfire/session.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#did ⇒ Object
readonly
Returns the value of attribute did.
-
#pds ⇒ Object
readonly
Returns the value of attribute pds.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
-
#xrpc ⇒ Object
readonly
Returns the value of attribute xrpc.
Instance Method Summary collapse
- #delete! ⇒ Object
- #get_session ⇒ Object
-
#initialize(credentials, should_open = true) ⇒ Session
constructor
A new instance of Session.
- #open! ⇒ Object
- #refresh! ⇒ Object
Methods included from RequestUtils
#at_uri, #create_record_uri, #create_session_uri, #default_authenticated_headers, #default_headers, #delete_record_uri, #delete_session_uri, #get_post_thread_uri, #get_session_uri, #mute_actor_uri, #query_obj_to_query_params, #refresh_session_uri, #refresh_token_headers, #resolve_handle, #upload_blob_uri
Constructor Details
#initialize(credentials, should_open = true) ⇒ Session
25 26 27 28 29 |
# File 'lib/atmosfire/session.rb', line 25 def initialize(credentials, should_open = true) @credentials = credentials @pds = credentials.pds open! if should_open end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
21 22 23 |
# File 'lib/atmosfire/session.rb', line 21 def access_token @access_token end |
#did ⇒ Object (readonly)
Returns the value of attribute did.
21 22 23 |
# File 'lib/atmosfire/session.rb', line 21 def did @did end |
#pds ⇒ Object (readonly)
Returns the value of attribute pds.
21 22 23 |
# File 'lib/atmosfire/session.rb', line 21 def pds @pds end |
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
21 22 23 |
# File 'lib/atmosfire/session.rb', line 21 def refresh_token @refresh_token end |
#xrpc ⇒ Object (readonly)
Returns the value of attribute xrpc.
21 22 23 |
# File 'lib/atmosfire/session.rb', line 21 def xrpc @xrpc end |
Instance Method Details
#delete! ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/atmosfire/session.rb', line 58 def delete! response = HTTParty.post( URI(delete_session_uri(pds)), headers: refresh_token_headers(self), ) if response.code == 200 { success: true } else raise UnauthorizedError end end |
#get_session ⇒ Object
54 55 56 |
# File 'lib/atmosfire/session.rb', line 54 def get_session @xrpc.get.com_atproto_server_getSession end |
#open! ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/atmosfire/session.rb', line 31 def open! @xrpc = XRPC::Client.new(@pds) response = @xrpc.post.com_atproto_server_createSession(identifier: @credentials.username, password: @credentials.pw) raise UnauthorizedError if response["accessJwt"].nil? @access_token = response["accessJwt"] @refresh_token = response["refreshJwt"] @did = response["did"] @xrpc = XRPC::Client.new(@pds, @access_token) @refresher = XRPC::Client.new(@pds, @refresh_token) end |
#refresh! ⇒ Object
45 46 47 48 49 50 |
# File 'lib/atmosfire/session.rb', line 45 def refresh! response = @refresher.post.com_atproto_server_refreshSession raise UnauthorizedError if response["accessJwt"].nil? @access_token = response["accessJwt"] @refresh_token = response["refreshJwt"] end |