Commit 3798762

mo <mo.khan@gmail.com>
2018-04-15 19:25:11
start to build a quick CLI to send an sms.
1 parent 8615a08
exe/incognito
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+require 'incognito'
+
+sms = Incognito::Sms.new
+puts ARGV.inspect
+sms.send(to: ARGV[0], message: ARGV[1])
lib/incognito.rb
@@ -1,5 +1,28 @@
 require "incognito/version"
+require 'dotenv'
+require 'twilio-ruby'
+require 'pathname'
+
+Dotenv.load(".env.local", Pathname.new(Dir.home).join(".incognitorc").to_s)
 
 module Incognito
-  # Your code goes here...
+  class Sms
+    def initialize(sid: ENV['TWILIO_SID'], token: ENV['TWILIO_TOKEN'], phone_number: ENV['TWILIO_NUMBER'])
+      @sid = sid
+      @token = token
+      @phone_number = phone_number
+    end
+
+    def send(to:, message:)
+      client.messages.create(body: message, from: phone_number, to: to)
+    end
+
+    private
+
+    attr_reader :sid, :token, :phone_number
+
+    def client
+      @client ||= Twilio::REST::Client.new(sid, token)
+    end
+  end
 end
.gitignore
@@ -6,3 +6,4 @@
 /pkg/
 /spec/reports/
 /tmp/
+.env.local
Gemfile.lock
@@ -2,11 +2,13 @@ PATH
   remote: .
   specs:
     incognito (0.1.0)
+      dotenv (~> 2.2)
       twilio-ruby (~> 5.8)
 
 GEM
   remote: https://rubygems.org/
   specs:
+    dotenv (2.2.2)
     faraday (0.14.0)
       multipart-post (>= 1.2, < 3)
     jwt (2.1.0)
incognito.gemspec
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
   spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
   spec.require_paths = ["lib"]
 
+  spec.add_dependency "dotenv", "~> 2.2"
   spec.add_dependency "twilio-ruby", "~> 5.8"
   spec.add_development_dependency "bundler", "~> 1.16"
   spec.add_development_dependency "rake", "~> 10.0"