Created
November 28, 2017 08:55
-
-
Save mktakuya/74137da05fc6640da2bf4dc70e66b83d to your computer and use it in GitHub Desktop.
苫小牧高専News FAX版のコード断片 その2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
feed_url: <%= ENV['FEED_URL'] %> | |
notifications: | |
fax: | |
twilio_account_sid: <%= ENV['TWILIO_ACCOUNT_SID'] %> | |
twilio_auth_token: <%= ENV['TWILIO_AUTH_TOKEN'] %> | |
twilio_from_number: <%= ENV['TWILIO_FROM_NUMBER'] %> | |
twilio_to_number: <%= ENV['TWILIO_TO_NUMBER'] %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
require 'twilio-ruby' | |
class FaxNotifier | |
def initialize(news, config) | |
@news = news | |
@fax_config = config | |
end | |
def notify | |
client = Twilio::REST::Client.new @fax_config['twilio_account_sid'], @fax_config['twilio_auth_token'] | |
from_number = @fax_config['twilio_from_number'].to_s | |
to_number = @fax_config['twilio_to_number'].to_s | |
category = @news.category | |
post_id = @news.link.split('/')[-1].gsub('.html', '') | |
media_url = "https://tmnct-news.mktakuya.net/fax?category=#{category}&post_id=#{post_id}" | |
client.fax.v1.faxes.create( | |
from: '+81' + from_number, | |
to: '+81' + to_number, | |
media_url: media_url, | |
quality: :standard | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment