twitty 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.
- checksums.yaml +7 -0
- data/.circleci/config.yml +38 -0
- data/.github/workflows/gempush.yml +40 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.txt +21 -0
- data/README.md +76 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/twitty.rb +16 -0
- data/lib/twitty/config.rb +20 -0
- data/lib/twitty/constants.rb +67 -0
- data/lib/twitty/errors.rb +11 -0
- data/lib/twitty/facade.rb +67 -0
- data/lib/twitty/payload.rb +52 -0
- data/lib/twitty/request.rb +48 -0
- data/lib/twitty/response.rb +19 -0
- data/lib/twitty/version.rb +3 -0
- data/twitty.gemspec +36 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4c5c39f405f8e68fc40b8e42efaf62682108e04d1dcc7cb6bfe987f3c31d8490
|
4
|
+
data.tar.gz: 93158d3ba7cb8f084b13e04b4e2821b965c45dc6eb7e4558e5ded54c6bc481c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 33fd5da653a371fd0cca74fe852485a5b80692d73c39113ac8a506a608fb806439acd22a602651946d525a9e23110878d13d948e9266c7d75d271e466131be33
|
7
|
+
data.tar.gz: f5f00e185e38bfa06d51f2d0ac34b068dfabb34b81f9b0a5fc0b09259e9e4ec08c2d9c04693b989e4a625a6921936d289d8661607c9695b7b4d297f543b3a07c
|
@@ -0,0 +1,38 @@
|
|
1
|
+
version: 2
|
2
|
+
references:
|
3
|
+
unit: &unit
|
4
|
+
run:
|
5
|
+
name: Run test suite
|
6
|
+
command: bundle exec rspec
|
7
|
+
restore: &restore
|
8
|
+
restore_cache:
|
9
|
+
keys:
|
10
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
11
|
+
# fallback to using the latest cache if no exact match is found
|
12
|
+
- v1-dependencies-
|
13
|
+
bundle: &bundle
|
14
|
+
run:
|
15
|
+
name: install dependencies
|
16
|
+
command: |
|
17
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
18
|
+
save: &save
|
19
|
+
save_cache:
|
20
|
+
paths:
|
21
|
+
- ./vendor/bundle
|
22
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
23
|
+
jobs:
|
24
|
+
"ruby-2.7":
|
25
|
+
docker:
|
26
|
+
- image: circleci/ruby:2.7
|
27
|
+
steps:
|
28
|
+
- checkout
|
29
|
+
- <<: *restore
|
30
|
+
- <<: *bundle
|
31
|
+
- <<: *save
|
32
|
+
- <<: *unit
|
33
|
+
|
34
|
+
workflows:
|
35
|
+
version: 2
|
36
|
+
build:
|
37
|
+
jobs:
|
38
|
+
- "ruby-2.7"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
name: Build + Publish
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Set up Ruby 2.7
|
15
|
+
uses: actions/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
version: 2.7.1
|
18
|
+
|
19
|
+
- name: Publish to GPR
|
20
|
+
run: |
|
21
|
+
mkdir -p $HOME/.gem
|
22
|
+
touch $HOME/.gem/credentials
|
23
|
+
chmod 0600 $HOME/.gem/credentials
|
24
|
+
printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
25
|
+
gem build *.gemspec
|
26
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
27
|
+
env:
|
28
|
+
GEM_HOST_API_KEY: ${{secrets.GPR_AUTH_TOKEN}}
|
29
|
+
OWNER: username
|
30
|
+
|
31
|
+
- name: Publish to RubyGems
|
32
|
+
run: |
|
33
|
+
mkdir -p $HOME/.gem
|
34
|
+
touch $HOME/.gem/credentials
|
35
|
+
chmod 0600 $HOME/.gem/credentials
|
36
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
37
|
+
gem build *.gemspec
|
38
|
+
gem push *.gem
|
39
|
+
env:
|
40
|
+
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.1
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at subin.tp@truecaller.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
twitty (0.1.0)
|
5
|
+
oauth
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
oauth (0.5.4)
|
12
|
+
rake (13.0.1)
|
13
|
+
rspec (3.9.0)
|
14
|
+
rspec-core (~> 3.9.0)
|
15
|
+
rspec-expectations (~> 3.9.0)
|
16
|
+
rspec-mocks (~> 3.9.0)
|
17
|
+
rspec-core (3.9.2)
|
18
|
+
rspec-support (~> 3.9.3)
|
19
|
+
rspec-expectations (3.9.2)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.9.0)
|
22
|
+
rspec-mocks (3.9.1)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.9.0)
|
25
|
+
rspec-support (3.9.3)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 2)
|
32
|
+
oauth
|
33
|
+
rake (~> 13.0)
|
34
|
+
rspec (~> 3.0)
|
35
|
+
twitty!
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Subin T P
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Twitty
|
2
|
+
|
3
|
+
Ruby client for Twitter Business APIs
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'twitty'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install twitty
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Initialize twitty in your project in an intializer or as required
|
24
|
+
|
25
|
+
```
|
26
|
+
$twitter = Twitty::Facade.new do |config|
|
27
|
+
config.consumer_key = 'consumer key '
|
28
|
+
config.consumer_secret = 'consumer secret'
|
29
|
+
config.access_token = 'access token'
|
30
|
+
config.access_token_secret = 'access token secret'
|
31
|
+
config.base_url = 'https://api.twitter.com'
|
32
|
+
config.environment = 'chatwootdev'
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
Use twitty to register your webhook on twitter as below
|
37
|
+
|
38
|
+
```
|
39
|
+
#fetch existing webhooks
|
40
|
+
$twitter.fetch_webhooks
|
41
|
+
|
42
|
+
#register a new webhook
|
43
|
+
$twitter.register_webhooks(url: "https://xyc.com/webhooks/twitter")
|
44
|
+
```
|
45
|
+
|
46
|
+
You should handle the crc checks from twitter by processing the get requests to your webhooks url with a controller method similar to
|
47
|
+
|
48
|
+
```
|
49
|
+
def twitter_crc
|
50
|
+
render json: { response_token: "sha256=#{$twitter.generate_crc(params[:crc_token])}" }
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
## Development
|
57
|
+
|
58
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
59
|
+
|
60
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
61
|
+
|
62
|
+
### Adding new endpoints
|
63
|
+
|
64
|
+
You can easily add new endpoints by adding a new hash with `url` and `required_params` in https://github.com/chatwoot/twitty/blob/master/lib/twitty/constants.rb
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/chatwoot/twitty. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://www.chatwoot.com/docs/code-of-conduct) code of conduct.
|
69
|
+
|
70
|
+
## License
|
71
|
+
|
72
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
73
|
+
|
74
|
+
## Code of Conduct
|
75
|
+
|
76
|
+
Everyone interacting in the Twitty project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://www.chatwoot.com/docs/code-of-conduct).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "twitty"
|
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__)
|
data/bin/setup
ADDED
data/lib/twitty.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'oauth'
|
2
|
+
require 'json'
|
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"
|
12
|
+
|
13
|
+
module Twitty
|
14
|
+
class Error < StandardError; end
|
15
|
+
# Your code goes here...
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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
|
+
|
10
|
+
|
11
|
+
def initialize(params = {})
|
12
|
+
@base_url = params[:base_url]
|
13
|
+
|
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
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
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
|
+
},
|
11
|
+
|
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
|
+
},
|
29
|
+
|
30
|
+
create_subscription: {
|
31
|
+
method: :post,
|
32
|
+
endpoint: '/1.1/account_activity/all/%{env}/subscriptions.json',
|
33
|
+
required_params: []
|
34
|
+
},
|
35
|
+
|
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
|
+
},
|
47
|
+
|
48
|
+
send_tweet_reply: {
|
49
|
+
method: :post,
|
50
|
+
endpoint: '/1.1/statuses/update.json',
|
51
|
+
required_params: [:tweet, :reply_to_tweet_id]
|
52
|
+
},
|
53
|
+
|
54
|
+
request_oauth_token: {
|
55
|
+
method: :post,
|
56
|
+
endpoint: '/oauth/request_token',
|
57
|
+
required_params: [:url]
|
58
|
+
},
|
59
|
+
|
60
|
+
access_token: {
|
61
|
+
method: :post,
|
62
|
+
endpoint: '/oauth/access_token',
|
63
|
+
required_params: [:oauth_token, :oauth_verifier]
|
64
|
+
}
|
65
|
+
}.freeze
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
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
|
17
|
+
|
18
|
+
|
19
|
+
def generate_crc(crc_token)
|
20
|
+
hash = OpenSSL::HMAC.digest('sha256', config.consumer_secret, crc_token)
|
21
|
+
return Base64.encode64(hash).strip!
|
22
|
+
end
|
23
|
+
|
24
|
+
|
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
|
31
|
+
|
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
|
38
|
+
|
39
|
+
private
|
40
|
+
|
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
|
45
|
+
|
46
|
+
def api_params(action, data)
|
47
|
+
build_payload(action, data)
|
48
|
+
end
|
49
|
+
|
50
|
+
def send_request(url, type, params)
|
51
|
+
Twitty::Request.new(url: url, type: type, payload: params, config: config).execute
|
52
|
+
end
|
53
|
+
|
54
|
+
def config
|
55
|
+
@config ||= Twitty::Config.new
|
56
|
+
end
|
57
|
+
|
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
|
62
|
+
|
63
|
+
def api_method(action)
|
64
|
+
API_CONFIG[action][:method]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Twitty
|
2
|
+
module Payload
|
3
|
+
EMPTY_PAYLOAD_ACTIONS = %w[fetch_webhooks register_webhook unregister_webhook fetch_subscriptions create_subscription remove_subscription].freeze
|
4
|
+
|
5
|
+
EMPTY_PAYLOAD_ACTIONS.each do |action|
|
6
|
+
define_method "#{action.to_s}_payload" do
|
7
|
+
{}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def build_payload(action, payload)
|
12
|
+
@payload = payload
|
13
|
+
send("#{action.to_s}_payload")
|
14
|
+
end
|
15
|
+
|
16
|
+
def send_direct_message_payload
|
17
|
+
{
|
18
|
+
"event": {
|
19
|
+
"type": "message_create",
|
20
|
+
"message_create": {
|
21
|
+
"target": {
|
22
|
+
"recipient_id": @payload[:recipient_id]
|
23
|
+
},
|
24
|
+
"message_data": {
|
25
|
+
"text": @payload[:message]
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}.to_json
|
30
|
+
end
|
31
|
+
|
32
|
+
def send_tweet_reply_payload
|
33
|
+
{
|
34
|
+
"status": @payload[:tweet],
|
35
|
+
"in_reply_to_status_id": @payload[:reply_to_tweet_id]
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def request_oauth_token_payload
|
40
|
+
{
|
41
|
+
oauth_callback: @payload[:url]
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def access_token_payload
|
46
|
+
{
|
47
|
+
oauth_token: @payload[:oauth_token],
|
48
|
+
oauth_verifier: @payload[:oauth_verifier]
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Twitty
|
2
|
+
class Request
|
3
|
+
attr_reader :url, :type, :payload, :config
|
4
|
+
|
5
|
+
HEADERS = {"Content-Type" => "application/json; charset=utf-8"}
|
6
|
+
|
7
|
+
def self.execute(params)
|
8
|
+
new(params)
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(params)
|
12
|
+
@url = params[:url]
|
13
|
+
@type = params[:type]
|
14
|
+
@payload = params[:payload]
|
15
|
+
@config = params[:config]
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute
|
19
|
+
send("api_#{type}")
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
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
|
30
|
+
end
|
31
|
+
|
32
|
+
def api_get
|
33
|
+
api_client.get(url, HEADERS)
|
34
|
+
end
|
35
|
+
|
36
|
+
def api_post
|
37
|
+
api_client.post(url, payload, HEADERS)
|
38
|
+
end
|
39
|
+
|
40
|
+
def api_put
|
41
|
+
api_client.put(url, payload, HEADERS)
|
42
|
+
end
|
43
|
+
|
44
|
+
def api_delete
|
45
|
+
api_client.delete(url, HEADERS)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Twitty
|
4
|
+
class Response
|
5
|
+
attr_reader :raw_response
|
6
|
+
|
7
|
+
def initialize(raw_response)
|
8
|
+
@raw_response = raw_response
|
9
|
+
end
|
10
|
+
|
11
|
+
def body
|
12
|
+
JSON.parse(raw_response.body)
|
13
|
+
end
|
14
|
+
|
15
|
+
def status
|
16
|
+
raw_response.code
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/twitty.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "twitty/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "twitty"
|
8
|
+
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"]
|
11
|
+
|
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"
|
16
|
+
|
17
|
+
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",
|
21
|
+
}
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# 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
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
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"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twitty
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Subin T P
|
8
|
+
- Pranav Raj S
|
9
|
+
- Sojan Jose
|
10
|
+
autorequire:
|
11
|
+
bindir: exe
|
12
|
+
cert_chain: []
|
13
|
+
date: 2020-05-13 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '2'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rake
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '13.0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '13.0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rspec
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '3.0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '3.0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: oauth
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :runtime
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
description: Twitty makes working with the twitter account subscriptions APIs much
|
72
|
+
easier
|
73
|
+
email:
|
74
|
+
- hello@thoughtwoot.com
|
75
|
+
- subin@thoughtwoot.com
|
76
|
+
- pranav@thoughtwoot.com
|
77
|
+
- sojan@thoughtwoot.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".circleci/config.yml"
|
83
|
+
- ".github/workflows/gempush.yml"
|
84
|
+
- ".gitignore"
|
85
|
+
- ".rspec"
|
86
|
+
- ".ruby-version"
|
87
|
+
- ".travis.yml"
|
88
|
+
- CODE_OF_CONDUCT.md
|
89
|
+
- Gemfile
|
90
|
+
- Gemfile.lock
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- bin/console
|
95
|
+
- bin/setup
|
96
|
+
- lib/twitty.rb
|
97
|
+
- lib/twitty/config.rb
|
98
|
+
- lib/twitty/constants.rb
|
99
|
+
- lib/twitty/errors.rb
|
100
|
+
- lib/twitty/facade.rb
|
101
|
+
- lib/twitty/payload.rb
|
102
|
+
- lib/twitty/request.rb
|
103
|
+
- lib/twitty/response.rb
|
104
|
+
- lib/twitty/version.rb
|
105
|
+
- twitty.gemspec
|
106
|
+
homepage: https://www.chatwoot.com
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata:
|
110
|
+
bug_tracker_uri: https://github.com/chatwoot/twitty/issues
|
111
|
+
homepage_uri: https://github.com/chatwoot/twitty
|
112
|
+
source_code_uri: https://github.com/chatwoot/twitty
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubygems_version: 3.1.2
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Twitter API wrapper
|
132
|
+
test_files: []
|