toccatore 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +7 -5
  3. data/lib/toccatore/base.rb +29 -1
  4. data/lib/toccatore/cli.rb +2 -0
  5. data/lib/toccatore/images/toccatore.png +0 -0
  6. data/lib/toccatore/version.rb +1 -1
  7. data/spec/base_spec.rb +32 -0
  8. data/spec/cli_spec.rb +7 -1
  9. data/spec/fixtures/vcr_cassettes/Toccatore_Base/send_notification_to_slack/datacite_related.yml +56 -0
  10. data/spec/fixtures/vcr_cassettes/Toccatore_Base/send_notification_to_slack/datacite_related_no_works.yml +56 -0
  11. data/spec/fixtures/vcr_cassettes/Toccatore_Base/send_notification_to_slack/orcid_update.yml +56 -0
  12. data/spec/fixtures/vcr_cassettes/Toccatore_Base/send_notification_to_slack/orcid_update_no_works.yml +56 -0
  13. data/spec/fixtures/vcr_cassettes/Toccatore_CLI/datacite_related/should_fail.yml +215 -406
  14. data/spec/fixtures/vcr_cassettes/Toccatore_CLI/datacite_related/should_query_by_DOI.yml +141 -186
  15. data/spec/fixtures/vcr_cassettes/Toccatore_CLI/datacite_related/should_query_by_related_identifier.yml +74 -47
  16. data/spec/fixtures/vcr_cassettes/Toccatore_CLI/datacite_related/should_succeed.yml +617 -792
  17. data/spec/fixtures/vcr_cassettes/Toccatore_CLI/datacite_related/should_succeed_with_no_works.yml +56 -3
  18. data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_fail.yml +59 -6
  19. data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_query_by_DOI.yml +162 -101
  20. data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_query_by_ORCID_ID.yml +369 -278
  21. data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_succeed.yml +295 -230
  22. data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_succeed_with_no_works.yml +56 -3
  23. data/spec/spec_helper.rb +1 -0
  24. data/toccatore.gemspec +1 -0
  25. metadata +21 -3
  26. data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_delete.yml +0 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c949197fc708de905e4b05d736b9344b3e5d319
4
- data.tar.gz: 758175d3ccf837bdcf56b6759137c0ab51a31e02
3
+ metadata.gz: 8698a6f69a4f27c74355a45e88cd1f6d0725d48e
4
+ data.tar.gz: 00da3c549c74c394783defee1ec0c6213ec13195
5
5
  SHA512:
6
- metadata.gz: 4ca83c0ae9ab948155fdadddc87311701150aa9706c53afe3e2fbb9d278efd0edb320903c94fad7e02ad568e99618a18cf96bd6b42914dbfdff0f54fb68ab90b
7
- data.tar.gz: 99a03f05d49be0191044d4735a101fc731a93bac90de2e89423842c4322e2c83464ad6116a31a30449cbadf7170af4d1e5fe90bda1a796dc47d19694f26c8dd3
6
+ metadata.gz: f345ab88662824dfd50bc174b10895f2bd3aaa87dc925b086c92a8492d69c3a7b946fcc7d76d9734fa1bd64cb0208ed4aca7f251cee6f4b4e111e301eb948946
7
+ data.tar.gz: 23a2dfe059d46d550f797ae7ffe4a33e7dabac58e34eff48748466147ac0de63597ca1593bb9d54f32baca3edc5756ce3bd2d173d01465081b655e234d1d29d1
data/Gemfile.lock CHANGED
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- toccatore (0.3.5)
4
+ toccatore (0.3.6)
5
5
  activesupport (~> 4.2, >= 4.2.5)
6
6
  dotenv (~> 2.1, >= 2.1.1)
7
7
  gender_detector (~> 1.0)
8
8
  maremma (~> 3.5)
9
9
  namae (~> 0.11.0)
10
+ slack-notifier (~> 2.1)
10
11
  thor (~> 0.19)
11
12
 
12
13
  GEM
@@ -20,8 +21,8 @@ GEM
20
21
  addressable (2.5.0)
21
22
  public_suffix (~> 2.0, >= 2.0.2)
22
23
  builder (3.2.3)
23
- codeclimate-test-reporter (1.0.7)
24
- simplecov
24
+ codeclimate-test-reporter (1.0.8)
25
+ simplecov (<= 0.13)
25
26
  crack (0.4.3)
26
27
  safe_yaml (~> 1.0.0)
27
28
  diff-lcs (1.3)
@@ -56,7 +57,7 @@ GEM
56
57
  namae (0.11.3)
57
58
  nokogiri (1.6.8.1)
58
59
  mini_portile2 (~> 2.1.0)
59
- oj (2.18.2)
60
+ oj (2.18.5)
60
61
  public_suffix (2.0.5)
61
62
  rack (2.0.1)
62
63
  rack-test (0.6.3)
@@ -81,9 +82,10 @@ GEM
81
82
  json (>= 1.8, < 3)
82
83
  simplecov-html (~> 0.10.0)
83
84
  simplecov-html (0.10.0)
85
+ slack-notifier (2.1.0)
84
86
  thor (0.19.4)
85
87
  thread_safe (0.3.6)
86
- tzinfo (1.2.2)
88
+ tzinfo (1.2.3)
87
89
  thread_safe (~> 0.1)
88
90
  vcr (3.0.3)
89
91
  webmock (1.24.6)
@@ -1,10 +1,15 @@
1
1
  require 'maremma'
2
2
  require 'active_support/all'
3
+ require 'erb'
4
+ require 'slack-notifier'
3
5
  require 'namae'
4
6
  require 'gender_detector'
5
7
 
6
8
  module Toccatore
7
9
  class Base
10
+ # icon for Slack messages
11
+ ICON_URL = "https://raw.githubusercontent.com/datacite/toccatore/master/lib/toccatore/images/toccatore.png"
12
+
8
13
  # load ENV variables from .env file if it exists
9
14
  env_file = File.expand_path("../../../.env", __FILE__)
10
15
  if File.exist?(env_file)
@@ -67,10 +72,17 @@ module Toccatore
67
72
  options[:offset] = page * job_batch_size
68
73
  process_data(options)
69
74
  end
75
+ text = "#{total} works processed for date range #{options[:from_date]} - #{options[:until_date]}."
70
76
  else
71
- puts "No works found for date range #{options[:from_date]} - #{options[:until_date]}."
77
+ text = "No works found for date range #{options[:from_date]} - #{options[:until_date]}."
78
+ puts text
72
79
  end
73
80
 
81
+ # send slack notification
82
+ options[:level] = total > 0 ? "good" : "warning"
83
+ options[:title] = "Report for #{source_id}"
84
+ send_notification_to_slack(text, options) if options[:slack_webhook_url].present?
85
+
74
86
  # return number of works queued
75
87
  total
76
88
  end
@@ -111,6 +123,22 @@ module Toccatore
111
123
  1000
112
124
  end
113
125
 
126
+ def send_notification_to_slack(text, options={})
127
+ return nil unless options[:slack_webhook_url].present?
128
+
129
+ attachment = {
130
+ title: options[:title] || "Report",
131
+ text: text,
132
+ color: options[:level] || "good"
133
+ }
134
+
135
+ notifier = Slack::Notifier.new options[:slack_webhook_url],
136
+ username: "Event Data Agent",
137
+ icon_url: ICON_URL
138
+ response = notifier.ping attachments: [attachment]
139
+ response.body
140
+ end
141
+
114
142
  def get_doi_ra(prefix)
115
143
  return nil if prefix.blank?
116
144
 
data/lib/toccatore/cli.rb CHANGED
@@ -19,6 +19,7 @@ module Toccatore
19
19
  desc "orcid_update", "push ORCID IDs from DataCite MDS to ORCID"
20
20
  method_option :access_token, type: :string, required: true
21
21
  method_option :push_url, type: :string
22
+ method_option :slack_webhook_url, type: :string
22
23
  method_option :from_date, type: :string, default: (Time.now.to_date - 1.day).iso8601
23
24
  method_option :until_date, type: :string, default: Time.now.to_date.iso8601
24
25
  method_option :q, type: :string
@@ -34,6 +35,7 @@ module Toccatore
34
35
  method_option :access_token, type: :string, required: true
35
36
  method_option :source_token, type: :string, required: true
36
37
  method_option :push_url, type: :string
38
+ method_option :slack_webhook_url, type: :string
37
39
  method_option :from_date, type: :string, default: (Time.now.to_date - 1.day).iso8601
38
40
  method_option :until_date, type: :string, default: Time.now.to_date.iso8601
39
41
  method_option :q, type: :string
Binary file
@@ -1,3 +1,3 @@
1
1
  module Toccatore
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
data/spec/base_spec.rb CHANGED
@@ -29,6 +29,38 @@ describe Toccatore::Base, vcr: true do
29
29
  end
30
30
  end
31
31
 
32
+ context "send_notification_to_slack" do
33
+ let(:slack_webhook_url) { ENV['SLACK_WEBHOOK_URL'] }
34
+
35
+ it "datacite_related" do
36
+ text = "12 works processed for date range 2015-04-07 - 2015-04-08."
37
+ options = { title: "Report for datacite_related", slack_webhook_url: slack_webhook_url }
38
+ expect(subject.send_notification_to_slack(text, options)).to eq("ok")
39
+ end
40
+
41
+ it "datacite_related no works" do
42
+ text = "No works found for date range 2015-04-07 - 2015-04-08."
43
+ options = { title: "Report for datacite_related",
44
+ slack_webhook_url: slack_webhook_url,
45
+ level: "warning" }
46
+ expect(subject.send_notification_to_slack(text, options)).to eq("ok")
47
+ end
48
+
49
+ it "orcid_update" do
50
+ text = "12 works processed for date range 2015-04-07 - 2015-04-08."
51
+ options = { title: "Report for orcid_update", slack_webhook_url: slack_webhook_url }
52
+ expect(subject.send_notification_to_slack(text, options)).to eq("ok")
53
+ end
54
+
55
+ it "orcid_update no works" do
56
+ text = "No works found for date range 2015-04-07 - 2015-04-08."
57
+ options = { title: "Report for orcid_update",
58
+ slack_webhook_url: slack_webhook_url,
59
+ level: "warning" }
60
+ expect(subject.send_notification_to_slack(text, options)).to eq("ok")
61
+ end
62
+ end
63
+
32
64
  context "get_doi_ra" do
33
65
  it "datacite" do
34
66
  expect(subject.get_doi_ra("10.5061")).to eq("DataCite")
data/spec/cli_spec.rb CHANGED
@@ -8,16 +8,18 @@ describe Toccatore::CLI do
8
8
 
9
9
  describe "version" do
10
10
  it 'has version' do
11
- expect { subject.__print_version }.to output("0.3.5\n").to_stdout
11
+ expect { subject.__print_version }.to output("0.3.6\n").to_stdout
12
12
  end
13
13
  end
14
14
 
15
15
  describe "orcid_update", vcr: true, :order => :defined do
16
16
  let(:push_url) { ENV['VOLPINO_URL'] }
17
17
  let(:access_token) { ENV['VOLPINO_TOKEN'] }
18
+ let(:slack_webhook_url) { ENV['SLACK_WEBHOOK_URL'] }
18
19
  let(:from_date) { "2015-04-07" }
19
20
  let(:until_date) { "2015-04-08" }
20
21
  let(:cli_options) { { push_url: push_url,
22
+ slack_webhook_url: slack_webhook_url,
21
23
  access_token: access_token,
22
24
  from_date: from_date,
23
25
  until_date: until_date } }
@@ -46,6 +48,7 @@ describe Toccatore::CLI do
46
48
  from_date = "2009-04-07"
47
49
  until_date = "2009-04-08"
48
50
  subject.options = { push_url: push_url,
51
+ slack_webhook_url: slack_webhook_url,
49
52
  access_token: access_token,
50
53
  from_date: from_date,
51
54
  until_date: until_date }
@@ -62,9 +65,11 @@ describe Toccatore::CLI do
62
65
  let(:push_url) { ENV['EVENTDATA_URL'] }
63
66
  let(:access_token) { ENV['EVENTDATA_TOKEN'] }
64
67
  let(:source_token) { ENV['SOURCE_TOKEN'] }
68
+ let(:slack_webhook_url) { ENV['SLACK_WEBHOOK_URL'] }
65
69
  let(:from_date) { "2015-04-07" }
66
70
  let(:until_date) { "2015-04-08" }
67
71
  let(:cli_options) { { push_url: push_url,
72
+ slack_webhook_url: slack_webhook_url,
68
73
  access_token: access_token,
69
74
  source_token: source_token,
70
75
  from_date: from_date,
@@ -89,6 +94,7 @@ describe Toccatore::CLI do
89
94
  from_date = "1899-04-07"
90
95
  until_date = "1899-04-08"
91
96
  subject.options = { push_url: push_url,
97
+ slack_webhook_url: slack_webhook_url,
92
98
  access_token: access_token,
93
99
  from_date: from_date,
94
100
  until_date: until_date }
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: "<SLACK_WEBHOOK_URL>"
6
+ body:
7
+ encoding: US-ASCII
8
+ string: payload=%7B%22username%22%3A%22Event+Data+Agent%22%2C%22icon_url%22%3A%22https%3A%2F%2Fraw.githubusercontent.com%2Fdatacite%2Ftoccatore%2Fmaster%2Flib%2Ftoccatore%2Fimages%2Ftoccatore.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22Report+for+datacite_related%22%2C%22text%22%3A%2212+works+processed+for+date+range+2015-04-07+-+2015-04-08.%22%2C%22color%22%3A%22good%22%7D%5D%7D
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Content-Type:
24
+ - text/html
25
+ Content-Length:
26
+ - '22'
27
+ Connection:
28
+ - keep-alive
29
+ Access-Control-Allow-Origin:
30
+ - "*"
31
+ Date:
32
+ - Wed, 29 Mar 2017 12:22:55 GMT
33
+ Referrer-Policy:
34
+ - no-referrer
35
+ Server:
36
+ - Apache
37
+ Strict-Transport-Security:
38
+ - max-age=31536000; includeSubDomains; preload
39
+ Vary:
40
+ - Accept-Encoding
41
+ X-Frame-Options:
42
+ - SAMEORIGIN
43
+ X-Slack-Backend:
44
+ - h
45
+ X-Cache:
46
+ - Miss from cloudfront
47
+ Via:
48
+ - 1.1 8a4d4882753d62d900bb1b7541308eca.cloudfront.net (CloudFront)
49
+ X-Amz-Cf-Id:
50
+ - NHshrt1mNkLoOKPf0Eb6EdL_WFYPdKTkLcWcuHUCLS0rn-b31QoKgw==
51
+ body:
52
+ encoding: ASCII-8BIT
53
+ string: ok
54
+ http_version:
55
+ recorded_at: Wed, 29 Mar 2017 12:22:55 GMT
56
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: "<SLACK_WEBHOOK_URL>"
6
+ body:
7
+ encoding: US-ASCII
8
+ string: payload=%7B%22username%22%3A%22Event+Data+Agent%22%2C%22icon_url%22%3A%22https%3A%2F%2Fraw.githubusercontent.com%2Fdatacite%2Ftoccatore%2Fmaster%2Flib%2Ftoccatore%2Fimages%2Ftoccatore.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22Report+for+datacite_related%22%2C%22text%22%3A%220+works+found+for+date+range+2015-04-07+-+2015-04-08.%22%2C%22color%22%3A%22warning%22%7D%5D%7D
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Content-Type:
24
+ - text/html
25
+ Content-Length:
26
+ - '22'
27
+ Connection:
28
+ - keep-alive
29
+ Access-Control-Allow-Origin:
30
+ - "*"
31
+ Date:
32
+ - Wed, 29 Mar 2017 12:32:14 GMT
33
+ Referrer-Policy:
34
+ - no-referrer
35
+ Server:
36
+ - Apache
37
+ Strict-Transport-Security:
38
+ - max-age=31536000; includeSubDomains; preload
39
+ Vary:
40
+ - Accept-Encoding
41
+ X-Frame-Options:
42
+ - SAMEORIGIN
43
+ X-Slack-Backend:
44
+ - h
45
+ X-Cache:
46
+ - Miss from cloudfront
47
+ Via:
48
+ - 1.1 ffaf96eee86cf7d96c222b2f54e79b63.cloudfront.net (CloudFront)
49
+ X-Amz-Cf-Id:
50
+ - sId6-A4zxQG3y6g80-ChvRT3r9j6sEDB7Xk2-YBlPktC2847t3eG2Q==
51
+ body:
52
+ encoding: ASCII-8BIT
53
+ string: ok
54
+ http_version:
55
+ recorded_at: Wed, 29 Mar 2017 12:32:15 GMT
56
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: "<SLACK_WEBHOOK_URL>"
6
+ body:
7
+ encoding: US-ASCII
8
+ string: payload=%7B%22username%22%3A%22Event+Data+Agent%22%2C%22icon_url%22%3A%22https%3A%2F%2Fraw.githubusercontent.com%2Fdatacite%2Ftoccatore%2Fmaster%2Flib%2Ftoccatore%2Fimages%2Ftoccatore.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22Report+for+orcid_update%22%2C%22text%22%3A%2212+works+processed+for+date+range+2015-04-07+-+2015-04-08.%22%2C%22color%22%3A%22good%22%7D%5D%7D
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Content-Type:
24
+ - text/html
25
+ Content-Length:
26
+ - '22'
27
+ Connection:
28
+ - keep-alive
29
+ Access-Control-Allow-Origin:
30
+ - "*"
31
+ Date:
32
+ - Wed, 29 Mar 2017 12:32:55 GMT
33
+ Referrer-Policy:
34
+ - no-referrer
35
+ Server:
36
+ - Apache
37
+ Strict-Transport-Security:
38
+ - max-age=31536000; includeSubDomains; preload
39
+ Vary:
40
+ - Accept-Encoding
41
+ X-Frame-Options:
42
+ - SAMEORIGIN
43
+ X-Slack-Backend:
44
+ - h
45
+ X-Cache:
46
+ - Miss from cloudfront
47
+ Via:
48
+ - 1.1 9ddc180a2ed3a76b4f04630a423d2191.cloudfront.net (CloudFront)
49
+ X-Amz-Cf-Id:
50
+ - m83jooakTi1cBV-qNAu3fzsAWk07G1je1icRGbFI2KiYFM34D2Np-w==
51
+ body:
52
+ encoding: ASCII-8BIT
53
+ string: ok
54
+ http_version:
55
+ recorded_at: Wed, 29 Mar 2017 12:32:55 GMT
56
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: "<SLACK_WEBHOOK_URL>"
6
+ body:
7
+ encoding: US-ASCII
8
+ string: payload=%7B%22username%22%3A%22Event+Data+Agent%22%2C%22icon_url%22%3A%22https%3A%2F%2Fraw.githubusercontent.com%2Fdatacite%2Ftoccatore%2Fmaster%2Flib%2Ftoccatore%2Fimages%2Ftoccatore.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22Report+for+orcid_update%22%2C%22text%22%3A%220+works+found+for+date+range+2015-04-07+-+2015-04-08.%22%2C%22color%22%3A%22warning%22%7D%5D%7D
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Content-Type:
24
+ - text/html
25
+ Content-Length:
26
+ - '22'
27
+ Connection:
28
+ - keep-alive
29
+ Access-Control-Allow-Origin:
30
+ - "*"
31
+ Date:
32
+ - Wed, 29 Mar 2017 12:32:57 GMT
33
+ Referrer-Policy:
34
+ - no-referrer
35
+ Server:
36
+ - Apache
37
+ Strict-Transport-Security:
38
+ - max-age=31536000; includeSubDomains; preload
39
+ Vary:
40
+ - Accept-Encoding
41
+ X-Frame-Options:
42
+ - SAMEORIGIN
43
+ X-Slack-Backend:
44
+ - h
45
+ X-Cache:
46
+ - Miss from cloudfront
47
+ Via:
48
+ - 1.1 116dfe20853b94f9e029d92f1353f8c8.cloudfront.net (CloudFront)
49
+ X-Amz-Cf-Id:
50
+ - eAUEy-sXUZzMpWkaWjQ5aSVrAvdRLAm-CBBLqx22pvzfLSeHgsJaog==
51
+ body:
52
+ encoding: ASCII-8BIT
53
+ string: ok
54
+ http_version:
55
+ recorded_at: Wed, 29 Mar 2017 12:32:59 GMT
56
+ recorded_with: VCR 3.0.3