preact 0.7.0 → 0.8.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.
data/lib/preact.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'preact/configuration'
2
2
  require 'preact/client'
3
+ require 'preact/background_logger'
3
4
 
4
5
  require 'preact/objects/api_object'
5
6
  require 'preact/objects/person'
@@ -42,7 +43,7 @@ module Preact
42
43
 
43
44
  def log_event(user, event, account = nil)
44
45
  # Don't send requests when disabled
45
- if configuration.disabled?
46
+ if configuration.nil? || configuration.disabled?
46
47
  logger.info "[Preact] Logging is disabled, not logging event"
47
48
  return nil
48
49
  elsif user.nil?
@@ -78,7 +79,7 @@ module Preact
78
79
 
79
80
  def log_account_event(event, account)
80
81
  # Don't send requests when disabled
81
- if configuration.disabled?
82
+ if configuration.nil? || configuration.disabled?
82
83
  logger.info "[Preact] Logging is disabled, not logging event"
83
84
  return nil
84
85
  elsif account.nil?
@@ -110,7 +111,7 @@ module Preact
110
111
 
111
112
  def update_person(user)
112
113
  # Don't send requests when disabled
113
- if configuration.disabled?
114
+ if configuration.nil? || configuration.disabled?
114
115
  logger.info "[Preact] Logging is disabled, not logging event"
115
116
  return nil
116
117
  elsif user.nil?
@@ -144,21 +145,24 @@ module Preact
144
145
  send_log(person, message_obj)
145
146
  end
146
147
 
147
- protected
148
-
149
- def send_log(person, event=nil)
150
- psn = person.as_json
151
- evt = event.nil? ? nil : event.as_json
152
-
153
- if defined?(Preact::Sidekiq)
154
- Preact::Sidekiq::PreactLoggingWorker.perform_async(psn, evt)
155
- else
156
- client.create_event(psn, evt)
157
- end
158
- end
159
-
160
148
  def client
161
149
  self.default_client ||= Client.new
162
150
  end
151
+
152
+ protected
153
+
154
+ def send_log(person, event=nil)
155
+ psn = person.as_json
156
+ evt = event.nil? ? nil : event.as_json
157
+
158
+ if defined?(Preact::Sidekiq)
159
+ Preact::Sidekiq::PreactLoggingWorker.perform_async(psn, evt)
160
+ else
161
+ #client.create_event(psn, evt)
162
+ # use the background thread logger
163
+ Preact::BackgroundLogger.new.async.perform(psn, evt)
164
+ end
165
+ end
166
+
163
167
  end
164
168
  end
@@ -0,0 +1,19 @@
1
+ require 'sucker_punch'
2
+
3
+ module Preact
4
+ class BackgroundLogger
5
+ include SuckerPunch::Job
6
+
7
+ def perform(psn, evt)
8
+ begin
9
+ ::Preact.client.create_event(psn, evt)
10
+ rescue RestClient::ResourceNotFound => ex
11
+ puts "404 error"
12
+ rescue SocketError => ex
13
+ puts "socket error: #{ex.message}"
14
+ rescue => ex
15
+ raise ex
16
+ end
17
+ end
18
+ end
19
+ end
@@ -2,7 +2,8 @@ class Preact::Event < Preact::ApiObject
2
2
 
3
3
  attr_accessor :name, :timestamp, :account
4
4
 
5
- attr_accessor :note, :links, :external_identifier, :extras
5
+ attr_accessor :note, :links, :external_identifier, :target_id, :revenue, :extras
6
+ attr_accessor :thumb_url, :link_url
6
7
 
7
8
  def add_link(name, href)
8
9
  self.links ||= []
@@ -15,12 +16,15 @@ class Preact::Event < Preact::ApiObject
15
16
  :name => self.name,
16
17
  :timestamp => self.timestamp,
17
18
  :account => self.account,
19
+ :revenue => self.revenue,
18
20
  :source => Preact.configuration.user_agent, # version of this logging library
19
21
 
20
22
  :note => self.note,
21
- :external_identifier => self.external_identifier,
23
+ :external_identifier => self.target_id || self.external_identifier,
22
24
  :extras => self.extras,
23
- :links => self.links.nil? ? nil : self.links.as_json
25
+ :links => self.links.nil? ? nil : self.links.as_json,
26
+ :thumb_url => self.thumb_url,
27
+ :link_url => self.link_url
24
28
  }
25
29
  end
26
30
 
@@ -1,3 +1,3 @@
1
1
  module Preact
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: preact
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Christopher Gooley
9
- - Zach Millman
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-04-03 00:00:00.000000000 Z
12
+ date: 2013-08-31 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rest-client
@@ -108,14 +107,31 @@ dependencies:
108
107
  - - ~>
109
108
  - !ruby/object:Gem::Version
110
109
  version: '1.0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: sucker_punch
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '1.0'
111
126
  description: API library to allow you to connect and submit messages and actions to
112
- your Preact project account
127
+ Preact
113
128
  email: gooley@preact.io
114
129
  executables: []
115
130
  extensions: []
116
131
  extra_rdoc_files:
117
132
  - LICENSE.txt
118
133
  files:
134
+ - lib/preact/background_logger.rb
119
135
  - lib/preact/client.rb
120
136
  - lib/preact/configuration.rb
121
137
  - lib/preact/objects/account.rb