mojura-mailchimp 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a0aaf113a8b1d68130637c07421a3471f0f3e07
4
+ data.tar.gz: d4388fa1a4daa88afbddb2369391013c23a2bbd7
5
+ SHA512:
6
+ metadata.gz: bc475f2828b5528e5307b8a6d8646e48fc3f2a281cf564550ccd05f04d365b3c547f99937715d76a41e9f747dc653fbc454404d018950d336a488efeae7a3dfb
7
+ data.tar.gz: a4974d4914048ec17a324f2451911d48ed7c50f3c217873812d33926b73fb4a8fb88bc1929046254b279052beeec4c075e39d732c3b1f8e3f8415b178c93f0e8
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ /.idea/
16
+ /*.gem
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ source 'http://gems.mojura.nl'
3
+
4
+ # Specify your gem's dependencies in mojura-mailchimp.gemspec
5
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Taco Jan Osinga
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # Mojura::Mailchimp
2
+
3
+ This MailChimp gem is a module for Mojura, a Content Management System.
4
+
5
+ The module can be used by editing a pageview and select 'MailChimp subscription' as web module. The maintainer can select a MailChimp list.
6
+ After saving, the user will see a small form, with which he or she can subscribe. Currently the users are added as pending users, meaning they
7
+ will receive an email to confirm their subscription.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'mojura-mailchimp'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mojura-mailchimp
22
+
23
+ ## Usage
24
+
25
+ Add to following line of code in the config.ru of your Mojura project, after the line ```require 'mojura'```, and use the module in the website.
26
+
27
+ require 'mojura-mailchimp'
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/tjosinga/mojura-mailchimp/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
@@ -0,0 +1,29 @@
1
+ $:.unshift(File.expand_path(File.dirname(__FILE__)))
2
+
3
+ require 'mojura'
4
+ require 'lib/mojura/mailchimp'
5
+
6
+ use Rack::Lint
7
+ use Rack::ContentLength
8
+ use Rack::ShowExceptions
9
+ use Rack::Runtime
10
+ use Rack::CommonLogger
11
+ use Rack::ETag
12
+
13
+ use Mojura::GemVersions
14
+
15
+ # Uncomment if your webserver doesn't support X-Sendfile (also see http://wiki.nginx.org/XSendfile)
16
+ use Mojura::StaticFiles
17
+ use Mojura::SendFiles
18
+
19
+ # Uncomment the prefered way for storing cookies.
20
+ # use Rack::Session::Memcache
21
+ use Rack::Session::Cookie, :secret => 'my_secret_cookie_string'
22
+
23
+ use Mojura::Formatter
24
+ use Mojura::Gatekeeper
25
+
26
+ use Mojura::MethodOverride
27
+ use Mojura::CookieTokens
28
+
29
+ run Mojura::App.new
@@ -0,0 +1,98 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+
4
+ module MojuraAPI
5
+
6
+ class MailChimpResource < RestResource
7
+
8
+ attr_reader :cached_listids, :cached_atk
9
+
10
+ def name
11
+ 'MailChimp resource.'
12
+ end
13
+
14
+ def description
15
+ 'A resource which post subscribers to a MailChimp list.'
16
+ end
17
+
18
+ def get_from_mailchimp(api_url, method = :get, payload = nil)
19
+ api_key = Settings.get_s(:api_key, :mailchimp)
20
+ if (api_key.empty?)
21
+ raise HTTPException.new('The api_key is not configured.')
22
+ end
23
+ data_center = api_key.scan(/\-(\w+)$/)[0][0]
24
+ url = "https://#{data_center}.api.mailchimp.com/3.0/" + api_url
25
+
26
+ headers = { Authorization: "apikey #{api_key}" }
27
+
28
+ begin
29
+ response = RestClient::Request.execute({
30
+ url: url,
31
+ method: method,
32
+ headers: headers,
33
+ payload: payload
34
+ })
35
+ rescue => e
36
+ json = e.response.nil? ? { 'detail' => e.message} : JSON.parse(e.response)
37
+ raise HTTPException.new(json['detail'])
38
+ end
39
+
40
+ data = JSON.parse(response)
41
+ data.symbolize_keys!
42
+ return data
43
+ end
44
+
45
+ def post(params)
46
+ request_json = JSON.generate({
47
+ email_address: params[:email],
48
+ status: 'pending',
49
+ merge_fields: {
50
+ FNAME: params[:firstname],
51
+ LNAME: params[:lastname]
52
+ }
53
+ })
54
+ api_url = "lists/#{params[:listid]}/members"
55
+ return get_from_mailchimp(api_url, :post, request_json)
56
+ end
57
+
58
+ def post_conditions
59
+ result = {
60
+ description: 'Adds an email address as a subscriber to MailChimp.',
61
+ attributes: {
62
+ listid: {required: true, type: String, description: 'The id of a MailChimp list.'},
63
+ email: {required: true, type: String, description: 'The email address.'},
64
+ firstname: {required: true, type: String, description: 'The first name.'},
65
+ lastname: {required: true, type: String, description: 'The last name.'},
66
+ }
67
+ }
68
+ return result
69
+ end
70
+
71
+ def all(params)
72
+ now = Time.now.to_i
73
+ result = []
74
+ if (@cached_listids.nil? || (now - @cached_at.to_i > 300))
75
+ data = get_from_mailchimp('lists')
76
+ data[:lists].each { | list_data |
77
+ result.push({id: list_data[:id], name: list_data[:name]})
78
+ }
79
+ @cached_listids = result
80
+ @cached_at = Time.now.to_i
81
+ return result
82
+ else
83
+ result = @cached_listids
84
+ end
85
+ return result;
86
+ end
87
+
88
+ def all_conditions
89
+ {
90
+ description: 'Returns an array of MailChimp Lists.',
91
+ }
92
+ end
93
+
94
+ end
95
+
96
+ API.register_resource(MailChimpResource.new('mailchimp', ''))
97
+
98
+ end
@@ -0,0 +1,5 @@
1
+ module Mojura
2
+ module Mailchimp
3
+ VERSION = '0.1.3'
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module Mojura
3
+
4
+ PluginsManager.register(File.dirname(__FILE__))
5
+
6
+ end
@@ -0,0 +1,25 @@
1
+ <div class="form-group">
2
+ <label for="listid_{{urid}}">{{locale_str_mailchimp_listid}}</label>
3
+ <select id="listid_{{urid}}" class="form-control" data-validation="required" name="setting_listid">
4
+ </select>
5
+ </div>
6
+
7
+ <script type="text/javascript">
8
+
9
+ (function($) {
10
+ "use strict";
11
+
12
+ $.getJSON("__api__/mailchimp", function(data) {
13
+ var $listid = $("#listid_{{urid}}");
14
+ $.each(data, function (i, item) {
15
+ $listid.append($('<option>', {
16
+ value: item.id,
17
+ text : item.name
18
+ }));
19
+ });
20
+ $("option[value=" + {{settings_listid }} + "]", $listid).prop("selected", "selected");
21
+ });
22
+
23
+ })(jQuery);
24
+
25
+ </script>
@@ -0,0 +1,5 @@
1
+ view_title = MailChimp subscription
2
+
3
+ listid = Select the listid where the user subscribes to.
4
+ already_list_member = Your e-mail address is already registered. Therefor this new registration is cancelled.
5
+ success = Your subscription is successfully received. We have send you an email to confirm your subscription.
@@ -0,0 +1,5 @@
1
+ view_title = MailChimp aanmeldingen
2
+
3
+ listid = Selecteer de MailChimp lijst waarop de gebruiker zich abonneert
4
+ already_list_member = Uw e-mailadres is al bij ons bekend. Zodoende is deze nieuwe aanmelding geannuleerd.
5
+ success = Je aanmelding is succesvol ontvangen. We hebben je een e-mail gestuurd om je aanmelding te bevestigen.
@@ -0,0 +1,64 @@
1
+ <form id="{{urid}}_form" action="__api__/mailchimp" method="post" onsubmit="event.preventDefault()">
2
+
3
+ <input type="hidden" name="listid" value="{{options.listid}}" />
4
+
5
+ <div class="form-group">
6
+ <input type="text" name="email" data-validation="required email" class="form-control" placeholder="{{locale_str_system_email}}">
7
+ </div>
8
+ <div class="form-group">
9
+ <input type="text" name="firstname" data-validation="required" class="form-control" placeholder="{{locale_str_users_firstname}}">
10
+ </div>
11
+ <div class="form-group">
12
+ <input type="text" name="lastname" data-validation="required" class="form-control" placeholder="{{locale_str_users_lastname}}">
13
+ </div>
14
+
15
+ <button type="submit" class="btn btn-primary" data-loading-text='{{locale_str_system_sending}}' data-complete-text='{{locale_str_system_success}}'>
16
+ {{locale_str_system_send}}
17
+ </button>
18
+
19
+ </form>
20
+
21
+ <div id="{{urid}}_success" class="hidden alert alert-success">
22
+ {{locale_str_mailchimp_success}}
23
+ </div>
24
+
25
+ <script type="application/javascript">
26
+
27
+ (function() {
28
+
29
+ "use strict";
30
+
31
+ var $form = $("#{{urid}}_form");
32
+
33
+ $form.submit(function (event) {
34
+ event.preventDefault();
35
+ $(".alert", $form).remove();
36
+ if (!Validator.validateForm($form[0])) {
37
+ return false;
38
+ }
39
+ var $btn = $(".btn-primary", $form);
40
+ $form.attr("method", "post");
41
+ $form.attr("action", "__api__/mailchimp");
42
+
43
+ $btn.button("loading");
44
+ $form.ajaxSubmit({
45
+ success: function () {
46
+ $btn.button("complete").addClass("btn-success disabled");
47
+ $form.remove();
48
+ $("#{{urid}}_success").removeClass("hidden");
49
+ },
50
+ error: function (e) {
51
+ var message = e.responseJSON.error.message;
52
+ if (message.indexOf("already a list member") > 0) {
53
+ message = "{{locale_str_mailchimp_already_list_member}}";
54
+ }
55
+ $form.prepend($("<div class='alert alert-danger'>" + message + "</div>"));
56
+ $btn.button('reset');
57
+ }
58
+ });
59
+ return false;
60
+ });
61
+
62
+ })(jQuery);
63
+
64
+ </script>
@@ -0,0 +1,13 @@
1
+ module MojuraWebApp
2
+
3
+ class MailChimpView < BaseView
4
+
5
+ def initialize(options = {})
6
+ super
7
+ end
8
+
9
+ end
10
+
11
+ WebApp.register_view('mailchimp', MailChimpView)
12
+
13
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mojura/lib/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'mojura-mailchimp'
8
+ spec.version = Mojura::Mailchimp::VERSION
9
+ spec.authors = ['Taco Jan Osinga']
10
+ spec.email = ['info@osingasoftware.nl']
11
+ spec.summary = 'This gem adds MailChimp functionality to your Mojura project.'
12
+ spec.description = 'The module can be used by editing a pageview and select \'MailChimp subscription\' as web module. The maintainer can select a MailChimp list. After saving, the user will see a small form, with which he or she can subscribe. Currently the users are added as pending users, meaning they will receive an email to confirm their subscription.'
13
+ spec.homepage = 'https://github.com/tjosinga/mojura-mailchimp'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1'
22
+ spec.add_development_dependency 'rake', '~> 10'
23
+ spec.add_development_dependency 'mojura', '~> 0'
24
+
25
+ spec.add_runtime_dependency 'rest-client', '~> 2'
26
+ end
@@ -0,0 +1,58 @@
1
+ # This project settings file works on three levels:
2
+ # - Private: Can only be declared in this file and can not be changed in the application.
3
+ # - Protected: These settings can only be read and maintained by administrators.
4
+ # - Public: These settings can be read by anyone and maintained by administrators.
5
+ #
6
+ # Each setting has the following fields:
7
+ # - Category: A string containing the name of the corresponding resource, object or view. If none is given, it uses "system".
8
+ # - Key: A string with the name [a-zA-Z0-9_]+ of the setting
9
+ # - Value: A mixed value, containing default datatypes, like strings, numbers, boolean and arrays.
10
+ #
11
+ # Declaring protected and public settings in this file overrides those defaults.
12
+ # Protected and public settings can be overriden by the administrator using the Settings resource of the API.
13
+
14
+
15
+ # Setting private settings
16
+ private:
17
+
18
+ # Setting core keys
19
+ core:
20
+
21
+ # Specify a realm of this project. It's used for authentication.
22
+ # The realm is used in the digest of the stored passwords of users.
23
+ # Therefor changing the realm will make all accounts inaccessible.
24
+ # Users must use the function to request a new password.
25
+ realm : mojuradev
26
+
27
+
28
+ # Mojura API uses a MongoDb. The following database is used:
29
+ database : osisoft_mojuradev
30
+
31
+ # Setting protected settings
32
+ protected:
33
+ data:
34
+ receiver: info@osingasoftware.nl
35
+
36
+ # By default all objects are readible by guests. Users are by default hidden for guests.
37
+ users:
38
+ object_rights:
39
+ User: 28736
40
+
41
+
42
+ # Setting default public settings
43
+ public:
44
+
45
+ core:
46
+
47
+ # Set to false if you prefer to use local versions of jQuery, CryptoJS, etc.,
48
+ # otherwise it use the corresponding libraries at Google Fastpage, CloudFlare or
49
+ # other CDNs.
50
+ use_external_hosted_files: true
51
+
52
+ # Set to true if the website is currently in development.
53
+ # It will generate more usefull information.
54
+ developing: true
55
+
56
+ # The default locale
57
+ locale: nl
58
+ supported_locales: [nl, en, de, es]
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mojura-mailchimp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Taco Jan Osinga
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mojura
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2'
69
+ description: The module can be used by editing a pageview and select 'MailChimp subscription'
70
+ as web module. The maintainer can select a MailChimp list. After saving, the user
71
+ will see a small form, with which he or she can subscribe. Currently the users are
72
+ added as pending users, meaning they will receive an email to confirm their subscription.
73
+ email:
74
+ - info@osingasoftware.nl
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - config.ru
84
+ - lib/mojura/api/resources/mailchimp/mailchimp.rest.rb
85
+ - lib/mojura/lib/version.rb
86
+ - lib/mojura/mailchimp.rb
87
+ - lib/mojura/webapp/views/mailchimp/coworkers/view_edit_settings.mustache
88
+ - lib/mojura/webapp/views/mailchimp/strings.en.kv
89
+ - lib/mojura/webapp/views/mailchimp/strings.nl.kv
90
+ - lib/mojura/webapp/views/mailchimp/view_main.mustache
91
+ - lib/mojura/webapp/views/mailchimp/view_main.rb
92
+ - mojura-mailchimp.gemspec
93
+ - project_settings.yaml
94
+ homepage: https://github.com/tjosinga/mojura-mailchimp
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.6.6
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: This gem adds MailChimp functionality to your Mojura project.
118
+ test_files: []