Skip to content

Commit

Permalink
Merge pull request #11 from revealbot/fix/post-request-for-token
Browse files Browse the repository at this point in the history
fix: use POST method for token request
  • Loading branch information
dmitrytrager authored Jan 17, 2025
2 parents 7731456 + 50cb98d commit c12559d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 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
4 changes: 2 additions & 2 deletions lib/panda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ 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 = connection.run_request(request.method, request.url, request.params, request.headers)
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
11 changes: 6 additions & 5 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 All @@ -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}"
Expand All @@ -39,10 +36,14 @@ def headers
)
end

def method
raw_method.downcase.to_sym
end

private

def get?
method == 'GET'
raw_method == 'GET'
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 c12559d

Please sign in to comment.