diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cf0688..e25008a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..fe05627 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## 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 diff --git a/lib/panda/client.rb b/lib/panda/client.rb index 5ccb444..19f563f 100644 --- a/lib/panda/client.rb +++ b/lib/panda/client.rb @@ -5,6 +5,7 @@ require 'panda/errors' require 'panda/http_request' require 'panda/http_response' +require 'panda/token_info' module Panda class Client @@ -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) diff --git a/lib/panda/token_info.rb b/lib/panda/token_info.rb new file mode 100644 index 0000000..24433ee --- /dev/null +++ b/lib/panda/token_info.rb @@ -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 diff --git a/lib/panda/version.rb b/lib/panda/version.rb index a8b2399..a0d50c5 100644 --- a/lib/panda/version.rb +++ b/lib/panda/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Panda - VERSION = '0.4.0' + VERSION = '0.5.0' end diff --git a/spec/cases/client_spec.rb b/spec/cases/client_spec.rb index 6bd4007..76ae289 100644 --- a/spec/cases/client_spec.rb +++ b/spec/cases/client_spec.rb @@ -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 diff --git a/spec/cases/collection_spec.rb b/spec/cases/collection_spec.rb index f41e60b..18c0afb 100644 --- a/spec/cases/collection_spec.rb +++ b/spec/cases/collection_spec.rb @@ -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' }, diff --git a/spec/cases/configuration_spec.rb b/spec/cases/configuration_spec.rb index 1adae59..203158b 100644 --- a/spec/cases/configuration_spec.rb +++ b/spec/cases/configuration_spec.rb @@ -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 diff --git a/spec/cases/token_info_spec.rb b/spec/cases/token_info_spec.rb new file mode 100644 index 0000000..1505504 --- /dev/null +++ b/spec/cases/token_info_spec.rb @@ -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