cloudxls 2.0.0.pre.beta → 2.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.
- checksums.yaml +4 -4
- data/lib/cloudxls.rb +88 -8
- data/lib/cloudxls/version.rb +1 -1
- data/test/cloudxls_test.rb +9 -2
- data/test/test.csv +1 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc4d555e2c11a064de173550ec112a8515b16604
|
4
|
+
data.tar.gz: 78a87ac79d22710035968edaa8b662dc90d18c33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a444d889a3a7243894721ee13f3267403cd7b596f5298713d31234ee3737172b94848d89fba0cdc2a1be43d69804469816423374f624c90224bb1d7d91829de
|
7
|
+
data.tar.gz: c4045675c18f8ed7eb7bc8430c41de16b134f17c4276e273b619ad84a5d9eaead6376e4189b0da68d8403cbd234fa9e34a527fb054b6d6baba5911fc2946a020
|
data/lib/cloudxls.rb
CHANGED
@@ -29,12 +29,22 @@ class Cloudxls
|
|
29
29
|
}
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
# Initializes a Write request
|
33
|
+
#
|
34
|
+
# @param [Hash] params request parameters as
|
35
|
+
# @return [WriteRequest] write request object
|
36
|
+
#
|
37
|
+
def write(params = nil)
|
38
|
+
WriteRequest.new(client_options).add_data(params)
|
34
39
|
end
|
35
40
|
|
36
|
-
|
37
|
-
|
41
|
+
# Initializes a Read request
|
42
|
+
#
|
43
|
+
# @param [Hash] params request parameters as
|
44
|
+
# @return [WriteRequest] write request object
|
45
|
+
#
|
46
|
+
def read(params = nil)
|
47
|
+
ReadRequest.new(client_options).add_data(params)
|
38
48
|
end
|
39
49
|
end
|
40
50
|
|
@@ -54,6 +64,10 @@ class Cloudxls
|
|
54
64
|
key
|
55
65
|
end
|
56
66
|
|
67
|
+
# Is Api Key for testing/sandbox only?
|
68
|
+
#
|
69
|
+
# @return [Boolean] write request object
|
70
|
+
#
|
57
71
|
def test_key?
|
58
72
|
api_key.to_s.downcase.start_with?("test")
|
59
73
|
end
|
@@ -66,6 +80,8 @@ class Cloudxls
|
|
66
80
|
end
|
67
81
|
end
|
68
82
|
|
83
|
+
# Internal. Starts the request.
|
84
|
+
#
|
69
85
|
def start(&block)
|
70
86
|
Net::HTTP.start(api_base, client_options[:port], use_ssl: true, &block)
|
71
87
|
end
|
@@ -74,10 +90,17 @@ class Cloudxls
|
|
74
90
|
"/#{client_options[:api_version]}/#{path}"
|
75
91
|
end
|
76
92
|
|
93
|
+
# Alias for #each
|
94
|
+
#
|
77
95
|
def data
|
78
96
|
each
|
79
97
|
end
|
80
98
|
|
99
|
+
# Writes to IO object
|
100
|
+
#
|
101
|
+
# @params [IO, #write] io
|
102
|
+
# @returns [IO]
|
103
|
+
#
|
81
104
|
def write_to(io)
|
82
105
|
each do |chunk|
|
83
106
|
io.write chunk
|
@@ -87,10 +110,19 @@ class Cloudxls
|
|
87
110
|
io.close
|
88
111
|
end
|
89
112
|
|
113
|
+
# Write response to file
|
114
|
+
#
|
115
|
+
# @params [String] path
|
116
|
+
# @returns [File]
|
117
|
+
#
|
90
118
|
def save_as(path)
|
91
119
|
write_to File.open(path, 'wb')
|
92
120
|
end
|
93
121
|
|
122
|
+
# Starts request and yields response to block
|
123
|
+
#
|
124
|
+
# @params [String] path
|
125
|
+
#
|
94
126
|
def each(&block)
|
95
127
|
raise "#{self.class.name} already executed" if @finished
|
96
128
|
|
@@ -116,7 +148,7 @@ class Cloudxls
|
|
116
148
|
end
|
117
149
|
end
|
118
150
|
|
119
|
-
class
|
151
|
+
class ReadRequest
|
120
152
|
include BaseRequest
|
121
153
|
|
122
154
|
# post_data is an array of key,value arrays. Reason:
|
@@ -126,6 +158,7 @@ class Cloudxls
|
|
126
158
|
# Example: [["separator", ","], ["csv", "hello,world"]]
|
127
159
|
attr_reader :post_data
|
128
160
|
attr_reader :client_options
|
161
|
+
attr_accessor :file_format
|
129
162
|
|
130
163
|
DATA_PARAMETERS = %w[excel file]
|
131
164
|
|
@@ -140,6 +173,10 @@ class Cloudxls
|
|
140
173
|
self
|
141
174
|
end
|
142
175
|
|
176
|
+
# Response as string
|
177
|
+
#
|
178
|
+
# @return [String]
|
179
|
+
#
|
143
180
|
def response_body
|
144
181
|
# TODO: optimize
|
145
182
|
str = ""
|
@@ -149,6 +186,28 @@ class Cloudxls
|
|
149
186
|
str
|
150
187
|
end
|
151
188
|
|
189
|
+
# Set request to JSON
|
190
|
+
#
|
191
|
+
# @returns [require] returns self
|
192
|
+
#
|
193
|
+
def as_json
|
194
|
+
self.file_format = "json"
|
195
|
+
self
|
196
|
+
end
|
197
|
+
|
198
|
+
# Set request to CSV
|
199
|
+
#
|
200
|
+
# @returns [WriteRequest] returns self
|
201
|
+
#
|
202
|
+
def as_csv
|
203
|
+
self.file_format = "csv"
|
204
|
+
self
|
205
|
+
end
|
206
|
+
|
207
|
+
# Response as Hash (used with json)
|
208
|
+
#
|
209
|
+
# @return [String]
|
210
|
+
#
|
152
211
|
def to_h
|
153
212
|
JSON.load(response_body)
|
154
213
|
end
|
@@ -156,11 +215,11 @@ class Cloudxls
|
|
156
215
|
protected
|
157
216
|
|
158
217
|
def path
|
159
|
-
path_to("read
|
218
|
+
path_to("read.#{file_format || "json"}")
|
160
219
|
end
|
161
220
|
end
|
162
221
|
|
163
|
-
class
|
222
|
+
class WriteRequest
|
164
223
|
include BaseRequest
|
165
224
|
# post_data is an array of key,value arrays. Reason:
|
166
225
|
# - A key can appear multiple times (for multiple sheets)
|
@@ -174,11 +233,19 @@ class Cloudxls
|
|
174
233
|
|
175
234
|
DATA_PARAMETERS = %w[data data_url csv csv_url json json_url]
|
176
235
|
|
236
|
+
# Add another configuration block, consisting of sheet configuration and data element.
|
237
|
+
#
|
238
|
+
# @params [Hash] params
|
239
|
+
# @returns [WriteRequest] returns self
|
240
|
+
#
|
177
241
|
def add_data(params = nil)
|
178
242
|
data_params = []
|
179
243
|
params.each do |key, value|
|
180
244
|
key = key.to_s
|
181
245
|
if DATA_PARAMETERS.include?(key)
|
246
|
+
if value.is_a?(File)
|
247
|
+
value = UploadIO.new(value, "text/csv", "data")
|
248
|
+
end
|
182
249
|
data_params << [key, value]
|
183
250
|
else
|
184
251
|
@post_data << [key, value]
|
@@ -188,18 +255,31 @@ class Cloudxls
|
|
188
255
|
self
|
189
256
|
end
|
190
257
|
|
258
|
+
# Set request to XLS
|
259
|
+
#
|
260
|
+
# @returns [WriteRequest] returns self
|
261
|
+
#
|
191
262
|
def as_xls
|
192
263
|
self.file_format = "xls"
|
193
264
|
self
|
194
265
|
end
|
195
266
|
|
267
|
+
# Set request to XLSX
|
268
|
+
#
|
269
|
+
# @returns [WriteRequest] returns self
|
270
|
+
#
|
196
271
|
def as_xlsx
|
197
272
|
self.file_format = "xlsx"
|
198
273
|
self
|
199
274
|
end
|
200
275
|
|
276
|
+
# Sets request to XLSX
|
277
|
+
#
|
278
|
+
# @returns [WriteRequest] returns self
|
279
|
+
#
|
201
280
|
def append_to(target_file)
|
202
|
-
|
281
|
+
io = UploadIO.new(target_file, "application/octet-stream", "target-file")
|
282
|
+
@post_data = [["target_file", io]] + @post_data
|
203
283
|
self
|
204
284
|
end
|
205
285
|
|
data/lib/cloudxls/version.rb
CHANGED
data/test/cloudxls_test.rb
CHANGED
@@ -8,15 +8,22 @@ class CloudxlsTest < Minitest::Test
|
|
8
8
|
assert_equal ["hello", "world"], hash.first["rows"][0]
|
9
9
|
end
|
10
10
|
|
11
|
+
def test_defaults
|
12
|
+
Cloudxls.api_key = "test_foo"
|
13
|
+
file = Cloudxls.write(csv: File.new("test/test.csv")).save_as("/tmp/foo.xls")
|
14
|
+
hash = Cloudxls.read(excel: File.new(file.path)).to_h
|
15
|
+
assert_equal ["hello", "world"], hash.first["rows"][0]
|
16
|
+
end
|
17
|
+
|
11
18
|
def test_accessors
|
12
19
|
Cloudxls.api_key = "test_foo"
|
13
20
|
assert_equal "test_foo", Cloudxls.api_key
|
14
21
|
|
15
22
|
Cloudxls.api_base = "sandbox.cloudxls.com"
|
16
|
-
assert_equal "sandbox.cloudxls.com", Cloudxls.
|
23
|
+
assert_equal "sandbox.cloudxls.com", Cloudxls.api_base
|
17
24
|
end
|
18
25
|
|
19
26
|
def test_test_api_keys
|
20
|
-
Cloudxls::
|
27
|
+
Cloudxls::WriteRequest.new(api_key: "test_foobar")
|
21
28
|
end
|
22
29
|
end
|
data/test/test.csv
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
hello,world
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudxls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Burkhard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multipart-post
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/cloudxls.rb
|
78
78
|
- lib/cloudxls/version.rb
|
79
79
|
- test/cloudxls_test.rb
|
80
|
+
- test/test.csv
|
80
81
|
- test/test_helper.rb
|
81
82
|
homepage: https://cloudxls.com
|
82
83
|
licenses: []
|
@@ -92,9 +93,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
93
|
version: '0'
|
93
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
95
|
requirements:
|
95
|
-
- - "
|
96
|
+
- - ">="
|
96
97
|
- !ruby/object:Gem::Version
|
97
|
-
version:
|
98
|
+
version: '0'
|
98
99
|
requirements: []
|
99
100
|
rubyforge_project:
|
100
101
|
rubygems_version: 2.5.1
|
@@ -103,4 +104,5 @@ specification_version: 4
|
|
103
104
|
summary: Ruby wrapper to read and write Excel through the cloudxls API.
|
104
105
|
test_files:
|
105
106
|
- test/cloudxls_test.rb
|
107
|
+
- test/test.csv
|
106
108
|
- test/test_helper.rb
|