hippo_activity_log 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9d613bc1d1e52586185fc5cb90f366f1a9db3790
4
+ data.tar.gz: f473b50efbf324e8369d2c6edd5e53ab22b59bdb
5
+ SHA512:
6
+ metadata.gz: 8c7808141fb4415526ede58c3dd16cee36a21f7bc0ae658a3adfe7938f26032cef57826daa7c392c1b4cf31e387ad66d4b8fd5e4cb6c9baa0eb3515769886eac
7
+ data.tar.gz: 589228ca094b68a9d629eac99ea747ce441fd00d20b07a123ba351bdc1ce0b5155c5008bdb4fa5b2e575435d0c9bbda34350079b236a7e29f8385d19bd333274
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 ElliottAYoung
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # HippoActivityLog
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'hippo_activity_log'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install hippo_activity_log
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'HippoActivityLog'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+
36
+ task default: :test
@@ -0,0 +1,5 @@
1
+ module HippoActivityLog
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ module HippoActivityLog
2
+ class EventsController < ApplicationController
3
+ protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }
4
+ before_action :authenticate_request!
5
+ respond_to :json
6
+
7
+ include HippoActivityLog::EventHelper
8
+
9
+ def index
10
+ # Ransack from given args
11
+ render json: queried_events(params[:filter], params[:sort], params[:page]), each_serializer: EventsSerializer
12
+ end
13
+
14
+ def create
15
+ build_event(params)
16
+ render json: 'ok', status: :ok
17
+ end
18
+
19
+ private
20
+
21
+ def authenticate_request!
22
+ if (params[:client_id] != ENV['EVENTS_CLIENT_ID']) || (params[:client_secret] != ENV['EVENTS_CLIENT_SECRET'])
23
+ head :unauthorized
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ module HippoActivityLog
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,28 @@
1
+ module HippoActivityLog
2
+ module EventHelper
3
+ def build_event(args)
4
+ Event.create({
5
+ object: args[:object],
6
+ object_id: args[:object].try('fetch', :id),
7
+ object_type: args[:resource],
8
+ author: args[:author],
9
+ author_id: args[:author].try('fetch', :id),
10
+ author_type: args[:author_type],
11
+ action: args[:event_type],
12
+ timestamp: args[:timestamp],
13
+ partner_id: args[:partner_id],
14
+ user: args[:user],
15
+ user_id: args[:user_id],
16
+ params: args[:event_args],
17
+ name: args[:event_class],
18
+ raw_data: args
19
+ })
20
+ end
21
+
22
+ def queried_events(filter_param, sort_param, page_param)
23
+ events = Event.ransack(filter_param)
24
+ events.sorts = sort_param == nil ? "id asc" : sort_param
25
+ events.result.paginate(page: page_param, per_page: 20)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ module HippoActivityLog
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ module HippoActivityLog
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module HippoActivityLog
2
+ class Event < ApplicationRecord
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ module HippoActivityLog
2
+ class EventsSerializer < ActiveModel::Serializer
3
+ attributes :object, :object_type, :author, :author_type, :action, :timestamp, :partner_id, :user, :params, :name
4
+ end
5
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ HippoActivityLog::Engine.routes.draw do
2
+ post '/events' => 'events#create', as: 'event'
3
+ get '/events' => 'events#index', as: 'events'
4
+ end
@@ -0,0 +1,24 @@
1
+ class CreateHippoActivityLogEvents < ActiveRecord::Migration
2
+ def change
3
+ create_table :hippo_activity_log_events do |t|
4
+ t.jsonb :object
5
+ t.integer :object_id, index: true
6
+ t.string :object_type, index: true
7
+
8
+ t.jsonb :author
9
+ t.integer :author_id, index: true
10
+ t.string :author_type, index: true
11
+
12
+ t.string :action
13
+ t.datetime :timestamp
14
+ t.integer :partner_id, index: true
15
+
16
+ t.jsonb :user, default: {}
17
+ t.integer :user_id, index: true
18
+ t.jsonb :params, default: {}
19
+
20
+ t.string :name, index: true
21
+ t.jsonb :raw_data
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ require "hippo_activity_log/engine"
2
+
3
+ module HippoActivityLog
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,13 @@
1
+ module HippoActivityLog
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace HippoActivityLog
4
+
5
+ initializer :append_migrations do |app|
6
+ unless app.root.to_s.match root.to_s
7
+ config.paths["db/migrate"].expanded.each do |expanded_path|
8
+ app.config.paths["db/migrate"] << expanded_path
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module HippoActivityLog
2
+ VERSION = '0.1.2'
3
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hippo_activity_log
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - ElliottAYoung
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ransack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.8.7
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.8'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.8.7
47
+ - !ruby/object:Gem::Dependency
48
+ name: active_model_serializers
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.10'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.10'
61
+ - !ruby/object:Gem::Dependency
62
+ name: sqlite3
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: The short-term storage POC for events from the Hippo Webhook
76
+ email:
77
+ - elliott.a.young@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - MIT-LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - app/controllers/hippo_activity_log/application_controller.rb
86
+ - app/controllers/hippo_activity_log/events_controller.rb
87
+ - app/helpers/hippo_activity_log/application_helper.rb
88
+ - app/helpers/hippo_activity_log/event_helper.rb
89
+ - app/jobs/hippo_activity_log/application_job.rb
90
+ - app/models/hippo_activity_log/application_record.rb
91
+ - app/models/hippo_activity_log/event.rb
92
+ - app/serializers/hippo_activity_log/events_serializer.rb
93
+ - config/routes.rb
94
+ - db/migrate/20180323200710_create_hippo_activity_log_events.rb
95
+ - lib/hippo_activity_log.rb
96
+ - lib/hippo_activity_log/engine.rb
97
+ - lib/hippo_activity_log/version.rb
98
+ homepage: https://github.com/ElliottAYoung/hippo_activity_log.git
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.6.12
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: The short-term storage POC for events from the Hippo Webhook
122
+ test_files: []