quickchart 1.0.0 → 1.1.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/quickchart.rb +36 -27
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7d246078cb3fbae9ff9376fc2d72ddfe58a657a2
|
|
4
|
+
data.tar.gz: ecf1f88d1b1df1462734807be48fe9f2c336bfb2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 102fb75efa3a2b507a20cbd2ebad1190befbd6fc316532a53954a7ade6aef25628a8372c36a6faa6a36cdcaa48d7a33555ad61aac447e64f407a44f20af8c311
|
|
7
|
+
data.tar.gz: cc15475158b1d66f45e3511a77d7fc2e9943184491c2222f907ffbfc13c1b591d35dc10885c61460f11e3e9ff20af70694b001190fd53078c85cdf71b6a0411d
|
data/lib/quickchart.rb
CHANGED
|
@@ -4,9 +4,25 @@ require 'rubygems'
|
|
|
4
4
|
require 'uri'
|
|
5
5
|
|
|
6
6
|
class QuickChart
|
|
7
|
-
attr_accessor :config,
|
|
7
|
+
attr_accessor :config,
|
|
8
|
+
:width,
|
|
9
|
+
:height,
|
|
10
|
+
:background_color,
|
|
11
|
+
:device_pixel_ratio,
|
|
12
|
+
:format,
|
|
13
|
+
:key,
|
|
14
|
+
:base_url
|
|
8
15
|
|
|
9
|
-
def initialize(
|
|
16
|
+
def initialize(
|
|
17
|
+
config,
|
|
18
|
+
width: 500,
|
|
19
|
+
height: 300,
|
|
20
|
+
background_color: '#ffffff',
|
|
21
|
+
device_pixel_ratio: 1.0,
|
|
22
|
+
format: 'png',
|
|
23
|
+
key: nil,
|
|
24
|
+
base_url: 'https://quickchart.io'
|
|
25
|
+
)
|
|
10
26
|
@config = config
|
|
11
27
|
@width = width
|
|
12
28
|
@height = height
|
|
@@ -14,6 +30,7 @@ class QuickChart
|
|
|
14
30
|
@device_pixel_ratio = device_pixel_ratio
|
|
15
31
|
@format = format
|
|
16
32
|
@key = key
|
|
33
|
+
@base_url = base_url
|
|
17
34
|
end
|
|
18
35
|
|
|
19
36
|
def get_url
|
|
@@ -23,20 +40,18 @@ class QuickChart
|
|
|
23
40
|
h: @height,
|
|
24
41
|
bkg: @background_color,
|
|
25
42
|
devicePixelRatio: @device_pixel_ratio,
|
|
26
|
-
f: @format
|
|
43
|
+
f: @format
|
|
27
44
|
}
|
|
28
|
-
if @key
|
|
29
|
-
params['key'] = @key
|
|
30
|
-
end
|
|
45
|
+
params['key'] = @key if @key
|
|
31
46
|
|
|
32
47
|
encoded = URI.encode_www_form(params)
|
|
33
|
-
|
|
48
|
+
"#{@base_url}/chart?#{encoded}"
|
|
34
49
|
end
|
|
35
50
|
|
|
36
51
|
def _http_post(path)
|
|
37
|
-
spec = Gem.loaded_specs[
|
|
38
|
-
version =
|
|
39
|
-
request_headers = {
|
|
52
|
+
spec = Gem.loaded_specs['quickchart']
|
|
53
|
+
version = spec ? spec.version.to_s : 'unknown'
|
|
54
|
+
request_headers = { 'user-agent' => "quickchart-ruby/#{version}" }
|
|
40
55
|
|
|
41
56
|
params = {
|
|
42
57
|
c: @config.is_a?(String) ? @config : @config.to_json,
|
|
@@ -44,39 +59,33 @@ class QuickChart
|
|
|
44
59
|
h: @height,
|
|
45
60
|
bkg: @background_color,
|
|
46
61
|
devicePixelRatio: @device_pixel_ratio,
|
|
47
|
-
f: @format
|
|
62
|
+
f: @format
|
|
48
63
|
}
|
|
49
|
-
if @key
|
|
50
|
-
params['key'] = @key
|
|
51
|
-
end
|
|
64
|
+
params['key'] = @key if @key
|
|
52
65
|
|
|
53
|
-
uri = URI(
|
|
66
|
+
uri = URI("#{@base_url}#{path}")
|
|
54
67
|
https = Net::HTTP.new(uri.host, uri.port)
|
|
55
68
|
https.use_ssl = true
|
|
56
69
|
req = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json')
|
|
57
70
|
req.body = params.to_json
|
|
58
71
|
|
|
59
|
-
|
|
72
|
+
https.request(req)
|
|
60
73
|
end
|
|
61
74
|
|
|
62
75
|
def get_short_url
|
|
63
|
-
res = _http_post(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
raise 'Request error: %s' % res.body
|
|
68
|
-
end
|
|
76
|
+
res = _http_post('/chart/create')
|
|
77
|
+
raise "Request error: #{res.body}" unless (200..300).cover? res.code.to_i
|
|
78
|
+
|
|
79
|
+
JSON.parse(res.body)['url']
|
|
69
80
|
end
|
|
70
81
|
|
|
71
82
|
def to_blob
|
|
72
|
-
res = _http_post(
|
|
73
|
-
|
|
83
|
+
res = _http_post('/chart')
|
|
84
|
+
res.body
|
|
74
85
|
end
|
|
75
86
|
|
|
76
87
|
def to_file(path)
|
|
77
88
|
data = to_blob
|
|
78
|
-
File.open(path,
|
|
79
|
-
|path| path.puts data
|
|
80
|
-
}
|
|
89
|
+
File.open(path, 'wb') { |path| path.puts data }
|
|
81
90
|
end
|
|
82
91
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: quickchart
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ian Webster
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-10-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Create chart images and embed them in emails, reports, and elsewhere.
|
|
14
14
|
email:
|