【发布时间】:2016-06-24 07:18:42
【问题描述】:
我想在 ruby on rails 中添加一个功能(更像是一个 gem),其中用户指定他们的服务提供者名称,然后它会自动获取相关配置并将其注入模型文件并创建必要的迁移。
我的问题是如何实现这一目标。我的意思是我应该使用哪种设计模式,这样每当用户指定其提供商名称(例如 Exotel、Sinch、Twilio 等)时,它就会将其相应的配置注入配置文件及其 api 设置以发送电子邮件和消息。
我已经检查过这个Question,但它似乎并没有解决我的问题。
例如Rails 的 Exotel api 配置是 -
Exotel.configure do |c|
c.exotel_sid = "Your exotel sid"
c.exotel_token = "Your exotel token"
end
发送消息
response = Exotel::Sms.send(:from => 'FROM_NUMBER', :to => 'TO_NUMBER', :body => 'MESSAGE BODY')
sms_id = response.sid #sid is used to find the delivery status and other details of the message in future.
虽然发送消息的 sinch 配置是 -
SinchSms.send('YOUR_APP_KEY', 'YOUR_APP_SECRET', "Your code is #{code}", phone_number)
render status: 200, nothing: true
现在我希望 gem 根据用户输入的服务提供商名称来完成所有这些工作,即,如果用户输入 Exotel,则 gem 将设置 exotel 设置,如果是 Sinch,则将设置 sinch 的配置。
【问题讨论】:
标签: ruby-on-rails ruby rails-activerecord exotel-api