Skip to content

Instantly share code, notes, and snippets.

View lolaodelola's full-sized avatar

Lola lolaodelola

View GitHub Profile
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
<% 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" %>
def landing
render 'landing'
end
def new
@affirmation = Affirmation.new
end
def create
Affirmation.create!(affirmation_params)
def receive
req_body = params['Body'].downcase
if (req_body == 'affirm') || (req_body == 'start')
  create
elsif req_body == 'stop'
   delete
end
end
def create
# app/models/affirmation.rb
has_many :sent_affirmations
has_many :developers, through: :sent_affirmation
d = Developer.new
d.uuid = SecureRandom.uuid
d.phone_number = '0984737424'
d.save
before_create :generate_uuid
private
def generate_uuid
self.uuid = SecureRandom.uuid
end
it 'creates a uuid before create' do
d = Developer.create!(phone_number: '0984737424')
expect(d.uuid).to_not be_nil
end
validates_presence_of :phone_number
scope :confirmed, -> { where(confirmed: true) }
TWILIO_SID = <YOUR TWILIO SID>
TWILIO_TOKEN = <YOUR TWILIO TOKEN>
TWILIO_NUMBER = <YOUR TWILIO PHONE NUMBER>