twitter_tweet_bot 1.1.0 → 1.2.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.
- checksums.yaml +4 -4
- data/README.md +9 -1
- data/lib/twitter_tweet_bot/api/params/boolean_param.rb +13 -0
- data/lib/twitter_tweet_bot/api/params/comma_separated_param.rb +21 -0
- data/lib/twitter_tweet_bot/api/params/hash_param.rb +13 -0
- data/lib/twitter_tweet_bot/api/params/string_param.rb +13 -0
- data/lib/twitter_tweet_bot/api/params/tweet_params.rb +53 -0
- data/lib/twitter_tweet_bot/api/params/users_me_params.rb +43 -0
- data/lib/twitter_tweet_bot/api/tweet.rb +14 -4
- data/lib/twitter_tweet_bot/api/users_me.rb +10 -4
- data/lib/twitter_tweet_bot/cache/configuration_ext.rb +1 -1
- data/lib/twitter_tweet_bot/cache.rb +1 -1
- data/lib/twitter_tweet_bot/client/api.rb +4 -4
- data/lib/twitter_tweet_bot/{configration.rb → configuration.rb} +1 -1
- data/lib/twitter_tweet_bot/entity/base.rb +13 -13
- data/lib/twitter_tweet_bot/entity/tweet.rb +4 -2
- data/lib/twitter_tweet_bot/entity/user.rb +4 -2
- data/lib/twitter_tweet_bot/version.rb +1 -1
- data/lib/twitter_tweet_bot.rb +4 -4
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0075abce451f1cc89c2cfaf56d04c9a18c3a1ae4e9bed984c8ec1a582689a944
|
4
|
+
data.tar.gz: 8d37895dec281683bf51db107ac3b4f02894d53380d797a7ff98aab0aa6d78a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0969b67fe82425486264df739eec73b98945eb339e39588d2117831949ca5667c8a2da7a9098dd25fc16a78fdb5318a416ddce331c939c0e34cd4b8dd553ada4'
|
7
|
+
data.tar.gz: ef888edd3e082f7371148c2471ce0ea0fa82c89da230506511681d7880df388ed72c349a8ee879debe1f7ffe2d3e9b65bf8fa82a6228d040026e844dd08eab00
|
data/README.md
CHANGED
@@ -44,7 +44,7 @@ TwitterTweetBot.configure do |config|
|
|
44
44
|
# Redirect URL After Authorization
|
45
45
|
config.redirect_uri = 'https://example.com/twitter/callback'
|
46
46
|
# Twitter's App Scopes with OAuth 2.0
|
47
|
-
config.scopes = [
|
47
|
+
config.scopes = %w[tweet.read tweet.write users.read offline.access]
|
48
48
|
end
|
49
49
|
```
|
50
50
|
|
@@ -94,6 +94,14 @@ TwitterTweetBot.post_tweet(token.access_token, 'Yeah!')
|
|
94
94
|
# @text="Yeah!">
|
95
95
|
```
|
96
96
|
|
97
|
+
##### With [some params](https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets)
|
98
|
+
|
99
|
+
```rb
|
100
|
+
TwitterTweetBot.post_tweet(token.access_token, 'Yeah! Yeah!') do |params|
|
101
|
+
params.reply = { in_reply_to_tweet_id: '*******************' }
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
97
105
|
#### Ex. Refresh an access token (required `'offline.access'` in scopes)
|
98
106
|
|
99
107
|
```rb
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module TwitterTweetBot
|
2
|
+
module API
|
3
|
+
module Params
|
4
|
+
module CommaSeparatedParam
|
5
|
+
DELIMITER = ','.freeze
|
6
|
+
|
7
|
+
def self.build(key, value)
|
8
|
+
{ key => formed_value(value) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.formed_value(value)
|
12
|
+
return value unless value.is_a?(Array)
|
13
|
+
|
14
|
+
value.join(DELIMITER)
|
15
|
+
end
|
16
|
+
|
17
|
+
private_constant :DELIMITER
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'twitter_tweet_bot/api/params/boolean_param'
|
2
|
+
require 'twitter_tweet_bot/api/params/string_param'
|
3
|
+
require 'twitter_tweet_bot/api/params/hash_param'
|
4
|
+
|
5
|
+
module TwitterTweetBot
|
6
|
+
module API
|
7
|
+
module Params
|
8
|
+
class TweetParams
|
9
|
+
private_class_method :new
|
10
|
+
|
11
|
+
# @yield [params]
|
12
|
+
# @yieldparam params [TwitterTweetBot::API::Params::TweetParams]
|
13
|
+
def self.build(&block)
|
14
|
+
new(&block).build
|
15
|
+
end
|
16
|
+
|
17
|
+
# @see https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets
|
18
|
+
AVAILABLE_PARAMS = {
|
19
|
+
for_super_followers_only: BooleanParam,
|
20
|
+
text: StringParam,
|
21
|
+
direct_message_deep_link: StringParam,
|
22
|
+
quote_tweet_id: StringParam,
|
23
|
+
reply_settings: StringParam,
|
24
|
+
geo: HashParam,
|
25
|
+
media: HashParam,
|
26
|
+
poll: HashParam,
|
27
|
+
reply: HashParam
|
28
|
+
}.freeze
|
29
|
+
|
30
|
+
# @yield [params]
|
31
|
+
# @yieldparam params [TwitterTweetBot::API::Params::TweetParams]
|
32
|
+
def initialize(&block)
|
33
|
+
block&.call(self)
|
34
|
+
end
|
35
|
+
|
36
|
+
def params
|
37
|
+
@params ||= {}
|
38
|
+
end
|
39
|
+
alias build params
|
40
|
+
|
41
|
+
private :params
|
42
|
+
|
43
|
+
AVAILABLE_PARAMS.each do |name, param_klass|
|
44
|
+
define_method("#{name}=") do |value|
|
45
|
+
params.merge!(param_klass.build(name, value))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private_constant :AVAILABLE_PARAMS
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'twitter_tweet_bot/api/params/comma_separated_param'
|
2
|
+
require 'twitter_tweet_bot/api/params/string_param'
|
3
|
+
|
4
|
+
module TwitterTweetBot
|
5
|
+
module API
|
6
|
+
module Params
|
7
|
+
class UsersMeParams
|
8
|
+
private_class_method :new
|
9
|
+
|
10
|
+
# @yield [params]
|
11
|
+
# @yieldparam params [TwitterTweetBot::API::Params::UsersMeParams]
|
12
|
+
def self.build(&block)
|
13
|
+
new(&block).build
|
14
|
+
end
|
15
|
+
|
16
|
+
# @yield [params]
|
17
|
+
# @yieldparam params [TwitterTweetBot::API::Params::UsersMeParams]
|
18
|
+
def initialize(&block)
|
19
|
+
block&.call(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
def params
|
23
|
+
@params ||= {}
|
24
|
+
end
|
25
|
+
alias build params
|
26
|
+
|
27
|
+
def expansions=(value)
|
28
|
+
params.merge!(StringParam.build('expansions', value))
|
29
|
+
end
|
30
|
+
|
31
|
+
def tweet_fields=(value)
|
32
|
+
params.merge!(CommaSeparatedParam.build('tweet.fields', value))
|
33
|
+
end
|
34
|
+
|
35
|
+
def user_fields=(value)
|
36
|
+
params.merge!(CommaSeparatedParam.build('user.fields', value))
|
37
|
+
end
|
38
|
+
|
39
|
+
private :params
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'twitter_tweet_bot/api/http'
|
2
|
+
require 'twitter_tweet_bot/api/params/tweet_params'
|
2
3
|
|
3
4
|
module TwitterTweetBot
|
4
5
|
module API
|
@@ -9,19 +10,28 @@ module TwitterTweetBot
|
|
9
10
|
|
10
11
|
API_ENDPOTNT = 'https://api.twitter.com/2/tweets'.freeze
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
# @param [String] access_token
|
14
|
+
# @param [String] text
|
15
|
+
# @yield [params]
|
16
|
+
# @yieldparam params [TwitterTweetBot::API::Params::TweetParams]
|
17
|
+
def self.post(access_token:, text:, **, &block)
|
18
|
+
new(access_token).post(
|
19
|
+
Params::TweetParams.build do |params|
|
20
|
+
params.text = text
|
21
|
+
block&.call(params)
|
22
|
+
end
|
23
|
+
)
|
14
24
|
end
|
15
25
|
|
16
26
|
def initialize(access_token)
|
17
27
|
@access_token = access_token
|
18
28
|
end
|
19
29
|
|
20
|
-
def post(
|
30
|
+
def post(params)
|
21
31
|
request(
|
22
32
|
:post_json,
|
23
33
|
API_ENDPOTNT,
|
24
|
-
|
34
|
+
params,
|
25
35
|
bearer_authorization_header(access_token)
|
26
36
|
)
|
27
37
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'twitter_tweet_bot/api/http'
|
2
|
+
require 'twitter_tweet_bot/api/params/users_me_params'
|
2
3
|
|
3
4
|
module TwitterTweetBot
|
4
5
|
module API
|
@@ -9,19 +10,24 @@ module TwitterTweetBot
|
|
9
10
|
|
10
11
|
API_ENDPOTNT = 'https://api.twitter.com/2/users/me'.freeze
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
# @param [String] access_token
|
14
|
+
# @yield [params]
|
15
|
+
# @yieldparam params [TwitterTweetBot::API::Params::UsersMeParams]
|
16
|
+
def self.fetch(access_token:, **, &block)
|
17
|
+
new(access_token).fetch(
|
18
|
+
Params::UsersMeParams.build(&block)
|
19
|
+
)
|
14
20
|
end
|
15
21
|
|
16
22
|
def initialize(access_token)
|
17
23
|
@access_token = access_token
|
18
24
|
end
|
19
25
|
|
20
|
-
def fetch(
|
26
|
+
def fetch(params)
|
21
27
|
request(
|
22
28
|
:get,
|
23
29
|
API_ENDPOTNT,
|
24
|
-
|
30
|
+
params,
|
25
31
|
bearer_authorization_header(access_token)
|
26
32
|
)
|
27
33
|
end
|
@@ -6,7 +6,7 @@ require 'twitter_tweet_bot/cache/entity_ext'
|
|
6
6
|
|
7
7
|
module TwitterTweetBot
|
8
8
|
Client.prepend(Cache::ClientExt)
|
9
|
-
|
9
|
+
Configuration.prepend(Cache::ConfigurationExt)
|
10
10
|
|
11
11
|
Entity::Authorization.include(Cache::EntityExt::Authorization)
|
12
12
|
Entity::Token.include(Cache::EntityExt::Token)
|
@@ -28,15 +28,15 @@ module TwitterTweetBot
|
|
28
28
|
)
|
29
29
|
end
|
30
30
|
|
31
|
-
def post_tweet(access_token, text)
|
31
|
+
def post_tweet(access_token, text, &block)
|
32
32
|
TwitterTweetBot::API::Tweet.post(
|
33
|
-
**params_with_config(access_token: access_token, text: text)
|
33
|
+
**params_with_config(access_token: access_token, text: text), &block
|
34
34
|
)
|
35
35
|
end
|
36
36
|
|
37
|
-
def users_me(access_token,
|
37
|
+
def users_me(access_token, &block)
|
38
38
|
TwitterTweetBot::API::UsersMe.fetch(
|
39
|
-
**params_with_config(access_token: access_token,
|
39
|
+
**params_with_config(access_token: access_token), &block
|
40
40
|
)
|
41
41
|
end
|
42
42
|
|
@@ -7,28 +7,28 @@ module TwitterTweetBot
|
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
9
|
class_methods do
|
10
|
+
# @param [Array] fields
|
10
11
|
def act_as_entity(*fields)
|
11
12
|
class_attribute :fields,
|
12
13
|
instance_writer: false,
|
13
14
|
default: fields
|
14
15
|
|
15
|
-
attr_reader
|
16
|
-
end
|
16
|
+
attr_reader :raw
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
18
|
+
fields.each do |field|
|
19
|
+
define_method(field) { target_fields[field] }
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
22
|
+
# @param [Hash] hash
|
23
|
+
define_method(:initialize) { |hash| @raw = Hash(hash) }
|
26
24
|
|
27
|
-
|
25
|
+
define_method(:target_fields) { raw }
|
26
|
+
private :target_fields
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
# @param [Hash] hash
|
30
|
+
def build(hash)
|
31
|
+
new(hash)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/lib/twitter_tweet_bot.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'twitter_tweet_bot/client'
|
2
|
-
require 'twitter_tweet_bot/
|
2
|
+
require 'twitter_tweet_bot/configuration'
|
3
3
|
require 'twitter_tweet_bot/version'
|
4
4
|
|
5
5
|
require 'active_support/core_ext/module/attribute_accessors'
|
6
6
|
require 'active_support/core_ext/module/delegation'
|
7
7
|
|
8
8
|
module TwitterTweetBot
|
9
|
-
|
9
|
+
NoConfigurationError = Class.new(StandardError).freeze
|
10
10
|
|
11
11
|
mattr_accessor :default_config
|
12
12
|
|
13
13
|
class << self
|
14
14
|
def configure(&block)
|
15
|
-
self.default_config =
|
15
|
+
self.default_config = Configuration.new(&block)
|
16
16
|
end
|
17
17
|
|
18
18
|
def client(config = nil)
|
@@ -29,7 +29,7 @@ module TwitterTweetBot
|
|
29
29
|
private
|
30
30
|
|
31
31
|
def default_config!
|
32
|
-
default_config or raise
|
32
|
+
default_config or raise NoConfigurationError
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter_tweet_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SongCastle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -42,6 +42,12 @@ files:
|
|
42
42
|
- lib/twitter_tweet_bot/api/http/get.rb
|
43
43
|
- lib/twitter_tweet_bot/api/http/headers.rb
|
44
44
|
- lib/twitter_tweet_bot/api/http/post.rb
|
45
|
+
- lib/twitter_tweet_bot/api/params/boolean_param.rb
|
46
|
+
- lib/twitter_tweet_bot/api/params/comma_separated_param.rb
|
47
|
+
- lib/twitter_tweet_bot/api/params/hash_param.rb
|
48
|
+
- lib/twitter_tweet_bot/api/params/string_param.rb
|
49
|
+
- lib/twitter_tweet_bot/api/params/tweet_params.rb
|
50
|
+
- lib/twitter_tweet_bot/api/params/users_me_params.rb
|
45
51
|
- lib/twitter_tweet_bot/api/refresh_token.rb
|
46
52
|
- lib/twitter_tweet_bot/api/tweet.rb
|
47
53
|
- lib/twitter_tweet_bot/api/users_me.rb
|
@@ -57,7 +63,7 @@ files:
|
|
57
63
|
- lib/twitter_tweet_bot/client.rb
|
58
64
|
- lib/twitter_tweet_bot/client/api.rb
|
59
65
|
- lib/twitter_tweet_bot/client/entity.rb
|
60
|
-
- lib/twitter_tweet_bot/
|
66
|
+
- lib/twitter_tweet_bot/configuration.rb
|
61
67
|
- lib/twitter_tweet_bot/entity.rb
|
62
68
|
- lib/twitter_tweet_bot/entity/authorization.rb
|
63
69
|
- lib/twitter_tweet_bot/entity/base.rb
|