Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add token_info method, bump version #9

Merged
merged 7 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
AlphaB marked this conversation as resolved.
Show resolved Hide resolved
- 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
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'panda/collection'
require 'panda/token_info'
Copy link
Member

@AlphaB AlphaB Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep imports sorted as they were

require 'panda/error_middleware'
require 'panda/errors'
require 'panda/http_request'
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we don't use this reader anywhere


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
Loading