portfoliomanager-rb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,386 @@
1
+ require "net/http"
2
+
3
+ module PortfolioManager
4
+ module Services
5
+ # Connection/Share Services
6
+ #
7
+ # The Connection/Share Services allows you to connect to existing Portfolio
8
+ # Manager accounts and share existing properties and meters. These services
9
+ # are divided into 2 sections.The first section includes services that allow
10
+ # you to respond to connection and share requests from existing Portfolio
11
+ # Manager users. In addition, there are services that allow you to
12
+ # disconnect from a user or remove any property or meter shares from a user.
13
+ # The second section includes services that will help you test the
14
+ # connection/share process within the Test environment. These services allow
15
+ # you to generate connection and share requests that are sent to you. This
16
+ # simulates the requests being submitted from other Portfolio Manager users.
17
+ # In addition, as you simulate generating these requests from other
18
+ # Portfolio Manager users, you will be able to submit values to custom
19
+ # fields that you define with each request. This set of web services are
20
+ # only available within the Test environment.
21
+ #
22
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection
23
+ module Connection
24
+ # Connection/Share
25
+ module ConnectionShare
26
+ # Live Environment
27
+ module Live
28
+ # Accept/Reject Pending Connection Requests
29
+ #
30
+ # This web service sends an accept or reject reply to a pending
31
+ # connection request along with an optional note based on the
32
+ # information provided in the XML request.
33
+ #
34
+ # @param account_id [Integer]
35
+ # @param sharing_response [PortfolioManager::Xml::SharingResponseType]
36
+ # @return [PortfolioManager::Xml::ResponseType]
37
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
38
+ # @raise [PortfolioManager::HTTPResponseError]
39
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/connect/post
40
+ def accept_reject_pending_connection_requests(account_id, sharing_response)
41
+ request(Net::HTTP::Post, path_for("connect", "account", account_id), {}, {}, sharing_response, "sharingResponse", PortfolioManager::Xml::SharingResponseType, basic_auth: true)
42
+ end
43
+
44
+ # Accept/Reject Pending Meter Share Requests
45
+ #
46
+ # This web service sends an accept or reject reply to a pending meter
47
+ # share request along with an optional note based on the information
48
+ # provided in the XML request.
49
+ #
50
+ # @param meter_id [Integer]
51
+ # @param sharing_response [PortfolioManager::Xml::SharingResponseType]
52
+ # @return [PortfolioManager::Xml::ResponseType]
53
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
54
+ # @raise [PortfolioManager::HTTPResponseError]
55
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/shareMeter/post
56
+ def accept_reject_pending_meter_share_requests(meter_id, sharing_response)
57
+ request(Net::HTTP::Post, path_for("share", "meter", meter_id), {}, {}, sharing_response, "sharingResponse", PortfolioManager::Xml::SharingResponseType, basic_auth: true)
58
+ end
59
+
60
+ # Accept/Reject Pending Property Share Requests
61
+ #
62
+ # This web service sends an accept or reject reply to a pending
63
+ # property share request along with an optional note based on the
64
+ # information provided in the XML request.
65
+ #
66
+ # @param property_id [Integer]
67
+ # @param sharing_response [PortfolioManager::Xml::SharingResponseType]
68
+ # @return [PortfolioManager::Xml::ResponseType]
69
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
70
+ # @raise [PortfolioManager::HTTPResponseError]
71
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/shareProperty/post
72
+ def accept_reject_pending_property_share_requests(property_id, sharing_response)
73
+ request(Net::HTTP::Post, path_for("share", "property", property_id), {}, {}, sharing_response, "sharingResponse", PortfolioManager::Xml::SharingResponseType, basic_auth: true)
74
+ end
75
+
76
+ # Disconnect From Customer
77
+ #
78
+ # This web service removes the existing connection between you and a
79
+ # specific customer. Any existing property and meter shares between
80
+ # you and the specific customer are also automatically removed by
81
+ # default or can be kept in place. An optional note indicating the
82
+ # reason can be included too. This optional note is provided in the
83
+ # XML request.
84
+ #
85
+ # @param account_id [Integer]
86
+ # @param terminate_sharing_response [PortfolioManager::Xml::TerminateShareResponseType]
87
+ # @param keep_shares [Boolean]
88
+ # @return [PortfolioManager::Xml::ResponseType]
89
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
90
+ # @raise [PortfolioManager::HTTPResponseError]
91
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/disconnect/post
92
+ def disconnect_from_customer(account_id, terminate_sharing_response, keep_shares = false)
93
+ request(Net::HTTP::Post, path_for("disconnect", "account", account_id), {
94
+ "keepShares" => keep_shares,
95
+ }, {}, terminate_sharing_response, "terminateSharingResponse", PortfolioManager::Xml::ResponseType, basic_auth: true)
96
+ end
97
+
98
+ # Get Notifications
99
+ #
100
+ # This web service returns a list of notifications that are generated
101
+ # when another user deletes or unshares a property or meter that you
102
+ # have access to. The purpose of these notifications is to help you
103
+ # stay in synch with your customer's data. Once a notification is
104
+ # read, it is marked as read (by default) and will not be available in
105
+ # subsequent calls. An option is available to mark those notifications
106
+ # as unread.
107
+ #
108
+ # The possible notification types are:
109
+ # * UNSHARE - Indicates that your access to a property or meter has been removed.
110
+ # * SHAREUPDATE - Indicates that your access level to a property or meter has changed.
111
+ #
112
+ # The DISCONNECT and TRANSFERPROPERTY notification types are not
113
+ # supported in the Test environment.
114
+ #
115
+ # Please see this {https://energystar-mesa.force.com/PortfolioManager/s/article/How-does-the-Get-Notifications-API-call-behave-differently-in-the-TEST-and-LIVE-web-service-environments FAQ page}
116
+ # for more information.
117
+ #
118
+ # @param clear [Boolean]
119
+ # @return [PortfolioManager::Xml::NotificationListType, PortfolioManager::Xml::ResponseType]
120
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
121
+ # @raise [PortfolioManager::HTTPResponseError]
122
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/notificationList/get
123
+ def get_notifications(clear = true)
124
+ request(Net::HTTP::Get, path_for("notification", "list"), {
125
+ "clear" => clear,
126
+ }, {}, nil, nil, PortfolioManager::Xml::NotificationListType, basic_auth: true)
127
+ end
128
+
129
+ # Get Pending Connection Requests
130
+ #
131
+ # This web service returns a list of pending customer connection
132
+ # requests. A connection to the customer must be established first
133
+ # before any properties and meters can be shared with you. The list of
134
+ # pending customer connection requests is returned in sets of 20.
135
+ #
136
+ # @param page [Integer]
137
+ # @return [PortfolioManager::Xml::PendingListType, PortfolioManager::Xml::ResponseType]
138
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
139
+ # @raise [PortfolioManager::HTTPResponseError]
140
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/pendingAccountList/get
141
+ def get_pending_connection_requests(page = 1)
142
+ request(Net::HTTP::Get, path_for("connect", "account", "pending", "list"), {
143
+ "page" => page,
144
+ }, {}, nil, nil, PortfolioManager::Xml::PendingListType, basic_auth: true)
145
+ end
146
+
147
+ # Get Pending Meter Share Requests
148
+ #
149
+ # This web service returns a list of pending property meter requests.
150
+ # These meter share requests belong to customers that you are already
151
+ # connected to. The corresponding properties do not have to be already
152
+ # shared with you. The list of pending meter share requests is
153
+ # returned in sets of 20.
154
+ #
155
+ # @param page [Integer]
156
+ # @return [PortfolioManager::Xml::PendingListType, PortfolioManager::Xml::ResponseType]
157
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
158
+ # @raise [PortfolioManager::HTTPResponseError]
159
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/pendingMeterList/get
160
+ def get_pending_meter_share_requests(page = 1)
161
+ request(Net::HTTP::Get, path_for("share", "meter", "pending", "list"), {
162
+ "page" => page,
163
+ }, {}, nil, nil, PortfolioManager::Xml::PendingListType, basic_auth: true)
164
+ end
165
+
166
+ # Get Pending Property Share Requests
167
+ #
168
+ # This web service returns a list of pending property share requests.
169
+ # These property share requests belong to customers that you are
170
+ # already connected to. The list of pending property share requests is
171
+ # returned in sets of 20.
172
+ #
173
+ # @param page [Integer]
174
+ # @return [PortfolioManager::Xml::PendingListType, PortfolioManager::Xml::ResponseType]
175
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
176
+ # @raise [PortfolioManager::HTTPResponseError]
177
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/pendingPropertyList/get
178
+ def get_pending_property_share_requests(page = 1)
179
+ request(Net::HTTP::Get, path_for("share", "property", "pending", "list"), {
180
+ "page" => page,
181
+ }, {}, nil, nil, PortfolioManager::Xml::PendingListType, basic_auth: true)
182
+ end
183
+
184
+ # Unshare Meter
185
+ #
186
+ # This web service removes an existing share between you and a
187
+ # specific meter. An optional note indicating the reason can be
188
+ # included too. This optional note is provided in the XML request.
189
+ #
190
+ # @param meter_id [Integer]
191
+ # @param terminate_sharing_response [TerminateShareResponseType]
192
+ # @return [PortfolioManager::Xml::ResponseType]
193
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
194
+ # @raise [PortfolioManager::HTTPResponseError]
195
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/unshareMeter/post
196
+ def unshare_meter(meter_id, terminate_sharing_response)
197
+ request(Net::HTTP::Post, path_for("unshare", "meter", meter_id), {}, {}, terminate_sharing_response, "terminateSharingResponse", PortfolioManager::Xml::ResponseType, basic_auth: true)
198
+ end
199
+
200
+ # Unshare Property
201
+ #
202
+ # This web service removes an existing share between you and a
203
+ # specific property. An optional note indicating the reason can be
204
+ # included too. This optional note is provided in the XML request.
205
+ #
206
+ # @param property_id [Integer]
207
+ # @param terminate_sharing_response [TerminateShareResponseType]
208
+ # @return [PortfolioManager::Xml::ResponseType]
209
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
210
+ # @raise [PortfolioManager::HTTPResponseError]
211
+ # @see https://portfoliomanager.energystar.gov/webservices/home/api/connection/unshareProperty/post
212
+ def unshare_property(property_id, terminate_sharing_response)
213
+ request(Net::HTTP::Post, path_for("unshare", "property", property_id), {}, {}, terminate_sharing_response, "terminateSharingResponse", PortfolioManager::Xml::ResponseType, basic_auth: true)
214
+ end
215
+ end
216
+
217
+ # Test Environment
218
+ module Test
219
+ end
220
+ end
221
+
222
+ # Simulating Connection/Share Requests
223
+ module SimulatingConnectionShareRequests
224
+ # Live Environment
225
+ module Live
226
+ end
227
+
228
+ # Test Environment
229
+ module Test
230
+ # Send Connection Request From Test Environment
231
+ #
232
+ # This web service sends a connection request from a customer to you.
233
+ # You must run this web service as the customer that you want the
234
+ # connection request to originate from and specify the account that
235
+ # receives the request. This simulates the customer sending a
236
+ # connection request to you. This web service is only available in the
237
+ # Test environment. After a connection request is sent, you can verify
238
+ # it by running the web service that returns a list of pending
239
+ # customer connections. A connection request cannot be sent if the two
240
+ # accounts are already connected.
241
+ #
242
+ # @param dx_account_id [Integer]
243
+ # @return [PortfolioManager::Xml::ResponseType]
244
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
245
+ # @raise [PortfolioManager::HTTPResponseError]
246
+ # @see https://portfoliomanager.energystar.gov/webservices/home/test/api/connection/invite/post
247
+ def send_connection_request_from_test_environment(dx_account_id)
248
+ request(Net::HTTP::Post, path_for("invite", "account", dx_account_id), {}, {}, nil, nil, PortfolioManager::Xml::ResponseType, basic_auth: true)
249
+ end
250
+
251
+ # Send Meter Share Request From Test Environment
252
+ #
253
+ # This web service sends a share request for a specific meter from a
254
+ # customer to you. You must run this web service as the customer that
255
+ # you want the meter share request to originate from and specify the
256
+ # account that receives the request. This simulates the customer
257
+ # sending a meter share request to you. Any existing share for this
258
+ # specific meter between you and this customer will be updated after
259
+ # submitting this service. If a meter share is pending
260
+ # acceptance/rejection, additional share requests cannot be sent. This
261
+ # web service is only available in the Test environment. After the
262
+ # meter share request is sent, you can verify it by running the web
263
+ # service that returns a list of pending meter share requests.
264
+ #
265
+ # @param dx_account_id [Integer]
266
+ # @param meter_id [Integer]
267
+ # @param access_level ["READ", "READ_WRITE"]
268
+ # @return [PortfolioManager::Xml::ResponseType]
269
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
270
+ # @raise [PortfolioManager::HTTPResponseError]
271
+ # @see https://portfoliomanager.energystar.gov/webservices/home/test/api/connection/inviteMeter/post
272
+ def send_meter_share_request_from_test_environment(dx_account_id, meter_id, access_level = "READ_WRITE")
273
+ request(Net::HTTP::Post, path_for("invite", "account", dx_account_id, "meter", meter_id), {
274
+ "accessLevel" => access_level,
275
+ }, {}, nil, nil, PortfolioManager::Xml::ResponseType, basic_auth: true)
276
+ end
277
+
278
+ # Send Property Share Request From Test Environment
279
+ #
280
+ # This web service sends a share request for a specific property from
281
+ # a customer to you. You must run this web service as the customer
282
+ # that you want the property share request to originate from and
283
+ # specify the account that receives the request. This simulates the
284
+ # customer sending a property share request to you. Any existing share
285
+ # for this specific property between you and this customer will be
286
+ # updated after submitting this service. If a property share is
287
+ # pending acceptance/rejection, additional share requests cannot be
288
+ # sent. This web service is only available in the Test environment.
289
+ # After the property share request is sent, you can verify it by
290
+ # running the web service that returns a list of pending property
291
+ # share requests.
292
+ #
293
+ # @param dx_account_id [Integer]
294
+ # @param property_id [Integer]
295
+ # @param access_level ["READ", "READ_WRITE"]
296
+ # @return [PortfolioManager::Xml::ResponseType]
297
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
298
+ # @raise [PortfolioManager::HTTPResponseError]
299
+ # @see https://portfoliomanager.energystar.gov/webservices/home/test/api/connection/inviteProperty/post
300
+ def send_meter_share_request_from_test_environment(dx_account_id, property_id, access_level = "READ_WRITE")
301
+ request(Net::HTTP::Post, path_for("invite", "account", dx_account_id, "property", property_id), {
302
+ "accessLevel" => access_level,
303
+ }, {}, nil, nil, PortfolioManager::Xml::ResponseType, basic_auth: true)
304
+ end
305
+
306
+ # Submit Customer-Level Custom Field Value(s)
307
+ #
308
+ # This web service submits data for a list of customer-level custom
309
+ # fields based on the data provided in the XML request from a specific
310
+ # Portfolio Manager customer to you. This web service is used within
311
+ # the Test environment to simulate a Portfolio Manager user providing
312
+ # data that is required by you during the connection process. You must
313
+ # run this web service as the customer that you the data to be
314
+ # provided from.
315
+ #
316
+ # @param dx_account_id [Integer]
317
+ # @param custom_field_list [PortfolioManager::Xml::CustomFieldList]
318
+ # @return [PortfolioManager::Xml::ResponseType]
319
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
320
+ # @raise [PortfolioManager::HTTPResponseError]
321
+ # @see https://portfoliomanager.energystar.gov/webservices/home/test/api/connection/accountCustomFieldValues/put
322
+ def submit_customer_level_custom_field_values(dx_account_id, custom_field_list)
323
+ request(Net::HTTP::Put, path_for("account", "customFieldList", "recipient", dx_account_id), {}, {}, custom_field_list, "customFieldList", PortfolioManager::Xml::ResponseType, basic_auth: true)
324
+ end
325
+
326
+ # Submit Meter-Level Custom Field Value(s)
327
+ #
328
+ # This web service submits data for a list of meter-level custom
329
+ # fields based on the data provided in the XML request from a specific
330
+ # Portfolio Manager customer to you. This web service is used within
331
+ # the Test environment to simulate a Portfolio Manager user providing
332
+ # data that is required by you during the share process. You must run
333
+ # this web service as the customer that you the data to be provided
334
+ # from.
335
+ #
336
+ # @param meter_id [Integer]
337
+ # @param dx_account_id [Integer]
338
+ # @param custom_field_list [PortfolioManager::Xml::CustomFieldList]
339
+ # @return [PortfolioManager::Xml::ResponseType]
340
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
341
+ # @raise [PortfolioManager::HTTPResponseError]
342
+ # @see https://portfoliomanager.energystar.gov/webservices/home/test/api/connection/meterCustomFieldValues/put
343
+ def submit_meter_level_custom_field_values(meter_id, dx_account_id, custom_field_list)
344
+ request(Net::HTTP::Put, path_for("meter", meter_id, "customFieldList", "recipient", dx_account_id), {}, {}, custom_field_list, "customFieldList", PortfolioManager::Xml::ResponseType, basic_auth: true)
345
+ end
346
+
347
+ # Submit Property-Level Custom Field Value(s)
348
+ #
349
+ # This web service submits data for a list of property-level custom
350
+ # fields based on the data provided in the XML request from a specific
351
+ # Portfolio Manager customer to you. This web service is used within
352
+ # the Test environment to simulate a Portfolio Manager user providing
353
+ # data that is required by you during the share process. You must run
354
+ # this web service as the customer that you the data to be provided
355
+ # from.
356
+ #
357
+ # @param property_id [Integer]
358
+ # @param dx_account_id [Integer]
359
+ # @param custom_field_list [PortfolioManager::Xml::CustomFieldList]
360
+ # @return [PortfolioManager::Xml::ResponseType]
361
+ # @raise [PortfolioManager::HTTPBasicCredentialsNotFoundError]
362
+ # @raise [PortfolioManager::HTTPResponseError]
363
+ # @see https://portfoliomanager.energystar.gov/webservices/home/test/api/connection/propertyCustomFieldValues/put
364
+ def submit_property_level_custom_field_values(property_id, dx_account_id, custom_field_list)
365
+ request(Net::HTTP::Put, path_for("property", property_id, "customFieldList", "recipient", dx_account_id), {}, {}, custom_field_list, "customFieldList", PortfolioManager::Xml::ResponseType, basic_auth: true)
366
+ end
367
+ end
368
+ end
369
+
370
+ # All Connection/Share Services
371
+ module All
372
+ # Live Environment
373
+ module Live
374
+ include PortfolioManager::Services::Connection::ConnectionShare::Live
375
+ include PortfolioManager::Services::Connection::SimulatingConnectionShareRequests::Live
376
+ end
377
+
378
+ # Test Environment
379
+ module Test
380
+ include PortfolioManager::Services::Connection::ConnectionShare::Test
381
+ include PortfolioManager::Services::Connection::SimulatingConnectionShareRequests::Test
382
+ end
383
+ end
384
+ end
385
+ end
386
+ end