Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit f54c5f93e9106e0d39b494a6979ac33e670eb2cb @dpacaud committed Sep 22, 2012
Showing with 2,645 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +72 −0 MandrillGrailsPlugin.groovy
  3. +4 −0 application.properties
  4. +38 −0 grails-app/conf/BuildConfig.groovy
  5. +32 −0 grails-app/conf/Config.groovy
  6. +43 −0 grails-app/conf/DataSource.groovy
  7. +13 −0 grails-app/conf/UrlMappings.groovy
  8. +90 −0 grails-app/services/org/grails/mandrill/HttpWrapperService.groovy
  9. +33 −0 grails-app/services/org/grails/mandrill/MandrillService.groovy
  10. +11 −0 grails-app/views/error.gsp
  11. BIN out/production/Mandrill/org/grails/mandrill/HttpWrapperService$_postText_closure1.class
  12. BIN out/production/Mandrill/org/grails/mandrill/HttpWrapperService$_postText_closure1_closure2.class
  13. BIN ...uction/Mandrill/org/grails/mandrill/HttpWrapperService$_postText_closure1_closure2_closure4.class
  14. BIN out/production/Mandrill/org/grails/mandrill/HttpWrapperService$_postText_closure1_closure3.class
  15. BIN ...uction/Mandrill/org/grails/mandrill/HttpWrapperService$_postText_closure1_closure3_closure5.class
  16. BIN out/production/Mandrill/org/grails/mandrill/HttpWrapperService.class
  17. BIN out/production/Mandrill/org/grails/mandrill/MandrillMessage.class
  18. BIN out/production/Mandrill/org/grails/mandrill/MandrillRecipient.class
  19. BIN out/production/Mandrill/org/grails/mandrill/MandrillService.class
  20. BIN out/test/Mandrill/org/grails/mandrill/MandrillServiceTests.class
  21. +26 −0 plugin.xml
  22. +29 −0 scripts/_Install.groovy
  23. +5 −0 scripts/_Uninstall.groovy
  24. +10 −0 scripts/_Upgrade.groovy
  25. +22 −0 src/groovy/org/grails/mandrill/MandrillMessage.groovy
  26. +9 −0 src/groovy/org/grails/mandrill/MandrillRecipient.groovy
  27. +51 −0 test/unit/org/grails/mandrill/MandrillServiceTests.groovy
  28. +33 −0 web-app/WEB-INF/applicationContext.xml
  29. +14 −0 web-app/WEB-INF/sitemesh.xml
  30. +572 −0 web-app/WEB-INF/tld/c.tld
  31. +671 −0 web-app/WEB-INF/tld/fmt.tld
  32. +550 −0 web-app/WEB-INF/tld/grails.tld
  33. +311 −0 web-app/WEB-INF/tld/spring.tld
@@ -0,0 +1,6 @@
+*.iml
+*.ipr
+*.iws
+.idea/
+target/
+grails-mandrill-*.zip
@@ -0,0 +1,72 @@
+class MandrillGrailsPlugin {
+ // the plugin version
+ def version = "0.1"
+ // the version or versions of Grails the plugin is designed for
+ def grailsVersion = "2.1 > *"
+ // the other plugins this plugin depends on
+ def dependsOn = [:]
+ // resources that are excluded from plugin packaging
+ def pluginExcludes = [
+ "grails-app/views/error.gsp"
+ ]
+
+ // TODO Fill in these fields
+ def title = "Grails Mandrill Plugin" // Headline display name of the plugin
+ def author = "Damien Pacaud"
+ def authorEmail = "damien.pacaud@gmail.com"
+ def description = '''\
+ This is a simple wrapper for the Mandrill REST API (http://www.mandrillapp.com)
+'''
+
+
+ // URL to the plugin's documentation
+ def documentation = "http://grails.org/plugin/mandrill"
+
+ // Extra (optional) plugin metadata
+
+ // License: one of 'APACHE', 'GPL2', 'GPL3'
+// def license = "APACHE"
+
+ // Details of company behind the plugin (if there is one)
+// def organization = [ name: "My Company", url: "http://www.my-company.com/" ]
+
+ // Any additional developers beyond the author specified above.
+// def developers = [ [ name: "Joe Bloggs", email: "joe@bloggs.net" ]]
+
+ // Location of the plugin's issue tracker.
+// def issueManagement = [ system: "JIRA", url: "http://jira.grails.org/browse/GPMYPLUGIN" ]
+
+ // Online location of the plugin's browseable source code.
+// def scm = [ url: "http://svn.codehaus.org/grails-plugins/" ]
+
+ def doWithWebDescriptor = { xml ->
+ // TODO Implement additions to web.xml (optional), this event occurs before
+ }
+
+ def doWithSpring = {
+ // TODO Implement runtime spring config (optional)
+ }
+
+ def doWithDynamicMethods = { ctx ->
+ // TODO Implement registering dynamic methods to classes (optional)
+ }
+
+ def doWithApplicationContext = { applicationContext ->
+ // TODO Implement post initialization spring config (optional)
+ }
+
+ def onChange = { event ->
+ // TODO Implement code that is executed when any artefact that this plugin is
+ // watching is modified and reloaded. The event contains: event.source,
+ // event.application, event.manager, event.ctx, and event.plugin.
+ }
+
+ def onConfigChange = { event ->
+ // TODO Implement code that is executed when the project configuration changes.
+ // The event is the same as for 'onChange'.
+ }
+
+ def onShutdown = { event ->
+ // TODO Implement code that is executed when the application shuts down (optional)
+ }
+}
@@ -0,0 +1,4 @@
+#Grails Metadata file
+#Fri Sep 21 18:06:16 CEST 2012
+app.grails.version=2.1.1
+app.name=mandrill
@@ -0,0 +1,38 @@
+grails.project.class.dir = "target/classes"
+grails.project.test.class.dir = "target/test-classes"
+grails.project.test.reports.dir = "target/test-reports"
+
+grails.project.dependency.resolution = {
+ // inherit Grails' default dependencies
+ inherits("global") {
+ // uncomment to disable ehcache
+ // excludes 'ehcache'
+ }
+ log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
+ repositories {
+ grailsCentral()
+ // uncomment the below to enable remote dependency resolution
+ // from public Maven repositories
+ //mavenLocal()
+ //mavenCentral()
+ //mavenRepo "http://snapshots.repository.codehaus.org"
+ //mavenRepo "http://repository.codehaus.org"
+ //mavenRepo "http://download.java.net/maven/2/"
+ //mavenRepo "http://repository.jboss.com/maven2/"
+ }
+ dependencies {
+ // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
+ compile('org.codehaus.groovy.modules.http-builder:http-builder:0.5.2') {
+ excludes "commons-logging", "xml-apis", "groovy"
+ }
+ // runtime 'mysql:mysql-connector-java:5.1.18'
+ }
+
+ plugins {
+ build(":tomcat:$grailsVersion",
+ ":release:2.0.3",
+ ":rest-client-builder:1.0.2") {
+ export = false
+ }
+ }
+}
@@ -0,0 +1,32 @@
+// configuration for plugin testing - will not be included in the plugin zip
+
+log4j = {
+ // Example of changing the log pattern for the default console
+ // appender:
+ //
+ //appenders {
+ // console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
+ //}
+
+ error 'org.codehaus.groovy.grails.web.servlet', // controllers
+ 'org.codehaus.groovy.grails.web.pages', // GSP
+ 'org.codehaus.groovy.grails.web.sitemesh', // layouts
+ 'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
+ 'org.codehaus.groovy.grails.web.mapping', // URL mapping
+ 'org.codehaus.groovy.grails.commons', // core / classloading
+ 'org.codehaus.groovy.grails.plugins', // plugins
+ 'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
+ 'org.springframework',
+ 'org.hibernate',
+ 'net.sf.ehcache.hibernate'
+
+ warn 'org.mortbay.log'
+}
+
+mandrill {
+ apiKey = "0093a6d3-d131-47c3-9e17-b5d77c506217"
+ //proxy {
+ // host = ""
+ // port = ""
+ //}
+}
@@ -0,0 +1,43 @@
+dataSource {
+ pooled = true
+ driverClassName = "org.h2.Driver"
+ username = "sa"
+ password = ""
+}
+hibernate {
+ cache.use_second_level_cache = true
+ cache.use_query_cache = false
+ cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
+}
+// environment specific settings
+environments {
+ development {
+ dataSource {
+ dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
+ url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
+ }
+ }
+ test {
+ dataSource {
+ dbCreate = "update"
+ url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
+ }
+ }
+ production {
+ dataSource {
+ dbCreate = "update"
+ url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
+ pooled = true
+ properties {
+ maxActive = -1
+ minEvictableIdleTimeMillis=1800000
+ timeBetweenEvictionRunsMillis=1800000
+ numTestsPerEvictionRun=3
+ testOnBorrow=true
+ testWhileIdle=true
+ testOnReturn=true
+ validationQuery="SELECT 1"
+ }
+ }
+ }
+}
@@ -0,0 +1,13 @@
+class UrlMappings {
+
+ static mappings = {
+ "/$controller/$action?/$id?"{
+ constraints {
+ // apply constraints here
+ }
+ }
+
+ "/"(view:"/index")
+ "500"(view:'/error')
+ }
+}
@@ -0,0 +1,90 @@
+
+package org.grails.mandrill
+
+import grails.converters.JSON
+import groovyx.net.http.ContentType
+import groovyx.net.http.HTTPBuilder
+import groovyx.net.http.Method
+
+class HttpWrapperService {
+ static transactional = false
+ def grailsApplication
+
+ def postText(String baseUrl, String path, query, method = Method.POST) {
+ try {
+
+ def ret = null
+ def http = new HTTPBuilder(baseUrl)
+
+ /*************************************
+ * Handling Proxy configuration
+ *************************************/
+
+ if(grailsApplication.config.mandrill.proxy?.host && grailsApplication.config.mandrill.proxy?.port){
+ if(grailsApplication.config.mandrill.proxy?.port?.isInteger()){
+ log.info "setting Proxy to : ${grailsApplication.config.mandrill.proxy.host} on port : ${grailsApplication.config.mandrill.proxy.port}"
+ http.setProxy(grailsApplication.config.mandrill.proxy.host,Integer.parseInt(grailsApplication.config.mandrill.proxy.port),null)
+ }
+ else {
+ throw new NumberFormatException("mandrill Proxy PORT must be an integer, please correct the config file")
+ }
+ }
+
+ // perform a POST request, expecting TEXT response
+ http.request(method, ContentType.TEXT) {
+
+ uri.path = path
+ body = new JSON(query)
+
+ headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
+ println uri
+ // response handler for a success response code
+ response.success = { resp, reader ->
+ println "response status: ${resp.statusLine}"
+ println 'Headers: -----------'
+ resp.headers.each { h ->
+ println " ${h.name} : ${h.value}"
+ }
+
+ ret = reader.getText()
+
+ println 'Response data: -----'
+ println ret
+ println '--------------------'
+ }
+
+ response.failure = { resp, reader ->
+ println "------ Failure ------ "
+ resp.headers.each { h ->
+ println " ${h.name} : ${h.value}"
+ }
+ ret = reader.getText()
+
+ println 'Response data: -----'
+ println ret
+ println '--------------------'
+ }
+ }
+ return ret
+
+ } catch (groovyx.net.http.HttpResponseException ex) {
+ println "toto"
+ println ex
+ return null
+ } catch (java.net.ConnectException ex) {
+ println "tata"
+ println ex
+ return null
+ }
+ catch (NumberFormatException nfe) {
+ log.error nfe.getMessage()
+ return null
+ }
+ catch (Exception e) {
+ println "titi"
+ println e
+ return null
+ }
+ }
+
+}
@@ -0,0 +1,33 @@
+package org.grails.mandrill
+
+
+class MandrillService {
+ static transactional = false
+ def httpWrapperService
+ def grailsApplication
+
+ def BASE_URL = "https://mandrillapp.com/api/1.0/"
+ //TODO : Handle the API key and throw an error when it is absent
+ def ping() {
+ def path = "users/ping.json"
+ def query = [key:grailsApplication.config.mandrill.apiKey]
+ return httpWrapperService.postText(BASE_URL, path ,query)
+ }
+
+
+ def info() {
+ def path = "users/info.json"
+ def query = [key:grailsApplication.config.mandrill.apiKey]
+ return httpWrapperService.postText(BASE_URL, path ,query)
+ }
+
+
+ def send(MandrillMessage message) {
+ def path = "messages/send.json"
+ def query = [key:grailsApplication.config.mandrill.apiKey,message:message]
+ return httpWrapperService.postText(BASE_URL, path ,query)
+ }
+
+
+
+}
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Grails Runtime Exception</title>
+ <meta name="layout" content="main">
+ <link rel="stylesheet" href="${resource(dir: 'css', file: 'errors.css')}" type="text/css">
+ </head>
+ <body>
+ <g:renderException exception="${exception}" />
+ </body>
+</html>
@@ -0,0 +1,26 @@
+<plugin name='mandrill' version='0.1' grailsVersion='2.1 &gt; *'>
+ <author>Damien Pacaud</author>
+ <authorEmail>damien.pacaud@gmail.com</authorEmail>
+ <title>Grails Mandrill Plugin</title>
+ <description> This is a simple wrapper for the Mandrill REST API (http://www.mandrillapp.com)
+</description>
+ <documentation>http://grails.org/plugin/mandrill</documentation>
+ <type>MandrillGrailsPlugin</type>
+ <resources>
+ <resource>org.grails.mandrill.HttpWrapperService</resource>
+ <resource>org.grails.mandrill.MandrillService</resource>
+ </resources>
+ <repositories>
+ <repository name='grailsCentral' url='http://grails.org/plugins' />
+ <repository name='http://repo.grails.org/grails/core' url='http://repo.grails.org/grails/core/' />
+ <repository name='mavenCentral' url='http://repo1.maven.org/maven2/' />
+ </repositories>
+ <dependencies>
+ <compile>
+ <dependency group='org.codehaus.groovy.modules.http-builder' name='http-builder' version='0.5.2' />
+ </compile>
+ </dependencies>
+ <plugins />
+ <runtimePluginRequirements />
+ <behavior />
+</plugin>
Oops, something went wrong.

0 comments on commit f54c5f9

Please sign in to comment.