Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Cloud Functions and Twitter API v2 #61

Merged
merged 10 commits into from Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Expand Up @@ -34,6 +34,11 @@ jobs:

- run: bundle exec rspec

- name: verify functions-framework-ruby
run: |
set -xe
bundle exec functions-framework-ruby --verify --verbose --target pribirthdaybot

- name: Slack Notification
uses: lazy-actions/slatify@master
if: always()
Expand Down
12 changes: 10 additions & 2 deletions Gemfile
Expand Up @@ -2,11 +2,19 @@

source "https://rubygems.org"

ruby "~> 3.2.0"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem "activesupport", require: "active_support/all"
gem "rake"
gem "twitter"
gem "functions_framework"
gem "google-cloud-firestore", require: "google/cloud/firestore"

# TODO: Use upstream after my patches are merged
# gem "simple_twitter"
gem "simple_twitter", github: "sue445/simple_twitter", branch: "develop"

gem "twitter_oauth2"

group :test do
gem "rspec"
Expand Down
155 changes: 121 additions & 34 deletions Gemfile.lock
@@ -1,3 +1,12 @@
GIT
remote: https://github.com/sue445/simple_twitter
revision: 4ce26a1afc1d0dc8e1eac47022c3dade376d5ff7
branch: develop
specs:
simple_twitter (1.0.0)
http (~> 4)
simple_oauth (~> 0.3.1)

GEM
remote: https://rubygems.org/
specs:
Expand All @@ -8,69 +17,142 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0)
buftok (0.3.0)
aes_key_wrap (1.1.0)
attr_required (1.0.1)
bindata (2.4.15)
cloud_events (0.7.0)
concurrent-ruby (1.2.2)
crack (0.4.5)
rexml
diff-lcs (1.5.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
equalizer (0.0.11)
faraday (2.7.7)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-follow_redirects (0.3.0)
faraday (>= 1, < 3)
faraday-net_http (3.0.2)
faraday-retry (2.2.0)
faraday (~> 2.0)
ffi (1.15.5)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
functions_framework (1.4.0)
cloud_events (>= 0.7.0, < 2.a)
puma (>= 4.3.0, < 7.a)
rack (>= 2.1, < 4.a)
gapic-common (0.19.1)
faraday (>= 1.9, < 3.a)
faraday-retry (>= 1.0, < 3.a)
google-protobuf (~> 3.14)
googleapis-common-protos (>= 1.3.12, < 2.a)
googleapis-common-protos-types (>= 1.3.1, < 2.a)
googleauth (~> 1.0)
grpc (~> 1.36)
google-cloud-core (1.6.0)
google-cloud-env (~> 1.0)
google-cloud-errors (~> 1.0)
google-cloud-env (1.6.0)
faraday (>= 0.17.3, < 3.0)
google-cloud-errors (1.3.1)
google-cloud-firestore (2.13.1)
concurrent-ruby (~> 1.0)
google-cloud-core (~> 1.5)
google-cloud-firestore-v1 (~> 0.10)
rbtree (~> 0.4.2)
google-cloud-firestore-v1 (0.10.0)
gapic-common (>= 0.17.1, < 2.a)
google-cloud-errors (~> 1.0)
google-cloud-location (>= 0.4, < 2.a)
google-cloud-location (0.5.1)
gapic-common (>= 0.19.1, < 2.a)
google-cloud-errors (~> 1.0)
google-protobuf (3.23.3-arm64-darwin)
googleapis-common-protos (1.4.0)
google-protobuf (~> 3.14)
googleapis-common-protos-types (~> 1.2)
grpc (~> 1.27)
googleapis-common-protos-types (1.6.0)
google-protobuf (~> 3.14)
googleauth (1.6.0)
faraday (>= 0.17.3, < 3.a)
jwt (>= 1.4, < 3.0)
memoist (~> 0.16)
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
grpc (1.56.0)
google-protobuf (~> 3.23)
googleapis-common-protos-types (~> 1.0)
grpc (1.56.0-x86_64-linux)
google-protobuf (~> 3.23)
googleapis-common-protos-types (~> 1.0)
hashdiff (1.0.1)
http (5.1.1)
addressable (~> 2.8)
http (4.4.1)
addressable (~> 2.3)
http-cookie (~> 1.0)
http-form_data (~> 2.2)
llhttp-ffi (~> 0.4.0)
http-parser (~> 1.2.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
http-form_data (2.3.0)
i18n (1.13.0)
http-parser (1.2.3)
ffi-compiler (>= 1.0, < 2.0)
httpclient (2.8.3)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
llhttp-ffi (0.4.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
minitest (5.18.0)
multipart-post (2.3.0)
naught (1.1.0)
json-jwt (1.16.3)
activesupport (>= 4.2)
aes_key_wrap
bindata
faraday (~> 2.0)
faraday-follow_redirects
jwt (2.7.1)
memoist (0.16.2)
minitest (5.18.1)
multi_json (1.15.0)
nio4r (2.5.9)
os (1.1.4)
public_suffix (5.0.1)
puma (6.3.0)
nio4r (~> 2.0)
rack (3.0.8)
rack-oauth2 (1.21.3)
activesupport
attr_required
httpclient
json-jwt (>= 1.11.0)
rack (>= 2.1.0)
rake (13.0.6)
rbtree (0.4.6)
rexml (3.2.5)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-its (1.3.0)
rspec-core (>= 3.0.0)
rspec-expectations (>= 3.0.0)
rspec-mocks (3.12.0)
rspec-mocks (3.12.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.0)
ruby2_keywords (0.0.5)
signet (0.17.0)
addressable (~> 2.8)
faraday (>= 0.17.5, < 3.a)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
simple_oauth (0.3.1)
thread_safe (0.3.6)
twitter (8.0.0)
addressable (~> 2.3)
buftok (~> 0.3.0)
equalizer (~> 0.0.11)
http (~> 5.1)
http-form_data (~> 2.3)
llhttp-ffi (~> 0.4.0)
memoizable (~> 0.4.0)
multipart-post (~> 2.0)
naught (~> 1.0)
simple_oauth (~> 0.3.0)
twitter_oauth2 (0.5.1)
rack-oauth2 (~> 1.19)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unf (0.1.4)
Expand All @@ -82,16 +164,21 @@ GEM
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
ruby
x86_64-darwin-17
arm64-darwin-22
x86_64-linux

DEPENDENCIES
activesupport
rake
functions_framework
google-cloud-firestore
rspec
rspec-its
twitter
simple_twitter!
twitter_oauth2
webmock

RUBY VERSION
ruby 3.2.2p53

BUNDLED WITH
2.2.3
2.4.14
7 changes: 0 additions & 7 deletions Rakefile

This file was deleted.

10 changes: 10 additions & 0 deletions app.rb
@@ -0,0 +1,10 @@
# frozen_string_literal: true

ENV["RACK_ENV"] ||= "development"
Bundler.require(:default, ENV["RACK_ENV"])

require_relative "lib/bot"

FunctionsFramework.cloud_event("pribirthdaybot") do |_request|
Bot.new.perform
end
14 changes: 3 additions & 11 deletions lib/bot.rb
@@ -1,6 +1,7 @@
Bundler.require(:default)

require_relative "./birthday_calendar_client"
require_relative "./twitter_client"

class Bot
def perform
Expand Down Expand Up @@ -53,17 +54,8 @@ def generate_birthday_message(date, names)
private

def post_tweet(tweet)
twitter_client.update(tweet)
twitter = TwitterClient.new("pribirthdaybot")
twitter.post_tweet(tweet)
puts tweet
end

def twitter_client
@twitter_client ||=
Twitter::REST::Client.new do |config|
config.consumer_key = ENV["TWITTER_V1_CONSUMER_KEY"]
config.consumer_secret = ENV["TWITTER_V1_CONSUMER_SECRET"]
config.access_token = ENV["TWITTER_V1_ACCESS_TOKEN"]
config.access_token_secret = ENV["TWITTER_V1_ACCESS_TOKEN_SECRET"]
end
end
end