smartsheet 2.77.0 → 2.101.1

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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +12 -12
  3. data/.rubocop.yml +4 -4
  4. data/.travis.yml +29 -15
  5. data/.yardopts +3 -3
  6. data/ADVANCED.md +78 -78
  7. data/CHANGELOG.md +133 -112
  8. data/Gemfile +6 -6
  9. data/LICENSE +202 -202
  10. data/README.md +248 -246
  11. data/Rakefile +29 -29
  12. data/bin/console +14 -14
  13. data/bin/setup +8 -8
  14. data/lib/smartsheet.rb +2 -2
  15. data/lib/smartsheet/api/body_builder.rb +25 -25
  16. data/lib/smartsheet/api/endpoint_spec.rb +54 -54
  17. data/lib/smartsheet/api/faraday_adapter/faraday_net_client.rb +45 -45
  18. data/lib/smartsheet/api/faraday_adapter/faraday_response.rb +70 -70
  19. data/lib/smartsheet/api/faraday_adapter/middleware/faraday_error_translator.rb +20 -20
  20. data/lib/smartsheet/api/faraday_adapter/middleware/response_parser.rb +25 -25
  21. data/lib/smartsheet/api/file_spec.rb +55 -55
  22. data/lib/smartsheet/api/header_builder.rb +96 -96
  23. data/lib/smartsheet/api/request.rb +42 -42
  24. data/lib/smartsheet/api/request_client.rb +43 -43
  25. data/lib/smartsheet/api/request_logger.rb +182 -182
  26. data/lib/smartsheet/api/request_spec.rb +57 -57
  27. data/lib/smartsheet/api/response_net_client_decorator.rb +54 -54
  28. data/lib/smartsheet/api/retry_logic.rb +40 -40
  29. data/lib/smartsheet/api/retry_net_client_decorator.rb +37 -37
  30. data/lib/smartsheet/api/url_builder.rb +25 -25
  31. data/lib/smartsheet/client.rb +193 -193
  32. data/lib/smartsheet/constants.rb +18 -18
  33. data/lib/smartsheet/endpoints/contacts/contacts.rb +30 -30
  34. data/lib/smartsheet/endpoints/events/events.rb +20 -20
  35. data/lib/smartsheet/endpoints/favorites/favorites.rb +159 -159
  36. data/lib/smartsheet/endpoints/folders/folders.rb +125 -125
  37. data/lib/smartsheet/endpoints/groups/groups.rb +83 -83
  38. data/lib/smartsheet/endpoints/home/home.rb +20 -20
  39. data/lib/smartsheet/endpoints/reports/reports.rb +100 -100
  40. data/lib/smartsheet/endpoints/reports/reports_share.rb +69 -69
  41. data/lib/smartsheet/endpoints/search/search.rb +30 -30
  42. data/lib/smartsheet/endpoints/server_info/server_info.rb +21 -21
  43. data/lib/smartsheet/endpoints/share/share.rb +58 -58
  44. data/lib/smartsheet/endpoints/sheets/automation_rules.rb +55 -55
  45. data/lib/smartsheet/endpoints/sheets/cells.rb +82 -82
  46. data/lib/smartsheet/endpoints/sheets/columns.rb +66 -66
  47. data/lib/smartsheet/endpoints/sheets/comments.rb +64 -64
  48. data/lib/smartsheet/endpoints/sheets/comments_attachments.rb +78 -78
  49. data/lib/smartsheet/endpoints/sheets/cross_sheet_references.rb +45 -45
  50. data/lib/smartsheet/endpoints/sheets/discussions.rb +84 -84
  51. data/lib/smartsheet/endpoints/sheets/discussions_attachments.rb +22 -22
  52. data/lib/smartsheet/endpoints/sheets/rows.rb +106 -106
  53. data/lib/smartsheet/endpoints/sheets/rows_attachments.rb +92 -92
  54. data/lib/smartsheet/endpoints/sheets/sheets.rb +514 -510
  55. data/lib/smartsheet/endpoints/sheets/sheets_attachments.rb +174 -174
  56. data/lib/smartsheet/endpoints/sheets/sheets_share.rb +69 -69
  57. data/lib/smartsheet/endpoints/sheets/sheets_summaries.rb +123 -0
  58. data/lib/smartsheet/endpoints/sights/sights.rb +101 -101
  59. data/lib/smartsheet/endpoints/sights/sights_share.rb +69 -69
  60. data/lib/smartsheet/endpoints/templates/templates.rb +29 -29
  61. data/lib/smartsheet/endpoints/token/token.rb +70 -66
  62. data/lib/smartsheet/endpoints/update_requests/sent_update_requests.rb +44 -44
  63. data/lib/smartsheet/endpoints/update_requests/update_requests.rb +74 -74
  64. data/lib/smartsheet/endpoints/users/alternate_emails.rb +79 -79
  65. data/lib/smartsheet/endpoints/users/users.rb +123 -77
  66. data/lib/smartsheet/endpoints/webhooks/webhooks.rb +71 -71
  67. data/lib/smartsheet/endpoints/workspaces/workspaces.rb +87 -87
  68. data/lib/smartsheet/endpoints/workspaces/workspaces_share.rb +70 -70
  69. data/lib/smartsheet/error.rb +69 -69
  70. data/lib/smartsheet/general_request.rb +74 -74
  71. data/lib/smartsheet/version.rb +5 -5
  72. data/smartsheet.gemspec +54 -54
  73. metadata +24 -12
@@ -1,57 +1,57 @@
1
- require 'json'
2
- require 'awrence'
3
-
4
- module Smartsheet
5
- module API
6
- # Specification for a single API request's arguments
7
- class RequestSpec
8
- attr_reader :file_spec, :url_args, :params, :header_overrides, :body
9
- private :file_spec
10
-
11
- # @param params [Hash{Object=>Object}] URL parameters for the request
12
- #
13
- # @param header_overrides [Hash{Object=>Object}] HTTP headers to sent in the request; these
14
- # override all default headers sent by the SDK and the particular endpoint
15
- #
16
- # @param body [Object] The body of the HTTP request, to be interpreted based on the endpoint
17
- # specification
18
- #
19
- # @param file_spec [PathFileSpec, ObjectFileSpec] Specification for files, to be used when
20
- # an endpoint requires a file upload
21
- #
22
- # @param **url_args [Hash{Symbol=>Object}] Values that will be used to fill in parameterized
23
- # segments of an endpoint path specificaiton
24
- def initialize(params: {}, header_overrides: {}, body: nil, file_spec: nil, **url_args)
25
- @url_args = url_args
26
- @params = params
27
- @header_overrides = header_overrides
28
- @body = body
29
- @file_spec = file_spec
30
- end
31
-
32
- def filename
33
- file_spec.filename
34
- end
35
-
36
- def content_type
37
- file_spec.content_type
38
- end
39
-
40
- def file_length
41
- file_spec.file_length
42
- end
43
-
44
- def json_body
45
- if body.nil? || body.is_a?(String)
46
- body
47
- else
48
- body.to_camelback_keys.to_json
49
- end
50
- end
51
-
52
- def file_body
53
- file_spec.upload_io
54
- end
55
- end
56
- end
57
- end
1
+ require 'json'
2
+ require 'awrence'
3
+
4
+ module Smartsheet
5
+ module API
6
+ # Specification for a single API request's arguments
7
+ class RequestSpec
8
+ attr_reader :file_spec, :url_args, :params, :header_overrides, :body
9
+ private :file_spec
10
+
11
+ # @param params [Hash{Object=>Object}] URL parameters for the request
12
+ #
13
+ # @param header_overrides [Hash{Object=>Object}] HTTP headers to sent in the request; these
14
+ # override all default headers sent by the SDK and the particular endpoint
15
+ #
16
+ # @param body [Object] The body of the HTTP request, to be interpreted based on the endpoint
17
+ # specification
18
+ #
19
+ # @param file_spec [PathFileSpec, ObjectFileSpec] Specification for files, to be used when
20
+ # an endpoint requires a file upload
21
+ #
22
+ # @param **url_args [Hash{Symbol=>Object}] Values that will be used to fill in parameterized
23
+ # segments of an endpoint path specificaiton
24
+ def initialize(params: {}, header_overrides: {}, body: nil, file_spec: nil, **url_args)
25
+ @url_args = url_args
26
+ @params = params
27
+ @header_overrides = header_overrides
28
+ @body = body
29
+ @file_spec = file_spec
30
+ end
31
+
32
+ def filename
33
+ file_spec.filename
34
+ end
35
+
36
+ def content_type
37
+ file_spec.content_type
38
+ end
39
+
40
+ def file_length
41
+ file_spec.file_length
42
+ end
43
+
44
+ def json_body
45
+ if body.nil? || body.is_a?(String)
46
+ body
47
+ else
48
+ body.to_camelback_keys.to_json
49
+ end
50
+ end
51
+
52
+ def file_body
53
+ file_spec.upload_io
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,55 +1,55 @@
1
- require 'plissken'
2
-
3
- require 'smartsheet/error'
4
-
5
- module Smartsheet
6
- module API
7
- # Passes requests to the decorated client, and parses responses into expected result types
8
- class ResponseNetClientDecorator
9
- def initialize(client, json_output: false, logger: MuteRequestLogger.new)
10
- @json_output = json_output
11
- @client = client
12
- @logger = logger
13
- end
14
-
15
- def make_request(request)
16
- response = begin
17
- client.make_request(request)
18
- rescue Smartsheet::HttpResponseError => e
19
- logger.log_http_error_response(request, e)
20
- raise e
21
- end
22
-
23
- parse(request, response)
24
- end
25
-
26
- private
27
-
28
- attr_reader :json_output, :client, :logger
29
-
30
- def parse(request, response)
31
- if response.success?
32
- logger.log_successful_response(response)
33
- parse_success(response)
34
- else
35
- logger.log_api_error_response(request, response)
36
- parse_failure(response)
37
- end
38
- end
39
-
40
- def parse_success(response)
41
- if json_output
42
- response.result.to_json
43
- elsif response.result.respond_to? :to_snake_keys
44
- response.result.to_snake_keys
45
- else
46
- response.result
47
- end
48
- end
49
-
50
- def parse_failure(response)
51
- raise Smartsheet::ApiError.new(response)
52
- end
53
- end
54
- end
1
+ require 'plissken'
2
+
3
+ require 'smartsheet/error'
4
+
5
+ module Smartsheet
6
+ module API
7
+ # Passes requests to the decorated client, and parses responses into expected result types
8
+ class ResponseNetClientDecorator
9
+ def initialize(client, json_output: false, logger: MuteRequestLogger.new)
10
+ @json_output = json_output
11
+ @client = client
12
+ @logger = logger
13
+ end
14
+
15
+ def make_request(request)
16
+ response = begin
17
+ client.make_request(request)
18
+ rescue Smartsheet::HttpResponseError => e
19
+ logger.log_http_error_response(request, e)
20
+ raise e
21
+ end
22
+
23
+ parse(request, response)
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :json_output, :client, :logger
29
+
30
+ def parse(request, response)
31
+ if response.success?
32
+ logger.log_successful_response(response)
33
+ parse_success(response)
34
+ else
35
+ logger.log_api_error_response(request, response)
36
+ parse_failure(response)
37
+ end
38
+ end
39
+
40
+ def parse_success(response)
41
+ if json_output
42
+ response.result.to_json
43
+ elsif response.result.respond_to? :to_snake_keys
44
+ response.result.to_snake_keys
45
+ else
46
+ response.result
47
+ end
48
+ end
49
+
50
+ def parse_failure(response)
51
+ raise Smartsheet::ApiError.new(response)
52
+ end
53
+ end
54
+ end
55
55
  end
@@ -1,40 +1,40 @@
1
- require 'smartsheet/constants'
2
-
3
- module Smartsheet
4
- module API
5
- # Accepts a callable proc and a predicate, calling the proc repeatedly with backoff until the
6
- # provided time limit is reached, or until the predicate applied to the proc's result returns
7
- # false.
8
- class RetryLogic
9
- include Smartsheet::Constants
10
-
11
- def initialize(max_retry_time: DEFAULT_MAX_RETRY_TIME, backoff_method: DEFAULT_BACKOFF_METHOD)
12
- @max_retry_time = max_retry_time
13
- @backoff_method = backoff_method
14
- end
15
-
16
- def run(should_retry, &method_to_run)
17
- end_time = Time.now.to_i + max_retry_time
18
-
19
- _run(method_to_run, should_retry, end_time, 0)
20
- end
21
-
22
- private
23
-
24
- attr_reader :backoff_method, :max_retry_time
25
-
26
- def _run(method_to_run, should_retry, end_time, iteration)
27
- result = method_to_run.call(iteration)
28
-
29
- backoff = backoff_method.call(iteration, result)
30
-
31
- if backoff == :stop || Time.now.to_i + backoff >= end_time || !should_retry.call(result)
32
- return result
33
- end
34
-
35
- sleep backoff
36
- _run(method_to_run, should_retry, end_time, iteration + 1)
37
- end
38
- end
39
- end
40
- end
1
+ require 'smartsheet/constants'
2
+
3
+ module Smartsheet
4
+ module API
5
+ # Accepts a callable proc and a predicate, calling the proc repeatedly with backoff until the
6
+ # provided time limit is reached, or until the predicate applied to the proc's result returns
7
+ # false.
8
+ class RetryLogic
9
+ include Smartsheet::Constants
10
+
11
+ def initialize(max_retry_time: DEFAULT_MAX_RETRY_TIME, backoff_method: DEFAULT_BACKOFF_METHOD)
12
+ @max_retry_time = max_retry_time
13
+ @backoff_method = backoff_method
14
+ end
15
+
16
+ def run(should_retry, &method_to_run)
17
+ end_time = Time.now.to_i + max_retry_time
18
+
19
+ _run(method_to_run, should_retry, end_time, 0)
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :backoff_method, :max_retry_time
25
+
26
+ def _run(method_to_run, should_retry, end_time, iteration)
27
+ result = method_to_run.call(iteration)
28
+
29
+ backoff = backoff_method.call(iteration, result)
30
+
31
+ if backoff == :stop || Time.now.to_i + backoff >= end_time || !should_retry.call(result)
32
+ return result
33
+ end
34
+
35
+ sleep backoff
36
+ _run(method_to_run, should_retry, end_time, iteration + 1)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,38 +1,38 @@
1
- require 'smartsheet/api/request_logger'
2
-
3
- module Smartsheet
4
- module API
5
- # Passes requests to the decorated client, retrying the request based on the provided
6
- # {RetryLogic} when retry-eligible errors arise
7
- class RetryNetClientDecorator
8
- SHOULD_RETRY = ->(response) { response.should_retry? }
9
-
10
- attr_reader :client, :retrier, :logger
11
- private :client, :retrier, :logger
12
-
13
- def initialize(client, retrier, logger: MuteRequestLogger.new)
14
- @client = client
15
- @retrier = retrier
16
- @logger = logger
17
- end
18
-
19
- def make_request(request)
20
- total_attempts = 0
21
-
22
- retried_response = retrier.run(SHOULD_RETRY) do |iteration|
23
- response = client.make_request(request)
24
-
25
- total_attempts = iteration + 1
26
- logger.log_retry_attempt(request, response, total_attempts) if SHOULD_RETRY.call(response)
27
- response
28
- end
29
-
30
- unless retried_response.success? || total_attempts < 2
31
- logger.log_retry_failure(total_attempts)
32
- end
33
-
34
- retried_response
35
- end
36
- end
37
- end
1
+ require 'smartsheet/api/request_logger'
2
+
3
+ module Smartsheet
4
+ module API
5
+ # Passes requests to the decorated client, retrying the request based on the provided
6
+ # {RetryLogic} when retry-eligible errors arise
7
+ class RetryNetClientDecorator
8
+ SHOULD_RETRY = ->(response) { response.should_retry? }
9
+
10
+ attr_reader :client, :retrier, :logger
11
+ private :client, :retrier, :logger
12
+
13
+ def initialize(client, retrier, logger: MuteRequestLogger.new)
14
+ @client = client
15
+ @retrier = retrier
16
+ @logger = logger
17
+ end
18
+
19
+ def make_request(request)
20
+ total_attempts = 0
21
+
22
+ retried_response = retrier.run(SHOULD_RETRY) do |iteration|
23
+ response = client.make_request(request)
24
+
25
+ total_attempts = iteration + 1
26
+ logger.log_retry_attempt(request, response, total_attempts) if SHOULD_RETRY.call(response)
27
+ response
28
+ end
29
+
30
+ unless retried_response.success? || total_attempts < 2
31
+ logger.log_retry_failure(total_attempts)
32
+ end
33
+
34
+ retried_response
35
+ end
36
+ end
37
+ end
38
38
  end
@@ -1,25 +1,25 @@
1
- require 'smartsheet/constants'
2
-
3
- module Smartsheet
4
- module API
5
- # Constructs parameterized URLs for accessing the Smartsheet API
6
- class UrlBuilder
7
- def initialize(endpoint_spec, request_spec, base_url)
8
- @segments = endpoint_spec.url_segments
9
- @args = request_spec.url_args
10
- @base_url = base_url
11
- end
12
-
13
- def build
14
- segments
15
- .collect { |seg| seg.is_a?(Symbol) ? args[seg] : seg }
16
- .unshift(base_url)
17
- .join('/')
18
- end
19
-
20
- private
21
-
22
- attr_accessor :segments, :args, :base_url
23
- end
24
- end
25
- end
1
+ require 'smartsheet/constants'
2
+
3
+ module Smartsheet
4
+ module API
5
+ # Constructs parameterized URLs for accessing the Smartsheet API
6
+ class UrlBuilder
7
+ def initialize(endpoint_spec, request_spec, base_url)
8
+ @segments = endpoint_spec.url_segments
9
+ @args = request_spec.url_args
10
+ @base_url = base_url
11
+ end
12
+
13
+ def build
14
+ segments
15
+ .collect { |seg| seg.is_a?(Symbol) ? args[seg] : seg }
16
+ .unshift(base_url)
17
+ .join('/')
18
+ end
19
+
20
+ private
21
+
22
+ attr_accessor :segments, :args, :base_url
23
+ end
24
+ end
25
+ end
@@ -1,193 +1,193 @@
1
- require 'smartsheet/api/faraday_adapter/faraday_net_client'
2
- require 'smartsheet/api/retry_net_client_decorator'
3
- require 'smartsheet/api/response_net_client_decorator'
4
- require 'smartsheet/api/request_client'
5
- require 'smartsheet/api/retry_logic'
6
- require 'smartsheet/api/request_logger'
7
- require 'smartsheet/general_request'
8
-
9
- require 'smartsheet/endpoints/contacts/contacts'
10
- require 'smartsheet/endpoints/events/events'
11
- require 'smartsheet/endpoints/favorites/favorites'
12
- require 'smartsheet/endpoints/folders/folders'
13
- require 'smartsheet/endpoints/groups/groups'
14
- require 'smartsheet/endpoints/home/home'
15
- require 'smartsheet/endpoints/reports/reports'
16
- require 'smartsheet/endpoints/search/search'
17
- require 'smartsheet/endpoints/server_info/server_info'
18
- require 'smartsheet/endpoints/sheets/sheets'
19
- require 'smartsheet/endpoints/sights/sights'
20
- require 'smartsheet/endpoints/templates/templates'
21
- require 'smartsheet/endpoints/token/token'
22
- require 'smartsheet/endpoints/update_requests/update_requests'
23
- require 'smartsheet/endpoints/users/users'
24
- require 'smartsheet/endpoints/webhooks/webhooks'
25
- require 'smartsheet/endpoints/workspaces/workspaces'
26
-
27
-
28
- module Smartsheet
29
- # The entry point to the SDK. API endpoint categories are accessed through this object's readable
30
- # attributes.
31
- #
32
- # @!attribute [r] contacts
33
- # @return [Contacts]
34
- # @!attribute [r] favorites
35
- # @return [Favorites]
36
- # @!attribute [r] folders
37
- # @return [Folders]
38
- # @!attribute [r] groups
39
- # @return [Groups]
40
- # @!attribute [r] home
41
- # @return [Home]
42
- # @!attribute [r] reports
43
- # @return [Reports]
44
- # @!attribute [r] search
45
- # @return [Search]
46
- # @!attribute [r] server_info
47
- # @return [ServerInfo]
48
- # @!attribute [r] sheets
49
- # @return [Sheets]
50
- # @!attribute [r] sights
51
- # @return [Sights]
52
- # @!attribute [r] templates
53
- # @return [Templates]
54
- # @!attribute [r] token
55
- # @return [Token]
56
- # @!attribute [r] update_requests
57
- # @return [UpdateRequests]
58
- # @!attribute [r] users
59
- # @return [Users]
60
- # @!attribute [r] webhooks
61
- # @return [Webhooks]
62
- # @!attribute [r] workspaces
63
- # @return [Workspaces]
64
- class Client
65
- include GeneralRequest
66
- include Smartsheet::Constants
67
-
68
- attr_reader :contacts, :events, :favorites, :folders, :groups, :home, :reports, :search, :server_info,
69
- :sheets, :sights, :templates, :token, :update_requests, :users, :webhooks,
70
- :workspaces
71
-
72
- # @param token [String] access token for the API; if nil or empty, uses environment variable
73
- # `SMARTSHEET_ACCESS_TOKEN`
74
- # @param logger [Logger] a logger to which request and response info will be recorded
75
- # @param log_full_body [Boolean] when true, request and response bodies will not be truncated in
76
- # the logs
77
- # @param user_agent [String] the name of the application, sent as part of the user agent for
78
- # requests; defaults as the name of the application
79
- # @param json_output [Boolean] when true, endpoints return raw JSON strings instead of hashes
80
- # @param assume_user [String] the email address of the user to impersonate; only available for
81
- # admin roles
82
- # @param max_retry_time [Fixnum] overrides the maximum number of seconds during which eligible
83
- # errors will be retried
84
- # @param backoff_method [Proc] overrides the backoff calculation method, accepting the index of
85
- # the current retry attempt (0-based) and returning the number of seconds to wait before
86
- # retrying the call again, or `:stop` to halt retrying and return the latest error.
87
- #
88
- # Example - Wait 1 second before the first retry, 2 seconds before
89
- # the second, and so on:
90
- # ```ruby
91
- # ->(x){ x + 1 }
92
- # ```
93
- #
94
- # Example - Try twice, then halt:
95
- # ```ruby
96
- # ->(x){ if x < 2 then x + 1 else :stop end }
97
- # ```
98
- # @param base_url [String] overrides the base URL used when constructing API calls; for example,
99
- # the default takes the form of `https://api.smartsheet.com/2.0`
100
- def initialize(
101
- token: nil,
102
- logger: nil,
103
- log_full_body: false,
104
- user_agent: nil,
105
- json_output: false,
106
- assume_user: nil,
107
- max_retry_time: nil,
108
- backoff_method: nil,
109
- base_url: API_URL
110
- )
111
-
112
- request_logger =
113
- logger ?
114
- API::RequestLogger.new(logger, log_full_body: log_full_body) :
115
- API::MuteRequestLogger.new
116
-
117
- token = token_env_var if token.nil? || token.empty?
118
-
119
- app_user_agent = user_agent.nil? ? File.basename($PROGRAM_NAME) : user_agent
120
-
121
- net_client = API::FaradayNetClient.new
122
-
123
- retry_logic = init_retry_logic(max_retry_time, backoff_method)
124
-
125
- retrying_client = API::RetryNetClientDecorator.new(
126
- net_client,
127
- retry_logic,
128
- logger: request_logger
129
- )
130
-
131
- response_client = API::ResponseNetClientDecorator.new(
132
- retrying_client,
133
- json_output: json_output,
134
- logger: request_logger
135
- )
136
-
137
- @client = API::RequestClient.new(
138
- token,
139
- response_client,
140
- base_url,
141
- app_user_agent: app_user_agent,
142
- assume_user: assume_user,
143
- logger: request_logger
144
- )
145
- build_categories
146
- end
147
-
148
- def inspect
149
- methods = (self.public_methods - Object.methods)
150
- .sort
151
- .map {|m| ':' + m.to_s}
152
- .join(', ')
153
-
154
- "#<Smartsheet::Client:#{self.object_id} #{methods}>"
155
- end
156
-
157
- private
158
-
159
- attr_reader :client
160
-
161
- def build_categories
162
- @contacts = Contacts.new(client)
163
- @events = Events.new(client)
164
- @favorites = Favorites.new(client)
165
- @folders = Folders.new(client)
166
- @groups = Groups.new(client)
167
- @home = Home.new(client)
168
- @reports = Reports.new(client)
169
- @search = Search.new(client)
170
- @server_info = ServerInfo.new(client)
171
- @sheets = Sheets.new(client)
172
- @sights = Sights.new(client)
173
- @token = Token.new(client)
174
- @templates = Templates.new(client)
175
- @update_requests = UpdateRequests.new(client)
176
- @users = Users.new(client)
177
- @webhooks = Webhooks.new(client)
178
- @workspaces = Workspaces.new(client)
179
- end
180
-
181
- def init_retry_logic(max_retry_time, backoff_method)
182
- retry_opts = {}
183
- retry_opts[:max_retry_time] = max_retry_time unless max_retry_time.nil?
184
- retry_opts[:backoff_method] = backoff_method unless backoff_method.nil?
185
-
186
- API::RetryLogic.new(**retry_opts)
187
- end
188
-
189
- def token_env_var
190
- ENV['SMARTSHEET_ACCESS_TOKEN']
191
- end
192
- end
193
- end
1
+ require 'smartsheet/api/faraday_adapter/faraday_net_client'
2
+ require 'smartsheet/api/retry_net_client_decorator'
3
+ require 'smartsheet/api/response_net_client_decorator'
4
+ require 'smartsheet/api/request_client'
5
+ require 'smartsheet/api/retry_logic'
6
+ require 'smartsheet/api/request_logger'
7
+ require 'smartsheet/general_request'
8
+
9
+ require 'smartsheet/endpoints/contacts/contacts'
10
+ require 'smartsheet/endpoints/events/events'
11
+ require 'smartsheet/endpoints/favorites/favorites'
12
+ require 'smartsheet/endpoints/folders/folders'
13
+ require 'smartsheet/endpoints/groups/groups'
14
+ require 'smartsheet/endpoints/home/home'
15
+ require 'smartsheet/endpoints/reports/reports'
16
+ require 'smartsheet/endpoints/search/search'
17
+ require 'smartsheet/endpoints/server_info/server_info'
18
+ require 'smartsheet/endpoints/sheets/sheets'
19
+ require 'smartsheet/endpoints/sights/sights'
20
+ require 'smartsheet/endpoints/templates/templates'
21
+ require 'smartsheet/endpoints/token/token'
22
+ require 'smartsheet/endpoints/update_requests/update_requests'
23
+ require 'smartsheet/endpoints/users/users'
24
+ require 'smartsheet/endpoints/webhooks/webhooks'
25
+ require 'smartsheet/endpoints/workspaces/workspaces'
26
+
27
+
28
+ module Smartsheet
29
+ # The entry point to the SDK. API endpoint categories are accessed through this object's readable
30
+ # attributes.
31
+ #
32
+ # @!attribute [r] contacts
33
+ # @return [Contacts]
34
+ # @!attribute [r] favorites
35
+ # @return [Favorites]
36
+ # @!attribute [r] folders
37
+ # @return [Folders]
38
+ # @!attribute [r] groups
39
+ # @return [Groups]
40
+ # @!attribute [r] home
41
+ # @return [Home]
42
+ # @!attribute [r] reports
43
+ # @return [Reports]
44
+ # @!attribute [r] search
45
+ # @return [Search]
46
+ # @!attribute [r] server_info
47
+ # @return [ServerInfo]
48
+ # @!attribute [r] sheets
49
+ # @return [Sheets]
50
+ # @!attribute [r] sights
51
+ # @return [Sights]
52
+ # @!attribute [r] templates
53
+ # @return [Templates]
54
+ # @!attribute [r] token
55
+ # @return [Token]
56
+ # @!attribute [r] update_requests
57
+ # @return [UpdateRequests]
58
+ # @!attribute [r] users
59
+ # @return [Users]
60
+ # @!attribute [r] webhooks
61
+ # @return [Webhooks]
62
+ # @!attribute [r] workspaces
63
+ # @return [Workspaces]
64
+ class Client
65
+ include GeneralRequest
66
+ include Smartsheet::Constants
67
+
68
+ attr_reader :contacts, :events, :favorites, :folders, :groups, :home, :reports, :search, :server_info,
69
+ :sheets, :sights, :templates, :token, :update_requests, :users, :webhooks,
70
+ :workspaces
71
+
72
+ # @param token [String] access token for the API; if nil or empty, uses environment variable
73
+ # `SMARTSHEET_ACCESS_TOKEN`
74
+ # @param logger [Logger] a logger to which request and response info will be recorded
75
+ # @param log_full_body [Boolean] when true, request and response bodies will not be truncated in
76
+ # the logs
77
+ # @param user_agent [String] the name of the application, sent as part of the user agent for
78
+ # requests; defaults as the name of the application
79
+ # @param json_output [Boolean] when true, endpoints return raw JSON strings instead of hashes
80
+ # @param assume_user [String] the email address of the user to impersonate; only available for
81
+ # admin roles
82
+ # @param max_retry_time [Fixnum] overrides the maximum number of seconds during which eligible
83
+ # errors will be retried
84
+ # @param backoff_method [Proc] overrides the backoff calculation method, accepting the index of
85
+ # the current retry attempt (0-based) and returning the number of seconds to wait before
86
+ # retrying the call again, or `:stop` to halt retrying and return the latest error.
87
+ #
88
+ # Example - Wait 1 second before the first retry, 2 seconds before
89
+ # the second, and so on:
90
+ # ```ruby
91
+ # ->(x){ x + 1 }
92
+ # ```
93
+ #
94
+ # Example - Try twice, then halt:
95
+ # ```ruby
96
+ # ->(x){ if x < 2 then x + 1 else :stop end }
97
+ # ```
98
+ # @param base_url [String] overrides the base URL used when constructing API calls; for example,
99
+ # the default takes the form of `https://api.smartsheet.com/2.0`
100
+ def initialize(
101
+ token: nil,
102
+ logger: nil,
103
+ log_full_body: false,
104
+ user_agent: nil,
105
+ json_output: false,
106
+ assume_user: nil,
107
+ max_retry_time: nil,
108
+ backoff_method: nil,
109
+ base_url: API_URL
110
+ )
111
+
112
+ request_logger =
113
+ logger ?
114
+ API::RequestLogger.new(logger, log_full_body: log_full_body) :
115
+ API::MuteRequestLogger.new
116
+
117
+ token = token_env_var if token.nil? || token.empty?
118
+
119
+ app_user_agent = user_agent.nil? ? File.basename($PROGRAM_NAME) : user_agent
120
+
121
+ net_client = API::FaradayNetClient.new
122
+
123
+ retry_logic = init_retry_logic(max_retry_time, backoff_method)
124
+
125
+ retrying_client = API::RetryNetClientDecorator.new(
126
+ net_client,
127
+ retry_logic,
128
+ logger: request_logger
129
+ )
130
+
131
+ response_client = API::ResponseNetClientDecorator.new(
132
+ retrying_client,
133
+ json_output: json_output,
134
+ logger: request_logger
135
+ )
136
+
137
+ @client = API::RequestClient.new(
138
+ token,
139
+ response_client,
140
+ base_url,
141
+ app_user_agent: app_user_agent,
142
+ assume_user: assume_user,
143
+ logger: request_logger
144
+ )
145
+ build_categories
146
+ end
147
+
148
+ def inspect
149
+ methods = (self.public_methods - Object.methods)
150
+ .sort
151
+ .map {|m| ':' + m.to_s}
152
+ .join(', ')
153
+
154
+ "#<Smartsheet::Client:#{self.object_id} #{methods}>"
155
+ end
156
+
157
+ private
158
+
159
+ attr_reader :client
160
+
161
+ def build_categories
162
+ @contacts = Contacts.new(client)
163
+ @events = Events.new(client)
164
+ @favorites = Favorites.new(client)
165
+ @folders = Folders.new(client)
166
+ @groups = Groups.new(client)
167
+ @home = Home.new(client)
168
+ @reports = Reports.new(client)
169
+ @search = Search.new(client)
170
+ @server_info = ServerInfo.new(client)
171
+ @sheets = Sheets.new(client)
172
+ @sights = Sights.new(client)
173
+ @token = Token.new(client)
174
+ @templates = Templates.new(client)
175
+ @update_requests = UpdateRequests.new(client)
176
+ @users = Users.new(client)
177
+ @webhooks = Webhooks.new(client)
178
+ @workspaces = Workspaces.new(client)
179
+ end
180
+
181
+ def init_retry_logic(max_retry_time, backoff_method)
182
+ retry_opts = {}
183
+ retry_opts[:max_retry_time] = max_retry_time unless max_retry_time.nil?
184
+ retry_opts[:backoff_method] = backoff_method unless backoff_method.nil?
185
+
186
+ API::RetryLogic.new(**retry_opts)
187
+ end
188
+
189
+ def token_env_var
190
+ ENV['SMARTSHEET_ACCESS_TOKEN']
191
+ end
192
+ end
193
+ end