preact 0.8.3 → 0.8.4
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/generators/preact_generator.rb +38 -8
- data/lib/preact/client.rb +9 -1
- data/lib/preact/configuration.rb +10 -4
- data/lib/preact/objects/account.rb +10 -1
- data/lib/preact/version.rb +1 -1
- data/lib/preact.rb +25 -1
- metadata +1 -1
@@ -8,21 +8,51 @@ class PreactGenerator < Rails::Generators::Base
|
|
8
8
|
# Preact Logging Configuration
|
9
9
|
# see documentation about configuration options here: https://github.com/preact/preact-ruby
|
10
10
|
Preact.configure do |config|
|
11
|
-
config.
|
12
|
-
|
11
|
+
# all standard configuration is done in the config/preact.yml file
|
12
|
+
# if you need to do smarter things during configuration, do them here
|
13
|
+
end
|
14
|
+
FILE
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_config_file
|
18
|
+
create_file "config/preact.yml", <<-FILE
|
19
|
+
# Preact Logging Configs
|
20
|
+
common: &defaults
|
21
|
+
|
22
|
+
# your Preact API credentials
|
23
|
+
code: "#{project_code}"
|
24
|
+
secret: "#{api_secret}"
|
13
25
|
|
14
26
|
# automatically log controller actions for authed users
|
15
27
|
# disable this if you want to only log manual events
|
16
|
-
|
28
|
+
autolog: true
|
17
29
|
|
18
30
|
# specify controller#action items that you want to ignore and not log to Preact.
|
19
31
|
# default is to not log sessions#create beacuse if you're using Devise, we get that already
|
20
|
-
|
32
|
+
autolog_ignored_actions:
|
33
|
+
- "sessions#create"
|
34
|
+
- "devise/sessions#create"
|
21
35
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
36
|
+
development:
|
37
|
+
<<: *defaults
|
38
|
+
|
39
|
+
# we usually suggest that you use a different project for development, to keep
|
40
|
+
# those events separate from production events
|
41
|
+
#code: "DEV_CODE"
|
42
|
+
#secret: "DEV_SECRET"
|
43
|
+
|
44
|
+
# you may also completely disable event logging in development
|
45
|
+
#disabled: false
|
46
|
+
|
47
|
+
staging:
|
48
|
+
<<: *defaults
|
49
|
+
|
50
|
+
# if you want to log staging events separately as well
|
51
|
+
#code: "STAGING_CODE"
|
52
|
+
#secret: "STAGING_SECRET"
|
53
|
+
|
54
|
+
# you may also completely disable event logging in staging
|
55
|
+
#disabled: false
|
26
56
|
FILE
|
27
57
|
end
|
28
58
|
|
data/lib/preact/client.rb
CHANGED
@@ -19,8 +19,16 @@ module Preact
|
|
19
19
|
|
20
20
|
data = post_request("/people", params)
|
21
21
|
end
|
22
|
+
|
23
|
+
def update_account(account)
|
24
|
+
params = {
|
25
|
+
:account => account
|
26
|
+
}
|
27
|
+
|
28
|
+
data = post_request("/accounts", params)
|
29
|
+
end
|
22
30
|
|
23
|
-
private
|
31
|
+
#private
|
24
32
|
|
25
33
|
def post_request(method, params={})
|
26
34
|
params = prepare_request_params(params)
|
data/lib/preact/configuration.rb
CHANGED
@@ -18,11 +18,11 @@ module Preact
|
|
18
18
|
attr_accessor :logger
|
19
19
|
|
20
20
|
# The URL of the API server
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
attr_accessor :scheme
|
22
|
+
attr_accessor :host
|
23
|
+
attr_accessor :base_path
|
24
24
|
|
25
|
-
def initialize
|
25
|
+
def initialize(defaults={})
|
26
26
|
@scheme = 'https'
|
27
27
|
@host = 'api.preact.io'
|
28
28
|
@base_path = '/api/v2'
|
@@ -33,6 +33,12 @@ module Preact
|
|
33
33
|
@person_builder = nil
|
34
34
|
|
35
35
|
@user_agent = "ruby-preact:#{Preact::VERSION}"
|
36
|
+
|
37
|
+
if defaults && defaults.is_a?(Hash)
|
38
|
+
defaults.each do |k,v|
|
39
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
40
|
+
end
|
41
|
+
end
|
36
42
|
end
|
37
43
|
|
38
44
|
def valid?
|
@@ -1,11 +1,20 @@
|
|
1
1
|
class Preact::Account < Preact::ApiObject
|
2
2
|
|
3
3
|
attr_accessor :id, :name
|
4
|
+
attr_accessor :license_status, :license_mrr, :license_type, :license_count, :license_value, :license_duration, :license_renewal
|
4
5
|
|
5
6
|
def as_json(options={})
|
6
7
|
{
|
7
8
|
:name => self.name,
|
8
|
-
:
|
9
|
+
:external_identifier=> self.id,
|
10
|
+
|
11
|
+
:license_type => self.license_type,
|
12
|
+
:license_count => self.license_count,
|
13
|
+
:license_renewal => self.license_renewal,
|
14
|
+
:license_value => self.license_value,
|
15
|
+
:license_mrr => self.license_mrr,
|
16
|
+
:license_duration => self.license_duration,
|
17
|
+
:license_status => self.license_status
|
9
18
|
}
|
10
19
|
end
|
11
20
|
|
data/lib/preact/version.rb
CHANGED
data/lib/preact.rb
CHANGED
@@ -26,7 +26,16 @@ module Preact
|
|
26
26
|
|
27
27
|
# Call this method to modify the configuration in your initializers
|
28
28
|
def configure
|
29
|
-
|
29
|
+
defaults = {}
|
30
|
+
# try to use the yml config if we're on rails and it exists
|
31
|
+
if defined? ::Rails
|
32
|
+
config_yml = File.join(::Rails.root.to_s,"config","preact.yml")
|
33
|
+
if File.exists?(config_yml)
|
34
|
+
defaults = YAML::load_file(config_yml)[::Rails.env]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
self.configuration ||= Configuration.new(defaults)
|
30
39
|
|
31
40
|
yield(configuration) if block_given?
|
32
41
|
|
@@ -133,6 +142,21 @@ module Preact
|
|
133
142
|
send_log(person)
|
134
143
|
end
|
135
144
|
|
145
|
+
def update_account(account)
|
146
|
+
# Don't send requests when disabled
|
147
|
+
if configuration.nil? || configuration.disabled?
|
148
|
+
logger.info "[Preact] Logging is disabled, not updating account"
|
149
|
+
return nil
|
150
|
+
elsif account.nil?
|
151
|
+
logger.info "[Preact] No account specified, not updating account"
|
152
|
+
return nil
|
153
|
+
end
|
154
|
+
|
155
|
+
account = configuration.convert_to_account(account)
|
156
|
+
|
157
|
+
client.update_account(account)
|
158
|
+
end
|
159
|
+
|
136
160
|
# message - a Hash with the following required keys
|
137
161
|
# :subject - subject of the message
|
138
162
|
# :body - body of the message
|