smartsheet 1.0.0.beta.0 → 1.0.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba8152aff078b8908b76631e7260f51810e42917
4
- data.tar.gz: 033b8f54c6e9ffb942d51b880b05430ea271ad8a
3
+ metadata.gz: 1cc15ce5cfbb1822363ff37ab362868d9395fcc5
4
+ data.tar.gz: 245e9e285c496ed02d8449441b020edfaeaa1cee
5
5
  SHA512:
6
- metadata.gz: 99d13d7fec3c7713e1bfd211179d89a505a8e9f5b0a8a3a849092ed79a00d2a9118cc83b7435e12881a5120f4056427b05d1853fd8c8a59a5afba234c0f524eb
7
- data.tar.gz: d35920faee71c41a5e3af38cc426a08e2e9d4127be78a50c4eee80e1f2803b2139af13526c54aaf46aa0c781385a4bafc5159c6ad0f551ebd3086f0a07eeda52
6
+ metadata.gz: 33892c0f87e810d3b7a22dd66dbf8f60418717e81f6e962aee171a014845a9f72244525e96087a9d69be00a2087672ca14df55d545a87b244ed43f2651e94d98
7
+ data.tar.gz: 89778f43258fb0c72aa28a5f3dd2115bfb9ef2a179fcd27e48ba6f649813c1fc9fac06de28cee897714ba316a588d1c15324386e0d457796111a53007373a7e6
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /.idea/
11
+ *.gem
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Smartsheet Ruby SDK [![Build Status](https://travis-ci.org/smartsheet-platform/smartsheet-ruby-sdk.svg?branch=master)](https://travis-ci.org/smartsheet-platform/smartsheet-ruby-sdk) [![Coverage Status](https://coveralls.io/repos/github/smartsheet-platform/smartsheet-ruby-sdk/badge.svg?branch=master)](https://coveralls.io/github/smartsheet-platform/smartsheet-ruby-sdk?branch=master)
1
+ # Smartsheet Ruby SDK [![Build Status](https://travis-ci.org/smartsheet-platform/smartsheet-ruby-sdk.svg?branch=master)](https://travis-ci.org/smartsheet-platform/smartsheet-ruby-sdk) [![Coverage Status](https://coveralls.io/repos/github/smartsheet-platform/smartsheet-ruby-sdk/badge.svg?branch=master)](https://coveralls.io/github/smartsheet-platform/smartsheet-ruby-sdk?branch=master) [![Gem Version](https://badge.fury.io/rb/smartsheet.svg)](https://badge.fury.io/rb/smartsheet)
2
2
 
3
3
  This is an SDK to simplify connecting to the [Smartsheet API](http://www.smartsheet.com/developers/api-documentation) from Ruby applications.
4
4
 
@@ -62,7 +62,7 @@ rescue Smartsheet::ApiError => e
62
62
  end
63
63
  ```
64
64
 
65
- See the [read-write-sheet](read-write-sheet/read_write_sheet.rb) example to see a more robust use case in action.
65
+ See the [read-write-sheet](https://github.com/smartsheet-samples/ruby-read-write-sheet) example to see a more robust use case in action.
66
66
 
67
67
  ## Basic Configuration
68
68
 
@@ -76,7 +76,8 @@ When creating the client object, pass an object with any of the following proper
76
76
  Smartsheet expects a standard Ruby logger. For example, to enable console logging of warnings and above, make a call such as the following:
77
77
 
78
78
  ```ruby
79
- logger = Logger.new(STDOUT, Logger::WARN)
79
+ logger = Logger.new(STDOUT)
80
+ logger.level = Logger::WARN
80
81
  smartsheet = Smartsheet::Client.new(logger: logger)
81
82
  ```
82
83
 
@@ -133,7 +134,7 @@ If you have any questions or issues with this SDK please post on [Stack Overflow
133
134
 
134
135
  Each specific release is available for download via [GitHub](https://github.com/smartsheet-platform/smartsheet-ruby-sdk/tags).
135
136
 
136
- **v1.0.0.beta.0 (October 2017)**
137
+ **v1.0.0.beta (October 2017)**
137
138
  Beta release of the Smartsheet SDK for Ruby
138
139
 
139
140
  *Note*: Minor changes that result in a patch version increment in RubyGems (such as updates to the README) will not be tagged as a Release in GitHub.
@@ -4,16 +4,19 @@ module Smartsheet
4
4
  module API
5
5
  class Censor
6
6
  EXPOSED_CHARS = 4
7
+ KEY_TO_STRING = ->(k){ k.to_s }
8
+ KEY_TO_DOWNCASE_STRING = ->(k){ k.to_s.downcase }
7
9
 
8
10
  def initialize(*blacklist)
9
11
  @blacklist = Set.new(blacklist)
10
12
  end
11
13
 
12
- def censor_hash(h)
13
- h.collect do |(k, v)|
14
- new_v = blacklist.include?(k.to_s) ? censor(v) : v
15
- [k, new_v]
16
- end.to_h
14
+ def censor_hash(h, case_insensitive: false)
15
+ if case_insensitive
16
+ _censor_hash(h, KEY_TO_DOWNCASE_STRING, downcased_blacklist)
17
+ else
18
+ _censor_hash(h, KEY_TO_STRING, blacklist)
19
+ end
17
20
  end
18
21
 
19
22
  def censor(str)
@@ -24,6 +27,21 @@ module Smartsheet
24
27
 
25
28
  private
26
29
 
30
+ def _censor_hash(h, key_transform, cased_blacklist)
31
+ h.collect do |(k, v)|
32
+ new_v =
33
+ cased_blacklist.include?(key_transform.call(k)) ?
34
+ censor(v) :
35
+ v
36
+
37
+ [k, new_v]
38
+ end.to_h
39
+ end
40
+
41
+ def downcased_blacklist
42
+ blacklist.collect { |x| x.downcase }
43
+ end
44
+
27
45
  attr_reader :blacklist
28
46
  end
29
47
 
@@ -72,7 +90,7 @@ module Smartsheet
72
90
  attr_reader :logger, :log_full_body
73
91
 
74
92
  def log_request_basics(level, request)
75
- logger.log(level) { "Request: #{request.method} #{build_logging_url(request)}" }
93
+ logger.log(level) { "Request: #{request.method.upcase} #{build_logging_url(request)}" }
76
94
  end
77
95
 
78
96
  def build_logging_url(request)
@@ -99,7 +117,8 @@ module Smartsheet
99
117
  end
100
118
 
101
119
  def log_headers(context, req_or_resp)
102
- logger.debug { "#{context} Headers: #{HEADER_CENSOR.censor_hash(req_or_resp.headers)}" }
120
+ censored_hash = HEADER_CENSOR.censor_hash(req_or_resp.headers, case_insensitive: true)
121
+ logger.debug { "#{context} Headers: #{censored_hash}" }
103
122
  end
104
123
 
105
124
  def log_body(context, body)
@@ -25,7 +25,7 @@ module Smartsheet
25
25
  response
26
26
  end
27
27
 
28
- unless retried_response.success?
28
+ unless retried_response.success? || total_attempts < 2
29
29
  logger.log_retry_failure(total_attempts)
30
30
  end
31
31
 
@@ -46,10 +46,10 @@ module Smartsheet
46
46
 
47
47
  request_logger =
48
48
  logger ?
49
- API::RequestLogger.new(logger, log_full_body) :
49
+ API::RequestLogger.new(logger, log_full_body: log_full_body) :
50
50
  API::MuteRequestLogger.new
51
51
 
52
- token = token_env_var if token.nil?
52
+ token = token_env_var if token.nil? || token.empty?
53
53
 
54
54
  net_client = API::FaradayNetClient.new
55
55
 
@@ -63,7 +63,8 @@ module Smartsheet
63
63
 
64
64
  response_client = API::ResponseNetClientDecorator.new(
65
65
  retrying_client,
66
- json_output: json_output
66
+ json_output: json_output,
67
+ logger: request_logger
67
68
  )
68
69
 
69
70
  @client = API::RequestClient.new(
@@ -77,6 +78,15 @@ module Smartsheet
77
78
  build_categories
78
79
  end
79
80
 
81
+ def inspect
82
+ methods = (self.public_methods - Object.methods)
83
+ .sort
84
+ .map {|m| ':' + m.to_s}
85
+ .join(', ')
86
+
87
+ "#<Smartsheet::Client:#{self.object_id} #{methods}>"
88
+ end
89
+
80
90
  private
81
91
 
82
92
  attr_reader :client
@@ -1,6 +1,6 @@
1
1
  module Smartsheet
2
2
  module Constants
3
- VERSION = '1.0.0.beta.0'.freeze
3
+ VERSION = '1.0.0.beta.2'.freeze
4
4
 
5
5
  USER_AGENT = 'smartsheet-ruby-sdk'.freeze
6
6
  API_URL = 'https://api.smartsheet.com/2.0'.freeze
@@ -12,10 +12,11 @@ Gem::Specification.new do |spec|
12
12
 
13
13
  spec.summary = 'An SDK to simplify connecting to the Smartsheet API from Ruby applications.'
14
14
  spec.description = <<-EOF
15
- This is an SDK to simplify connecting to the [Smartsheet API](http://www.smartsheet.com/developers/api-documentation) from Ruby applications.
16
- *Please note that this SDK is beta and may change significantly in the future.*
15
+ This is an SDK to simplify connecting to the Smartsheet API
16
+ (http://www.smartsheet.com/developers/api-documentation) from Ruby applications.
17
+ Please note that this SDK is beta and may change significantly in the future.
17
18
  EOF
18
- spec.homepage = 'http://smartsheet.com/developers'
19
+ spec.homepage = 'https://github.com/smartsheet-platform/smartsheet-ruby-sdk'
19
20
  spec.license = 'Apache-2.0'
20
21
 
21
22
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
@@ -27,10 +28,12 @@ Gem::Specification.new do |spec|
27
28
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
29
  f.match(/^(test|spec|features)/)
29
30
  end
30
- spec.bindir = 'exe'
31
+ spec.bindir = 'bin'
31
32
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
33
  spec.require_paths = ['lib']
33
34
 
35
+ spec.required_ruby_version = '> 2.2'
36
+
34
37
  spec.add_dependency 'faraday', '~> 0.13.1'
35
38
  spec.add_dependency 'plissken', '~> 1.2'
36
39
  spec.add_dependency 'awrence', '~> 1.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartsheet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta.0
4
+ version: 1.0.0.beta.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Smartsheet
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-10 00:00:00.000000000 Z
11
+ date: 2017-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -179,8 +179,9 @@ dependencies:
179
179
  - !ruby/object:Gem::Version
180
180
  version: '3.2'
181
181
  description: |2
182
- This is an SDK to simplify connecting to the [Smartsheet API](http://www.smartsheet.com/developers/api-documentation) from Ruby applications.
183
- *Please note that this SDK is beta and may change significantly in the future.*
182
+ This is an SDK to simplify connecting to the Smartsheet API
183
+ (http://www.smartsheet.com/developers/api-documentation) from Ruby applications.
184
+ Please note that this SDK is beta and may change significantly in the future.
184
185
  email: api@smartsheet.com
185
186
  executables: []
186
187
  extensions: []
@@ -249,10 +250,8 @@ files:
249
250
  - lib/smartsheet/error.rb
250
251
  - lib/smartsheet/general_request.rb
251
252
  - lib/smartsheet/version.rb
252
- - read-write-sheet/config.json
253
- - read-write-sheet/read_write_sheet.rb
254
253
  - smartsheet.gemspec
255
- homepage: http://smartsheet.com/developers
254
+ homepage: https://github.com/smartsheet-platform/smartsheet-ruby-sdk
256
255
  licenses:
257
256
  - Apache-2.0
258
257
  metadata: {}
@@ -262,9 +261,9 @@ require_paths:
262
261
  - lib
263
262
  required_ruby_version: !ruby/object:Gem::Requirement
264
263
  requirements:
265
- - - ">="
264
+ - - ">"
266
265
  - !ruby/object:Gem::Version
267
- version: '0'
266
+ version: '2.2'
268
267
  required_rubygems_version: !ruby/object:Gem::Requirement
269
268
  requirements:
270
269
  - - ">"
@@ -1,4 +0,0 @@
1
- {
2
- "token": "TOKEN",
3
- "sheet_id": "SHEET_ID"
4
- }
@@ -1,89 +0,0 @@
1
- require 'smartsheet/client'
2
-
3
-
4
- def row_update(row_id, column_id, value)
5
- {
6
- id: row_id,
7
- cells: [{
8
- columnId: column_id,
9
- value: value
10
- }]
11
- }
12
- end
13
-
14
- def column_map(sheet)
15
- column_map = {}
16
- sheet[:columns].each do |column|
17
- column_map[column[:title]] = column[:id]
18
- end
19
-
20
- column_map
21
- end
22
-
23
- def get_cell_by_column(row, column_id)
24
- row[:cells].find {|cell| cell[:column_id] == column_id}
25
- end
26
-
27
- def get_cell_by_column_name(row, column_name, column_map)
28
- get_cell_by_column(row, column_map[column_name])
29
- end
30
-
31
- def build_update_complete_row(row, column_map)
32
- status_cell = get_cell_by_column_name(row, 'Status', column_map)
33
- remaining_cell = get_cell_by_column_name(row, 'Remaining', column_map)
34
-
35
- if status_cell[:display_value] == 'Complete'
36
- unless remaining_cell[:display_value] == '0'
37
- puts "Updating row #{row[:row_number]}"
38
- row_update(row[:id], remaining_cell[:column_id], 0)
39
- end
40
- end
41
- end
42
-
43
- def build_update_complete_rows_body(sheet)
44
- column_map = column_map(sheet)
45
- update_rows = []
46
- sheet[:rows].each do |row|
47
- update_row = build_update_complete_row(row, column_map)
48
- update_rows.push(update_row) unless update_row.nil?
49
- end
50
-
51
- update_rows
52
- end
53
-
54
- def update_complete_rows(sheet_id, client)
55
- sheet = client.sheets.get(sheet_id: sheet_id)
56
-
57
- update_rows_body = build_update_complete_rows_body(sheet)
58
- if update_rows_body.empty?
59
- puts 'No Update Required'
60
- return
61
- end
62
-
63
- client.sheets.rows.update(sheet_id: sheet[:id], body: update_rows_body)
64
- end
65
-
66
- def load_config(config_name)
67
- file = File.open(config_name)
68
-
69
- JSON.load(file)
70
- end
71
-
72
-
73
- config = load_config('config.json')
74
-
75
- client = Smartsheet::Client.new(token: config['token'])
76
-
77
- begin
78
- update_complete_rows(config['sheet_id'], client)
79
- rescue Smartsheet::ApiError => e
80
- puts "API returned error:"
81
- puts "\terror code: #{e.error_code}"
82
- puts "\tref id: #{e.ref_id}"
83
- puts "\tmessage: #{e.message}"
84
- end
85
-
86
-
87
-
88
-
89
-