activity_consumer 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +15 -0
- data/app/assets/images/activity_consumer/cross.png +0 -0
- data/app/assets/images/activity_consumer/tick.png +0 -0
- data/app/assets/javascripts/activity_consumer/application.js +15 -0
- data/app/assets/stylesheets/activity_consumer/application.scss +43 -0
- data/app/assets/stylesheets/activity_consumer/table.scss +10 -0
- data/app/controllers/activity_consumer/application_controller.rb +3 -0
- data/app/controllers/activity_consumer/remote_activities_controller.rb +63 -0
- data/app/helpers/activity_consumer/application_helper.rb +4 -0
- data/app/models/activity_consumer/remote_activity.rb +21 -0
- data/app/services/activity_consumer/configuration.rb +24 -0
- data/app/services/activity_consumer/remote_activity_importer.rb +40 -0
- data/app/services/activity_consumer/remote_activity_rest_client.rb +77 -0
- data/app/views/activity_consumer/remote_activities/index.html.erb +32 -0
- data/app/views/activity_consumer/remote_activities/show.html.erb +37 -0
- data/app/views/layouts/activity_consumer/application.html.erb +17 -0
- data/config/locales/de.yml +18 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20130725170303_create_activity_consumer_remote_activities.rb +16 -0
- data/db/migrate/20130817171648_add_etag_to_remote_activities.rb +5 -0
- data/lib/activity_consumer/engine.rb +13 -0
- data/lib/activity_consumer/version.rb +3 -0
- data/lib/activity_consumer.rb +26 -0
- data/lib/tasks/activity_consumer_tasks.rake +4 -0
- data/spec/controllers/activity_consumer/remote_activities_controller_spec.rb +72 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +67 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +28 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +295 -0
- data/spec/dummy/log/test.log +45193 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/tmp/cache/assets/CB9/640/sprockets%2F055df7094ed3c73903db121ec7947478 +0 -0
- data/spec/dummy/tmp/cache/assets/CDD/880/sprockets%2F0994815802d4bd56bf29a9c53bab6520 +0 -0
- data/spec/dummy/tmp/cache/assets/CEF/070/sprockets%2F833e7786517acf485f377186a1eb1ea6 +0 -0
- data/spec/dummy/tmp/cache/assets/CF3/F30/sprockets%2Fc0fff716a78291e8e6e3659a50b59824 +0 -0
- data/spec/dummy/tmp/cache/assets/D26/790/sprockets%2F4928ff8fb0382efb99f6362f4f1e2831 +0 -0
- data/spec/dummy/tmp/cache/assets/D26/A70/sprockets%2Fe8aae21d8889a7c4473672ff0c5396e7 +0 -0
- data/spec/dummy/tmp/cache/assets/DA5/890/sprockets%2F849c2c9c50783eb3f65bc4b2d5feb0e6 +0 -0
- data/spec/dummy/tmp/cache/assets/DCB/E30/sprockets%2F9c1335eaffea6e3a58425adc4c28a35f +0 -0
- data/spec/dummy/tmp/cache/assets/DD8/8A0/sprockets%2Ffb4d7aea2f81d5c9837b9e02586f1acf +0 -0
- data/spec/dummy/tmp/cache/assets/E3F/5B0/sprockets%2Fc4ab6ddfbe50dfb200e08f2ad0b21e1f +0 -0
- data/spec/fixtures/vcr_cassettes/activities-controller.yml +36 -0
- data/spec/fixtures/vcr_cassettes/activities-delta.yml +36 -0
- data/spec/fixtures/vcr_cassettes/activities-etag-abc123.yml +40 -0
- data/spec/fixtures/vcr_cassettes/activities-etag-def456.yml +40 -0
- data/spec/fixtures/vcr_cassettes/activities-etag-xyz789.yml +36 -0
- data/spec/fixtures/vcr_cassettes/activities-foo-and-bar.yml +38 -0
- data/spec/fixtures/vcr_cassettes/activities-foo.yml +36 -0
- data/spec/fixtures/vcr_cassettes/activities.yml +36 -0
- data/spec/fixtures/vcr_cassettes/unknown-activities.yml +36 -0
- data/spec/models/activity_consumer/remote_activity_spec.rb +22 -0
- data/spec/services/activity_consumer/configuration_spec.rb +17 -0
- data/spec/services/activity_consumer/remote_activity_importer_spec.rb +121 -0
- data/spec/services/activity_consumer/remote_activity_rest_client_spec.rb +157 -0
- data/spec/spec_helper.rb +23 -0
- metadata +312 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e856e7fcb239433b20bfc7dd7780bc56679e96c
|
4
|
+
data.tar.gz: 224848a664ec46753ab55589b8724dafe16db723
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5ce5c2a8c5f812ed8162244dade5a4e5cc872130431cda212126bfa5c77b0157823f72f88946c38a8b3629cfbf41c7b58df269c19108c7dd4e9cccf40f60eb56
|
7
|
+
data.tar.gz: 4c490afac2e202555e8006588ec5befc3ecb4928e734c56e1eabc10dee9d6e4193e5a7baf2a11210a1d3509750026147af8bdb88fe6801c3cbc6798ced40f835
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
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.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
8
|
+
load 'rails/tasks/engine.rake'
|
9
|
+
Bundler::GemHelper.install_tasks
|
10
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
11
|
+
require 'rspec/core'
|
12
|
+
require 'rspec/core/rake_task'
|
13
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
14
|
+
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
15
|
+
task :default => :spec
|
Binary file
|
Binary file
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,43 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
14
|
+
|
15
|
+
body {
|
16
|
+
background-color: #a9a9a9;
|
17
|
+
|
18
|
+
font-family: verdana;
|
19
|
+
}
|
20
|
+
|
21
|
+
section#main {
|
22
|
+
margin: 50px;
|
23
|
+
padding: 20px;
|
24
|
+
|
25
|
+
border: 2px solid gray;
|
26
|
+
background-color: white;
|
27
|
+
|
28
|
+
border-radius:8px;
|
29
|
+
-moz-border-radius:8px;
|
30
|
+
-webkit-border-radius:8px;
|
31
|
+
|
32
|
+
hr {
|
33
|
+
border: 1px solid gray;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
a {
|
38
|
+
color: #444;
|
39
|
+
|
40
|
+
&:visited {
|
41
|
+
color: #888
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_dependency "activity_consumer/application_controller"
|
2
|
+
|
3
|
+
module ActivityConsumer
|
4
|
+
class RemoteActivitiesController < ApplicationController
|
5
|
+
# GET /remote_activities
|
6
|
+
# GET /remote_activities.json
|
7
|
+
def index
|
8
|
+
@remote_activities = RemoteActivity.order('created_at DESC, timestamp DESC')
|
9
|
+
|
10
|
+
respond_to do |format|
|
11
|
+
format.html # index.html.erb
|
12
|
+
format.json { render json: @remote_activities }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /remote_activities/1
|
17
|
+
# GET /remote_activities/1.json
|
18
|
+
def show
|
19
|
+
@remote_activity = RemoteActivity.find(params[:id])
|
20
|
+
|
21
|
+
respond_to do |format|
|
22
|
+
format.html # show.html.erb
|
23
|
+
format.json { render json: @remote_activity }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def import_latest
|
28
|
+
begin
|
29
|
+
stats = ActivityConsumer::RemoteActivityImporter.new(:delta).import
|
30
|
+
|
31
|
+
if stats[:no_activities] == 0 && stats[:no_errors] == 0
|
32
|
+
flash[:notice] = I18n.translate('import_notification.nothing')
|
33
|
+
else
|
34
|
+
flash[:notice] = I18n.translate('import_notification.success', message: compile_stats_message(stats))
|
35
|
+
end
|
36
|
+
if stats[:no_errors] > 0
|
37
|
+
flash[:error] = I18n.translate('import_notification.error', stats)
|
38
|
+
end
|
39
|
+
rescue => e
|
40
|
+
flash[:error] = I18n.translate('import_notification.exception', message: e.message)
|
41
|
+
Rails.logger.error "Error during activity import"
|
42
|
+
Rails.logger.error e.message
|
43
|
+
Rails.logger.error e.backtrace.join("\n")
|
44
|
+
end
|
45
|
+
|
46
|
+
redirect_to :back
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def compile_stats_message stats
|
52
|
+
messages = []
|
53
|
+
stats[:activities].each_key do |type|
|
54
|
+
stats[:activities][type].each_key do |action|
|
55
|
+
messages << I18n.translate("import_notification.#{type}_#{action}", count: stats[:activities][type][action])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
result = I18n.translate('import_notification.no_activities', count: stats[:no_activities])
|
59
|
+
result << messages.join(", ")
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActivityConsumer
|
2
|
+
|
3
|
+
class RemoteActivity < ActiveRecord::Base
|
4
|
+
|
5
|
+
attr_accessible :action, :payload, :timestamp, :etag, :was_successful, :error
|
6
|
+
validates_presence_of :action, :timestamp
|
7
|
+
|
8
|
+
serialize :payload, Hash
|
9
|
+
|
10
|
+
def self.latest_timestamp
|
11
|
+
return nil unless RemoteActivity.count > 0
|
12
|
+
RemoteActivity.order("timestamp DESC").first.timestamp.iso8601
|
13
|
+
end
|
14
|
+
|
15
|
+
def short_type
|
16
|
+
type.gsub(/.*Remote/, '').gsub(/Activity/, '').underscore
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ActivityConsumer
|
2
|
+
|
3
|
+
# Stores the ActivityConsumer configuration.
|
4
|
+
class Configuration
|
5
|
+
|
6
|
+
# @example
|
7
|
+
# ActivityConsumer.configure do |c|
|
8
|
+
# c.activity_uri = 'example.com'
|
9
|
+
# end
|
10
|
+
attr_accessor :activity_uri, :activity_fullexport_uri, :auth, :import_types
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
self.activity_uri = 'http://inoxio-cim.dev/activities.json'
|
16
|
+
self.activity_fullexport_uri = 'http://inoxio-cim.dev/activities/fullexport.json'
|
17
|
+
self.auth = {user: 'user', password: 'secret'}
|
18
|
+
self.import_types = []
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module ActivityConsumer
|
2
|
+
|
3
|
+
class RemoteActivityImporter
|
4
|
+
|
5
|
+
def initialize(mode = :delta)
|
6
|
+
@client = RemoteActivityRestClient.new(mode)
|
7
|
+
end
|
8
|
+
|
9
|
+
def import
|
10
|
+
stats = {no_activities: 0, no_errors: 0, activities: {}}
|
11
|
+
|
12
|
+
activities.each do |activity|
|
13
|
+
begin
|
14
|
+
activity.import!
|
15
|
+
activity.update_attributes(was_successful: true)
|
16
|
+
stats[:no_activities] += 1
|
17
|
+
stats[:activities][activity.short_type.to_sym] ||= Hash.new(0)
|
18
|
+
stats[:activities][activity.short_type.to_sym][activity.action.to_sym] += 1
|
19
|
+
rescue => e
|
20
|
+
activity.update_attributes(was_successful: false, error: e.message)
|
21
|
+
Rails.logger.error "Error during activity import"
|
22
|
+
Rails.logger.error e.message
|
23
|
+
Rails.logger.error e.backtrace.join("\n")
|
24
|
+
stats[:no_errors] += 1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
RemoteActivity.last.update_attributes(etag: @client.latest_etag) if RemoteActivity.last
|
29
|
+
stats
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def activities
|
35
|
+
@client.fetch
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module ActivityConsumer
|
4
|
+
|
5
|
+
class RemoteActivityRestClient
|
6
|
+
include HTTParty
|
7
|
+
attr_reader :latest_etag
|
8
|
+
|
9
|
+
def initialize(mode = :delta)
|
10
|
+
@mode = mode
|
11
|
+
end
|
12
|
+
|
13
|
+
def fetch
|
14
|
+
Rails.logger.info "GET #{request_url}"
|
15
|
+
response = self.class.get(request_url, basic_auth: auth)
|
16
|
+
Rails.logger.info "Response: #{response}"
|
17
|
+
if response.success?
|
18
|
+
@latest_etag = response.headers['ETag']
|
19
|
+
activities = []
|
20
|
+
response['activities'].each do |activity|
|
21
|
+
activity = activity.deep_symbolize_keys
|
22
|
+
|
23
|
+
Rails.logger.info "trying to import #{activity}"
|
24
|
+
if !ActivityConsumer.configuration.import_types.include?(activity[:activity_type])
|
25
|
+
Rails.logger.info "type not in: #{ActivityConsumer.configuration.import_types} ... skipping!"
|
26
|
+
next
|
27
|
+
end
|
28
|
+
|
29
|
+
activities << sub_class_from_type(activity[:activity_type]).new(activity.except(:activity_type))
|
30
|
+
end
|
31
|
+
activities
|
32
|
+
else
|
33
|
+
# this just raises the net/http response that was raised
|
34
|
+
Rails.logger.error response.response
|
35
|
+
raise response.response
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def is_fresh?
|
40
|
+
url = ActivityConsumer.configuration.activity_uri
|
41
|
+
etag = RemoteActivity.last ? RemoteActivity.last.etag : ''
|
42
|
+
Rails.logger.info "HEAD #{url} with ETag #{etag}"
|
43
|
+
response = self.class.head(url, basic_auth: auth, headers: {"If-None-Match" => etag})
|
44
|
+
Rails.logger.info "Response code: #{response.code}"
|
45
|
+
|
46
|
+
return response.code == 304
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def sub_class_from_type(type)
|
52
|
+
('Remote' + type.capitalize + 'Activity').constantize
|
53
|
+
end
|
54
|
+
|
55
|
+
def request_url
|
56
|
+
case @mode
|
57
|
+
when :delta
|
58
|
+
ActivityConsumer.configuration.activity_uri + request_params
|
59
|
+
when :initial
|
60
|
+
ActivityConsumer.configuration.activity_fullexport_uri
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def request_params
|
65
|
+
latest = RemoteActivity.latest_timestamp
|
66
|
+
latest ? "?since=#{latest}" : ""
|
67
|
+
end
|
68
|
+
|
69
|
+
def auth
|
70
|
+
{
|
71
|
+
username: ActivityConsumer.configuration.auth[:user],
|
72
|
+
password: ActivityConsumer.configuration.auth[:password]
|
73
|
+
}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<h1>Protokoll der letzten Importe</h1>
|
2
|
+
|
3
|
+
<table id="remote_activities">
|
4
|
+
<tr>
|
5
|
+
<th>ID</th>
|
6
|
+
<th>Type / Action</th>
|
7
|
+
<th>Imported At</th>
|
8
|
+
<th>Timestamp</th>
|
9
|
+
<th>Summary</th>
|
10
|
+
<th class="error">Error</th>
|
11
|
+
</tr>
|
12
|
+
|
13
|
+
<% @remote_activities.each do |remote_activity| %>
|
14
|
+
<tr>
|
15
|
+
<td><%= link_to "##{remote_activity.id}", remote_activity_path(remote_activity) %></td>
|
16
|
+
<td>
|
17
|
+
<% if remote_activity.was_successful %>
|
18
|
+
<%= image_tag 'activity_consumer/tick.png' %>
|
19
|
+
<% else %>
|
20
|
+
<%= image_tag 'activity_consumer/cross.png' %>
|
21
|
+
<% end %>
|
22
|
+
|
23
|
+
<%= remote_activity.short_type.upcase %>
|
24
|
+
<%= remote_activity.action.upcase %>
|
25
|
+
</td>
|
26
|
+
<td><%=l remote_activity.created_at, format: :short %></td>
|
27
|
+
<td><%=l remote_activity.timestamp, format: :short %></td>
|
28
|
+
<td><%= remote_activity.payload_summary %></td>
|
29
|
+
<td><%= remote_activity.error %></td>
|
30
|
+
</tr>
|
31
|
+
<% end %>
|
32
|
+
</table>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<article id="remote_activity">
|
2
|
+
|
3
|
+
<h1>
|
4
|
+
Import #<%= @remote_activity.id %>
|
5
|
+
<%= @remote_activity.short_type.upcase %>
|
6
|
+
<%= @remote_activity.action.upcase %>
|
7
|
+
</h1>
|
8
|
+
|
9
|
+
<div class="timestamp">
|
10
|
+
<span class="label"><%=t 'activity_consumer.imported_at' %></span>:
|
11
|
+
<%=l @remote_activity.created_at, format: :short %>
|
12
|
+
</div>
|
13
|
+
<div class="timestamp">
|
14
|
+
<span class="label"><%=t 'activity_consumer.timestamp' %></span>:
|
15
|
+
<%=l @remote_activity.timestamp, format: :short %>
|
16
|
+
</div>
|
17
|
+
<div class="timestamp">
|
18
|
+
<span class="label"><%=t 'activity_consumer.etag' %></span>:
|
19
|
+
<%= @remote_activity.etag %>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<pre><%= JSON.pretty_generate @remote_activity.payload %></pre>
|
23
|
+
|
24
|
+
<p>
|
25
|
+
<% if @remote_activity.was_successful %>
|
26
|
+
<%= image_tag 'activity_consumer/tick.png' %> <%=t 'activity_consumer.successful' %>
|
27
|
+
<% else %>
|
28
|
+
<%= image_tag 'activity_consumer/cross.png' %> <%=t 'activity_consumer.failure' %>
|
29
|
+
<% end %>
|
30
|
+
</p>
|
31
|
+
|
32
|
+
<% if @remote_activity.error.present? %>
|
33
|
+
<div class="error"><%= @remote_activity.error %></div>
|
34
|
+
<% end %>
|
35
|
+
|
36
|
+
<%= link_to 'Back', remote_activities_path %>
|
37
|
+
</article>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>ActivityConsumer</title>
|
5
|
+
<%= stylesheet_link_tag "activity_consumer/application", :media => "all" %>
|
6
|
+
<%= javascript_include_tag "activity_consumer/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<section id="main">
|
12
|
+
<%= yield %>
|
13
|
+
</section>
|
14
|
+
|
15
|
+
|
16
|
+
</body>
|
17
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
de:
|
2
|
+
import_notification:
|
3
|
+
nothing: 'Es gab nichts zu importieren.'
|
4
|
+
success: 'Import abgeschlossen. %{message}'
|
5
|
+
no_activities:
|
6
|
+
one: 'Eine Änderung: '
|
7
|
+
other: '%{count} Änderungen: '
|
8
|
+
error: '%{no_errors} Fehler beim Import.'
|
9
|
+
exception: 'Import ging komplett in die Hose: %{message}'
|
10
|
+
foo_create:
|
11
|
+
one: "ein neues Foo"
|
12
|
+
other: "%{count} neue Foos"
|
13
|
+
foo_update:
|
14
|
+
one: "ein geändertes Foo"
|
15
|
+
other: "%{count} geänderte Foos"
|
16
|
+
foo_destroy:
|
17
|
+
one: "ein gelöschtes Foo"
|
18
|
+
other: "%{count} gelöschte Foos"
|
data/config/routes.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateActivityConsumerRemoteActivities < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def change
|
4
|
+
create_table :activity_consumer_remote_activities do |t|
|
5
|
+
t.string :type, null: false
|
6
|
+
t.string :action
|
7
|
+
t.datetime :timestamp
|
8
|
+
t.text :payload
|
9
|
+
t.boolean :was_successful
|
10
|
+
t.text :error
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ActivityConsumer
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace ActivityConsumer
|
4
|
+
|
5
|
+
config.generators do |g|
|
6
|
+
g.test_framework :rspec, :fixture => false
|
7
|
+
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
8
|
+
g.assets false
|
9
|
+
g.helper false
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "activity_consumer/engine"
|
2
|
+
|
3
|
+
module ActivityConsumer
|
4
|
+
|
5
|
+
extend self
|
6
|
+
|
7
|
+
# Used to configure ActivityConsumer.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# ActivityConsumer.configure do |c|
|
11
|
+
# c.some_config_option = true
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# @yield the configuration block
|
15
|
+
# @yieldparam config [ActivityConsumer::Configuration] the configuration object
|
16
|
+
# @return [void]
|
17
|
+
def configure
|
18
|
+
yield configuration
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [ActivityConsumer::Configuration] the ActivityConsumer configuration.
|
22
|
+
def configuration
|
23
|
+
@configuration ||= Configuration.new
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
# stub implementation of a RemoteActivity sub-class
|
5
|
+
class RemoteFooActivity < ActivityConsumer::RemoteActivity
|
6
|
+
def import!; end
|
7
|
+
end
|
8
|
+
|
9
|
+
module ActivityConsumer
|
10
|
+
|
11
|
+
describe RemoteActivitiesController do
|
12
|
+
|
13
|
+
describe "GET import_latest" do
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
request.env["HTTP_REFERER"] = "where_i_came_from"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "uses RemoteActivityImporter" do
|
20
|
+
ActivityConsumer::RemoteActivityImporter.any_instance.should_receive(:import).once.and_return({})
|
21
|
+
get :import_latest, use_route: :activity_consumer
|
22
|
+
response.should redirect_to("where_i_came_from")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "fills flash message with stats of import" do
|
26
|
+
stats = {
|
27
|
+
no_activities: 13, no_errors: 4,
|
28
|
+
activities: { foo: { create: 8, update: 2, destroy: 3 } }
|
29
|
+
}
|
30
|
+
ActivityConsumer::RemoteActivityImporter.any_instance.should_receive(:import).once.and_return(stats)
|
31
|
+
get :import_latest, use_route: :activity_consumer
|
32
|
+
|
33
|
+
flash[:error].should == "4 Fehler beim Import."
|
34
|
+
flash[:notice].should == "Import abgeschlossen. 13 Änderungen: 8 neue Foos, 2 geänderte Foos, 3 gelöschte Foos"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "shows no error message when there was no error" do
|
38
|
+
stats = {
|
39
|
+
no_activities: 13, no_errors: 0,
|
40
|
+
activities: { foo: { create: 8, update: 2, destroy: 3 } }
|
41
|
+
}
|
42
|
+
ActivityConsumer::RemoteActivityImporter.any_instance.should_receive(:import).once.and_return(stats)
|
43
|
+
get :import_latest, use_route: :activity_consumer
|
44
|
+
|
45
|
+
flash[:error].should be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it "shows a dedicated message when there was nothing to import" do
|
49
|
+
stats = {
|
50
|
+
no_errors: 0, no_activities: 0, activities: {}
|
51
|
+
}
|
52
|
+
ActivityConsumer::RemoteActivityImporter.any_instance.should_receive(:import).once.and_return(stats)
|
53
|
+
get :import_latest, use_route: :activity_consumer
|
54
|
+
|
55
|
+
flash[:notice].should == "Es gab nichts zu importieren."
|
56
|
+
end
|
57
|
+
|
58
|
+
it "actually imports stuff" do
|
59
|
+
VCR.insert_cassette 'activities-controller'
|
60
|
+
ActivityConsumer.configure do |c|
|
61
|
+
c.activity_uri = 'http://inoxio-cim.dev/activities.json'
|
62
|
+
c.import_types = ['Foo']
|
63
|
+
end
|
64
|
+
|
65
|
+
get :import_latest, use_route: :activity_consumer
|
66
|
+
flash[:error].should == nil
|
67
|
+
flash[:notice].should == "Import abgeschlossen. 3 Änderungen: ein neues Foo, ein geändertes Foo, ein gelöschtes Foo"
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|