From c07f413d8946b186d5ddc663aefcb4f9ecdf20ff Mon Sep 17 00:00:00 2001 From: dmitrytrager Date: Thu, 16 Jan 2025 17:01:14 +0100 Subject: [PATCH] fix: use POST method for token request --- CHANGELOG.md | 6 +++++- lib/panda.rb | 10 ++++++++-- lib/panda/client.rb | 6 +++--- lib/panda/http_request.rb | 17 +++++++++++------ lib/panda/version.rb | 2 +- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe05627..1c00410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ ## 0.5.0 -* Add `token_info` [method](https://business-api.tiktok.com/portal/docs?id=1765927978092545) to validate TikTok profiles \ No newline at end of file +* Add `token_info` [method](https://business-api.tiktok.com/portal/docs?id=1765927978092545) to validate TikTok profiles + +## 0.5.1 + +* Use POST method for `token_info` request \ No newline at end of file diff --git a/lib/panda.rb b/lib/panda.rb index ce6c0fe..1fcd240 100644 --- a/lib/panda.rb +++ b/lib/panda.rb @@ -18,15 +18,21 @@ def config @config ||= Panda::Configuration.new end - def make_get_request(request) + def make_request(request) connection = Faraday.new do |conn| conn.use Panda::ErrorMiddleware conn.request :json conn.response :json end - response = connection.get(request.url, request.params, request.headers) + response = do_request(connection, request) Panda::HTTPResponse.new(response.status, response.headers, response.body) end + + def do_request(connection, request) + return connection.post(request.url, request.params, request.headers) if request.post? + + connection.get(request.url, request.params, request.headers) + end end end diff --git a/lib/panda/client.rb b/lib/panda/client.rb index 19f563f..524cc6a 100644 --- a/lib/panda/client.rb +++ b/lib/panda/client.rb @@ -64,13 +64,13 @@ def token_info private def get_token(path, params = {}) - request = Panda::HTTPRequest.new('GET', path, params) - Panda::TokenInfo.new(Panda.make_get_request(request)) + request = Panda::HTTPRequest.new('POST', path, params) + Panda::TokenInfo.new(Panda.make_request(request)) end def get_collection(path, params = {}) request = Panda::HTTPRequest.new('GET', path, params, 'Access-Token' => access_token) - Panda::Collection.new(Panda.make_get_request(request), self) + Panda::Collection.new(Panda.make_request(request), self) end end end diff --git a/lib/panda/http_request.rb b/lib/panda/http_request.rb index 6a12f74..9194310 100644 --- a/lib/panda/http_request.rb +++ b/lib/panda/http_request.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'panda/version' +require 'uri' module Panda class HTTPRequest @@ -13,10 +14,6 @@ def initialize(method, path, params = {}, headers = {}) @raw_headers = headers end - def method - raw_method - end - def url uri = URI.parse(Panda.config.api_base_url) uri.path = "/open_api/#{Panda.config.api_version}/#{raw_path}" @@ -39,10 +36,18 @@ def headers ) end - private - def get? method == 'GET' end + + def post? + method == 'POST' + end + + private + + def method + raw_method + end end end diff --git a/lib/panda/version.rb b/lib/panda/version.rb index a0d50c5..38bf466 100644 --- a/lib/panda/version.rb +++ b/lib/panda/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Panda - VERSION = '0.5.0' + VERSION = '0.5.1' end