cloudxls 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/cloudxls/version.rb +1 -1
- data/lib/cloudxls.rb +31 -9
- data/test/cloudxls_test.rb +30 -10
- data/test/integration_test.rb +25 -0
- metadata +4 -11
- data/examples/async.rb +0 -24
- data/examples/data.csv +0 -2
- data/examples/files.rb +0 -19
- data/examples/full.rb +0 -42
- data/examples/inline.rb +0 -25
- data/examples/multi_sheet.rb +0 -28
- data/examples/template.xls +0 -0
- data/examples/template.xlsx +0 -0
- data/examples/templates.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7e1697a99d75266681864389273a9aff73f0db3
|
4
|
+
data.tar.gz: 667f2e5d6d326f687626081345482560e012330c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48fabb7292c78214523a1b06cecb227833799da0cc4abec208f04472d5c4ec1777fa0d0281268762cc291fab3c1b6cde9f6a3378cd4c1d14696b87a5aaa3c36b
|
7
|
+
data.tar.gz: 61bffb4c9848e56a758e87a3eca36ba1da357a6c9b8f844ac3e8044baabfb34e5c2894165a8cef56c7d223a72446ab66967ee29d8bda69b711acdaf79d59f440
|
data/README.md
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
|
5
5
|
Or in your Gemfile
|
6
6
|
|
7
|
-
gem 'cloudxls', '~> 2.0.
|
7
|
+
gem 'cloudxls', '~> 2.0.2'
|
8
8
|
|
9
9
|
# Documentation
|
10
10
|
|
11
|
-
Additional documentation: [https://docs.cloudxls.com](docs.cloudxls.com)
|
11
|
+
Additional documentation: [https://docs.cloudxls.com](https://docs.cloudxls.com)
|
12
12
|
|
13
13
|
# Quick Start Guide
|
14
14
|
|
@@ -29,10 +29,10 @@ to the sandbox test API.
|
|
29
29
|
|
30
30
|
## Read-API
|
31
31
|
|
32
|
-
Send an xls or xlsx file using the `Cloudxls#read` method. `#
|
32
|
+
Send an xls or xlsx file using the `Cloudxls#read` method. `#as_json` will start the request and `#to_h` parses the json into a ruby hash.
|
33
33
|
|
34
34
|
```ruby
|
35
|
-
data = Cloudxls.read(file: File.new("/path/to/my-excel.xls")).to_h
|
35
|
+
data = Cloudxls.read(file: File.new("/path/to/my-excel.xls")).as_json.to_h
|
36
36
|
```
|
37
37
|
|
38
38
|
Output
|
data/lib/cloudxls/version.rb
CHANGED
data/lib/cloudxls.rb
CHANGED
@@ -3,30 +3,43 @@ require 'json'
|
|
3
3
|
require 'net/http'
|
4
4
|
require 'net/http/post/multipart'
|
5
5
|
|
6
|
+
require 'cloudxls/version'
|
6
7
|
|
7
8
|
class Cloudxls
|
9
|
+
|
8
10
|
class ApiError < Exception
|
9
11
|
end
|
10
12
|
|
11
13
|
@sandbox_base = "sandbox.cloudxls.com"
|
12
14
|
@api_version = "v2".freeze
|
15
|
+
@api_key = nil
|
16
|
+
@api_base = nil
|
13
17
|
|
14
18
|
class << self
|
15
|
-
|
16
|
-
|
17
|
-
|
19
|
+
attr_writer :api_key,
|
20
|
+
:api_base
|
21
|
+
|
22
|
+
attr_accessor :api_version,
|
18
23
|
:sandbox_base,
|
19
24
|
:port
|
20
25
|
|
21
26
|
def client_options
|
22
27
|
{
|
23
|
-
api_key:
|
24
|
-
api_version:
|
25
|
-
api_base:
|
28
|
+
api_key: api_key,
|
29
|
+
api_version: api_version,
|
30
|
+
api_base: api_base,
|
26
31
|
port: 443
|
27
32
|
}
|
28
33
|
end
|
29
34
|
|
35
|
+
def api_key
|
36
|
+
@api_key ||= ENV["CLOUDXLS_API_KEY"]
|
37
|
+
end
|
38
|
+
|
39
|
+
def api_base
|
40
|
+
@api_base ||= ENV.fetch("CLOUDXLS_API_BASE", "api.cloudxls.com")
|
41
|
+
end
|
42
|
+
|
30
43
|
# Initializes a Write request
|
31
44
|
#
|
32
45
|
# @param [Hash] params request parameters as
|
@@ -87,6 +100,9 @@ class Cloudxls
|
|
87
100
|
"/#{client_options[:api_version]}/#{path}"
|
88
101
|
end
|
89
102
|
|
103
|
+
def user_agent
|
104
|
+
"cloudxls-ruby #{VERSION}"
|
105
|
+
end
|
90
106
|
|
91
107
|
# Starts request and yields response to block
|
92
108
|
#
|
@@ -96,9 +112,7 @@ class Cloudxls
|
|
96
112
|
raise "#{self.class.name} already executed" if @finished
|
97
113
|
|
98
114
|
start do |http|
|
99
|
-
request =
|
100
|
-
request.basic_auth api_key, ""
|
101
|
-
request['User-Agent'] = "cloudxls-ruby #{VERSION}"
|
115
|
+
request = build_request
|
102
116
|
|
103
117
|
if block_given?
|
104
118
|
http.request(request) do |response|
|
@@ -115,6 +129,14 @@ class Cloudxls
|
|
115
129
|
@finished = true
|
116
130
|
self
|
117
131
|
end
|
132
|
+
|
133
|
+
|
134
|
+
def build_request
|
135
|
+
request = Net::HTTP::Post::Multipart.new(self.path, @post_data)
|
136
|
+
request.basic_auth api_key, ""
|
137
|
+
request['User-Agent'] = user_agent
|
138
|
+
request
|
139
|
+
end
|
118
140
|
end
|
119
141
|
|
120
142
|
module BaseResponse
|
data/test/cloudxls_test.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class CloudxlsTest < Minitest::Test
|
4
|
-
def
|
5
|
-
Cloudxls.api_key =
|
6
|
-
file = Cloudxls.write(csv: "hello,world").as_xls.save_as("/tmp/foo.xls")
|
7
|
-
hash = Cloudxls.read(excel: File.new(file.path)).to_h
|
8
|
-
assert_equal ["hello", "world"], hash.first["rows"][0]
|
4
|
+
def setup
|
5
|
+
Cloudxls.api_key = nil
|
9
6
|
end
|
10
7
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
def test_env_variables
|
9
|
+
ENV["CLOUDXLS_API_KEY"] = "env-var"
|
10
|
+
assert_equal "env-var", Cloudxls.api_key
|
11
|
+
|
12
|
+
Cloudxls.api_key = "custom"
|
13
|
+
assert_equal "custom", Cloudxls.api_key
|
14
|
+
ensure
|
15
|
+
ENV.delete("CLOUDXLS_API_KEY")
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_accessors
|
@@ -26,4 +26,24 @@ class CloudxlsTest < Minitest::Test
|
|
26
26
|
def test_test_api_keys
|
27
27
|
Cloudxls::WriteRequest.new(api_key: "test_foobar")
|
28
28
|
end
|
29
|
+
|
30
|
+
def test_version
|
31
|
+
assert Cloudxls::VERSION.start_with?("2.")
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_user_agent
|
35
|
+
assert Cloudxls::WriteRequest.new.user_agent.start_with?("cloudxls-ruby 2.")
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_path_to
|
39
|
+
assert_equal "/v2/", Cloudxls::WriteRequest.new.path_to("")
|
40
|
+
assert_equal "/v2/hello-world", Cloudxls::WriteRequest.new.path_to("hello-world")
|
41
|
+
assert_equal "/v2.1/", Cloudxls::WriteRequest.new(api_version: "v2.1").path_to("")
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_build_request
|
45
|
+
req = Cloudxls::WriteRequest.new(api_key: "your-api-key").build_request
|
46
|
+
refute_nil req["User-Agent"]
|
47
|
+
end
|
48
|
+
|
29
49
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# Tests with sandbox. requires a valid test key
|
4
|
+
#
|
5
|
+
class IntegrationTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
Cloudxls.api_key = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_defaults_text
|
11
|
+
skip unless ENV["CLOUDXLS_API_KEY"]
|
12
|
+
|
13
|
+
file = Cloudxls.write(csv: "hello,world").as_xls.save_as("/tmp/foo.xls")
|
14
|
+
hash = Cloudxls.read(excel: File.new(file.path)).as_json.to_h
|
15
|
+
assert_equal ["hello", "world"], hash.first["rows"][0]
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_defaults_file
|
19
|
+
skip unless ENV["CLOUDXLS_API_KEY"]
|
20
|
+
|
21
|
+
file = Cloudxls.write(csv: File.new("test/test.csv")).as_xls.save_as("/tmp/foo.xls")
|
22
|
+
hash = Cloudxls.read(excel: File.new(file.path)).as_json.to_h
|
23
|
+
assert_equal ["hello", "world"], hash.first["rows"][0]
|
24
|
+
end
|
25
|
+
end
|
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.
|
4
|
+
version: 2.0.2
|
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-
|
11
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multipart-post
|
@@ -65,18 +65,10 @@ files:
|
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
67
|
- cloudxls.gemspec
|
68
|
-
- examples/async.rb
|
69
|
-
- examples/data.csv
|
70
|
-
- examples/files.rb
|
71
|
-
- examples/full.rb
|
72
|
-
- examples/inline.rb
|
73
|
-
- examples/multi_sheet.rb
|
74
|
-
- examples/template.xls
|
75
|
-
- examples/template.xlsx
|
76
|
-
- examples/templates.rb
|
77
68
|
- lib/cloudxls.rb
|
78
69
|
- lib/cloudxls/version.rb
|
79
70
|
- test/cloudxls_test.rb
|
71
|
+
- test/integration_test.rb
|
80
72
|
- test/test.csv
|
81
73
|
- test/test_helper.rb
|
82
74
|
homepage: https://cloudxls.com
|
@@ -104,5 +96,6 @@ specification_version: 4
|
|
104
96
|
summary: Ruby wrapper to read and write Excel through the cloudxls API.
|
105
97
|
test_files:
|
106
98
|
- test/cloudxls_test.rb
|
99
|
+
- test/integration_test.rb
|
107
100
|
- test/test.csv
|
108
101
|
- test/test_helper.rb
|
data/examples/async.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# ruby examples/async.rb
|
2
|
-
#
|
3
|
-
# Use this in a Rails/Sinatra action to redirect user
|
4
|
-
# directly to the file download (expires after 10min).
|
5
|
-
|
6
|
-
require_relative '../lib/cloudxls'
|
7
|
-
|
8
|
-
unless ENV["CLOUDXLS_API_KEY"]
|
9
|
-
puts "--- WARNING ---"
|
10
|
-
puts "Please add environment variable CLOUDXLS_API_KEY"
|
11
|
-
puts "export CLOUDXLS_API_KEY=YOUR_API_KEY"
|
12
|
-
puts "---------------"
|
13
|
-
exit
|
14
|
-
end
|
15
|
-
|
16
|
-
CloudXLS.api_key = ENV["CLOUDXLS_API_KEY"];
|
17
|
-
|
18
|
-
resp = CloudXLS.async({
|
19
|
-
data: { text: "Greeting,Greetee\nHello,World" },
|
20
|
-
sheet: { name: 'Hello World' },
|
21
|
-
doc: { filename: 'hello-world' }
|
22
|
-
})
|
23
|
-
|
24
|
-
puts "Download file from: #{resp.url}"
|
data/examples/data.csv
DELETED
data/examples/files.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# ruby examples/files.rb
|
2
|
-
|
3
|
-
require_relative '../lib/cloudxls'
|
4
|
-
|
5
|
-
unless ENV["CLOUDXLS_API_KEY"]
|
6
|
-
puts "--- WARNING ---"
|
7
|
-
puts "Please add environment variable CLOUDXLS_API_KEY"
|
8
|
-
puts "export CLOUDXLS_API_KEY=YOUR_API_KEY"
|
9
|
-
puts "---------------"
|
10
|
-
exit
|
11
|
-
end
|
12
|
-
|
13
|
-
CloudXLS.api_key = ENV["CLOUDXLS_API_KEY"];
|
14
|
-
|
15
|
-
resp = CloudXLS.inline({
|
16
|
-
data: { file: File.new("./examples/data.csv") }
|
17
|
-
})
|
18
|
-
|
19
|
-
File.open("out-file.xls", "wb") { |f| f.write resp }
|
data/examples/full.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# ruby examples/full.rb
|
2
|
-
#
|
3
|
-
# With all the options
|
4
|
-
|
5
|
-
require_relative '../lib/cloudxls'
|
6
|
-
|
7
|
-
unless ENV["CLOUDXLS_API_KEY"]
|
8
|
-
puts "--- WARNING ---"
|
9
|
-
puts "Please add environment variable CLOUDXLS_API_KEY"
|
10
|
-
puts "export CLOUDXLS_API_KEY=YOUR_API_KEY"
|
11
|
-
puts "---------------"
|
12
|
-
exit
|
13
|
-
end
|
14
|
-
|
15
|
-
CloudXLS.api_key = ENV["CLOUDXLS_API_KEY"];
|
16
|
-
|
17
|
-
resp = CloudXLS.inline({
|
18
|
-
sheets: {
|
19
|
-
"Sheet1" => {
|
20
|
-
data: {
|
21
|
-
text: "Greeting;Greetee;Date\nHello;World;2011-01-02",
|
22
|
-
separator: ";",
|
23
|
-
date_format: "YYYY-MM-DD", # is default
|
24
|
-
encoding: "UTF-8", # is default
|
25
|
-
},
|
26
|
-
sheet: {
|
27
|
-
cell: "C3", # define cell
|
28
|
-
filters: true, # adds filter boxes
|
29
|
-
auto_size_columns: true, # adjust column width (experimental)
|
30
|
-
cell_formats: "@,@,dd-mmm-yyyy"
|
31
|
-
}
|
32
|
-
},
|
33
|
-
"Sheet3!B2" => {data: {file: File.new("./examples/data.csv") }},
|
34
|
-
},
|
35
|
-
doc: {
|
36
|
-
filename: "output",
|
37
|
-
template: File.new("./examples/template.xls")
|
38
|
-
}
|
39
|
-
})
|
40
|
-
|
41
|
-
File.open("out-full.xls", "wb") { |f| f.write resp }
|
42
|
-
puts "File saved: ./out-full.xls"
|
data/examples/inline.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# ruby examples/inline.rb
|
2
|
-
#
|
3
|
-
# Use to directly download file.
|
4
|
-
|
5
|
-
require_relative '../lib/cloudxls'
|
6
|
-
|
7
|
-
unless ENV["CLOUDXLS_API_KEY"]
|
8
|
-
puts "--- WARNING ---"
|
9
|
-
puts "Please add environment variable CLOUDXLS_API_KEY"
|
10
|
-
puts "export CLOUDXLS_API_KEY=YOUR_API_KEY"
|
11
|
-
puts "---------------"
|
12
|
-
exit
|
13
|
-
end
|
14
|
-
|
15
|
-
CloudXLS.api_key = ENV["CLOUDXLS_API_KEY"];
|
16
|
-
|
17
|
-
resp = CloudXLS.inline({
|
18
|
-
data: { text: "Greeting,Greetee\nHello,World" },
|
19
|
-
sheet: { name: 'Hello World' },
|
20
|
-
doc: { filename: 'hello-world' }
|
21
|
-
})
|
22
|
-
|
23
|
-
|
24
|
-
File.open("out.xls", "wb") { |f| f.write resp }
|
25
|
-
puts "File saved"
|
data/examples/multi_sheet.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# ruby examples/multi_sheet.rb
|
2
|
-
|
3
|
-
require_relative '../lib/cloudxls'
|
4
|
-
|
5
|
-
unless ENV["CLOUDXLS_API_KEY"]
|
6
|
-
puts "--- WARNING ---"
|
7
|
-
puts "Please add environment variable CLOUDXLS_API_KEY"
|
8
|
-
puts "export CLOUDXLS_API_KEY=YOUR_API_KEY"
|
9
|
-
puts "---------------"
|
10
|
-
exit
|
11
|
-
end
|
12
|
-
|
13
|
-
CloudXLS.api_key = ENV["CLOUDXLS_API_KEY"];
|
14
|
-
|
15
|
-
resp = CloudXLS.inline({
|
16
|
-
sheets: {
|
17
|
-
"Sheet1" => {
|
18
|
-
data: {text: "Greeting,Greetee\nHello,World" },
|
19
|
-
sheet: {cell: "C3" }
|
20
|
-
},
|
21
|
-
"Sheet2!D4" => {data: {text: "Greeting,Greetee\nHello,World" }},
|
22
|
-
"Sheet3!B2" => {data: {file: File.new("./examples/data.csv") }},
|
23
|
-
}
|
24
|
-
})
|
25
|
-
|
26
|
-
|
27
|
-
File.open("out-multi_sheet.xls", "wb") { |f| f.write resp }
|
28
|
-
puts "File saved"
|
data/examples/template.xls
DELETED
Binary file
|
data/examples/template.xlsx
DELETED
Binary file
|
data/examples/templates.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# ruby examples/templates.rb
|
2
|
-
#
|
3
|
-
# Merge data into excel files.
|
4
|
-
|
5
|
-
require_relative '../lib/cloudxls'
|
6
|
-
|
7
|
-
unless ENV["CLOUDXLS_API_KEY"]
|
8
|
-
puts "--- WARNING ---"
|
9
|
-
puts "Please add environment variable CLOUDXLS_API_KEY"
|
10
|
-
puts "export CLOUDXLS_API_KEY=YOUR_API_KEY"
|
11
|
-
puts "---------------"
|
12
|
-
exit
|
13
|
-
end
|
14
|
-
|
15
|
-
CloudXLS.api_key = ENV["CLOUDXLS_API_KEY"];
|
16
|
-
|
17
|
-
resp = CloudXLS.inline({
|
18
|
-
data: { text: "Greeting,Greetee\nHello,World" },
|
19
|
-
sheet: { name: 'Hello World' },
|
20
|
-
doc: { template: File.new("./examples/template.xls") }
|
21
|
-
})
|
22
|
-
|
23
|
-
|
24
|
-
File.open("out-template.xls", "wb") { |f| f.write resp }
|
25
|
-
puts "File saved: ./out-template.xls"
|
26
|
-
|
27
|
-
resp = CloudXLS.inline({
|
28
|
-
data: { text: "Greeting,Greetee\nHello,World" },
|
29
|
-
sheet: { name: 'Hello World' },
|
30
|
-
doc: { template: File.new("./examples/template.xlsx") }
|
31
|
-
})
|
32
|
-
|
33
|
-
File.open("out-template.xlsx", "wb") { |f| f.write resp }
|
34
|
-
puts "File saved: ./out-template.xlsx"
|