Add a new service to import some data from Mastodon accounts: * Find users by username, store Mastodon account ID in local db when found * Import display name (don't overwrite existing) * Import avatar (don't overwrite existing)
28 lines
608 B
Ruby
28 lines
608 B
Ruby
class RestApiService < ApplicationService
|
|
private
|
|
|
|
def base_url
|
|
raise NotImplementedError
|
|
end
|
|
|
|
def headers
|
|
raise NotImplementedError
|
|
end
|
|
|
|
def endpoint_url(path)
|
|
"#{base_url}/#{path.gsub(/^\//, '')}"
|
|
end
|
|
|
|
def get(path, params = {})
|
|
res = Faraday.get endpoint_url(path), params, headers
|
|
# TODO handle unsuccessful responses with no valid JSON body
|
|
JSON.parse(res.body)
|
|
end
|
|
|
|
def post(path, payload)
|
|
res = Faraday.post endpoint_url(path), payload.to_json, headers
|
|
# TODO handle unsuccessful responses with no valid JSON body
|
|
JSON.parse(res.body)
|
|
end
|
|
end
|