gds-api-adapters 69.1.0 → 71.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,131 +0,0 @@
1
- require_relative "../base"
2
-
3
- module GdsApi
4
- module PerformancePlatform
5
- class DataOut < GdsApi::Base
6
- # Fetch all service feedback from the performance platform for a given transaction
7
- # page slug.
8
- #
9
- # Makes a +GET+ request.
10
- #
11
- # The results are ordered date ascending.
12
- #
13
- # @param transaction_page_slug [String] The slug for which service feedback is
14
- # needed.
15
- #
16
- # # @example
17
- #
18
- # performance_platform_data_out.service_feedback('register-to-vote')
19
- #
20
- # #=> {
21
- # "data": [
22
- # {
23
- # "_day_start_at": "2014-06-10T00:00:00+00:00",
24
- # "_hour_start_at": "2014-06-10T00:00:00+00:00",
25
- # "_id": "20140610_register-to-vote",
26
- # "_month_start_at": "2014-06-01T00:00:00+00:00",
27
- # "_quarter_start_at": "2014-04-01T00:00:00+00:00",
28
- # "_timestamp": "2014-06-10T00:00:00+00:00",
29
- # "_updated_at": "2014-06-11T00:30:50.901000+00:00",
30
- # "_week_start_at": "2014-06-09T00:00:00+00:00",
31
- # "comments": 217,
32
- # "period": "day",
33
- # "rating_1": 4,
34
- # "rating_2": 6,
35
- # "rating_3": 7,
36
- # "rating_4": 74,
37
- # "rating_5": 574,
38
- # "slug": "register-to-vote",
39
- # "total": 665
40
- # },
41
- # ...
42
- # }
43
- def service_feedback(transaction_page_slug)
44
- get_json("#{endpoint}/data/#{transaction_page_slug}/customer-satisfaction")
45
- end
46
-
47
- # Fetching statistics data from the performance platform for a given page slug
48
- #
49
- # Makes a +GET+ request.
50
- #
51
- # @param slug [String] Points to the page for which we are requesting
52
- # statistics.
53
- # @param is_multipart [Boolean] Flag that marks whether the slug is multipart
54
- # or not:
55
- #
56
- # - simple: `/european-health-insurance-card`
57
- # - multipart: `/european-health-insurance-card/123`
58
- #
59
- # # @examples
60
- #
61
- # 1. Without multipart filtering:
62
- #
63
- # performance_platform_data_out.search_terms('/european-health-insurance-card')
64
- #
65
- # 2. With multipart filtering:
66
- #
67
- # performance_platform_data_out.searches('/european-health-insurance-card', true)
68
- # performance_platform_data_out.page_views('/european-health-insurance-card', true)
69
- # performance_platform_data_out.problem_reports('/european-health-insurance-card', true)
70
-
71
- def search_terms(slug)
72
- options = {
73
- slug: slug,
74
- transaction: "search-terms",
75
- group_by: "searchKeyword",
76
- collect: "searchUniques:sum",
77
- }
78
- statistics(options)
79
- end
80
-
81
- def searches(slug, is_multipart)
82
- options = {
83
- slug: slug,
84
- transaction: "search-terms",
85
- group_by: "pagePath",
86
- collect: "searchUniques:sum",
87
- }
88
- statistics(options, is_multipart)
89
- end
90
-
91
- def page_views(slug, is_multipart)
92
- options = {
93
- slug: slug,
94
- transaction: "page-statistics",
95
- group_by: "pagePath",
96
- collect: "uniquePageviews:sum",
97
- }
98
- statistics(options, is_multipart)
99
- end
100
-
101
- def problem_reports(slug, is_multipart)
102
- options = {
103
- slug: slug,
104
- transaction: "page-contacts",
105
- group_by: "pagePath",
106
- collect: "total:sum",
107
- }
108
- statistics(options, is_multipart)
109
- end
110
-
111
- # This can be used as a free form call to the performance platform.
112
- # The performance platform uses Backdrop and its query language for
113
- # storing and querying data.
114
- # Backdrop can be found here: https://github.com/alphagov/backdrop
115
- def statistics(options, is_multipart = false)
116
- params = {
117
- group_by: options[:group_by],
118
- collect: options[:collect],
119
- duration: 42,
120
- period: "day",
121
- end_at: Date.today.to_time.getutc.iso8601,
122
- }
123
-
124
- filter_param = is_multipart ? :filter_by_prefix : :filter_by
125
- params[filter_param] = "pagePath:" + options[:slug]
126
-
127
- get_json("#{endpoint}/data/govuk-info/#{options[:transaction]}#{query_string(params)}")
128
- end
129
- end
130
- end
131
- end
@@ -1,45 +0,0 @@
1
- module GdsApi
2
- module TestHelpers
3
- module PerformancePlatform
4
- module DataIn
5
- PP_DATA_IN_ENDPOINT = "http://www.performance.dev.gov.uk".freeze
6
-
7
- def stub_service_feedback_day_aggregate_submission(slug, request_body = nil)
8
- post_stub = stub_http_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/#{slug}/customer-satisfaction")
9
- post_stub.with(body: request_body) unless request_body.nil?
10
- post_stub.to_return(status: 200)
11
- end
12
-
13
- def stub_corporate_content_problem_report_count_submission(submissions = nil)
14
- post_stub = stub_http_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/gov-uk-content/feedback-count")
15
- post_stub.with(body: submissions.to_json) unless submissions.nil?
16
- post_stub.to_return(status: 200)
17
- end
18
-
19
- def stub_corporate_content_urls_with_the_most_problem_reports_submission(submissions = nil)
20
- post_stub = stub_http_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/gov-uk-content/top-urls")
21
- post_stub.with(body: submissions.to_json) unless submissions.nil?
22
- post_stub.to_return(status: 200)
23
- end
24
-
25
- def stub_problem_report_daily_totals_submission(submissions = nil)
26
- post_stub = stub_http_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/govuk-info/page-contacts")
27
- post_stub.with(body: submissions.to_json) unless submissions.nil?
28
- post_stub.to_return(status: 200)
29
- end
30
-
31
- def stub_service_feedback_bucket_unavailable_for(slug)
32
- stub_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/#{slug}/customer-satisfaction").to_return(status: 404)
33
- end
34
-
35
- def stub_pp_isnt_available
36
- stub_request(:post, /#{PP_DATA_IN_ENDPOINT}\/.*/).to_return(status: 503)
37
- end
38
-
39
- def stub_pp_dataset_unavailable
40
- stub_request(:any, /#{PP_DATA_IN_ENDPOINT}/).to_return(status: 404)
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,98 +0,0 @@
1
- module GdsApi
2
- module TestHelpers
3
- module PerformancePlatform
4
- module DataOut
5
- PP_DATA_OUT_ENDPOINT = "https://www.performance.service.gov.uk".freeze
6
-
7
- def stub_service_feedback(slug, response_body = {})
8
- stub_http_request(:get, "#{PP_DATA_OUT_ENDPOINT}/data/#{slug}/customer-satisfaction")
9
- .to_return(status: 200, body: response_body.to_json)
10
- end
11
-
12
- def stub_data_set_not_available(slug)
13
- stub_http_request(:get, "#{PP_DATA_OUT_ENDPOINT}/data/#{slug}/customer-satisfaction")
14
- .to_return(status: 404)
15
- end
16
-
17
- def stub_service_not_available
18
- stub_request(:any, /#{PP_DATA_OUT_ENDPOINT}\/.*/).to_return(status: 503)
19
- end
20
-
21
- def stub_search_terms(slug, response_body = {})
22
- options = {
23
- slug: slug,
24
- transaction: "search-terms",
25
- group_by: "searchKeyword",
26
- collect: "searchUniques:sum",
27
- }
28
- stub_statistics(options, false, response_body)
29
- end
30
-
31
- def stub_searches(slug, is_multipart, response_body = {})
32
- options = {
33
- slug: slug,
34
- transaction: "search-terms",
35
- group_by: "pagePath",
36
- collect: "searchUniques:sum",
37
- }
38
- stub_statistics(options, is_multipart, response_body)
39
- end
40
-
41
- def stub_page_views(slug, is_multipart, response_body = {})
42
- options = {
43
- slug: slug,
44
- transaction: "page-statistics",
45
- group_by: "pagePath",
46
- collect: "uniquePageviews:sum",
47
- }
48
- stub_statistics(options, is_multipart, response_body)
49
- end
50
-
51
- def stub_problem_reports(slug, is_multipart, response_body = {})
52
- options = {
53
- slug: slug,
54
- transaction: "page-contacts",
55
- group_by: "pagePath",
56
- collect: "total:sum",
57
- }
58
- stub_statistics(options, is_multipart, response_body)
59
- end
60
-
61
- def stub_statistics(options, is_multipart, response_body = {})
62
- params = {
63
- group_by: options[:group_by],
64
- collect: options[:collect],
65
- duration: 42,
66
- period: "day",
67
- end_at: Date.today.to_time.getutc.iso8601,
68
- }
69
-
70
- filter_param = is_multipart ? :filter_by_prefix : :filter_by
71
- params[filter_param] = "pagePath:" + options[:slug]
72
-
73
- stub_http_request(:get, "#{PP_DATA_OUT_ENDPOINT}/data/govuk-info/#{options[:transaction]}")
74
- .with(query: params)
75
- .to_return(status: 200, body: response_body.to_json)
76
- end
77
-
78
- def stub_search_404(slug)
79
- stub_request(:get, "#{PP_DATA_OUT_ENDPOINT}/data/govuk-info/search-terms")
80
- .with(query: hash_including(filter_by: slug))
81
- .to_return(status: 404, headers: { content_type: "application/json" })
82
- end
83
-
84
- def stub_page_views_404(slug)
85
- stub_request(:get, "#{PP_DATA_OUT_ENDPOINT}/data/govuk-info/page-statistics")
86
- .with(query: hash_including(filter_by: slug))
87
- .to_return(status: 404, headers: { content_type: "application/json" })
88
- end
89
-
90
- def stub_problem_reports_404(slug)
91
- stub_request(:get, "#{PP_DATA_OUT_ENDPOINT}/data/govuk-info/page-contacts")
92
- .with(query: hash_including(filter_by: slug))
93
- .to_return(status: 404, headers: { content_type: "application/json" })
94
- end
95
- end
96
- end
97
- end
98
- end