test-pack-1 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +28 -0
  3. data/README.md +872 -0
  4. data/lib/test_pack_1.rb +63 -0
  5. data/lib/test_pack_1/api_helper.rb +275 -0
  6. data/lib/test_pack_1/configuration.rb +63 -0
  7. data/lib/test_pack_1/controllers/alerts_controller.rb +381 -0
  8. data/lib/test_pack_1/controllers/assets_controller.rb +227 -0
  9. data/lib/test_pack_1/controllers/base_controller.rb +51 -0
  10. data/lib/test_pack_1/controllers/configuration_data_controller.rb +76 -0
  11. data/lib/test_pack_1/controllers/data_controller.rb +349 -0
  12. data/lib/test_pack_1/controllers/statuses_controller.rb +215 -0
  13. data/lib/test_pack_1/exceptions/api_exception.rb +20 -0
  14. data/lib/test_pack_1/http/auth/custom_query_auth.rb +16 -0
  15. data/lib/test_pack_1/http/faraday_client.rb +64 -0
  16. data/lib/test_pack_1/http/http_call_back.rb +24 -0
  17. data/lib/test_pack_1/http/http_client.rb +104 -0
  18. data/lib/test_pack_1/http/http_context.rb +20 -0
  19. data/lib/test_pack_1/http/http_method_enum.rb +13 -0
  20. data/lib/test_pack_1/http/http_request.rb +50 -0
  21. data/lib/test_pack_1/http/http_response.rb +23 -0
  22. data/lib/test_pack_1/models/aggregate_mode_enum.rb +23 -0
  23. data/lib/test_pack_1/models/alert_item.rb +104 -0
  24. data/lib/test_pack_1/models/base_model.rb +36 -0
  25. data/lib/test_pack_1/models/calculation_mode_enum.rb +20 -0
  26. data/lib/test_pack_1/models/client_configuration.rb +62 -0
  27. data/lib/test_pack_1/models/configuration_item.rb +55 -0
  28. data/lib/test_pack_1/models/data_item.rb +92 -0
  29. data/lib/test_pack_1/models/data_per_category_item.rb +82 -0
  30. data/lib/test_pack_1/models/data_per_category_response.rb +63 -0
  31. data/lib/test_pack_1/models/data_real_time_item.rb +83 -0
  32. data/lib/test_pack_1/models/data_signal.rb +53 -0
  33. data/lib/test_pack_1/models/data_signal_configuration.rb +66 -0
  34. data/lib/test_pack_1/models/data_signal_item.rb +62 -0
  35. data/lib/test_pack_1/models/device.rb +208 -0
  36. data/lib/test_pack_1/models/device_model.rb +53 -0
  37. data/lib/test_pack_1/models/metadata_field.rb +44 -0
  38. data/lib/test_pack_1/models/power_curve.rb +60 -0
  39. data/lib/test_pack_1/models/power_curve_value.rb +44 -0
  40. data/lib/test_pack_1/models/resolution_enum.rb +41 -0
  41. data/lib/test_pack_1/models/site.rb +44 -0
  42. data/lib/test_pack_1/models/site_with_data.rb +78 -0
  43. data/lib/test_pack_1/models/status_category_enum.rb +26 -0
  44. data/lib/test_pack_1/models/status_item.rb +161 -0
  45. data/lib/test_pack_1/models/time_zone_configuration.rb +76 -0
  46. data/lib/test_pack_1/models/turbine_type.rb +89 -0
  47. data/lib/test_pack_1/test_pack1_client.rb +51 -0
  48. data/test/controllers/controller_test_base.rb +33 -0
  49. data/test/controllers/test_assets_controller.rb +46 -0
  50. data/test/controllers/test_configuration_data_controller.rb +44 -0
  51. data/test/http_response_catcher.rb +20 -0
  52. data/test/test_helper.rb +99 -0
  53. metadata +219 -0
@@ -0,0 +1,215 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module TestPack1
7
+ # StatusesController
8
+ class StatusesController < BaseController
9
+ @instance = StatusesController.new
10
+
11
+ class << self
12
+ attr_accessor :instance
13
+ end
14
+
15
+ def instance
16
+ self.class.instance
17
+ end
18
+
19
+ # Gets active statuses for multiple devices. This request can also be made
20
+ # using the POST method, with a JSON request body instead of query
21
+ # parameters.
22
+ # @param [List of Integer] device_ids Required parameter: Which devices to
23
+ # get statuses for.
24
+ # @param [List of StatusCategoryEnum] category Optional parameter: Which
25
+ # status categories to get statuses for.
26
+ # @param [List of String] fields Optional parameter: Which fields to include
27
+ # in the response. Valid fields are those defined in the `StatusItem`
28
+ # schema. By default all fields are included.
29
+ # @param [List of String] sort_by Optional parameter: Which fields to sort
30
+ # the response items by. By default the items are sorted by
31
+ # timestampStart.
32
+ # @param [Boolean] sort_asc Optional parameter: Whether to sort the items in
33
+ # ascending order.
34
+ # @param [Integer] page_size Optional parameter: The number of items to
35
+ # return per page.
36
+ # @param [Integer] page Optional parameter: Which page to return when the
37
+ # number of items exceed the page size.
38
+ # @return List of StatusItem response from the API call
39
+ def get_active_statuses(device_ids,
40
+ category = nil,
41
+ fields = nil,
42
+ sort_by = nil,
43
+ sort_asc = false,
44
+ page_size = 50,
45
+ page = 1)
46
+ # Prepare query url.
47
+ _path_url = '/activestatus.json'
48
+ _query_builder = Configuration.get_base_uri
49
+ _query_builder << _path_url
50
+ _query_builder = APIHelper.append_url_with_query_parameters(
51
+ _query_builder,
52
+ {
53
+ 'deviceIds' => device_ids,
54
+ 'category' => category,
55
+ 'fields' => fields,
56
+ 'sortBy' => sort_by,
57
+ 'sortAsc' => sort_asc,
58
+ 'pageSize' => page_size,
59
+ 'page' => page
60
+ },
61
+ array_serialization: Configuration.array_serialization
62
+ )
63
+ _query_url = APIHelper.clean_url _query_builder
64
+ # Prepare headers.
65
+ _headers = {
66
+ 'accept' => 'application/json'
67
+ }
68
+ # Prepare and execute HttpRequest.
69
+ _request = @http_client.get(
70
+ _query_url,
71
+ headers: _headers
72
+ )
73
+ CustomQueryAuth.apply(_request)
74
+ _context = execute_request(_request)
75
+ # Validate response against endpoint and global error codes.
76
+ if _context.response.status_code == 400
77
+ raise APIException.new(
78
+ 'The request cannot be fulfilled due to bad syntax.',
79
+ _context
80
+ )
81
+ elsif _context.response.status_code == 401
82
+ raise APIException.new(
83
+ 'One of the following: * The request is missing a valid API key. *' \
84
+ ' The API key does not authorize access the requested' \
85
+ ' data. Devices or data signals can be limited. ',
86
+ _context
87
+ )
88
+ elsif _context.response.status_code == 405
89
+ raise APIException.new(
90
+ 'The HTTP method is not allowed for the endpoint.',
91
+ _context
92
+ )
93
+ elsif _context.response.status_code == 429
94
+ raise APIException.new(
95
+ 'The API key has been used in too many requests in a given amount' \
96
+ ' of time. The following headers will be set in the' \
97
+ ' response: * X-Rate-Limit-Limit - The total number of' \
98
+ ' allowed requests for this period. *' \
99
+ ' X-Rate-Limit-Remaining - The remaining number of' \
100
+ ' requests for this period. * X-Rate-Limit-Reset - The' \
101
+ ' number of seconds left until the end of this period. ',
102
+ _context
103
+ )
104
+ end
105
+ validate_response(_context)
106
+ # Return appropriate response type.
107
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
108
+ decoded.map { |element| StatusItem.from_hash(element) }
109
+ end
110
+
111
+ # Gets statuses for multiple devices during the given time period. This
112
+ # request can also be made using the POST method, with a JSON request body
113
+ # instead of query parameters.
114
+ # @param [List of Integer] device_ids Required parameter: Which devices to
115
+ # get statuses for.
116
+ # @param [DateTime] timestamp_start Required parameter: The first timestamp
117
+ # to get data for. Timestamps ending with 'Z' are treated as UTC. Other
118
+ # timestamps are treated as local time in your system-configured time
119
+ # zone.
120
+ # @param [DateTime] timestamp_end Required parameter: The last timestamp to
121
+ # get data for. Timestamps ending with 'Z' are treated as UTC. Other
122
+ # timestamps are treated as local time in your system-configured time
123
+ # zone.
124
+ # @param [List of StatusCategoryEnum] category Optional parameter: Which
125
+ # status categories to get statuses for.
126
+ # @param [List of String] fields Optional parameter: Which fields to include
127
+ # in the response. Valid fields are those defined in the `StatusItem`
128
+ # schema. By default all fields are included.
129
+ # @param [List of String] sort_by Optional parameter: Which fields to sort
130
+ # the response items by. By default the items are sorted by
131
+ # timestampStart.
132
+ # @param [Boolean] sort_asc Optional parameter: Whether to sort the items in
133
+ # ascending order.
134
+ # @param [Integer] page_size Optional parameter: The number of items to
135
+ # return per page.
136
+ # @param [Integer] page Optional parameter: Which page to return when the
137
+ # number of items exceed the page size.
138
+ # @return List of StatusItem response from the API call
139
+ def get_statuses(device_ids,
140
+ timestamp_start,
141
+ timestamp_end,
142
+ category = nil,
143
+ fields = nil,
144
+ sort_by = nil,
145
+ sort_asc = false,
146
+ page_size = 50,
147
+ page = 1)
148
+ # Prepare query url.
149
+ _path_url = '/status.json'
150
+ _query_builder = Configuration.get_base_uri
151
+ _query_builder << _path_url
152
+ _query_builder = APIHelper.append_url_with_query_parameters(
153
+ _query_builder,
154
+ {
155
+ 'deviceIds' => device_ids,
156
+ 'timestampStart' => timestamp_start,
157
+ 'timestampEnd' => timestamp_end,
158
+ 'category' => category,
159
+ 'fields' => fields,
160
+ 'sortBy' => sort_by,
161
+ 'sortAsc' => sort_asc,
162
+ 'pageSize' => page_size,
163
+ 'page' => page
164
+ },
165
+ array_serialization: Configuration.array_serialization
166
+ )
167
+ _query_url = APIHelper.clean_url _query_builder
168
+ # Prepare headers.
169
+ _headers = {
170
+ 'accept' => 'application/json'
171
+ }
172
+ # Prepare and execute HttpRequest.
173
+ _request = @http_client.get(
174
+ _query_url,
175
+ headers: _headers
176
+ )
177
+ CustomQueryAuth.apply(_request)
178
+ _context = execute_request(_request)
179
+ # Validate response against endpoint and global error codes.
180
+ if _context.response.status_code == 400
181
+ raise APIException.new(
182
+ 'The request cannot be fulfilled due to bad syntax.',
183
+ _context
184
+ )
185
+ elsif _context.response.status_code == 401
186
+ raise APIException.new(
187
+ 'One of the following: * The request is missing a valid API key. *' \
188
+ ' The API key does not authorize access the requested' \
189
+ ' data. Devices or data signals can be limited. ',
190
+ _context
191
+ )
192
+ elsif _context.response.status_code == 405
193
+ raise APIException.new(
194
+ 'The HTTP method is not allowed for the endpoint.',
195
+ _context
196
+ )
197
+ elsif _context.response.status_code == 429
198
+ raise APIException.new(
199
+ 'The API key has been used in too many requests in a given amount' \
200
+ ' of time. The following headers will be set in the' \
201
+ ' response: * X-Rate-Limit-Limit - The total number of' \
202
+ ' allowed requests for this period. *' \
203
+ ' X-Rate-Limit-Remaining - The remaining number of' \
204
+ ' requests for this period. * X-Rate-Limit-Reset - The' \
205
+ ' number of seconds left until the end of this period. ',
206
+ _context
207
+ )
208
+ end
209
+ validate_response(_context)
210
+ # Return appropriate response type.
211
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
212
+ decoded.map { |element| StatusItem.from_hash(element) }
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,20 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module TestPack1
7
+ # Class for exceptions when there is a network error, status code error, etc.
8
+ class APIException < StandardError
9
+ attr_reader :context, :response_code
10
+
11
+ # The constructor.
12
+ # @param [String] The reason for raising an exception.
13
+ # @param [HttpContext] The HttpContext of the API call.
14
+ def initialize(reason, context)
15
+ super(reason)
16
+ @context = context
17
+ @response_code = context.response.status_code
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module TestPack1
7
+ # Utility class for custom query_parameter authorization.
8
+ class CustomQueryAuth
9
+ # Add custom authentication to the request.
10
+ # @param [HttpRequest] The HttpRequest object to which authentication will
11
+ # be added.
12
+ def self.apply(http_request)
13
+ http_request.add_query_parameter('apiToken', Configuration.api_token)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,64 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ require 'faraday/http_cache'
7
+ require 'faraday_middleware'
8
+
9
+ module TestPack1
10
+ # An implementation of HttpClient.
11
+ class FaradayClient < HttpClient
12
+ # The constructor.
13
+ def initialize(timeout: nil, cache: false,
14
+ max_retries: nil, retry_interval: nil)
15
+ @connection = Faraday.new do |faraday|
16
+ faraday.use Faraday::HttpCache, serializer: Marshal if cache
17
+ faraday.use FaradayMiddleware::FollowRedirects
18
+ faraday.request :multipart
19
+ faraday.request :url_encoded
20
+ faraday.ssl[:ca_file] = Certifi.where
21
+ faraday.request :retry, max: max_retries, interval: if max_retries &&
22
+ retry_interval
23
+ retry_interval
24
+ end
25
+ faraday.adapter Faraday.default_adapter
26
+ faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
27
+ faraday.options[:open_timeout] = timeout if timeout
28
+ end
29
+ end
30
+
31
+ # Method overridden from HttpClient.
32
+ def execute_as_string(http_request)
33
+ response = @connection.send(
34
+ http_request.http_method.downcase,
35
+ http_request.query_url
36
+ ) do |request|
37
+ request.headers = http_request.headers
38
+ unless http_request.parameters.empty?
39
+ request.body = http_request.parameters
40
+ end
41
+ end
42
+ convert_response(response)
43
+ end
44
+
45
+ # Method overridden from HttpClient.
46
+ def execute_as_binary(http_request)
47
+ response = @connection.send(
48
+ http_request.http_method.downcase,
49
+ http_request.query_url
50
+ ) do |request|
51
+ request.headers = http_request.headers
52
+ unless http_request.parameters.empty?
53
+ request.body = http_request.parameters
54
+ end
55
+ end
56
+ convert_response(response)
57
+ end
58
+
59
+ # Method overridden from HttpClient.
60
+ def convert_response(response)
61
+ HttpResponse.new(response.status, response.headers, response.body)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,24 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module TestPack1
7
+ # HttpCallBack allows defining callables for pre and post API calls.
8
+ class HttpCallBack
9
+ # A controller will call this method before making an HTTP Request.
10
+ # @param [HttpRequest] The HttpRequest object which the HttpClient
11
+ # will execute.
12
+ def on_before_request(_http_request)
13
+ raise NotImplementedError, 'This method needs
14
+ to be implemented in a child class.'
15
+ end
16
+
17
+ # A controller will call this method after making an HTTP Request.
18
+ # @param [HttpContext] The HttpContext of the API call.
19
+ def on_after_response(_http_context)
20
+ raise NotImplementedError, 'This method needs
21
+ to be implemented in a child class.'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,104 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module TestPack1
7
+ # An interface for the methods that an HTTP Client must implement.
8
+ #
9
+ # This class should not be instantiated but should be used as a base class
10
+ # for HTTP Client classes.
11
+ class HttpClient
12
+ # Execute an HttpRequest when the response is expected to be a string.
13
+ # @param [HttpRequest] The HttpRequest to be executed.
14
+ def execute_as_string(_http_request)
15
+ raise NotImplementedError, 'This method needs
16
+ to be implemented in a child class.'
17
+ end
18
+
19
+ # Execute an HttpRequest when the response is expected to be binary.
20
+ # @param [HttpRequest] The HttpRequest to be executed.
21
+ def execute_as_binary(_http_request)
22
+ raise NotImplementedError, 'This method needs
23
+ to be implemented in a child class.'
24
+ end
25
+
26
+ # Converts the HTTP Response from the client to an HttpResponse object.
27
+ # @param [Dynamic] The response object received from the client.
28
+ def convert_response(_response)
29
+ raise NotImplementedError, 'This method needs
30
+ to be implemented in a child class.'
31
+ end
32
+
33
+ # Get a GET HttpRequest object.
34
+ # @param [String] The URL to send the request to.
35
+ # @param [Hash, Optional] The headers for the HTTP Request.
36
+ def get(query_url,
37
+ headers: {})
38
+ HttpRequest.new(HttpMethodEnum::GET,
39
+ query_url,
40
+ headers: headers)
41
+ end
42
+
43
+ # Get a HEAD HttpRequest object.
44
+ # @param [String] The URL to send the request to.
45
+ # @param [Hash, Optional] The headers for the HTTP Request.
46
+ def head(query_url,
47
+ headers: {})
48
+ HttpRequest.new(HttpMethodEnum::HEAD,
49
+ query_url,
50
+ headers: headers)
51
+ end
52
+
53
+ # Get a POST HttpRequest object.
54
+ # @param [String] The URL to send the request to.
55
+ # @param [Hash, Optional] The headers for the HTTP Request.
56
+ # @param [Hash, Optional] The parameters for the HTTP Request.
57
+ def post(query_url,
58
+ headers: {},
59
+ parameters: {})
60
+ HttpRequest.new(HttpMethodEnum::POST,
61
+ query_url,
62
+ headers: headers,
63
+ parameters: parameters)
64
+ end
65
+
66
+ # Get a PUT HttpRequest object.
67
+ # @param [String] The URL to send the request to.
68
+ # @param [Hash, Optional] The headers for the HTTP Request.
69
+ # @param [Hash, Optional] The parameters for the HTTP Request.
70
+ def put(query_url,
71
+ headers: {},
72
+ parameters: {})
73
+ HttpRequest.new(HttpMethodEnum::PUT,
74
+ query_url,
75
+ headers: headers,
76
+ parameters: parameters)
77
+ end
78
+
79
+ # Get a PATCH HttpRequest object.
80
+ # @param [String] The URL to send the request to.
81
+ # @param [Hash, Optional] The headers for the HTTP Request.
82
+ # @param [Hash, Optional] The parameters for the HTTP Request.
83
+ def patch(query_url,
84
+ headers: {},
85
+ parameters: {})
86
+ HttpRequest.new(HttpMethodEnum::PATCH,
87
+ query_url,
88
+ headers: headers,
89
+ parameters: parameters)
90
+ end
91
+
92
+ # Get a DELETE HttpRequest object.
93
+ # @param [String] The URL to send the request to.
94
+ # @param [Hash, Optional] The headers for the HTTP Request.
95
+ def delete(query_url,
96
+ headers: {},
97
+ parameters: {})
98
+ HttpRequest.new(HttpMethodEnum::DELETE,
99
+ query_url,
100
+ headers: headers,
101
+ parameters: parameters)
102
+ end
103
+ end
104
+ end