wicz / sisal Goto Github PK
View Code? Open in Web Editor NEWSMS abstraction layer in Ruby
SMS abstraction layer in Ruby
Two minor issues:
Sisal::Providers::TropoProvider(token: '123')
*Provider
implementation details from the user. You can decide whether or not to expose that as a developer API later but I'd consider it a private detail for now.Your Sisal
module feels very overengineered :-/
I suggest moving all of its contents to a Sisal::Configuration
object and having it look like this:
module Sisal
class Configuration
def self.default
config = new
config.provider(:twilio, :class => TwilioProvider)
config.provider(:tropo, :class => TropoProvider)
config.provider(:clickatell, :class => ClickatellProvider)
config
end
def initialize
self.providers = Hash.new { |h,k| h[k] = {} }
end
def provider(name, params)
providers[name].update(params)
end
# override the provide rather than merging
def provider!(name, params)
providers[name] = params
end
def default_provider
providers[default_provider]
end
attr_accessor :providers
attr_writer :default_provider
end
end
Then in lib/sisal.rb
module Sisal
class << self
def configuration
self.configuration ||= Configuration.default
end
attr_writer :configuration
end
end
Usage for most users:
config = Sisal.configuration
config.default_provider = :tropo
config.provider(:tropo, token: '123')
config.provider(:clickatell, api_id: '123', user: 'user', password: 'pass')
config.provider(:twilio, account_id: '123', token: '123', from: '552500')
For advanced users:
config = Sisal.configuration
config.default_provider = :something
# add a new kind of provider
config.provider(:something, :class => SomethingProvider, ...)
# edit an existing provider
config.provider(:twilio, :token => "...")
# replace an existing provider's params
config.provider!(:tropo, :class => MyCustomTropoProvider, ...)
For crazy users:
Sisal.configuration = ZomgObject
# ... you're on your own, buddy.
But this still avoids weird instance_eval
hacks, and dynamic class lookups, name based dependencies, and awkward reset logic on a singleton object. Each time you (as the maintainer) add a new provider you need to update only one line of code in the Configuration.default
method, a small price to pay for arbitrary naming and explicit mapping.
Your code will need a license before you release, and ideally I'd like to see it added before the end of the course. See the discussion at the bottom of this ticket for thoughts on that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.