lib/twtxt/yarn.rb in twtxt-0.0.1 vs lib/twtxt/yarn.rb in twtxt-0.0.2
- old
+ new
@@ -1,19 +1,28 @@
require "httparty"
require "json"
module Twtxt
module Yarn
+ def yarn_twtxt_link(yarn_id)
+ profile_components = yarn_id.split("@")
+ profile_domain = profile_components[2]
+ profile_name = profile_components[1]
+ "https://#{profile_domain}/user/#{profile_name}/twtxt.txt"
+ end
+
def api_endpoint(yarnpod)
"https://#{yarnpod}/api/v1"
end
def get_jwt_token(username, password, endpoint)
response = HTTParty.post("#{endpoint}/auth", body: { username: username, password: password }.to_json, headers: { "Content-Type" => "application/json" })
JSON.parse(response.body)["token"]
end
+ module_function :yarn_twtxt_link, :api_endpoint, :get_jwt_token
+
def authenticated_headers(token)
{ "Token" => "#{token}", "Content-Type" => "application/json" }
end
class Credentials
@@ -43,9 +52,17 @@
end
def whoami
self.class.get("#{@endpoint}/whoami", headers: @headers)
end
+
+ # def follow_yarn_profile(username, nick = nil) # acts on @shreyan@twtxt.net style usernames
+ # if nick == nil
+ # nick = username.split("@")[1]
+ # end
+ # twtxt_link = yarn_twtxt_link(username)
+ # self.class.post("#{@endpoint}/follow", body: { nick: nick, url: twtxt_link }.to_json, headers: @headers)
+ # end
# def get_profile_twts(username, page)
# self.class.get("#{@endpoint}/profile/#{username}/twts?page=#{page}", headers: @headers)
# end