twitty 0.1.2 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94a8d618eb91b2e104f808cdb3b4a1bd32663f2b03f03317c5113de4f4a8639c
4
- data.tar.gz: ea116a4b5eaee3fca8b968dac8ac5dc658602df2b049427a4e78aa870f5bb4cf
3
+ metadata.gz: a93f92340fb4931676b89a3d20f869aae7e87f5fb2a9831d506e6c0d41c9dc18
4
+ data.tar.gz: a541340dd6566a95219f8feaacccf46604e968e41042d076f2b0e8e709e4ff5f
5
5
  SHA512:
6
- metadata.gz: c66cfe86a7100d07d318e09917327b5fb2e36478b577f768167afa86eb27e1672a55c4915ea546bc4850a88c115f01a985b4edade96fc42e8297d2d5e45aeded
7
- data.tar.gz: bd8afc3e729fecd14527e07d8c56853df82d587278b7eb3203e43025b78fb51b551652d0aadf5e8529282298b0350482d99c46f99a553397c73a356acafefa26
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.GEM_HOST_API_KEY }}\n" > $HOME/.gem/credentials
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
- GEM_HOST_API_KEY: ${{secrets.GPR_AUTH_TOKEN}}
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 "https://rubygems.org"
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.2)
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.4)
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
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "twitty"
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 "irb"
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 "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"
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
- module Twitty
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
- module Twitty
2
- class Config
3
- attr_accessor :consumer_key,
4
- :consumer_secret,
5
- :access_token,
6
- :access_token_secret,
7
- :base_url,
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
- def initialize(params = {})
12
- @base_url = params[:base_url]
9
+ def initialize(params = {})
10
+ @base_url = params[:base_url]
13
11
 
14
- @consumer_key = params[:consumer_key]
15
- @consumer_secret = params[:consumer_secret]
16
- @access_token = params[:access_token]
17
- @access_token_secret = params[:access_token_secret]
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
@@ -1,97 +1,95 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Twitty
4
- module Constants
5
- API_CONFIG = {
6
- fetch_webhooks: {
7
- method: :get,
8
- endpoint: '/1.1/account_activity/all/%{env}/webhooks.json',
9
- required_params: []
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
- register_webhook: {
13
- method: :post,
14
- endpoint: '/1.1/account_activity/all/%{env}/webhooks.json?url=%{url}',
15
- required_params: [:url]
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
- create_subscription: {
31
- method: :post,
32
- endpoint: '/1.1/account_activity/all/%{env}/subscriptions.json',
33
- required_params: []
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
- remove_subscription: {
37
- method: :delete,
38
- endpoint: '/1.1/account_activity/all/%{env}/subscriptions/%{user_id}.json',
39
- required_params: [:user_id]
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
- send_tweet_reply: {
49
- method: :post,
50
- endpoint: '/1.1/statuses/update.json',
51
- required_params: [:tweet, :reply_to_tweet_id]
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
- request_oauth_token: {
55
- method: :post,
56
- endpoint: '/oauth/request_token',
57
- required_params: [:url]
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
- access_token: {
61
- method: :post,
62
- endpoint: '/oauth/access_token',
63
- required_params: [:oauth_token, :oauth_verifier]
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
- destroy_tweet: {
67
- method: :post,
68
- endpoint: '/1.1/statuses/destroy/%{tweet_id}.json',
69
- required_params: [:tweet_id]
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
- retweet: {
73
- method: :post,
74
- endpoint: '/1.1/statuses/retweet/%{tweet_id}.json',
75
- required_params: [:tweet_id]
76
- },
53
+ request_oauth_token: {
54
+ method: :post,
55
+ endpoint: '/oauth/request_token',
56
+ required_params: [:url]
57
+ },
77
58
 
78
- unretweet: {
79
- method: :post,
80
- endpoint: '/1.1/statuses/unretweet/%{tweet_id}.json',
81
- required_params: [:tweet_id]
82
- },
59
+ access_token: {
60
+ method: :post,
61
+ endpoint: '/oauth/access_token',
62
+ required_params: [:oauth_token, :oauth_verifier]
63
+ },
83
64
 
84
- like_tweet: {
85
- method: :post,
86
- endpoint: '/1.1/favorites/create.json',
87
- required_params: [:tweet_id]
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
- unlike_tweet: {
91
- method: :post,
92
- endpoint: '/1.1/favorites/destroy.json',
93
- required_params: [:tweet_id]
94
- }
95
- }.freeze
96
- end
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
- module Twitty
4
- class Facade
5
- include Twitty::Constants
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
- def generate_crc(crc_token)
20
- hash = OpenSSL::HMAC.digest('sha256', config.consumer_secret, crc_token)
21
- return Base64.encode64(hash).strip!
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
- def override_client_tokens(access_token, access_token_secret)
26
- config.access_token = access_token
27
- config.access_token_secret = access_token_secret
28
- end
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
- def define_actions(action, data)
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
- private
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
- def validate_params(action, data)
42
- missing_params = (API_CONFIG[action][:required_params] - data.keys.map(&:to_sym))
43
- raise Twitty::Errors::MissingParams, missing_params.join(',') unless missing_params.empty?
44
- end
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
- def api_params(action, data)
47
- build_payload(action, data)
48
- end
41
+ def api_params(action, data)
42
+ build_payload(action, data)
43
+ end
49
44
 
50
- def send_request(url, type, params)
51
- Twitty::Request.new(url: url, type: type, payload: params, config: config).execute
52
- end
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
- def config
55
- @config ||= Twitty::Config.new
56
- end
49
+ def config
50
+ @config ||= Twitty::Config.new
51
+ end
57
52
 
58
- def api_url(action, data)
59
- url_params = data.merge(env: config.environment).map { |k,v| [k, CGI.escape(v)] }.to_h
60
- "#{config.base_url}#{API_CONFIG[action][:endpoint]}" % url_params
61
- end
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
- def api_method(action)
64
- API_CONFIG[action][:method]
65
- end
58
+ def api_method(action)
59
+ API_CONFIG[action][:method]
66
60
  end
67
61
  end
@@ -1,67 +1,65 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Twitty
4
- module Payload
5
- EMPTY_PAYLOAD_ACTIONS = %w[fetch_webhooks register_webhook unregister_webhook fetch_subscriptions
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
- EMPTY_PAYLOAD_ACTIONS.each do |action|
9
- define_method "#{action.to_s}_payload" do
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
- def build_payload(action, payload)
15
- @payload = payload
16
- send("#{action.to_s}_payload")
17
- end
13
+ def build_payload(action, payload)
14
+ @payload = payload
15
+ send("#{action}_payload")
16
+ end
18
17
 
19
- def send_direct_message_payload
20
- {
21
- "event": {
22
- "type": "message_create",
23
- "message_create": {
24
- "target": {
25
- "recipient_id": @payload[:recipient_id]
26
- },
27
- "message_data": {
28
- "text": @payload[:message]
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
- end
31
+ }.to_json
32
+ end
41
33
 
42
- def request_oauth_token_payload
43
- {
44
- oauth_callback: @payload[:url]
45
- }
46
- end
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
- def access_token_payload
49
- {
50
- oauth_token: @payload[:oauth_token],
51
- oauth_verifier: @payload[:oauth_verifier]
52
- }
53
- end
41
+ def request_oauth_token_payload
42
+ {
43
+ oauth_callback: @payload[:url]
44
+ }
45
+ end
54
46
 
55
- def like_tweet_payload
56
- {
57
- "id": @payload[:tweet_id]
58
- }
59
- end
47
+ def access_token_payload
48
+ {
49
+ oauth_token: @payload[:oauth_token],
50
+ oauth_verifier: @payload[:oauth_verifier]
51
+ }
52
+ end
60
53
 
61
- def unlike_tweet_payload
62
- {
63
- "id": @payload[:tweet_id]
64
- }
65
- end
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
@@ -1,48 +1,46 @@
1
- module Twitty
2
- class Request
3
- attr_reader :url, :type, :payload, :config
1
+ class Twitty::Request
2
+ attr_reader :url, :type, :payload, :config
4
3
 
5
- HEADERS = {"Content-Type" => "application/json; charset=utf-8"}
4
+ HEADERS = { 'Content-Type' => 'application/json; charset=utf-8' }
6
5
 
7
- def self.execute(params)
8
- new(params)
9
- end
6
+ def self.execute(params)
7
+ new(params)
8
+ end
10
9
 
11
- def initialize(params)
12
- @url = params[:url]
13
- @type = params[:type]
14
- @payload = params[:payload]
15
- @config = params[:config]
16
- end
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
- def execute
19
- send("api_#{type}")
20
- end
17
+ def execute
18
+ send("api_#{type}")
19
+ end
21
20
 
22
- private
21
+ private
23
22
 
24
- def api_client
25
- @api_client ||= begin
26
- consumer = OAuth::Consumer.new(config.consumer_key, config.consumer_secret, {:site => config.base_url})
27
- token = {:oauth_token => config.access_token, :oauth_token_secret => config.access_token_secret }
28
- OAuth::AccessToken.from_hash(consumer, token)
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
- def api_get
33
- api_client.get(url, HEADERS)
34
- end
31
+ def api_get
32
+ api_client.get(url, HEADERS)
33
+ end
35
34
 
36
- def api_post
37
- api_client.post(url, payload, HEADERS)
38
- end
35
+ def api_post
36
+ api_client.post(url, payload, HEADERS)
37
+ end
39
38
 
40
- def api_put
41
- api_client.put(url, payload, HEADERS)
42
- end
39
+ def api_put
40
+ api_client.put(url, payload, HEADERS)
41
+ end
43
42
 
44
- def api_delete
45
- api_client.delete(url, HEADERS)
46
- end
43
+ def api_delete
44
+ api_client.delete(url, HEADERS)
47
45
  end
48
46
  end
@@ -1,19 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Twitty
4
- class Response
5
- attr_reader :raw_response
3
+ class Twitty::Response
4
+ attr_reader :raw_response
6
5
 
7
- def initialize(raw_response)
8
- @raw_response = raw_response
9
- end
6
+ def initialize(raw_response)
7
+ @raw_response = raw_response
8
+ end
10
9
 
11
- def body
12
- JSON.parse(raw_response.body)
13
- end
10
+ def body
11
+ JSON.parse(raw_response.body)
12
+ end
14
13
 
15
- def status
16
- raw_response.code
17
- end
14
+ def status
15
+ raw_response.code
18
16
  end
19
17
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twitty
4
- VERSION = "0.1.2"
4
+ VERSION = '0.1.4'
5
5
  end
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 "twitty/version"
3
+ require 'twitty/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "twitty"
6
+ spec.name = 'twitty'
8
7
  spec.version = Twitty::VERSION
9
- spec.authors = ["Subin T P", "Pranav Raj S", "Sojan Jose"]
10
- spec.email = ["hello@thoughtwoot.com","subin@thoughtwoot.com", "pranav@thoughtwoot.com", "sojan@thoughtwoot.com"]
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 = %q{Twitter API wrapper}
13
- spec.description = %q{Twitty makes working with the twitter account subscriptions APIs much easier}
14
- spec.homepage = "https://www.chatwoot.com"
15
- spec.license = "MIT"
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
- "bug_tracker_uri" => "https://github.com/chatwoot/twitty/issues",
19
- "homepage_uri" => "https://github.com/chatwoot/twitty",
20
- "source_code_uri" => "https://github.com/chatwoot/twitty",
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 = Dir.chdir(File.expand_path('..', __FILE__)) do
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 = "exe"
27
+ spec.bindir = 'exe'
29
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
- spec.require_paths = ["lib"]
29
+ spec.require_paths = ['lib']
31
30
 
32
- spec.add_development_dependency "bundler", "~> 2"
33
- spec.add_development_dependency "rake", "~> 13.0"
34
- spec.add_development_dependency "rspec", "~> 3.0"
35
- spec.add_runtime_dependency "oauth"
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.2
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-03-11 00:00:00.000000000 Z
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.3
130
+ rubygems_version: 3.2.15
129
131
  signing_key:
130
132
  specification_version: 4
131
133
  summary: Twitter API wrapper