twitty 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +5 -0
- data/.github/workflows/gempush.yml +3 -3
- data/.rubocop.yml +35 -0
- data/.rubocop_todo.yml +83 -0
- data/Gemfile +5 -2
- data/Gemfile.lock +31 -2
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/lib/twitty.rb +9 -10
- data/lib/twitty/config.rb +13 -16
- data/lib/twitty/constants.rb +81 -83
- data/lib/twitty/facade.rb +44 -50
- data/lib/twitty/payload.rb +50 -52
- data/lib/twitty/request.rb +33 -35
- data/lib/twitty/response.rb +10 -12
- data/lib/twitty/version.rb +1 -1
- data/twitty.gemspec +19 -20
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a93f92340fb4931676b89a3d20f869aae7e87f5fb2a9831d506e6c0d41c9dc18
|
4
|
+
data.tar.gz: a541340dd6566a95219f8feaacccf46604e968e41042d076f2b0e8e709e4ff5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c10e43f42e74d4dd9bb4a0efb988ff33f14eb5a7bd9a4da2facdf2f623b9fdbbb8eb8eca466faf50f04d0ec0ff7cf6f6e547eec653d17a6d039f3916b8f61856
|
7
|
+
data.tar.gz: a347f3007ff6c516706053a0a2251183e0c66e44af2e4e5b39d55d331415d43e69608604aa095342ab9403fd70da2cbcdcfe139f688f6e4cf16c20bca817466d
|
data/.circleci/config.yml
CHANGED
@@ -20,6 +20,10 @@ references:
|
|
20
20
|
paths:
|
21
21
|
- ./vendor/bundle
|
22
22
|
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
23
|
+
rubocop: &rubocop
|
24
|
+
run:
|
25
|
+
name: Run rubocop
|
26
|
+
command: bundle exec rubocop
|
23
27
|
jobs:
|
24
28
|
"ruby-2.7":
|
25
29
|
docker:
|
@@ -29,6 +33,7 @@ jobs:
|
|
29
33
|
- <<: *restore
|
30
34
|
- <<: *bundle
|
31
35
|
- <<: *save
|
36
|
+
- <<: *rubocop
|
32
37
|
- <<: *unit
|
33
38
|
|
34
39
|
workflows:
|
@@ -33,10 +33,10 @@ jobs:
|
|
33
33
|
mkdir -p $HOME/.gem
|
34
34
|
touch $HOME/.gem/credentials
|
35
35
|
chmod 0600 $HOME/.gem/credentials
|
36
|
-
printf -- "---\n:github: Bearer ${{ env.
|
36
|
+
printf -- "---\n:github: Bearer ${{ env.GPR_AUTH_TOKEN }}\n" > $HOME/.gem/credentials
|
37
37
|
gem build *.gemspec
|
38
38
|
gem push --KEY github --host https://rubygems.pkg.github.com/${{ env.OWNER }} *.gem
|
39
39
|
continue-on-error: true
|
40
40
|
env:
|
41
|
-
|
42
|
-
OWNER: chatwoot
|
41
|
+
GPR_AUTH_TOKEN: ${{secrets.GPR_AUTH_TOKEN}}
|
42
|
+
OWNER: chatwoot
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rspec
|
4
|
+
inherit_from: .rubocop_todo.yml
|
5
|
+
|
6
|
+
Layout/LineLength:
|
7
|
+
Max: 150
|
8
|
+
Metrics/ClassLength:
|
9
|
+
Max: 125
|
10
|
+
RSpec/ExampleLength:
|
11
|
+
Max: 25
|
12
|
+
Style/Documentation:
|
13
|
+
Enabled: false
|
14
|
+
Style/ExponentialNotation:
|
15
|
+
Enabled: false
|
16
|
+
Style/FrozenStringLiteralComment:
|
17
|
+
Enabled: false
|
18
|
+
Style/SymbolArray:
|
19
|
+
Enabled: false
|
20
|
+
Style/ClassAndModuleChildren:
|
21
|
+
EnforcedStyle: compact
|
22
|
+
RSpec/NestedGroups:
|
23
|
+
Enabled: true
|
24
|
+
Max: 4
|
25
|
+
RSpec/MessageSpies:
|
26
|
+
Enabled: false
|
27
|
+
Metrics/CyclomaticComplexity:
|
28
|
+
Max: 7
|
29
|
+
RSpec/NamedSubject:
|
30
|
+
Enabled: false
|
31
|
+
# we should bring this down
|
32
|
+
RSpec/MultipleMemoizedHelpers:
|
33
|
+
Max: 12
|
34
|
+
AllCops:
|
35
|
+
NewCops: enable
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2021-03-22 15:23:29 UTC using RuboCop version 1.11.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: Include.
|
11
|
+
# Include: **/*.gemspec
|
12
|
+
Gemspec/RequiredRubyVersion:
|
13
|
+
Exclude:
|
14
|
+
- 'twitty.gemspec'
|
15
|
+
|
16
|
+
# Offense count: 3
|
17
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
18
|
+
# IgnoredMethods: refine
|
19
|
+
Metrics/BlockLength:
|
20
|
+
Max: 30
|
21
|
+
|
22
|
+
# Offense count: 1
|
23
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
24
|
+
Metrics/MethodLength:
|
25
|
+
Max: 13
|
26
|
+
|
27
|
+
# Offense count: 3
|
28
|
+
RSpec/BeforeAfterAll:
|
29
|
+
Exclude:
|
30
|
+
- 'spec/spec_helper.rb'
|
31
|
+
- 'spec/rails_helper.rb'
|
32
|
+
- 'spec/support/**/*.rb'
|
33
|
+
- 'spec/twitty/config_spec.rb'
|
34
|
+
- 'spec/twitty/facade_spec.rb'
|
35
|
+
- 'spec/twitty/request_spec.rb'
|
36
|
+
|
37
|
+
# Offense count: 6
|
38
|
+
# Cop supports --auto-correct.
|
39
|
+
# Configuration parameters: SkipBlocks, EnforcedStyle.
|
40
|
+
# SupportedStyles: described_class, explicit
|
41
|
+
RSpec/DescribedClass:
|
42
|
+
Exclude:
|
43
|
+
- 'spec/twitty/config_spec.rb'
|
44
|
+
- 'spec/twitty/facade_spec.rb'
|
45
|
+
- 'spec/twitty/request_spec.rb'
|
46
|
+
|
47
|
+
# Offense count: 16
|
48
|
+
# Configuration parameters: AssignmentOnly.
|
49
|
+
RSpec/InstanceVariable:
|
50
|
+
Exclude:
|
51
|
+
- 'spec/twitty/config_spec.rb'
|
52
|
+
- 'spec/twitty/facade_spec.rb'
|
53
|
+
- 'spec/twitty/request_spec.rb'
|
54
|
+
|
55
|
+
# Offense count: 2
|
56
|
+
# Cop supports --auto-correct.
|
57
|
+
# Configuration parameters: EnforcedStyle.
|
58
|
+
# SupportedStyles: nested, compact
|
59
|
+
Style/ClassAndModuleChildren:
|
60
|
+
Exclude:
|
61
|
+
- 'lib/twitty/errors.rb'
|
62
|
+
|
63
|
+
# Offense count: 1
|
64
|
+
# Cop supports --auto-correct.
|
65
|
+
# Configuration parameters: EnforcedStyle.
|
66
|
+
# SupportedStyles: format, sprintf, percent
|
67
|
+
Style/FormatString:
|
68
|
+
Exclude:
|
69
|
+
- 'lib/twitty/facade.rb'
|
70
|
+
|
71
|
+
# Offense count: 1
|
72
|
+
# Cop supports --auto-correct.
|
73
|
+
Style/HashTransformValues:
|
74
|
+
Exclude:
|
75
|
+
- 'lib/twitty/facade.rb'
|
76
|
+
|
77
|
+
# Offense count: 1
|
78
|
+
# Cop supports --auto-correct.
|
79
|
+
# Configuration parameters: EnforcedStyle.
|
80
|
+
# SupportedStyles: literals, strict
|
81
|
+
Style/MutableConstant:
|
82
|
+
Exclude:
|
83
|
+
- 'lib/twitty/request.rb'
|
data/Gemfile
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in twitty.gemspec
|
6
6
|
gemspec
|
7
7
|
gem 'oauth'
|
8
|
+
gem 'rubocop', require: false
|
9
|
+
gem 'rubocop-performance', require: false
|
10
|
+
gem 'rubocop-rspec', require: false
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
twitty (0.1.
|
4
|
+
twitty (0.1.3)
|
5
5
|
oauth
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
ast (2.4.2)
|
10
11
|
diff-lcs (1.3)
|
11
|
-
oauth (0.5.
|
12
|
+
oauth (0.5.6)
|
13
|
+
parallel (1.20.1)
|
14
|
+
parser (3.0.0.0)
|
15
|
+
ast (~> 2.4.1)
|
16
|
+
rainbow (3.0.0)
|
12
17
|
rake (13.0.1)
|
18
|
+
regexp_parser (2.1.1)
|
19
|
+
rexml (3.2.5)
|
13
20
|
rspec (3.9.0)
|
14
21
|
rspec-core (~> 3.9.0)
|
15
22
|
rspec-expectations (~> 3.9.0)
|
@@ -23,6 +30,25 @@ GEM
|
|
23
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
24
31
|
rspec-support (~> 3.9.0)
|
25
32
|
rspec-support (3.9.3)
|
33
|
+
rubocop (1.11.0)
|
34
|
+
parallel (~> 1.10)
|
35
|
+
parser (>= 3.0.0.0)
|
36
|
+
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
regexp_parser (>= 1.8, < 3.0)
|
38
|
+
rexml
|
39
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
40
|
+
ruby-progressbar (~> 1.7)
|
41
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
42
|
+
rubocop-ast (1.4.1)
|
43
|
+
parser (>= 2.7.1.5)
|
44
|
+
rubocop-performance (1.10.1)
|
45
|
+
rubocop (>= 0.90.0, < 2.0)
|
46
|
+
rubocop-ast (>= 0.4.0)
|
47
|
+
rubocop-rspec (2.2.0)
|
48
|
+
rubocop (~> 1.0)
|
49
|
+
rubocop-ast (>= 1.1.0)
|
50
|
+
ruby-progressbar (1.11.0)
|
51
|
+
unicode-display_width (2.0.0)
|
26
52
|
|
27
53
|
PLATFORMS
|
28
54
|
ruby
|
@@ -32,6 +58,9 @@ DEPENDENCIES
|
|
32
58
|
oauth
|
33
59
|
rake (~> 13.0)
|
34
60
|
rspec (~> 3.0)
|
61
|
+
rubocop
|
62
|
+
rubocop-performance
|
63
|
+
rubocop-rspec
|
35
64
|
twitty!
|
36
65
|
|
37
66
|
BUNDLED WITH
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'twitty'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "twitty"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/lib/twitty.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
require 'oauth'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
4
|
+
require 'twitty/version'
|
5
|
+
require 'twitty/constants'
|
6
|
+
require 'twitty/config'
|
7
|
+
require 'twitty/payload'
|
8
|
+
require 'twitty/request'
|
9
|
+
require 'twitty/response'
|
10
|
+
require 'twitty/errors'
|
11
|
+
require 'twitty/facade'
|
12
12
|
|
13
|
-
|
14
|
-
class Error < StandardError; end
|
13
|
+
class Twitty::Error < StandardError
|
15
14
|
# Your code goes here...
|
16
15
|
end
|
data/lib/twitty/config.rb
CHANGED
@@ -1,20 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
:environment
|
9
|
-
|
1
|
+
class Twitty::Config
|
2
|
+
attr_accessor :consumer_key,
|
3
|
+
:consumer_secret,
|
4
|
+
:access_token,
|
5
|
+
:access_token_secret,
|
6
|
+
:base_url,
|
7
|
+
:environment
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
def initialize(params = {})
|
10
|
+
@base_url = params[:base_url]
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
12
|
+
@consumer_key = params[:consumer_key]
|
13
|
+
@consumer_secret = params[:consumer_secret]
|
14
|
+
@access_token = params[:access_token]
|
15
|
+
@access_token_secret = params[:access_token_secret]
|
19
16
|
end
|
20
17
|
end
|
data/lib/twitty/constants.rb
CHANGED
@@ -1,97 +1,95 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Twitty
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
},
|
3
|
+
module Twitty::Constants
|
4
|
+
API_CONFIG = {
|
5
|
+
fetch_webhooks: {
|
6
|
+
method: :get,
|
7
|
+
endpoint: '/1.1/account_activity/all/%<env>s/webhooks.json',
|
8
|
+
required_params: []
|
9
|
+
},
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
unregister_webhook: {
|
19
|
-
method: :delete,
|
20
|
-
endpoint: '/1.1/account_activity/all/%{env}/webhooks/%{id}.json',
|
21
|
-
required_params: [:id]
|
22
|
-
},
|
23
|
-
|
24
|
-
fetch_subscriptions: {
|
25
|
-
method: :get,
|
26
|
-
endpoint: '/1.1/account_activity/all/%{env}/subscriptions.json',
|
27
|
-
required_params: []
|
28
|
-
},
|
11
|
+
register_webhook: {
|
12
|
+
method: :post,
|
13
|
+
endpoint: '/1.1/account_activity/all/%<env>s/webhooks.json?url=%<url>s',
|
14
|
+
required_params: [:url]
|
15
|
+
},
|
29
16
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
17
|
+
unregister_webhook: {
|
18
|
+
method: :delete,
|
19
|
+
endpoint: '/1.1/account_activity/all/%<env>s/webhooks/%<id>s.json',
|
20
|
+
required_params: [:id]
|
21
|
+
},
|
35
22
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
send_direct_message: {
|
43
|
-
method: :post,
|
44
|
-
endpoint: '/1.1/direct_messages/events/new.json',
|
45
|
-
required_params: [:message, :recipient_id]
|
46
|
-
},
|
23
|
+
fetch_subscriptions: {
|
24
|
+
method: :get,
|
25
|
+
endpoint: '/1.1/account_activity/all/%<env>s/subscriptions.json',
|
26
|
+
required_params: []
|
27
|
+
},
|
47
28
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
29
|
+
create_subscription: {
|
30
|
+
method: :post,
|
31
|
+
endpoint: '/1.1/account_activity/all/%<env>s/subscriptions.json',
|
32
|
+
required_params: []
|
33
|
+
},
|
53
34
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
35
|
+
remove_subscription: {
|
36
|
+
method: :delete,
|
37
|
+
endpoint: '/1.1/account_activity/all/%<env>s/subscriptions/%<user_id>s.json',
|
38
|
+
required_params: [:user_id]
|
39
|
+
},
|
59
40
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
41
|
+
send_direct_message: {
|
42
|
+
method: :post,
|
43
|
+
endpoint: '/1.1/direct_messages/events/new.json',
|
44
|
+
required_params: [:message, :recipient_id]
|
45
|
+
},
|
65
46
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
47
|
+
send_tweet_reply: {
|
48
|
+
method: :post,
|
49
|
+
endpoint: '/1.1/statuses/update.json',
|
50
|
+
required_params: [:tweet, :reply_to_tweet_id]
|
51
|
+
},
|
71
52
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
53
|
+
request_oauth_token: {
|
54
|
+
method: :post,
|
55
|
+
endpoint: '/oauth/request_token',
|
56
|
+
required_params: [:url]
|
57
|
+
},
|
77
58
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
59
|
+
access_token: {
|
60
|
+
method: :post,
|
61
|
+
endpoint: '/oauth/access_token',
|
62
|
+
required_params: [:oauth_token, :oauth_verifier]
|
63
|
+
},
|
83
64
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
65
|
+
destroy_tweet: {
|
66
|
+
method: :post,
|
67
|
+
endpoint: '/1.1/statuses/destroy/%<tweet_id>s.json',
|
68
|
+
required_params: [:tweet_id]
|
69
|
+
},
|
89
70
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
71
|
+
retweet: {
|
72
|
+
method: :post,
|
73
|
+
endpoint: '/1.1/statuses/retweet/%<tweet_id>s.json',
|
74
|
+
required_params: [:tweet_id]
|
75
|
+
},
|
76
|
+
|
77
|
+
unretweet: {
|
78
|
+
method: :post,
|
79
|
+
endpoint: '/1.1/statuses/unretweet/%<tweet_id>s.json',
|
80
|
+
required_params: [:tweet_id]
|
81
|
+
},
|
82
|
+
|
83
|
+
like_tweet: {
|
84
|
+
method: :post,
|
85
|
+
endpoint: '/1.1/favorites/create.json',
|
86
|
+
required_params: [:tweet_id]
|
87
|
+
},
|
88
|
+
|
89
|
+
unlike_tweet: {
|
90
|
+
method: :post,
|
91
|
+
endpoint: '/1.1/favorites/destroy.json',
|
92
|
+
required_params: [:tweet_id]
|
93
|
+
}
|
94
|
+
}.freeze
|
97
95
|
end
|
data/lib/twitty/facade.rb
CHANGED
@@ -1,67 +1,61 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
include Twitty::Payload
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
yield(config) if block_given?
|
10
|
-
end
|
11
|
-
|
12
|
-
API_CONFIG.each do |action, _config|
|
13
|
-
define_method action do |data = {}|
|
14
|
-
define_actions(action, data)
|
15
|
-
end
|
16
|
-
end
|
3
|
+
class Twitty::Facade
|
4
|
+
include Twitty::Constants
|
5
|
+
include Twitty::Payload
|
17
6
|
|
7
|
+
def initialize
|
8
|
+
yield(config) if block_given?
|
9
|
+
end
|
18
10
|
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
API_CONFIG.each do |action, _config|
|
12
|
+
define_method action do |data = {}|
|
13
|
+
define_actions(action, data)
|
22
14
|
end
|
15
|
+
end
|
23
16
|
|
17
|
+
def generate_crc(crc_token)
|
18
|
+
hash = OpenSSL::HMAC.digest('sha256', config.consumer_secret, crc_token)
|
19
|
+
Base64.encode64(hash).strip!
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
private
|
22
|
+
def override_client_tokens(access_token, access_token_secret)
|
23
|
+
config.access_token = access_token
|
24
|
+
config.access_token_secret = access_token_secret
|
25
|
+
end
|
31
26
|
|
32
|
-
|
33
|
-
validate_params(action, data)
|
34
|
-
response = send_request(api_url(action, data), api_method(action),
|
35
|
-
api_params(action, data))
|
36
|
-
response = Twitty::Response.new(response)
|
37
|
-
end
|
27
|
+
private
|
38
28
|
|
39
|
-
|
29
|
+
def define_actions(action, data)
|
30
|
+
validate_params(action, data)
|
31
|
+
response = send_request(api_url(action, data), api_method(action),
|
32
|
+
api_params(action, data))
|
33
|
+
Twitty::Response.new(response)
|
34
|
+
end
|
40
35
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
def validate_params(action, data)
|
37
|
+
missing_params = (API_CONFIG[action][:required_params] - data.keys.map(&:to_sym))
|
38
|
+
raise Twitty::Errors::MissingParams, missing_params.join(',') unless missing_params.empty?
|
39
|
+
end
|
45
40
|
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
def api_params(action, data)
|
42
|
+
build_payload(action, data)
|
43
|
+
end
|
49
44
|
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
def send_request(url, type, params)
|
46
|
+
Twitty::Request.new(url: url, type: type, payload: params, config: config).execute
|
47
|
+
end
|
53
48
|
|
54
|
-
|
55
|
-
|
56
|
-
|
49
|
+
def config
|
50
|
+
@config ||= Twitty::Config.new
|
51
|
+
end
|
57
52
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
53
|
+
def api_url(action, data)
|
54
|
+
url_params = data.merge(env: config.environment).map { |k, v| [k, CGI.escape(v)] }.to_h
|
55
|
+
"#{config.base_url}#{API_CONFIG[action][:endpoint]}" % url_params
|
56
|
+
end
|
62
57
|
|
63
|
-
|
64
|
-
|
65
|
-
end
|
58
|
+
def api_method(action)
|
59
|
+
API_CONFIG[action][:method]
|
66
60
|
end
|
67
61
|
end
|
data/lib/twitty/payload.rb
CHANGED
@@ -1,67 +1,65 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Twitty
|
4
|
-
|
5
|
-
|
6
|
-
create_subscription remove_subscription destroy_tweet retweet unretweet].freeze
|
3
|
+
module Twitty::Payload
|
4
|
+
EMPTY_PAYLOAD_ACTIONS = %w[fetch_webhooks register_webhook unregister_webhook fetch_subscriptions
|
5
|
+
create_subscription remove_subscription destroy_tweet retweet unretweet].freeze
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
7
|
+
EMPTY_PAYLOAD_ACTIONS.each do |action|
|
8
|
+
define_method "#{action}_payload" do
|
9
|
+
{}
|
12
10
|
end
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
def build_payload(action, payload)
|
14
|
+
@payload = payload
|
15
|
+
send("#{action}_payload")
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
}
|
18
|
+
def send_direct_message_payload
|
19
|
+
{
|
20
|
+
event: {
|
21
|
+
type: 'message_create',
|
22
|
+
message_create: {
|
23
|
+
target: {
|
24
|
+
recipient_id: @payload[:recipient_id]
|
25
|
+
},
|
26
|
+
message_data: {
|
27
|
+
text: @payload[:message]
|
30
28
|
}
|
31
29
|
}
|
32
|
-
}.to_json
|
33
|
-
end
|
34
|
-
|
35
|
-
def send_tweet_reply_payload
|
36
|
-
{
|
37
|
-
"status": @payload[:tweet],
|
38
|
-
"in_reply_to_status_id": @payload[:reply_to_tweet_id]
|
39
30
|
}
|
40
|
-
|
31
|
+
}.to_json
|
32
|
+
end
|
41
33
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
34
|
+
def send_tweet_reply_payload
|
35
|
+
{
|
36
|
+
status: @payload[:tweet],
|
37
|
+
in_reply_to_status_id: @payload[:reply_to_tweet_id]
|
38
|
+
}
|
39
|
+
end
|
47
40
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
41
|
+
def request_oauth_token_payload
|
42
|
+
{
|
43
|
+
oauth_callback: @payload[:url]
|
44
|
+
}
|
45
|
+
end
|
54
46
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
47
|
+
def access_token_payload
|
48
|
+
{
|
49
|
+
oauth_token: @payload[:oauth_token],
|
50
|
+
oauth_verifier: @payload[:oauth_verifier]
|
51
|
+
}
|
52
|
+
end
|
60
53
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
54
|
+
def like_tweet_payload
|
55
|
+
{
|
56
|
+
id: @payload[:tweet_id]
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def unlike_tweet_payload
|
61
|
+
{
|
62
|
+
id: @payload[:tweet_id]
|
63
|
+
}
|
66
64
|
end
|
67
65
|
end
|
data/lib/twitty/request.rb
CHANGED
@@ -1,48 +1,46 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
attr_reader :url, :type, :payload, :config
|
1
|
+
class Twitty::Request
|
2
|
+
attr_reader :url, :type, :payload, :config
|
4
3
|
|
5
|
-
|
4
|
+
HEADERS = { 'Content-Type' => 'application/json; charset=utf-8' }
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def self.execute(params)
|
7
|
+
new(params)
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
def initialize(params)
|
11
|
+
@url = params[:url]
|
12
|
+
@type = params[:type]
|
13
|
+
@payload = params[:payload]
|
14
|
+
@config = params[:config]
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def execute
|
18
|
+
send("api_#{type}")
|
19
|
+
end
|
21
20
|
|
22
|
-
|
21
|
+
private
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
23
|
+
def api_client
|
24
|
+
@api_client ||= begin
|
25
|
+
consumer = OAuth::Consumer.new(config.consumer_key, config.consumer_secret, { site: config.base_url })
|
26
|
+
token = { oauth_token: config.access_token, oauth_token_secret: config.access_token_secret }
|
27
|
+
OAuth::AccessToken.from_hash(consumer, token)
|
30
28
|
end
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
def api_get
|
32
|
+
api_client.get(url, HEADERS)
|
33
|
+
end
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
def api_post
|
36
|
+
api_client.post(url, payload, HEADERS)
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
def api_put
|
40
|
+
api_client.put(url, payload, HEADERS)
|
41
|
+
end
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
end
|
43
|
+
def api_delete
|
44
|
+
api_client.delete(url, HEADERS)
|
47
45
|
end
|
48
46
|
end
|
data/lib/twitty/response.rb
CHANGED
@@ -1,19 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
attr_reader :raw_response
|
3
|
+
class Twitty::Response
|
4
|
+
attr_reader :raw_response
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def initialize(raw_response)
|
7
|
+
@raw_response = raw_response
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def body
|
11
|
+
JSON.parse(raw_response.body)
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
14
|
+
def status
|
15
|
+
raw_response.code
|
18
16
|
end
|
19
17
|
end
|
data/lib/twitty/version.rb
CHANGED
data/twitty.gemspec
CHANGED
@@ -1,36 +1,35 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require 'twitty/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'twitty'
|
8
7
|
spec.version = Twitty::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
8
|
+
spec.authors = ['Subin T P', 'Pranav Raj S', 'Sojan Jose']
|
9
|
+
spec.email = ['hello@thoughtwoot.com', 'subin@thoughtwoot.com', 'pranav@thoughtwoot.com', 'sojan@thoughtwoot.com']
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
11
|
+
spec.summary = 'Twitter API wrapper'
|
12
|
+
spec.description = 'Twitty makes working with the twitter account subscriptions APIs much easier'
|
13
|
+
spec.homepage = 'https://www.chatwoot.com'
|
14
|
+
spec.license = 'MIT'
|
16
15
|
|
17
16
|
spec.metadata = {
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
'bug_tracker_uri' => 'https://github.com/chatwoot/twitty/issues',
|
18
|
+
'homepage_uri' => 'https://github.com/chatwoot/twitty',
|
19
|
+
'source_code_uri' => 'https://github.com/chatwoot/twitty'
|
21
20
|
}
|
22
21
|
|
23
22
|
# Specify which files should be added to the gem when it is released.
|
24
23
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
-
spec.files
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
25
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
26
|
end
|
28
|
-
spec.bindir =
|
27
|
+
spec.bindir = 'exe'
|
29
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
-
spec.require_paths = [
|
29
|
+
spec.require_paths = ['lib']
|
31
30
|
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_runtime_dependency
|
31
|
+
spec.add_development_dependency 'bundler', '~> 2'
|
32
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
|
+
spec.add_runtime_dependency 'oauth'
|
36
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Subin T P
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-05-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -83,6 +83,8 @@ files:
|
|
83
83
|
- ".github/workflows/gempush.yml"
|
84
84
|
- ".gitignore"
|
85
85
|
- ".rspec"
|
86
|
+
- ".rubocop.yml"
|
87
|
+
- ".rubocop_todo.yml"
|
86
88
|
- ".ruby-version"
|
87
89
|
- ".travis.yml"
|
88
90
|
- CODE_OF_CONDUCT.md
|
@@ -125,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
127
|
- !ruby/object:Gem::Version
|
126
128
|
version: '0'
|
127
129
|
requirements: []
|
128
|
-
rubygems_version: 3.2.
|
130
|
+
rubygems_version: 3.2.15
|
129
131
|
signing_key:
|
130
132
|
specification_version: 4
|
131
133
|
summary: Twitter API wrapper
|