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