Module: Twtxt::Yarn

Included in:
Session
Defined in:
lib/twtxt/yarn.rb

Defined Under Namespace

Classes: Credentials, Session

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.api_endpoint(yarnpod) ⇒ Object



13
14
15
# File 'lib/twtxt/yarn.rb', line 13

def api_endpoint(yarnpod)
  "https://#{yarnpod}/api/v1"
end

.get_jwt_token(username, password, endpoint) ⇒ Object



17
18
19
20
# File 'lib/twtxt/yarn.rb', line 17

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


6
7
8
9
10
11
# File 'lib/twtxt/yarn.rb', line 6

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

Instance Method Details

#authenticated_headers(token) ⇒ Object



24
25
26
# File 'lib/twtxt/yarn.rb', line 24

def authenticated_headers(token)
  { "Token" => "#{token}", "Content-Type" => "application/json" }
end