236 shaares
110 liens privés
110 liens privés
1 résultat
taggé
mastodon
Quick & dirty test of mastodon api
require 'mastodon'
require 'oauth2'
require 'fileutils'
APP_NAME = "tcmasto"
SCOPE = "read write follow"
## INITIALISATION
def init
url = "your_domain_url" # exemple : https://framapiaf.org
tcmasto_client = Mastodon::REST::Client.new(base_url: url)
tcmasto_app = tcmasto_client.create_app( APP_NAME, "urn:ietf:wg:oauth:2.0:oob", SCOPE)
oauth_client = OAuth2::Client.new( tcmasto_app.client_id,
tcmasto_app.client_secret,
site: url)
email = "yourmail@whatever.com"
password= "yourpassword"
token = oauth_client.password.get_token(email, password, scope: SCOPE)
return {
"url" => url,
"client_id" => tcmasto_app.client_id,
"client_secret" => tcmasto_app.client_secret,
"email" => email,
"access_token" => token.token
}
end
class TCMasto
attr_accessor :client
def initialize config
@client = Mastodon::REST::Client.new(base_url: config["url"],
bearer_token: config["access_token"])
end
def pouet (msg)
resp = @client.create_status( msg )
end
end
config = init()
myClient = TCMasto.new config
myClient.pouet ("Hello world")