Class: Tinysky::Client
- Inherits:
-
Object
- Object
- Tinysky::Client
- Defined in:
- lib/tinysky/client.rb
Instance Attribute Summary collapse
-
#access_jwt ⇒ Object
readonly
Returns the value of attribute access_jwt.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
Instance Method Summary collapse
- #create_record(text, options) ⇒ Object
- #create_session ⇒ Object
-
#initialize(credentials) ⇒ Client
constructor
A new instance of Client.
- #upload_blob(blob_data, content_type) ⇒ Object
Constructor Details
#initialize(credentials) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 |
# File 'lib/tinysky/client.rb', line 5 def initialize(credentials) @credentials = credentials @connection = Tinysky.generate_connection @access_jwt = nil @expires_at = nil end |
Instance Attribute Details
#access_jwt ⇒ Object (readonly)
Returns the value of attribute access_jwt.
3 4 5 |
# File 'lib/tinysky/client.rb', line 3 def access_jwt @access_jwt end |
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
3 4 5 |
# File 'lib/tinysky/client.rb', line 3 def expires_at @expires_at end |
Instance Method Details
#create_record(text, options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tinysky/client.rb', line 29 def create_record(text, ) create_session if expired_token? feed_post = FeedPost.new(text, ) body = { collection: Tinysky::Lexicon::FEED_POST, record: feed_post.to_hash, repo: @credentials[:handle] } headers = {"Authorization" => "Bearer #{@access_jwt}"} path = Tinysky::Endpoints::REPO_CREATE_RECORD @connection.post(path, body, headers) end |
#create_session ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tinysky/client.rb', line 13 def create_session body = { identifier: @credentials[:handle], password: @credentials[:app_password] } path = Tinysky::Endpoints::SERVER_CREATE_SESSION response = @connection.post(path, body) @access_jwt = response.body["accessJwt"] payload, _header = JWT.decode(@access_jwt, nil, false) @expires_at = Time.at(payload["exp"]) response end |
#upload_blob(blob_data, content_type) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tinysky/client.rb', line 46 def upload_blob(blob_data, content_type) create_session if expired_token? headers = { "Authorization" => "Bearer #{@access_jwt}", "Content-Type" => content_type } path = Tinysky::Endpoints::REPO_UPLOAD_BLOB @connection.post(path, blob_data, headers) end |