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
class AffirmationText | |
def initialize() | |
@client = Twilio::REST::Client.new(ENV['TWILIO_SID'], ENV['TWILIO_TOKEN']) | |
end | |
def message(dev_phone_number, affirmation) | |
@client.messages.create( | |
from: ENV['TWILIO_NUMBER'], | |
to: dev_phone_number, | |
body: affirmation |
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
<% if flash[:notice] %> | |
<div class="notice"><%= flash[:notice] %></div> | |
<% end %> | |
<h1>Submit an Affirmation</h1> | |
<%= form_for @affirmation do |f| %> | |
<div class="form-group"> | |
<%= f.label :affirmation%><br /> | |
<%= f.text_area :affirmation, placeholder: "Submit your affirmation", id: "affirmation" %> | |
</div> | |
<%= f.submit "Create" %> |
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
def landing | |
render 'landing' | |
end | |
def new | |
@affirmation = Affirmation.new | |
end | |
def create | |
Affirmation.create!(affirmation_params) |
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
def receive | |
req_body = params['Body'].downcase | |
if (req_body == 'affirm') || (req_body == 'start') | |
create | |
elsif req_body == 'stop' | |
delete | |
end | |
end | |
def create |
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
# app/models/affirmation.rb | |
has_many :sent_affirmations | |
has_many :developers, through: :sent_affirmation | |
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
d = Developer.new | |
d.uuid = SecureRandom.uuid | |
d.phone_number = '0984737424' | |
d.save |
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
before_create :generate_uuid | |
private | |
def generate_uuid | |
self.uuid = SecureRandom.uuid | |
end |
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
it 'creates a uuid before create' do | |
d = Developer.create!(phone_number: '0984737424') | |
expect(d.uuid).to_not be_nil | |
end |
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
validates_presence_of :phone_number | |
scope :confirmed, -> { where(confirmed: true) } |
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
TWILIO_SID = <YOUR TWILIO SID> | |
TWILIO_TOKEN = <YOUR TWILIO TOKEN> | |
TWILIO_NUMBER = <YOUR TWILIO PHONE NUMBER> |