Skip to content

Instantly share code, notes, and snippets.

@mktakuya
Created November 28, 2017 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mktakuya/74137da05fc6640da2bf4dc70e66b83d to your computer and use it in GitHub Desktop.
Save mktakuya/74137da05fc6640da2bf4dc70e66b83d to your computer and use it in GitHub Desktop.
苫小牧高専News FAX版のコード断片 その2
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'] %>
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