douyin_sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: affaaa50b4deabbdd3133a09a380b2d84295e5c9477536973b68f325f0989d8e
4
+ data.tar.gz: 49f7ff6ce7770d66d2e6eb51914ae894f832f87c50fb14d62cada4d2456d327c
5
+ SHA512:
6
+ metadata.gz: ff3fddc940bed86a5d79ea14a159288bbcf6d453f4bb3cc5dfecbc57cf68ff4e1573dd6f7c4fdea1a1fd86ed5cced4a8a9b0f522820ca6b109ded29b4446060a
7
+ data.tar.gz: 3a820257d4609d129d9866a788d4e9a3f41e3e9ec7d6d0f387a39be0e4beb67b4b3afa6e837a00a9833a7fd9eb3face7bb138a65fa9305dd2cc06651ed24b9df
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in douyin_sdk.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 dhuSaverin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,77 @@
1
+ # DouyinSdk
2
+
3
+ Douyin SDK for Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'douyin_sdk'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install douyin_sdk
20
+
21
+ ## Usage
22
+ 1.配置 ClientKey 和 ClientSecret
23
+
24
+ ```ruby
25
+ $client = DouyinSdk::Client.new(client_key, client_secret)
26
+ ```
27
+
28
+ * 抖音Oauth 2授权
29
+
30
+ 1.获取用户授权链接:
31
+ ```ruby
32
+ $client.auth_code_url(redirect_uri, scope)
33
+ ```
34
+ reirect_url为回调接收地址,scope为要获取的权限,详见官方文档
35
+
36
+ 2.用户扫码授权后,根据code获取用户access_token,open_id和refresh_token等信息
37
+ ```ruby
38
+ $client.access_token(code)
39
+ ```
40
+
41
+ * 刷新access_token
42
+
43
+ ```ruby
44
+ $client.refresh_token(refresh_token)
45
+ ```
46
+
47
+ * 获取用户公开信息
48
+
49
+ ```ruby
50
+ $client.user_info(access_token, open_id)
51
+ ```
52
+
53
+ * 获取粉丝列表(需要在开放平台申请用户管理接口权限)
54
+
55
+ ```ruby
56
+ $client.fan_list(access_token, open_id)
57
+ ```
58
+ * 查询授权账号视频数据
59
+
60
+ ```ruby
61
+ $client.video_list(access_token, open_id)
62
+ ```
63
+
64
+ * 查询指定视频数据
65
+
66
+ item_id为抖音视频id
67
+ ```ruby
68
+ $client.video_data(access_token, open_id, item_id)
69
+ ```
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dhuSaverin/douyin_sdk. This project is intended to be a safe, welcoming space for collaboration.
73
+
74
+ ## License
75
+
76
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
77
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "douyin_sdk"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,43 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "douyin_sdk/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "douyin_sdk"
8
+ spec.version = DouyinSdk::VERSION
9
+ spec.authors = ["dhuSaverin"]
10
+ spec.email = ["sjtdhu@163.com"]
11
+
12
+ spec.summary = %q{Douyin SDK for Ruby}
13
+ spec.description = %q{Douyin SDK for Ruby}
14
+ spec.homepage = "https://github.com/dhuSaverin/douyin_sdk"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/dhuSaverin/douyin_sdk"
23
+ spec.metadata["changelog_uri"] = "https://github.com/dhuSaverin/douyin_sdk"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.17"
39
+ spec.add_development_dependency "rake", "~> 12.3.3"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ spec.add_development_dependency "typhoeus"
42
+
43
+ end
@@ -0,0 +1,14 @@
1
+ require "douyin_sdk/version"
2
+ require "douyin_sdk/client"
3
+
4
+ module DouyinSdk
5
+
6
+ class << self
7
+
8
+ def endpoint_url(url)
9
+ "https://open.douyin.com"+url
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ require "douyin_sdk/oauth"
3
+ require "douyin_sdk/user"
4
+ require "douyin_sdk/video"
5
+
6
+ module DouyinSdk
7
+
8
+ class Client
9
+
10
+ include Oauth
11
+
12
+ attr_accessor :client_key, :client_secret, :scope # Time.now + expires_in
13
+ # attr_accessor :access_token
14
+
15
+ def initialize(client_key, client_secret)
16
+ @client_key = client_key
17
+ @client_key = client_secret
18
+ end
19
+
20
+
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ module DouyinSdk
3
+ module Oauth
4
+
5
+ #获取授权连接
6
+ def auth_code_url(redirect_uri, scope="user_info")
7
+ action = '/platform/oauth/connect/'
8
+ DouyinSdk.endpoint_url(action + "?client_key=#{client_key}&response_type=code&scope=#{scope}&redirect_uri=#{redirect_uri}")
9
+ end
10
+
11
+ #获取access_token
12
+ def access_token(code)
13
+ action = '/oauth/access_token/'
14
+ res = Typhoeus.post(DouyinSdk.endpoint_url(action + "?client_key=#{client_key}&client_secret=#{client_secret}&code=#{code}&grant_type=authorization_code"))
15
+ JSON.parse(res.body)
16
+ end
17
+
18
+ #刷新access_token
19
+ def refresh_token(refresh_token)
20
+ action = '/oauth/refresh_token/'
21
+ res = Typhoeus.get(DouyinSdk.endpoint_url(action + "?refresh_token=#{refresh_token}&client_key=#{CLIENT_KEY}&grant_type=refresh_token"))
22
+ JSON.parse(res.body)
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ module DouyinSdk
3
+ module User
4
+
5
+ #获取用户信息
6
+ def user_info(access_token, open_id)
7
+ action = '/oauth/userinfo/'
8
+ res = Typhoeus.post(DouyinSdk.endpoint_url(action + "?access_token=#{access_token}&open_id=#{open_id}"))
9
+ JSON.parse(res.body)
10
+ end
11
+
12
+ #获取粉丝列表
13
+ def fan_list(access_token, open_id, count = 10, cursor = 0)
14
+ action = '/fans/list/'
15
+ res = Typhoeus.post(DouyinSdk.endpoint_url(action + "?access_token=#{access_token}&open_id=#{open_id}&count=#{count}&cursor=#{cursor}"))
16
+ JSON.parse(res.body)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module DouyinSdk
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ module DouyinSdk
3
+ module Video
4
+
5
+ #获取用户视频列表
6
+ def video_list(access_token, open_id, count = 10, cursor = 0)
7
+ action = '/video/list/'
8
+ res = Typhoeus.get(DouyinSdk.endpoint_url(action + "?access_token=#{access_token}&open_id=#{open_id}&count=#{count}&cursor=#{cursor}"))
9
+ JSON.parse(res.body)
10
+ end
11
+
12
+ #查询指定视频数据
13
+ def video_data(access_token, open_id, item_id)
14
+ action = '/video/data/'
15
+ res = Typhoeus.post(DouyinSdk.endpoint_url(action + "?access_token=#{access_token}&open_id=#{open_id}"), headers: {'Content-Type': 'application/json'}, body: {item_ids: [item_id] }.to_json)
16
+ JSON.parse(res.body)
17
+ end
18
+
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: douyin_sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - dhuSaverin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-07-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: typhoeus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Douyin SDK for Ruby
70
+ email:
71
+ - sjtdhu@163.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - LICENSE.txt
78
+ - README.md
79
+ - Rakefile
80
+ - bin/console
81
+ - bin/setup
82
+ - douyin_sdk.gemspec
83
+ - lib/douyin_sdk.rb
84
+ - lib/douyin_sdk/client.rb
85
+ - lib/douyin_sdk/oauth.rb
86
+ - lib/douyin_sdk/user.rb
87
+ - lib/douyin_sdk/version.rb
88
+ - lib/douyin_sdk/video.rb
89
+ homepage: https://github.com/dhuSaverin/douyin_sdk
90
+ licenses:
91
+ - MIT
92
+ metadata:
93
+ homepage_uri: https://github.com/dhuSaverin/douyin_sdk
94
+ source_code_uri: https://github.com/dhuSaverin/douyin_sdk
95
+ changelog_uri: https://github.com/dhuSaverin/douyin_sdk
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.0.1
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Douyin SDK for Ruby
115
+ test_files: []