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.
@@ -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.code = "#{project_code}"
12
- config.secret = "#{api_secret}"
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
- config.autolog = true
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
- config.autolog_ignored_actions = ["sessions#create", "devise/sessions#create"]
32
+ autolog_ignored_actions:
33
+ - "sessions#create"
34
+ - "devise/sessions#create"
21
35
 
22
- # disable in Rails non-production environments
23
- # uncomment this if you don't want to log development activities
24
- #config.disabled = !Rails.env.production?
25
- end
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)
@@ -18,11 +18,11 @@ module Preact
18
18
  attr_accessor :logger
19
19
 
20
20
  # The URL of the API server
21
- attr_reader :scheme
22
- attr_reader :host
23
- attr_reader :base_path
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
- :id => self.id
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
 
@@ -1,3 +1,3 @@
1
1
  module Preact
2
- VERSION = "0.8.3"
2
+ VERSION = "0.8.4"
3
3
  end
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
- self.configuration ||= Configuration.new
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: preact
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: