launchrock-sync 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +10 -0
- data/README.md +22 -0
- data/Rakefile +20 -0
- data/bin/launchrock-sync +14 -0
- data/lib/launchrock-sync.rb +9 -0
- data/lib/launchrock-sync/models/sync_client.rb +87 -0
- data/lib/launchrock-sync/models/sync_runner.rb +34 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0311006cd29fccc55b9d3762a707526d47227024
|
4
|
+
data.tar.gz: 9cf07c8c8c81d245484fd5814359ec33e076c336
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 64cf385bab85a4176de9f54d1eef19e6e5af857c5543870a0eda720d9043ae84242b56e24f1ee0e4585ad0d18cb73bbe7729823bd4dd349be0091c9f230cc439
|
7
|
+
data.tar.gz: 80ce00e5408f8e35ab8b6587fd2cebf0048dc1a5349e065e4241099d5e345d9063b9a6538b2a8cc3a0ea14e8a1bce59830b7d59eefff31e9503deba36ad7d7aa
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Launchrock-Sync
|
2
|
+
=========
|
3
|
+
|
4
|
+
|
5
|
+
Provides functionality to sync list from launchrock to a mail provider (right now, only MailChimp is supported).
|
6
|
+
|
7
|
+
Instructions
|
8
|
+
--------
|
9
|
+
|
10
|
+
1. Install ruby
|
11
|
+
2. Install launchrock-sync gem: gem install `launchrock-sync`
|
12
|
+
3. Add config file to `.launchrock-sync.yml` where binary will run (see [sample config file](https://github.com/kenmazaika/launchrock-sync/blob/master/examples/sample_config.yml))
|
13
|
+
4. Run `launchrock-sync` to sync the latest.
|
14
|
+
|
15
|
+
Executing Syncing
|
16
|
+
-----
|
17
|
+
|
18
|
+
The following methods are supported to sync the contacts
|
19
|
+
|
20
|
+
1. Manually kickoff sync
|
21
|
+
2. Have cron kick it off
|
22
|
+
3. Put in screen session and pass `daemon=true sleep_threshold=x` as bash parameters, where x is the number of seconds to sleep between iterations
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
require 'rake/testtask'
|
14
|
+
Rake::TestTask.new(:test) do |test|
|
15
|
+
test.test_files = FileList['test/**/*_test.rb']
|
16
|
+
test.libs = ['lib', 'test']
|
17
|
+
end
|
18
|
+
|
19
|
+
task :default => :test
|
20
|
+
|
data/bin/launchrock-sync
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'launchrock-sync'
|
3
|
+
|
4
|
+
runner = LaunchrockSync::SyncRunner.new( ENV['config'] || File.join(Dir.pwd, '.launchrock-sync.yml') )
|
5
|
+
|
6
|
+
if ENV['daemon']
|
7
|
+
while(true)
|
8
|
+
puts "launchrock-sync"
|
9
|
+
runner.run
|
10
|
+
sleep(ENV['sleep_threshold'].try(:to_i) || 60)
|
11
|
+
end
|
12
|
+
else
|
13
|
+
runner.run
|
14
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'active_support/all'
|
5
|
+
require 'launchrock'
|
6
|
+
require 'mailchimp'
|
7
|
+
|
8
|
+
Dir[File.dirname(__FILE__) + '/launchrock-sync/*.rb'].each {|m| require m}
|
9
|
+
Dir[File.dirname(__FILE__) + '/launchrock-sync/models/*.rb'].each {|m| require m}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module LaunchrockSync
|
2
|
+
class SyncClient
|
3
|
+
attr_accessor :attributes
|
4
|
+
|
5
|
+
def initialize(attributes)
|
6
|
+
self.attributes = attributes.deep_symbolize_keys
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
def launchrock_users
|
13
|
+
self.launchrock_site.users.map(&:to_hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
def launchrock_site
|
17
|
+
return @site if @site
|
18
|
+
@site = self.launchrock_client.site_named(attributes[:launchrock][:site])
|
19
|
+
raise "No site info found" unless @site
|
20
|
+
|
21
|
+
@site
|
22
|
+
end
|
23
|
+
|
24
|
+
def launchrock_client
|
25
|
+
@launchrock_client ||= Launchrock::Client.find_by_email_and_password(
|
26
|
+
attributes[:launchrock][:email],
|
27
|
+
attributes[:launchrock][:password]
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def provider_client
|
33
|
+
@provider_client ||= provider_class.new(attributes[:sync][:options])
|
34
|
+
end
|
35
|
+
|
36
|
+
def provider_class
|
37
|
+
"LaunchrockSync::SyncClient::#{attributes[:sync][:provider]}Client".constantize
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def sync(&block)
|
42
|
+
users = self.launchrock_users
|
43
|
+
timestamp = attributes[:last] ? Time.parse(attributes[:last]) : nil
|
44
|
+
if timestamp
|
45
|
+
users = users.find_all do |user|
|
46
|
+
Time.parse(user[:timestamp]) > timestamp
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
users.each do |user|
|
51
|
+
t = Time.parse(user[:timestamp])
|
52
|
+
timestamp = t if timestamp.nil? || timestamp < t
|
53
|
+
|
54
|
+
self.provider_client.add(user[:email])
|
55
|
+
block.call(user) if block
|
56
|
+
end
|
57
|
+
|
58
|
+
timestamp
|
59
|
+
end
|
60
|
+
|
61
|
+
class MailChimpClient
|
62
|
+
attr_accessor :attributes
|
63
|
+
|
64
|
+
def initialize(attributes)
|
65
|
+
self.attributes = attributes
|
66
|
+
end
|
67
|
+
|
68
|
+
def add(email)
|
69
|
+
api.listSubscribe( {
|
70
|
+
:id => list['id'],
|
71
|
+
:email_address => email,
|
72
|
+
:merge_vars => Hash.new,
|
73
|
+
:double_optin => false,
|
74
|
+
:send_welcome => false
|
75
|
+
} )
|
76
|
+
end
|
77
|
+
|
78
|
+
def list
|
79
|
+
@list ||= api.lists['data'].find {|a| a['name'] == attributes[:list] }
|
80
|
+
end
|
81
|
+
|
82
|
+
def api
|
83
|
+
@api ||= Mailchimp::API.new(attributes[:api_key])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module LaunchrockSync
|
2
|
+
class SyncRunner
|
3
|
+
attr_accessor :configuration_file
|
4
|
+
|
5
|
+
def initialize(configuration_file)
|
6
|
+
self.configuration_file = configuration_file
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
t = sync_client.sync do |user|
|
11
|
+
puts "Added! #{user[:email]}"
|
12
|
+
end
|
13
|
+
|
14
|
+
update_config_file!(t)
|
15
|
+
end
|
16
|
+
|
17
|
+
def update_config_file!(t)
|
18
|
+
new_config = configuration.merge('last' => t.to_s(:db)).to_yaml
|
19
|
+
File.open(configuration_file, 'w') do |file|
|
20
|
+
file.write(new_config)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def sync_client
|
25
|
+
LaunchrockSync::SyncClient.new(self.configuration)
|
26
|
+
end
|
27
|
+
|
28
|
+
def configuration
|
29
|
+
File.open(configuration_file) do |f|
|
30
|
+
return YAML.load(f.read)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: launchrock-sync
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ken mazaika
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: launchrock
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mailchimp
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A ruby gem to sync between launchrock and mailing list providers
|
42
|
+
email: kenmazaika@gmail.com
|
43
|
+
executables:
|
44
|
+
- launchrock-sync
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files:
|
47
|
+
- README.md
|
48
|
+
files:
|
49
|
+
- Gemfile
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- lib/launchrock-sync.rb
|
53
|
+
- lib/launchrock-sync/models/sync_client.rb
|
54
|
+
- lib/launchrock-sync/models/sync_runner.rb
|
55
|
+
- bin/launchrock-sync
|
56
|
+
homepage: https://github.com/kenmazaika/launchrock-sync
|
57
|
+
licenses:
|
58
|
+
- Yoloswag
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.0.0
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: A ruby gem to integrate with the launchrock API and mailing list providers
|
80
|
+
test_files: []
|