Class: LaunchrockSync::SyncClient
- Inherits:
-
Object
- Object
- LaunchrockSync::SyncClient
- Defined in:
- lib/launchrock-sync/models/sync_client.rb
Defined Under Namespace
Classes: MailChimpClient
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ SyncClient
constructor
A new instance of SyncClient.
- #launchrock_client ⇒ Object
- #launchrock_site ⇒ Object
- #launchrock_users ⇒ Object
- #provider_class ⇒ Object
- #provider_client ⇒ Object
- #sync(&block) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ SyncClient
Returns a new instance of SyncClient.
5 6 7 |
# File 'lib/launchrock-sync/models/sync_client.rb', line 5 def initialize(attributes) self.attributes = attributes.deep_symbolize_keys end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/launchrock-sync/models/sync_client.rb', line 3 def attributes @attributes end |
Instance Method Details
#launchrock_client ⇒ Object
24 25 26 27 28 29 |
# File 'lib/launchrock-sync/models/sync_client.rb', line 24 def launchrock_client @launchrock_client ||= Launchrock::Client.find_by_email_and_password( attributes[:launchrock][:email], attributes[:launchrock][:password] ) end |
#launchrock_site ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/launchrock-sync/models/sync_client.rb', line 16 def launchrock_site return @site if @site @site = self.launchrock_client.site_named(attributes[:launchrock][:site]) raise "No site info found" unless @site @site end |
#launchrock_users ⇒ Object
12 13 14 |
# File 'lib/launchrock-sync/models/sync_client.rb', line 12 def launchrock_users self.launchrock_site.users.map(&:to_hash) end |
#provider_class ⇒ Object
36 37 38 |
# File 'lib/launchrock-sync/models/sync_client.rb', line 36 def provider_class "LaunchrockSync::SyncClient::#{attributes[:sync][:provider]}Client".constantize end |
#provider_client ⇒ Object
32 33 34 |
# File 'lib/launchrock-sync/models/sync_client.rb', line 32 def provider_client @provider_client ||= provider_class.new(attributes[:sync][:options]) end |
#sync(&block) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/launchrock-sync/models/sync_client.rb', line 41 def sync(&block) users = self.launchrock_users = attributes[:last] ? Time.parse(attributes[:last]) : nil if users = users.find_all do |user| Time.parse(user[:timestamp]) > end end users.each do |user| t = Time.parse(user[:timestamp]) = t if .nil? || < t self.provider_client.add(user[:email]) block.call(user) if block end end |