Skip to content

Commit

Permalink
fix: use POST method for token request
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrytrager committed Jan 16, 2025
1 parent 7731456 commit 88bfc21
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.0

* Add `token_info` [method](https://business-api.tiktok.com/portal/docs?id=1765927978092545) to validate TikTok profiles
* 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
8 changes: 6 additions & 2 deletions lib/panda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ 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 = if request.post?
connection.post(request.url, request.params, request.headers)
else
connection.get(request.url, request.params, request.headers)
end
Panda::HTTPResponse.new(response.status, response.headers, response.body)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/panda/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions lib/panda/http_request.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'panda/version'
require 'uri'

module Panda
class HTTPRequest
Expand Down Expand Up @@ -44,5 +45,9 @@ def headers
def get?
method == 'GET'
end

def post?
method == 'POST'
end
end
end
2 changes: 1 addition & 1 deletion lib/panda/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Panda
VERSION = '0.5.0'
VERSION = '0.5.1'
end

0 comments on commit 88bfc21

Please sign in to comment.