google-calendar-apimatic-sdk 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 (94) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +28 -0
  3. data/README.md +168 -0
  4. data/bin/console +15 -0
  5. data/lib/calendar_api/api_helper.rb +10 -0
  6. data/lib/calendar_api/apis/base_api.rb +67 -0
  7. data/lib/calendar_api/apis/calendar_list_api.rb +63 -0
  8. data/lib/calendar_api/apis/channels_api.rb +42 -0
  9. data/lib/calendar_api/apis/events_api.rb +354 -0
  10. data/lib/calendar_api/apis/free_busy_api.rb +37 -0
  11. data/lib/calendar_api/apis/oauth_authorization_api.rb +87 -0
  12. data/lib/calendar_api/client.rb +103 -0
  13. data/lib/calendar_api/configuration.rb +177 -0
  14. data/lib/calendar_api/exceptions/api_exception.rb +21 -0
  15. data/lib/calendar_api/exceptions/error_response_error1_exception.rb +46 -0
  16. data/lib/calendar_api/exceptions/oauth_provider_exception.rb +64 -0
  17. data/lib/calendar_api/http/api_response.rb +19 -0
  18. data/lib/calendar_api/http/auth/oauth_2.rb +162 -0
  19. data/lib/calendar_api/http/http_call_back.rb +10 -0
  20. data/lib/calendar_api/http/http_method_enum.rb +10 -0
  21. data/lib/calendar_api/http/http_request.rb +10 -0
  22. data/lib/calendar_api/http/http_response.rb +10 -0
  23. data/lib/calendar_api/http/proxy_settings.rb +22 -0
  24. data/lib/calendar_api/logging/configuration/api_logging_configuration.rb +186 -0
  25. data/lib/calendar_api/logging/sdk_logger.rb +17 -0
  26. data/lib/calendar_api/models/attachment.rb +115 -0
  27. data/lib/calendar_api/models/attendee.rb +167 -0
  28. data/lib/calendar_api/models/auto_decline_mode.rb +40 -0
  29. data/lib/calendar_api/models/base_model.rb +110 -0
  30. data/lib/calendar_api/models/birthday_properties.rb +96 -0
  31. data/lib/calendar_api/models/birthday_type.rb +48 -0
  32. data/lib/calendar_api/models/calendar_access_role.rb +44 -0
  33. data/lib/calendar_api/models/calendar_list_entry.rb +278 -0
  34. data/lib/calendar_api/models/calendar_list_entry_conference_properties.rb +83 -0
  35. data/lib/calendar_api/models/calendar_list_entry_notification_settings.rb +85 -0
  36. data/lib/calendar_api/models/calendar_list_response.rb +129 -0
  37. data/lib/calendar_api/models/calendar_notification.rb +86 -0
  38. data/lib/calendar_api/models/calendar_notification_method.rb +27 -0
  39. data/lib/calendar_api/models/calendar_notification_type.rb +48 -0
  40. data/lib/calendar_api/models/channel.rb +129 -0
  41. data/lib/calendar_api/models/channel_params.rb +75 -0
  42. data/lib/calendar_api/models/channel_type.rb +36 -0
  43. data/lib/calendar_api/models/chat_status.rb +36 -0
  44. data/lib/calendar_api/models/conference_create_request.rb +99 -0
  45. data/lib/calendar_api/models/conference_create_request_status.rb +76 -0
  46. data/lib/calendar_api/models/conference_data.rb +137 -0
  47. data/lib/calendar_api/models/conference_data_version.rb +43 -0
  48. data/lib/calendar_api/models/conference_entry_point.rb +126 -0
  49. data/lib/calendar_api/models/conference_request_status_code.rb +40 -0
  50. data/lib/calendar_api/models/conference_solution.rb +95 -0
  51. data/lib/calendar_api/models/conference_solution_key.rb +74 -0
  52. data/lib/calendar_api/models/conference_solution_type.rb +40 -0
  53. data/lib/calendar_api/models/custom_location.rb +75 -0
  54. data/lib/calendar_api/models/entry_point_type.rb +44 -0
  55. data/lib/calendar_api/models/error_response.rb +75 -0
  56. data/lib/calendar_api/models/error_response_error.rb +104 -0
  57. data/lib/calendar_api/models/error_response_error_errors_items.rb +95 -0
  58. data/lib/calendar_api/models/event.rb +551 -0
  59. data/lib/calendar_api/models/event_date_time.rb +107 -0
  60. data/lib/calendar_api/models/event_list.rb +208 -0
  61. data/lib/calendar_api/models/event_order_by.rb +36 -0
  62. data/lib/calendar_api/models/event_reminders.rb +95 -0
  63. data/lib/calendar_api/models/event_source.rb +86 -0
  64. data/lib/calendar_api/models/event_status.rb +40 -0
  65. data/lib/calendar_api/models/event_transparency.rb +37 -0
  66. data/lib/calendar_api/models/event_type.rb +52 -0
  67. data/lib/calendar_api/models/event_visibility.rb +44 -0
  68. data/lib/calendar_api/models/extended_properties.rb +87 -0
  69. data/lib/calendar_api/models/focus_time_properties.rb +99 -0
  70. data/lib/calendar_api/models/free_busy_calendar.rb +103 -0
  71. data/lib/calendar_api/models/free_busy_error.rb +85 -0
  72. data/lib/calendar_api/models/free_busy_group.rb +94 -0
  73. data/lib/calendar_api/models/free_busy_request.rb +150 -0
  74. data/lib/calendar_api/models/free_busy_request_item.rb +72 -0
  75. data/lib/calendar_api/models/free_busy_response.rb +135 -0
  76. data/lib/calendar_api/models/oauth_provider_error.rb +62 -0
  77. data/lib/calendar_api/models/oauth_scope.rb +41 -0
  78. data/lib/calendar_api/models/oauth_token.rb +96 -0
  79. data/lib/calendar_api/models/office_location.rb +116 -0
  80. data/lib/calendar_api/models/out_of_office_properties.rb +88 -0
  81. data/lib/calendar_api/models/person.rb +106 -0
  82. data/lib/calendar_api/models/reminder.rb +83 -0
  83. data/lib/calendar_api/models/reminder_method.rb +36 -0
  84. data/lib/calendar_api/models/response_status.rb +44 -0
  85. data/lib/calendar_api/models/send_updates.rb +40 -0
  86. data/lib/calendar_api/models/stop_channel_request.rb +85 -0
  87. data/lib/calendar_api/models/time_period.rb +102 -0
  88. data/lib/calendar_api/models/watch_request.rb +113 -0
  89. data/lib/calendar_api/models/working_location_properties.rb +107 -0
  90. data/lib/calendar_api/models/working_location_type.rb +40 -0
  91. data/lib/calendar_api/utilities/date_time_helper.rb +11 -0
  92. data/lib/calendar_api/utilities/file_wrapper.rb +28 -0
  93. data/lib/calendar_api.rb +114 -0
  94. metadata +176 -0
@@ -0,0 +1,177 @@
1
+ # calendar_api
2
+ #
3
+ # This file was automatically generated by APIMATIC v3.0 (
4
+ # https://www.apimatic.io ).
5
+
6
+ module CalendarApi
7
+ # An enum for SDK environments.
8
+ class Environment
9
+ # PRODUCTION: Google Calendar API v3
10
+ ENVIRONMENT = [
11
+ PRODUCTION = 'production'.freeze
12
+ ].freeze
13
+
14
+ # Converts a string or symbol into a valid Environment constant.
15
+ def self.from_value(value, default_value = PRODUCTION)
16
+ return default_value if value.nil?
17
+
18
+ default_value
19
+ end
20
+ end
21
+
22
+ # An enum for API servers.
23
+ class Server
24
+ SERVER = [
25
+ DEFAULT = 'default'.freeze,
26
+ AUTH_SERVER = 'auth server'.freeze,
27
+ ACCESS_TOKEN_SERVER = 'access token server'.freeze
28
+ ].freeze
29
+
30
+ # Converts a string or symbol into a valid Server constant.
31
+ def self.from_value(value, default_value = DEFAULT)
32
+ return default_value if value.nil?
33
+
34
+ str = value.to_s.strip.downcase
35
+ case str
36
+ when 'default' then DEFAULT
37
+ when 'auth_server' then AUTH_SERVER
38
+ when 'access_token_server' then ACCESS_TOKEN_SERVER
39
+
40
+ else
41
+ warn "[Server] Unknown server '#{value}', falling back to #{default_value} "
42
+ default_value
43
+ end
44
+ end
45
+ end
46
+
47
+ # All configuration including auth info and base URI for the API access
48
+ # are configured in this class.
49
+ class Configuration < CoreLibrary::HttpClientConfiguration
50
+ # The attribute readers for properties.
51
+ attr_reader :environment, :authorization_code_auth_credentials
52
+
53
+ class << self
54
+ attr_reader :environments
55
+ end
56
+
57
+ def initialize(
58
+ connection: nil, adapter: :net_http_persistent, timeout: 30,
59
+ max_retries: 0, retry_interval: 1, backoff_factor: 2,
60
+ retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
61
+ retry_methods: %i[get put], http_callback: nil, proxy_settings: nil,
62
+ logging_configuration: nil, environment: Environment::PRODUCTION,
63
+ authorization_code_auth_credentials: nil
64
+ )
65
+ super connection: connection, adapter: adapter, timeout: timeout,
66
+ max_retries: max_retries, retry_interval: retry_interval,
67
+ backoff_factor: backoff_factor, retry_statuses: retry_statuses,
68
+ retry_methods: retry_methods, http_callback: http_callback,
69
+ proxy_settings: proxy_settings,
70
+ logging_configuration: logging_configuration
71
+
72
+ # Current API environment
73
+ @environment = String(environment)
74
+
75
+ # The object holding OAuth 2 Authorization Code Grant credentials
76
+ @authorization_code_auth_credentials = authorization_code_auth_credentials
77
+
78
+ # Initializing OAuth 2 Authorization Code Grant credentials with the provided auth parameters
79
+ @authorization_code_auth_credentials = authorization_code_auth_credentials
80
+
81
+ # The Http Client to use for making requests.
82
+ set_http_client CoreLibrary::FaradayClient.new(self)
83
+ end
84
+
85
+ def clone_with(connection: nil, adapter: nil, timeout: nil,
86
+ max_retries: nil, retry_interval: nil, backoff_factor: nil,
87
+ retry_statuses: nil, retry_methods: nil, http_callback: nil,
88
+ proxy_settings: nil, logging_configuration: nil,
89
+ environment: nil, authorization_code_auth_credentials: nil)
90
+ connection ||= self.connection
91
+ adapter ||= self.adapter
92
+ timeout ||= self.timeout
93
+ max_retries ||= self.max_retries
94
+ retry_interval ||= self.retry_interval
95
+ backoff_factor ||= self.backoff_factor
96
+ retry_statuses ||= self.retry_statuses
97
+ retry_methods ||= self.retry_methods
98
+ http_callback ||= self.http_callback
99
+ proxy_settings ||= self.proxy_settings
100
+ logging_configuration ||= self.logging_configuration
101
+ environment ||= self.environment
102
+ authorization_code_auth_credentials ||= self.authorization_code_auth_credentials
103
+
104
+ Configuration.new(
105
+ connection: connection, adapter: adapter, timeout: timeout,
106
+ max_retries: max_retries, retry_interval: retry_interval,
107
+ backoff_factor: backoff_factor, retry_statuses: retry_statuses,
108
+ retry_methods: retry_methods, http_callback: http_callback,
109
+ proxy_settings: proxy_settings,
110
+ logging_configuration: logging_configuration, environment: environment,
111
+ authorization_code_auth_credentials: authorization_code_auth_credentials
112
+ )
113
+ end
114
+
115
+
116
+ # All the environments the SDK can run in.
117
+ ENVIRONMENTS = {
118
+ Environment::PRODUCTION => {
119
+ Server::DEFAULT => 'https://www.googleapis.com/calendar/v3',
120
+ Server::AUTH_SERVER => 'https://accounts.google.com/o/oauth2/v2',
121
+ Server::ACCESS_TOKEN_SERVER => 'https://oauth2.googleapis.com'
122
+ }
123
+ }.freeze
124
+
125
+ # Generates the appropriate base URI for the environment and the server.
126
+ # @param [Configuration::Server] server The server enum for which the base URI is
127
+ # required.
128
+ # @return [String] The base URI.
129
+ def get_base_uri(server = Server::DEFAULT)
130
+ ENVIRONMENTS[environment][server].clone
131
+ end
132
+
133
+ # Builds a Configuration instance using environment variables.
134
+ def self.build_default_config_from_env
135
+ # === Core environment ===
136
+ environment = Environment.from_value(ENV.fetch('ENVIRONMENT', 'production'))
137
+ timeout = (ENV['TIMEOUT'] || 30).to_f
138
+ max_retries = (ENV['MAX_RETRIES'] || 0).to_i
139
+ retry_interval = (ENV['RETRY_INTERVAL'] || 1).to_f
140
+ backoff_factor = (ENV['BACKOFF_FACTOR'] || 2).to_f
141
+ retry_statuses = ENV.fetch('RETRY_STATUSES',
142
+ '[408, 413, 429, 500, 502, 503, 504, 521, 522, 524]').gsub(/[\[\]]/, '')
143
+ .split(',')
144
+ .map(&:strip)
145
+ .map do |item|
146
+ item.match?(/\A\d+\z/) ? item.to_i : item.downcase
147
+ end
148
+ retry_methods = ENV.fetch('RETRY_METHODS', '%i[get put]').gsub(/[\[\]]/, '')
149
+ .split(',')
150
+ .map(&:strip)
151
+ .map do |item|
152
+ item.match?(/\A\d+\z/) ? item.to_i : item.downcase
153
+ end
154
+
155
+ # === Authentication credentials ===
156
+ authorization_code_auth_credentials = AuthorizationCodeAuthCredentials.from_env
157
+
158
+ # === Proxy settings ===
159
+ proxy_settings = ProxySettings.from_env
160
+ # === Logging Configuration ===
161
+ logging_configuration = LoggingConfiguration.from_env if LoggingConfiguration.any_logging_configured?
162
+
163
+ Configuration.new(
164
+ environment: environment,
165
+ timeout: timeout,
166
+ max_retries: max_retries,
167
+ retry_interval: retry_interval,
168
+ backoff_factor: backoff_factor,
169
+ retry_statuses: retry_statuses,
170
+ retry_methods: retry_methods,
171
+ authorization_code_auth_credentials: authorization_code_auth_credentials,
172
+ proxy_settings: proxy_settings,
173
+ logging_configuration: logging_configuration
174
+ )
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,21 @@
1
+ # calendar_api
2
+ #
3
+ # This file was automatically generated by APIMATIC v3.0 (
4
+ # https://www.apimatic.io ).
5
+
6
+ module CalendarApi
7
+ # Class for exceptions when there is a network error, status code error, etc.
8
+ class APIException < CoreLibrary::ApiException
9
+ # Provides a human-readable string representation of the object.
10
+ def to_s
11
+ class_name = self.class.name.split('::').last
12
+ "<#{class_name} status_code: #{@response_code}, reason: #{@reason}>"
13
+ end
14
+
15
+ # Provides a debugging-friendly string with detailed object information.
16
+ def inspect
17
+ class_name = self.class.name.split('::').last
18
+ "<#{class_name} status_code: #{@response_code.inspect}, reason: #{@reason.inspect}>"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,46 @@
1
+ # calendar_api
2
+ #
3
+ # This file was automatically generated by APIMATIC v3.0 (
4
+ # https://www.apimatic.io ).
5
+
6
+ module CalendarApi
7
+ # Standard Google API error response wrapper.
8
+ class ErrorResponseError1Exception < APIException
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
12
+ # Error details.
13
+ # @return [ErrorResponseError]
14
+ attr_accessor :error
15
+
16
+ # The constructor.
17
+ # @param [String] reason The reason for raising an exception.
18
+ # @param [HttpResponse] response The HttpReponse of the API call.
19
+ def initialize(reason, response)
20
+ super(reason, response)
21
+ hash = APIHelper.json_deserialize(@response.raw_body)
22
+ unbox(hash)
23
+ end
24
+
25
+ # Populates this object by extracting properties from a hash.
26
+ # @param [Hash] hash The deserialized response sent by the server in the
27
+ # response body.
28
+ def unbox(hash)
29
+ return nil unless hash
30
+
31
+ @error = ErrorResponseError.from_hash(hash['error']) if hash['error']
32
+ end
33
+
34
+ # Provides a human-readable string representation of the object.
35
+ def to_s
36
+ class_name = self.class.name.split('::').last
37
+ "<#{class_name} error: #{@error}>"
38
+ end
39
+
40
+ # Provides a debugging-friendly string with detailed object information.
41
+ def inspect
42
+ class_name = self.class.name.split('::').last
43
+ "<#{class_name} error: #{@error.inspect}>"
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,64 @@
1
+ # calendar_api
2
+ #
3
+ # This file was automatically generated by APIMATIC v3.0 (
4
+ # https://www.apimatic.io ).
5
+
6
+ module CalendarApi
7
+ # OAuth 2 Authorization endpoint exception.
8
+ class OauthProviderException < APIException
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
12
+ # Gets or sets error code.
13
+ # @return [OauthProviderError]
14
+ attr_accessor :error
15
+
16
+ # Gets or sets human-readable text providing additional information on
17
+ # error.
18
+ # Used to assist the client developer in understanding the error that
19
+ # occurred.
20
+ # @return [String]
21
+ attr_accessor :error_description
22
+
23
+ # Gets or sets a URI identifying a human-readable web page with information
24
+ # about the error, used to provide the client developer with additional
25
+ # information about the error.
26
+ # @return [String]
27
+ attr_accessor :error_uri
28
+
29
+ # The constructor.
30
+ # @param [String] reason The reason for raising an exception.
31
+ # @param [HttpResponse] response The HttpReponse of the API call.
32
+ def initialize(reason, response)
33
+ super(reason, response)
34
+ hash = APIHelper.json_deserialize(@response.raw_body)
35
+ unbox(hash)
36
+ end
37
+
38
+ # Populates this object by extracting properties from a hash.
39
+ # @param [Hash] hash The deserialized response sent by the server in the
40
+ # response body.
41
+ def unbox(hash)
42
+ return nil unless hash
43
+
44
+ @error = hash.key?('error') ? hash['error'] : nil
45
+ @error_description =
46
+ hash.key?('error_description') ? hash['error_description'] : SKIP
47
+ @error_uri = hash.key?('error_uri') ? hash['error_uri'] : SKIP
48
+ end
49
+
50
+ # Provides a human-readable string representation of the object.
51
+ def to_s
52
+ class_name = self.class.name.split('::').last
53
+ "<#{class_name} error: #{@error}, error_description: #{@error_description}, error_uri:"\
54
+ " #{@error_uri}>"
55
+ end
56
+
57
+ # Provides a debugging-friendly string with detailed object information.
58
+ def inspect
59
+ class_name = self.class.name.split('::').last
60
+ "<#{class_name} error: #{@error.inspect}, error_description: #{@error_description.inspect},"\
61
+ " error_uri: #{@error_uri.inspect}>"
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,19 @@
1
+ # calendar_api
2
+ #
3
+ # This file was automatically generated by APIMATIC v3.0 (
4
+ # https://www.apimatic.io ).
5
+
6
+ module CalendarApi
7
+ # Http response received.
8
+ class ApiResponse < CoreLibrary::ApiResponse
9
+ # The constructor
10
+ # @param [HttpResponse] http_response The original, raw response from the api.
11
+ # @param [Object] data The data field specified for the response.
12
+ # @param [Array<String>] errors Any errors returned by the server.
13
+ def initialize(http_response,
14
+ data: nil,
15
+ errors: nil)
16
+ super
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,162 @@
1
+ # calendar_api
2
+ #
3
+ # This file was automatically generated by APIMATIC v3.0 (
4
+ # https://www.apimatic.io ).
5
+
6
+ module CalendarApi
7
+ # Utility class for OAuth 2 authorization and token management.
8
+ class Oauth2 < CoreLibrary::HeaderAuth
9
+ include CoreLibrary
10
+ # Display error message on occurrence of authentication failure.
11
+ # @returns [String] The oAuth error message.
12
+ def error_message
13
+ 'AuthorizationCodeAuth: OAuthToken is undefined or expired.'
14
+ end
15
+
16
+ # Initialization constructor.
17
+ def initialize(authorization_code_auth_credentials, config)
18
+ auth_params = {}
19
+ @_oauth_client_id = authorization_code_auth_credentials.oauth_client_id unless
20
+ authorization_code_auth_credentials.nil? || authorization_code_auth_credentials.oauth_client_id.nil?
21
+ @_oauth_client_secret = authorization_code_auth_credentials.oauth_client_secret unless
22
+ authorization_code_auth_credentials.nil? || authorization_code_auth_credentials.oauth_client_secret.nil?
23
+ @_oauth_redirect_uri = authorization_code_auth_credentials.oauth_redirect_uri unless
24
+ authorization_code_auth_credentials.nil? || authorization_code_auth_credentials.oauth_redirect_uri.nil?
25
+ @_oauth_token = authorization_code_auth_credentials.oauth_token unless
26
+ authorization_code_auth_credentials.nil? || authorization_code_auth_credentials.oauth_token.nil?
27
+ @_oauth_scopes = authorization_code_auth_credentials.oauth_scopes unless
28
+ authorization_code_auth_credentials.nil? || authorization_code_auth_credentials.oauth_scopes.nil?
29
+ @_config = config
30
+ @_o_auth_api = OauthAuthorizationApi.new(config)
31
+ auth_params[:Authorization] = "Bearer #{@_oauth_token.access_token}" unless @_oauth_token.nil?
32
+
33
+ super auth_params
34
+ end
35
+
36
+ # Validates the oAuth token.
37
+ # @return [Boolean] true if the token is present and not expired.
38
+ def valid
39
+ !@_oauth_token.nil? && !token_expired?(@_oauth_token)
40
+ end
41
+
42
+ # Builds and returns an authorization URL.
43
+ # The user is expected to obtain an authorization code from this URL and then call the
44
+ # fetch token function with that authorization code.
45
+ # @param [String] state An opaque state string.
46
+ # @param [Hash] additional_params Any additional query parameters to be added to the URL.
47
+ # @return [String] The authorization URL.
48
+ def get_authorization_url(state: nil, additional_params: nil)
49
+ auth_url = @_config.get_base_uri_executor.call(Server::AUTH_SERVER)
50
+ auth_url += '/auth'
51
+ query_params = {
52
+ 'response_type' => 'code',
53
+ 'client_id' => @_oauth_client_id,
54
+ 'redirect_uri' => @_oauth_redirect_uri
55
+ }
56
+ query_params['scope'] = Array(@_o_auth_scopes).compact.join(' ') if @_o_auth_scopes
57
+ query_params['state'] = state if state
58
+ query_params.merge!(additional_params) if additional_params
59
+ auth_url = APIHelper.append_url_with_query_parameters(auth_url,
60
+ query_params)
61
+ APIHelper.clean_url(auth_url)
62
+ end
63
+
64
+ # Builds the basic auth header for endpoints in the OAuth Authorization Controller.
65
+ # @return [String] The value of the Authentication header.
66
+ def build_basic_auth_header
67
+ "Basic #{AuthHelper.get_base64_encoded_value(@_oauth_client_id, @_oauth_client_secret)}"
68
+ end
69
+
70
+ # Fetches the token.
71
+ # @param [String] auth_code The authentication code.
72
+ # @param [Hash] additional_params Any additional form parameters.
73
+ # @return [OAuthToken] The oAuth token instance.
74
+ def fetch_token(auth_code, additional_params: nil)
75
+ token = @_o_auth_api.request_token(
76
+ build_basic_auth_header,
77
+ auth_code,
78
+ @_oauth_redirect_uri,
79
+ _field_parameters: additional_params
80
+ ).data
81
+ if token.respond_to?('expires_in') && !token.expires_in.nil?
82
+ token.expiry = AuthHelper.get_token_expiry(token.expires_in, Time.now.utc.to_i)
83
+ end
84
+ token
85
+ end
86
+
87
+ # Checks if OAuth token has expired.
88
+ # @param [OAuthToken] token The oAuth token instance.
89
+ # @return [Boolean] true if the token is present and not expired.
90
+ def token_expired?(token)
91
+ token.respond_to?('expiry') && AuthHelper.token_expired?(token.expiry)
92
+ end
93
+
94
+ # Refreshes OAuth token.
95
+ # @param [Hash] additional_params Any additional form parameters.
96
+ # @return [OAuthToken] The oAuth token instance.
97
+ def refresh_token(additional_params: nil)
98
+ token = @_o_auth_api.refresh_token(
99
+ build_basic_auth_header,
100
+ @_oauth_token.refresh_token,
101
+ scope: !@_oauth_scopes.nil? ? Array(@_oauth_scopes).compact.join(' ') : nil,
102
+ _field_parameters: additional_params
103
+ ).data
104
+ if token.respond_to?('expires_in') && !token.expires_in.nil?
105
+ token.expiry = AuthHelper.get_token_expiry(token.expires_in, Time.now.utc.to_i)
106
+ end
107
+ token
108
+ end
109
+ end
110
+
111
+ # Data class for AuthorizationCodeAuthCredentials.
112
+ class AuthorizationCodeAuthCredentials
113
+ attr_reader :oauth_client_id, :oauth_client_secret, :oauth_redirect_uri,
114
+ :oauth_token, :oauth_scopes
115
+
116
+ def initialize(oauth_client_id:, oauth_client_secret:, oauth_redirect_uri:,
117
+ oauth_token: nil, oauth_scopes: nil)
118
+ raise ArgumentError, 'oauth_client_id cannot be nil' if oauth_client_id.nil?
119
+ raise ArgumentError, 'oauth_client_secret cannot be nil' if oauth_client_secret.nil?
120
+ raise ArgumentError, 'oauth_redirect_uri cannot be nil' if oauth_redirect_uri.nil?
121
+
122
+ @oauth_client_id = oauth_client_id
123
+ @oauth_client_secret = oauth_client_secret
124
+ @oauth_redirect_uri = oauth_redirect_uri
125
+ @oauth_token = oauth_token
126
+ @oauth_scopes = oauth_scopes
127
+ end
128
+
129
+ def self.from_env
130
+ oauth_client_id = ENV['OAUTH_CLIENT_ID']
131
+ oauth_client_secret = ENV['OAUTH_CLIENT_SECRET']
132
+ oauth_redirect_uri = ENV['OAUTH_REDIRECT_URI']
133
+ oauth_scopes = ENV['OAUTH_SCOPES']
134
+ all_nil = [
135
+ oauth_client_id,
136
+ oauth_client_secret,
137
+ oauth_redirect_uri
138
+ ].all?(&:nil?)
139
+ return nil if all_nil
140
+
141
+ new(oauth_client_id: oauth_client_id,
142
+ oauth_client_secret: oauth_client_secret,
143
+ oauth_redirect_uri: oauth_redirect_uri, oauth_scopes: oauth_scopes)
144
+ end
145
+
146
+ def clone_with(oauth_client_id: nil, oauth_client_secret: nil,
147
+ oauth_redirect_uri: nil, oauth_token: nil, oauth_scopes: nil)
148
+ oauth_client_id ||= self.oauth_client_id
149
+ oauth_client_secret ||= self.oauth_client_secret
150
+ oauth_redirect_uri ||= self.oauth_redirect_uri
151
+ oauth_token ||= self.oauth_token
152
+ oauth_scopes ||= self.oauth_scopes
153
+
154
+ AuthorizationCodeAuthCredentials.new(
155
+ oauth_client_id: oauth_client_id,
156
+ oauth_client_secret: oauth_client_secret,
157
+ oauth_redirect_uri: oauth_redirect_uri, oauth_token: oauth_token,
158
+ oauth_scopes: oauth_scopes
159
+ )
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,10 @@
1
+ # calendar_api
2
+ #
3
+ # This file was automatically generated by APIMATIC v3.0 (
4
+ # https://www.apimatic.io ).
5
+
6
+ module CalendarApi
7
+ # HttpCallBack allows defining callables for pre and post API calls.
8
+ class HttpCallBack < CoreLibrary::HttpCallback
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # calendar_api
2
+ #
3
+ # This file was automatically generated by APIMATIC v3.0 (
4
+ # https://www.apimatic.io ).
5
+
6
+ module CalendarApi
7
+ # HTTP Methods Enumeration.
8
+ class HttpMethodEnum < CoreLibrary::HttpMethod
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # calendar_api
2
+ #
3
+ # This file was automatically generated by APIMATIC v3.0 (
4
+ # https://www.apimatic.io ).
5
+
6
+ module CalendarApi
7
+ # Represents a single Http Request.
8
+ class HttpRequest < CoreLibrary::HttpRequest
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # calendar_api
2
+ #
3
+ # This file was automatically generated by APIMATIC v3.0 (
4
+ # https://www.apimatic.io ).
5
+
6
+ module CalendarApi
7
+ # Http response received.
8
+ class HttpResponse < CoreLibrary::HttpResponse
9
+ end
10
+ end
@@ -0,0 +1,22 @@
1
+ # calendar_api
2
+ #
3
+ # This file was automatically generated by APIMATIC v3.0 (
4
+ # https://www.apimatic.io ).
5
+
6
+ module CalendarApi
7
+ ##
8
+ # ProxySettings encapsulates HTTP proxy configuration for Faraday,
9
+ # including optional basic authentication.
10
+ #
11
+ class ProxySettings < CoreLibrary::ProxySettings
12
+ def self.from_env
13
+ address = ENV['PROXY_ADDRESS']
14
+ port = ENV['PROXY_PORT']
15
+ username = ENV['PROXY_USERNAME']
16
+ password = ENV['PROXY_PASSWORD']
17
+ return nil if address.nil? || address.strip.empty?
18
+
19
+ new(address: address, port: port, username: username, password: password)
20
+ end
21
+ end
22
+ end