simple_tweet 2.1.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e6a6c9e3275f29c3b1aefcc8bb0c9fb8959d596777f057493cd6027c584abb5
4
- data.tar.gz: 0d6bcec1bf0c2995ede08425c78512d96027b20346a0f1c966e0b03b7e8a29bd
3
+ metadata.gz: 824d9a2b160763d55494fef995e0e63974afd881c07098a96f2e3acc19a9439e
4
+ data.tar.gz: c1c5050eaa9edce06a831c81202405daad44196454528295e759c83e1947ab5d
5
5
  SHA512:
6
- metadata.gz: 306443b68c1b9ba56b96d78f462981f1af82eb288339a55cbd490dd15c8deaa78d00da7e3dccc5ec9b6a3988ba792dc5bfd0ded53840082cc57abc7857851e25
7
- data.tar.gz: c247c2c61666c96b80358c7b303f680a782db1e9b381aa859baeb32169f67d0602a209d9d674f99c2d6400e11c0357b37ccb35b0e2532269f3124f9e0ac7c360
6
+ metadata.gz: b782ae0dae6a0f7e54ba7985c1950def54e285d57da83334abb9a3a32d9b2e848c9525190ce058f1f30ee04f1e78edb2aa91361ee5461c40ae3ef80b9e0ee160
7
+ data.tar.gz: '0980b93e87c9e7b9ff278db95c0748d6ac4ec02f5fb7bcd8fee132e935886d13b4b992b34eccf574cc411fcc278e3bed852068007dcf1aa9842daf60f49a9f04'
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6
2
+ TargetRubyVersion: 3.0
3
3
 
4
4
  Style/StringLiterals:
5
5
  Enabled: true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "cgi"
2
4
  require "oauth"
3
5
  require "json"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "json"
2
4
 
3
5
  module SimpleTweet
@@ -5,16 +7,35 @@ module SimpleTweet
5
7
  # mediaのuploadはapi 1.1しか用意されていないため、それを使う。
6
8
  class Client < V1::Client
7
9
  TW_TWEET_PATH = "/2/tweets"
8
- UA = "SimpleTweet/#{SimpleTweet::VERSION}"
10
+ TW_METADATA_CREATE_PATH = "/1.1/media/metadata/create.json"
11
+ UA = "SimpleTweet/#{SimpleTweet::VERSION}".freeze
9
12
 
10
13
  def tweet(message:, media_ids: [])
11
- json = {
12
- text: message,
13
- }
14
+ json = { text: message }
14
15
  json[:media] = { media_ids: media_ids } unless media_ids.empty?
15
16
  header = { "User-Agent": UA, "content-type": "application/json" }
16
- res = access_token.post(TW_TWEET_PATH, json.to_json, header)
17
- ::JSON.parse(res.body, symbolize_names: true)
17
+ access_token.post(TW_TWEET_PATH, json.to_json, header)
18
+ end
19
+
20
+ def tweet_with_media(message:, media_type:, media:, alt_text: nil)
21
+ media_ids = upload_media(media_type: media_type, media: media)
22
+ unless alt_text.nil?
23
+ media_ids.each do |media_id|
24
+ create_media_metadata(media_id: media_id, alt_text: alt_text)
25
+ end
26
+ end
27
+ tweet(message: message, media_ids: media_ids)
28
+ end
29
+
30
+ private
31
+
32
+ def create_media_metadata(media_id:, alt_text:)
33
+ header = { "content-type": "application/json; charset=UTF-8" }
34
+ req = ::Net::HTTP::Post.new(TW_METADATA_CREATE_PATH, header)
35
+ req.body = { media_id: media_id, alt_text: { text: alt_text } }.to_json
36
+ res = request(req)
37
+ throw UploadMediaError, "create_media_metadata failed: #{res.code} #{res.body}" if res.code != "200"
38
+ res
18
39
  end
19
40
  end
20
41
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleTweet
4
- VERSION = "2.1.0"
4
+ VERSION = "2.3.0"
5
5
  end
data/simple_tweet.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = ""
13
13
  spec.homepage = "https://github.com/nota/simple_tweet"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.6.0"
15
+ spec.required_ruby_version = ">= 3.0.0"
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = spec.homepage
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_tweet
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kugayama Nana
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-02 00:00:00.000000000 Z
11
+ date: 2023-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post
@@ -72,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 2.6.0
75
+ version: 3.0.0
76
76
  required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - ">="