Skip to content

Commit

Permalink
Merge pull request #9 from revealbot/chore/tiktok-access-lost-DD-4674
Browse files Browse the repository at this point in the history
Add token_info method, bump version
  • Loading branch information
dmitrytrager authored Jan 3, 2025
2 parents ae8250b + 333e0e7 commit 7731456
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 5 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ jobs:
strategy:
matrix:
ruby-version:
- 2.7
- 3.0
- '2.7'
- '3.0'
- '3.1'
- '3.2'
- '3.3'

steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.5.0

* Add `token_info` [method](https://business-api.tiktok.com/portal/docs?id=1765927978092545) to validate TikTok profiles
16 changes: 16 additions & 0 deletions lib/panda/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'panda/errors'
require 'panda/http_request'
require 'panda/http_response'
require 'panda/token_info'

module Panda
class Client
Expand Down Expand Up @@ -52,6 +53,21 @@ def report(advertiser_id, report_type, dimensions, params = {})
)
end

def token_info
get_token(
'tt_user/token_info/get/',
app_id: Panda.config.app_id,
access_token: access_token
)
end

private

def get_token(path, params = {})
request = Panda::HTTPRequest.new('GET', path, params)
Panda::TokenInfo.new(Panda.make_get_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)
Expand Down
15 changes: 15 additions & 0 deletions lib/panda/token_info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Panda
class TokenInfo
attr_reader :data

def initialize(response)
@data = response.parsed_body.fetch('data', {})
end

def [](key)
data[key]
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.4.0'
VERSION = '0.5.0'
end
10 changes: 10 additions & 0 deletions spec/cases/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@
subject.advertiser_info(ids, fields: fields)
end
end

describe '#token_info' do
it 'calls #get_token' do
expect(subject)
.to receive(:get_token)
.with('tt_user/token_info/get/', { app_id: Panda.config.app_id, access_token: token })

subject.token_info
end
end
end
2 changes: 1 addition & 1 deletion spec/cases/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
end

it 'gets result list' do
collection = Panda::Collection.new(response, nil)
collection = described_class.new(response, nil)

expect(collection).to contain_exactly(
{ 'id' => 'test_id_1', 'name' => 'test_name_1' },
Expand Down
2 changes: 1 addition & 1 deletion spec/cases/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
subject { described_class.new }

it 'sets default API base url' do
expect(subject.api_base_url).to eq(Panda::Configuration::API_BASE_URL)
expect(subject.api_base_url).to eq(described_class::API_BASE_URL)
end
end
29 changes: 29 additions & 0 deletions spec/cases/token_info_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require 'spec_helper'

describe Panda::TokenInfo do
let(:response) { Panda::HTTPResponse.new(200, {}, token_response_body) }

context 'response with result list field in data field' do
let(:token_response_body) do
{
'message' => 'OK',
'code' => 0,
'data' => {
'app_id' => Panda.config.app_id,
'creator_id' => 'test_creator_id',
'scope' => 'user.info.basic'
},
'request_id': '2020031009181201018904922342087A16'
}
end

it 'gets token info' do
token_info = described_class.new(response)

expect(token_info['creator_id']).to eq('test_creator_id')
expect(token_info['scope']).to eq('user.info.basic')
end
end
end

0 comments on commit 7731456

Please sign in to comment.