test-pack-1 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,76 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ require 'date'
7
+ module TestPack1
8
+ # your system-configured time zone configuration.
9
+ class TimeZoneConfiguration < BaseModel
10
+ # The title of the time zone.
11
+ # @return [String]
12
+ attr_accessor :title
13
+
14
+ # The UTC offset for the time zone.
15
+ # @return [Float]
16
+ attr_accessor :utc_offset
17
+
18
+ # The UTC offset for the time zone during daylight savings time.
19
+ # @return [Float]
20
+ attr_accessor :utc_offset_dst
21
+
22
+ # The start of daylight savings time in the time zone. This timestamp is
23
+ # given in the UTC time zone.
24
+ # @return [DateTime]
25
+ attr_accessor :dst_timestamp_start
26
+
27
+ # The end of daylight savings time in the time zone. This timestamp is given
28
+ # in the UTC time zone.
29
+ # @return [DateTime]
30
+ attr_accessor :dst_timestamp_end
31
+
32
+ # A mapping from model property names to API property names.
33
+ def self.names
34
+ @_hash = {} if @_hash.nil?
35
+ @_hash['title'] = 'title'
36
+ @_hash['utc_offset'] = 'utcOffset'
37
+ @_hash['utc_offset_dst'] = 'utcOffsetDst'
38
+ @_hash['dst_timestamp_start'] = 'dstTimestampStart'
39
+ @_hash['dst_timestamp_end'] = 'dstTimestampEnd'
40
+ @_hash
41
+ end
42
+
43
+ def initialize(title = nil,
44
+ utc_offset = nil,
45
+ utc_offset_dst = nil,
46
+ dst_timestamp_start = nil,
47
+ dst_timestamp_end = nil)
48
+ @title = title
49
+ @utc_offset = utc_offset
50
+ @utc_offset_dst = utc_offset_dst
51
+ @dst_timestamp_start = dst_timestamp_start
52
+ @dst_timestamp_end = dst_timestamp_end
53
+ end
54
+
55
+ # Creates an instance of the object from a hash.
56
+ def self.from_hash(hash)
57
+ return nil unless hash
58
+
59
+ # Extract variables from the hash.
60
+ title = hash['title']
61
+ utc_offset = hash['utcOffset']
62
+ utc_offset_dst = hash['utcOffsetDst']
63
+ dst_timestamp_start = APIHelper.rfc3339(hash['dstTimestampStart']) if
64
+ hash['dstTimestampStart']
65
+ dst_timestamp_end = APIHelper.rfc3339(hash['dstTimestampEnd']) if
66
+ hash['dstTimestampEnd']
67
+
68
+ # Create object from extracted values.
69
+ TimeZoneConfiguration.new(title,
70
+ utc_offset,
71
+ utc_offset_dst,
72
+ dst_timestamp_start,
73
+ dst_timestamp_end)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,89 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module TestPack1
7
+ # Turbine-specific type information.
8
+ class TurbineType < BaseModel
9
+ # TODO: Write general description for this method
10
+ # @return [Integer]
11
+ attr_accessor :turbine_type_id
12
+
13
+ # TODO: Write general description for this method
14
+ # @return [String]
15
+ attr_accessor :title
16
+
17
+ # TODO: Write general description for this method
18
+ # @return [String]
19
+ attr_accessor :manufacturer
20
+
21
+ # TODO: Write general description for this method
22
+ # @return [String]
23
+ attr_accessor :model
24
+
25
+ # The model of the turbine controller.
26
+ # @return [String]
27
+ attr_accessor :controller
28
+
29
+ # The model of the turbine controller.
30
+ # @return [Integer]
31
+ attr_accessor :rated_power
32
+
33
+ # The model of the turbine controller.
34
+ # @return [Float]
35
+ attr_accessor :max_rotor_speed
36
+
37
+ # A mapping from model property names to API property names.
38
+ def self.names
39
+ @_hash = {} if @_hash.nil?
40
+ @_hash['turbine_type_id'] = 'turbineTypeId'
41
+ @_hash['title'] = 'title'
42
+ @_hash['manufacturer'] = 'manufacturer'
43
+ @_hash['model'] = 'model'
44
+ @_hash['controller'] = 'controller'
45
+ @_hash['rated_power'] = 'ratedPower'
46
+ @_hash['max_rotor_speed'] = 'maxRotorSpeed'
47
+ @_hash
48
+ end
49
+
50
+ def initialize(turbine_type_id = nil,
51
+ title = nil,
52
+ manufacturer = nil,
53
+ model = nil,
54
+ controller = nil,
55
+ rated_power = nil,
56
+ max_rotor_speed = nil)
57
+ @turbine_type_id = turbine_type_id
58
+ @title = title
59
+ @manufacturer = manufacturer
60
+ @model = model
61
+ @controller = controller
62
+ @rated_power = rated_power
63
+ @max_rotor_speed = max_rotor_speed
64
+ end
65
+
66
+ # Creates an instance of the object from a hash.
67
+ def self.from_hash(hash)
68
+ return nil unless hash
69
+
70
+ # Extract variables from the hash.
71
+ turbine_type_id = hash['turbineTypeId']
72
+ title = hash['title']
73
+ manufacturer = hash['manufacturer']
74
+ model = hash['model']
75
+ controller = hash['controller']
76
+ rated_power = hash['ratedPower']
77
+ max_rotor_speed = hash['maxRotorSpeed']
78
+
79
+ # Create object from extracted values.
80
+ TurbineType.new(turbine_type_id,
81
+ title,
82
+ manufacturer,
83
+ model,
84
+ controller,
85
+ rated_power,
86
+ max_rotor_speed)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,51 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module TestPack1
7
+ # test_pack_1 client class.
8
+ class TestPack1Client
9
+ # Singleton access to statuses controller.
10
+ # @return [StatusesController] Returns the controller instance.
11
+ def statuses
12
+ StatusesController.instance
13
+ end
14
+
15
+ # Singleton access to data controller.
16
+ # @return [DataController] Returns the controller instance.
17
+ def data
18
+ DataController.instance
19
+ end
20
+
21
+ # Singleton access to alerts controller.
22
+ # @return [AlertsController] Returns the controller instance.
23
+ def alerts
24
+ AlertsController.instance
25
+ end
26
+
27
+ # Singleton access to configuration_data controller.
28
+ # @return [ConfigurationDataController] Returns the controller instance.
29
+ def configuration_data
30
+ ConfigurationDataController.instance
31
+ end
32
+
33
+ # Singleton access to assets controller.
34
+ # @return [AssetsController] Returns the controller instance.
35
+ def assets
36
+ AssetsController.instance
37
+ end
38
+
39
+ # Returns the configuration class for easy access.
40
+ # @return [Configuration] Returns the actual configuration class.
41
+ def config
42
+ Configuration
43
+ end
44
+
45
+ # Initializer with authentication and configuration parameters.
46
+ def initialize(api_token: nil)
47
+ Configuration.api_token = api_token if
48
+ api_token
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,33 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ require 'json'
7
+ require 'test/unit'
8
+ require 'test_pack_1.rb'
9
+ require_relative '../test_helper.rb'
10
+ require_relative '../http_response_catcher.rb'
11
+
12
+ class ControllerTestBase < Test::Unit::TestCase
13
+ include TestPack1
14
+
15
+ class << self
16
+ attr_accessor :controller
17
+ end
18
+
19
+ # Called only once for a test class before any test has executed.
20
+ def self.startup
21
+ @@api_client = TestPack1Client.new
22
+ @@request_timeout = 30
23
+ @@assert_precision = 0.01
24
+
25
+
26
+ end
27
+
28
+ # Called once before every test case.
29
+ def setup
30
+ @response_catcher = HttpResponseCatcher.new
31
+ self.class.controller.http_call_back = @response_catcher
32
+ end
33
+ end
@@ -0,0 +1,46 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ require_relative 'controller_test_base'
7
+
8
+ class AssetsControllerTests < ControllerTestBase
9
+ # Called only once for the class before any test has executed
10
+ def self.startup
11
+ self.controller = @@api_client.assets
12
+ end
13
+
14
+ # Gets a list of sites that the API key has permissions for. This request can also be made using the POST method, with a JSON request body instead of query parameters.
15
+ def test_test_get_sites()
16
+ # Parameters for the API call
17
+ fields = nil
18
+ page_size = 50
19
+ page = 1
20
+
21
+ # Perform the API call through the SDK function
22
+ result = self.class.controller.get_sites(fields, page_size, page)
23
+
24
+ # Test response code
25
+ assert_equal(@response_catcher.response.status_code, 200)
26
+
27
+ # Test headers
28
+ expected_headers = {}
29
+ expected_headers['content-type'] = 'application/json'
30
+
31
+ assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
32
+
33
+ # Test whether the captured response is as we expected
34
+ assert_not_nil(result)
35
+ expected_body = JSON.parse(
36
+ '[{"siteId":1,"title":"Wind farm 1","country":"Sweden","identity":"SE-WF1",'\
37
+ '"metadata":[{"key":"Address","value":"Wind Street 123"},{"key":"Phone","val'\
38
+ 'ue":"555 123 456"}]},{"siteId":2,"title":"Solar site 1","country":"Spain","'\
39
+ 'identity":"ES-SS1","metadata":[{"key":"Address","value":"Sun Street 456"},{'\
40
+ '"key":"Phone","value":"555 456 789"}]}]'
41
+ )
42
+ received_body = JSON.parse(@response_catcher.response.raw_body)
43
+ assert(TestHelper.match_body(expected_body, received_body))
44
+ end
45
+
46
+ end
@@ -0,0 +1,44 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ require_relative 'controller_test_base'
7
+
8
+ class ConfigurationDataControllerTests < ControllerTestBase
9
+ # Called only once for the class before any test has executed
10
+ def self.startup
11
+ self.controller = @@api_client.configuration_data
12
+ end
13
+
14
+ # Gets your system-wide configuration data. This request can also be made using the POST method, with a JSON request body instead of query parameters.
15
+ def test_test_get_configuration()
16
+
17
+ # Perform the API call through the SDK function
18
+ result = self.class.controller.get_configuration()
19
+
20
+ # Test response code
21
+ assert_equal(@response_catcher.response.status_code, 200)
22
+
23
+ # Test headers
24
+ expected_headers = {}
25
+ expected_headers['content-type'] = 'application/json'
26
+
27
+ assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
28
+
29
+ # Test whether the captured response is as we expected
30
+ assert_not_nil(result)
31
+ expected_body = JSON.parse(
32
+ '[{"client":{"title":"Intro (Greenbyte AB)","tag":"intro","urlWeb":"https:/'\
33
+ '/intro.greenbyte.cloud/","urlApi":"https://intro.greenbyte.cloud/api/2.0/"}'\
34
+ ',"timeZone":{"title":"Europe/Stockholm","utcOffset":1,"utcOffsetDst":2,"dst'\
35
+ 'TimestampStart":"2020-03-29T01:00:00","dstTimestampEnd":"2020-10-25T01:00:0'\
36
+ '0"},"dataSignals":{"availabilityTimeDataSignalId":430,"availabilityProducti'\
37
+ 'onDataSignalId":445,"lostProductionDataSignalId":432,"performanceDataSignal'\
38
+ 'Id":436}}]'
39
+ )
40
+ received_body = JSON.parse(@response_catcher.response.raw_body)
41
+ assert(TestHelper.match_body(expected_body, received_body))
42
+ end
43
+
44
+ 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
+
7
+ # HttpResponseCatcher
8
+ class HttpResponseCatcher < TestPack1::HttpCallBack
9
+ attr_accessor :response
10
+
11
+ def on_before_request(request) end
12
+
13
+ # Catching the response
14
+ def on_after_response(context)
15
+ @response = context.response
16
+ end
17
+ end
18
+
19
+
20
+
@@ -0,0 +1,99 @@
1
+ # test_pack_1
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ require 'tempfile'
7
+ require 'open-uri'
8
+ # TestHelper Class
9
+ class TestHelper
10
+ @cache = Hash.new
11
+
12
+ # Class method to compare the received headers with the expected headers.
13
+ # @param [Hash] A hash of expected headers (keys in lower case).
14
+ # @param [Hash] A hash of received headers.
15
+ # @param [Boolean, optional] A flag which determines if we allow
16
+ # extra headers.
17
+ def self.match_headers(expected_headers,
18
+ received_headers,
19
+ allow_extra: true)
20
+ return false if (received_headers.length < expected_headers.length) ||
21
+ ((allow_extra == false) &&
22
+ (received_headers.length > expected_headers.length))
23
+
24
+ received_headers = Hash[received_headers.map { |k, v| [k.to_s.downcase, v] }]
25
+ expected_headers.each do |e_key, e_value|
26
+ return false unless received_headers.key?(e_key)
27
+ return false if (e_value != nil) &&
28
+ (e_value != received_headers[e_key])
29
+ end
30
+
31
+ true
32
+ end
33
+
34
+ # Class method to compare the received body with the expected body.
35
+ # @param [Dynamic] The expected body.
36
+ # @param [Dynamic] The received body.
37
+ # @param [Boolean, optional] A flag which determines if we check values
38
+ # in dictionaries.
39
+ # @param [Boolean, optional] A flag which determines if we check the order
40
+ # of array elements.
41
+ # @param [Boolean, optional] A flag which determines if we check the count
42
+ # of array elements.
43
+ def self.match_body(expected_body,
44
+ received_body,
45
+ check_values: false,
46
+ check_order: false,
47
+ check_count: false)
48
+ if expected_body.instance_of? Hash
49
+ return false unless received_body.instance_of? Hash
50
+ for key in expected_body.keys
51
+ return false unless received_body.keys.include? key
52
+ if check_values or expected_body[key].instance_of? Hash
53
+ return false unless TestHelper.match_body(expected_body[key],
54
+ received_body[key],
55
+ check_values: check_values,
56
+ check_order: check_order,
57
+ check_count: check_count)
58
+ end
59
+ end
60
+ elsif expected_body.instance_of? Array
61
+ return False unless received_body.instance_of? Array
62
+ if check_count == true && (expected_body.length != received_body.length)
63
+ return false
64
+ else
65
+ previous_matches = Array.new
66
+ expected_body.each.with_index do |expected_element, i|
67
+ matches = (received_body.map.with_index do |received_element, j|
68
+ j if TestHelper.match_body(expected_element,
69
+ received_element,
70
+ check_values: check_values,
71
+ check_order: check_order,
72
+ check_count: check_count)
73
+ end).compact
74
+ return false if matches.length == 0
75
+ if check_order == true
76
+ return false if i != 0 && matches.map { |x| previous_matches.map { |y| y > x }.all? }.all?
77
+ previous_matches = matches
78
+ end
79
+ end
80
+ end
81
+ elsif expected_body != received_body
82
+ return false
83
+ end
84
+ true
85
+ end
86
+
87
+ # Class method which takes a URL, downloads the file
88
+ # (if not already downloaded for this test session)
89
+ # and returns the path of the file.
90
+ # @param [String] The URL of the required file.
91
+ def self.get_file(url)
92
+ unless @cache.keys.include? url
93
+ @cache[url] = Tempfile.new('APIMatic')
94
+ @cache[url].binmode
95
+ @cache[url].write(open(url, { ssl_ca_cert: Certifi.where }).read)
96
+ end
97
+ @cache[url].path
98
+ end
99
+ end