From f635aa4cd78649b1cbabdc23bba34db2368f74c4 Mon Sep 17 00:00:00 2001 From: Brooke Kuhlmann Date: Tue, 22 Apr 2025 11:19:10 -0600 Subject: [PATCH] Added log endpoint Necessary to handle the request and response of the log API endpoint. --- lib/trmnl/api/endpoints/log.rb | 14 ++++++++++++ spec/lib/trmnl/api/endpoints/log_spec.rb | 27 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 lib/trmnl/api/endpoints/log.rb create mode 100644 spec/lib/trmnl/api/endpoints/log_spec.rb diff --git a/lib/trmnl/api/endpoints/log.rb b/lib/trmnl/api/endpoints/log.rb new file mode 100644 index 0000000..953b43c --- /dev/null +++ b/lib/trmnl/api/endpoints/log.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module TRMNL + module API + module Endpoints + # Handles API request/response. + class Log + include Dependencies[:client] + + def call(token:, **) = client.post("log", headers: {"Access-Token" => token}, **) + end + end + end +end diff --git a/spec/lib/trmnl/api/endpoints/log_spec.rb b/spec/lib/trmnl/api/endpoints/log_spec.rb new file mode 100644 index 0000000..f845ee4 --- /dev/null +++ b/spec/lib/trmnl/api/endpoints/log_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe TRMNL::API::Endpoints::Log do + subject(:endpoint) { described_class.new client: } + + include_context "with application dependencies" + + let(:client) { TRMNL::API::Client.new http: } + + describe "#call" do + let :http do + HTTP::Fake::Client.new do + post "/api/log" do + headers["Content-Type"] = "application/json" + status 204 + end + end + end + + it "answers record" do + result = endpoint.call token: "secret" + expect(result.success.status).to eq(204) + end + end +end