Sha256: fb6c145ef4263f8eaf79a60d5ce5efdfbbbe36acaa366d93f06ed771d2da2ef6
Contents?: true
Size: 1.75 KB
Versions: 3
Compression:
Stored size: 1.75 KB
Contents
class ErrplaneGenerator < Rails::Generator::Base def add_options!(option) option.on("-k", "--api-key=API_KEY", String, "API key for your Errplane organization") {|v| options[:api_key] = v} option.on("-a", "--application-id=APP_ID", String, "Your Errplane application id (optional)") {|v| options[:application_id] = v} end def manifest if options[:api_key].blank? puts "You must provide an API key using -k or --api-key." exit end begin puts options unless options[:application_id] puts "Contacting Errplane API" application_name = "ApplicationName" api_key = options[:api_key] connection = Net::HTTP.new("errplane.com", 443) connection.use_ssl = true connection.verify_mode = OpenSSL::SSL::VERIFY_NONE url = "/api/v1/applications?api_key=#{api_key}&name=#{application_name}" response = connection.post(url, nil) @application = JSON.parse(response.body) end unless response.is_a?(Net::HTTPSuccess) raise "The Errplane API returned an error: #{response.inspect}" end rescue => e puts "We ran into a problem creating your application via the API!" puts "If this issue persists, contact us at support@errplane.com with the following details:" puts "API Key: #{e.class}: #{options[:api_key]}" puts "#{e.class}: #{e.message}" end record do |m| m.template "initializer.rb", "config/initializers/errplane.rb", :assigns => { :application_id => options[:application_id] || @application["key"] || secure_random.hex(4), :api_key => options[:api_key] } end end def secure_random defined?(SecureRandom) ? SecureRandom : ActiveSupport::SecureRandom end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
errplane-0.6.6 | generators/errplane/errplane_generator.rb |
errplane-0.6.5 | generators/errplane/errplane_generator.rb |
errplane-0.6.4 | generators/errplane/errplane_generator.rb |