Class: RubySky::Raw::Client
- Inherits:
-
Object
- Object
- RubySky::Raw::Client
- Extended by:
- SendRequester
- Includes:
- SendRequester
- Defined in:
- lib/rubysky/raw/client.rb
Overview
:nodoc:
Defined Under Namespace
Modules: SendRequester
Constant Summary collapse
- CREATE_SESSION_PATH =
"/xrpc/com.atproto.server.createSession"- GET_SESSION_PATH =
"/xrpc/com.atproto.server.getSession"- REFRESH_SESSION_PATH =
"/xrpc/com.atproto.server.refreshSession"- CREATE_RECORD_PATH =
"/xrpc/com.atproto.repo.createRecord"- UPLOAD_BLOB_PATH =
"/xrpc/com.atproto.repo.uploadBlob"- POST_COLLECTION =
"app.bsky.feed.post"
Instance Attribute Summary collapse
-
#pds ⇒ Object
readonly
Returns the value of attribute pds.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Class Method Summary collapse
- .create_session(identifier:, password:, pds:) ⇒ Object
- .from_refresh_jwt(refresh_jwt:, pds:) ⇒ Object
Instance Method Summary collapse
-
#initialize(pds:, session:) ⇒ Client
constructor
A new instance of Client.
- #post(text:, embed: nil, created_at: DateTime.now.iso8601) ⇒ Object
- #upload_blob(file:, mime_type:) ⇒ Object
- #upload_image(file:, mime_type:, alt: "") ⇒ Object
Constructor Details
#initialize(pds:, session:) ⇒ Client
Returns a new instance of Client.
67 68 69 70 |
# File 'lib/rubysky/raw/client.rb', line 67 def initialize(pds:, session:) @pds = pds @session = session end |
Instance Attribute Details
#pds ⇒ Object (readonly)
Returns the value of attribute pds.
47 48 49 |
# File 'lib/rubysky/raw/client.rb', line 47 def pds @pds end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
47 48 49 |
# File 'lib/rubysky/raw/client.rb', line 47 def session @session end |
Class Method Details
.create_session(identifier:, password:, pds:) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rubysky/raw/client.rb', line 49 def self.create_session(identifier:, password:, pds:) res = send_post(pds:, path: CREATE_SESSION_PATH, body: { identifier: identifier, password: password }.to_json) ensure_success(res:, called_from: CREATE_SESSION_PATH) json = JSON.parse(res.body) new( pds:, session: Session.from_hash(json) ) end |
.from_refresh_jwt(refresh_jwt:, pds:) ⇒ Object
61 62 63 64 65 |
# File 'lib/rubysky/raw/client.rb', line 61 def self.from_refresh_jwt(refresh_jwt:, pds:) allocate.tap do |this| this.send :refresh!, refresh_jwt:, pds: end end |
Instance Method Details
#post(text:, embed: nil, created_at: DateTime.now.iso8601) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rubysky/raw/client.rb', line 72 def post(text:, embed: nil, created_at: DateTime.now.iso8601) # refresh if needed record = { text: text, createdAt: created_at } # : Hash[Symbol, untyped] facets = parse_facets(text:) record[:facets] = facets unless facets.empty? record[:embed] = if res = send_post(pds: @pds, path: CREATE_RECORD_PATH, body: { repo: @session.handle, collection: POST_COLLECTION, record: }.to_json, auth: @session.access_jwt) ensure_success(res:, called_from: CREATE_RECORD_PATH) Post.from_hash(JSON.parse(res.body)) end |
#upload_blob(file:, mime_type:) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rubysky/raw/client.rb', line 96 def upload_blob(file:, mime_type:) body = file.read res = send_post(pds: @pds, path: UPLOAD_BLOB_PATH, body:, headers: { "Content-Type" => mime_type, "Accept" => "application/json" }, auth: @session.access_jwt) ensure_success(res:, called_from: UPLOAD_BLOB_PATH) JSON.parse(res.body)["blob"] end |
#upload_image(file:, mime_type:, alt: "") ⇒ Object
110 111 112 113 |
# File 'lib/rubysky/raw/client.rb', line 110 def upload_image(file:, mime_type:, alt: "") blob = upload_blob(file:, mime_type:) { "image" => blob, "alt" => alt } end |