-
Notifications
You must be signed in to change notification settings - Fork 14
/
gds_api.rb
205 lines (187 loc) · 5.74 KB
/
gds_api.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
require "addressable"
require "plek"
require "time"
require "gds_api/account_api"
require "gds_api/asset_manager"
require "gds_api/calendars"
require "gds_api/content_store"
require "gds_api/email_alert_api"
require "gds_api/places_manager"
require "gds_api/licence_application"
require "gds_api/link_checker_api"
require "gds_api/local_links_manager"
require "gds_api/locations_api"
require "gds_api/maslow"
require "gds_api/organisations"
require "gds_api/publishing_api"
require "gds_api/router"
require "gds_api/search"
require "gds_api/search_api_v2"
require "gds_api/support"
require "gds_api/support_api"
require "gds_api/worldwide"
# @api documented
module GdsApi
# Creates a GdsApi::AccountApi adapter
#
# This will set a bearer token if a ACCOUNT_API_BEARER_TOKEN environment
# variable is set
#
# @return [GdsApi::AccountApi]
def self.account_api(options = {})
GdsApi::AccountApi.new(
Plek.find("account-api"),
{ bearer_token: ENV["ACCOUNT_API_BEARER_TOKEN"] }.merge(options),
)
end
# Creates a GdsApi::AssetManager adapter
#
# This will set a bearer token if a ASSET_MANAGER_BEARER_TOKEN environment
# variable is set
#
# @return [GdsApi::AssetManager]
def self.asset_manager(options = {})
GdsApi::AssetManager.new(
Plek.find("asset-manager"),
{ bearer_token: ENV["ASSET_MANAGER_BEARER_TOKEN"] }.merge(options),
)
end
# Creates a GdsApi::Calendars adapter
#
# @return [GdsApi::Calendars]
def self.calendars(options = {})
GdsApi::Calendars.new(Plek.new.website_root, options)
end
# Creates a GdsApi::ContentStore adapter
#
# This will set a bearer token if a CONTENT_STORE_BEARER_TOKEN environment
# variable is set
#
# @return [GdsApi::ContentStore]
def self.content_store(options = {})
GdsApi::ContentStore.new(
Plek.find("content-store"),
{ bearer_token: ENV["CONTENT_STORE_BEARER_TOKEN"] }.merge(options),
)
end
# Creates a GdsApi::EmailAlertApi adapter
#
# This will set a bearer token if a EMAIL_ALERT_API_BEARER_TOKEN environment
# variable is set
#
# @return [GdsApi::EmailAlertApi]
def self.email_alert_api(options = {})
GdsApi::EmailAlertApi.new(
Plek.find("email-alert-api"),
{ bearer_token: ENV["EMAIL_ALERT_API_BEARER_TOKEN"] }.merge(options),
)
end
# Creates a GdsApi::places-manager adapter
#
# @return [GdsApi::PlacesManager]
def self.places_manager(options = {})
GdsApi::PlacesManager.new(Plek.find("places-manager"), options)
end
# Creates a GdsApi::LicenceApplication
#
# @return [GdsApi::LicenceApplication]
def self.licence_application(options = {})
GdsApi::LicenceApplication.new(Plek.find("licensify"), options)
end
# Creates a GdsApi::LinkCheckerApi adapter
#
# This will set a bearer token if a LINK_CHECKER_API_BEARER_TOKEN environment
# variable is set
#
# @return [GdsApi::LinkCheckerApi]
def self.link_checker_api(options = {})
GdsApi::LinkCheckerApi.new(
Plek.find("link-checker-api"),
{ bearer_token: ENV["LINK_CHECKER_API_BEARER_TOKEN"] }.merge(options),
)
end
# Creates a GdsApi::LocalLinksManager adapter
#
# @return [GdsApi::LocalLinksManager]
def self.local_links_manager(options = {})
GdsApi::LocalLinksManager.new(Plek.find("local-links-manager"), options)
end
# Creates a GdsApi::LocationsApi adapter
#
# @return [GdsApi::LocationsApi]
def self.locations_api(options = {})
GdsApi::LocationsApi.new(Plek.find("locations-api"), options)
end
# Creates a GdsApi::Maslow adapter
#
# It's set to use an external url as an endpoint as the Maslow adapter is
# used to generate external links
#
# @return [GdsApi::Maslow]
def self.maslow(options = {})
GdsApi::Maslow.new(Plek.new.external_url_for("maslow"), options)
end
# Creates a GdsApi::Organisations adapter for accessing Whitehall
# APIs through the origin, where the requests will be handled by
# Collections frontend.
#
# @return [GdsApi::Organisations]
def self.organisations(options = {})
GdsApi::Organisations.new(Plek.new.website_root, options)
end
# Creates a GdsApi::PublishingApi adapter
#
# This will set a bearer token if a PUBLISHING_API_BEARER_TOKEN environment
# variable is set
#
# @return [GdsApi::PublishingApi]
def self.publishing_api(options = {})
GdsApi::PublishingApi.new(
Plek.find("publishing-api"),
{ bearer_token: ENV["PUBLISHING_API_BEARER_TOKEN"] }.merge(options),
)
end
# Creates a GdsApi::Router adapter for communicating with Router API
#
# This will set a bearer token if a ROUTER_API_BEARER_TOKEN environment
# variable is set
#
# @return [GdsApi::Router]
def self.router(options = {})
GdsApi::Router.new(
Plek.find("router-api"),
{ bearer_token: ENV["ROUTER_API_BEARER_TOKEN"] }.merge(options),
)
end
# Creates a GdsApi::Search adapter to access via a search.* hostname
#
# @return [GdsApi::Search]
def self.search(options = {})
GdsApi::Search.new(Plek.find("search-api"), options)
end
# Creates a GdsApi::Support adapter
#
# @return [GdsApi::Support]
def self.support(options = {})
GdsApi::Support.new(Plek.find("support"), options)
end
# Creates a GdsApi::SupportApi adapter
#
# This will set a bearer token if a SUPPORT_API_BEARER_TOKEN environment
# variable is set
#
# @return [GdsApi::SupportApi]
def self.support_api(options = {})
GdsApi::SupportApi.new(
Plek.find("support-api"),
{ bearer_token: ENV["SUPPORT_API_BEARER_TOKEN"] }.merge(options),
)
end
# Creates a GdsApi::Worldwide adapter for accessing Whitehall APIs on a
# whitehall-frontend host
#
# @return [GdsApi::Worldwide]
def self.worldwide(options = {})
GdsApi::Worldwide.new(Plek.new.website_root, options)
end
end