quickchart 1.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 +7 -0
- data/lib/quickchart.rb +82 -0
- metadata +49 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 8aede191351c17b72c0b7267eeb0391c30825247
|
|
4
|
+
data.tar.gz: 581984d476d580b983b2eac51b4b20aa625e8024
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1a214be167a5019561ef1cd330a063f175509d6f67d19c6809e50bfb5457ef5a29a98a54820ce8e27c41b71334f6bcb7228e80e0c064aedd8cebdac707768bec
|
|
7
|
+
data.tar.gz: de9942cce6d852994cc71d067f3ed2f4ea9c8050ff65bf8e105cace9c2bee9d661947217d4645859f79bad37832df319b8797f9b5d8b45412e7d6a4d3630b7a6
|
data/lib/quickchart.rb
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'uri'
|
|
5
|
+
|
|
6
|
+
class QuickChart
|
|
7
|
+
attr_accessor :config, :width, :height, :background_color, :device_pixel_ratio, :format, :key
|
|
8
|
+
|
|
9
|
+
def initialize(config, width: 500, height: 300, background_color: '#ffffff', device_pixel_ratio: 1.0, format: 'png', key: nil)
|
|
10
|
+
@config = config
|
|
11
|
+
@width = width
|
|
12
|
+
@height = height
|
|
13
|
+
@background_color = background_color
|
|
14
|
+
@device_pixel_ratio = device_pixel_ratio
|
|
15
|
+
@format = format
|
|
16
|
+
@key = key
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_url
|
|
20
|
+
params = {
|
|
21
|
+
c: @config.is_a?(String) ? @config : @config.to_json,
|
|
22
|
+
w: @width,
|
|
23
|
+
h: @height,
|
|
24
|
+
bkg: @background_color,
|
|
25
|
+
devicePixelRatio: @device_pixel_ratio,
|
|
26
|
+
f: @format,
|
|
27
|
+
}
|
|
28
|
+
if @key
|
|
29
|
+
params['key'] = @key
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
encoded = URI.encode_www_form(params)
|
|
33
|
+
return 'https://quickchart.io/chart?%s' % encoded
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def _http_post(path)
|
|
37
|
+
spec = Gem.loaded_specs["quickchart"]
|
|
38
|
+
version = if spec then spec.version.to_s else 'unknown' end
|
|
39
|
+
request_headers = {"user-agent" => "quickchart-ruby/%s" % version}
|
|
40
|
+
|
|
41
|
+
params = {
|
|
42
|
+
c: @config.is_a?(String) ? @config : @config.to_json,
|
|
43
|
+
w: @width,
|
|
44
|
+
h: @height,
|
|
45
|
+
bkg: @background_color,
|
|
46
|
+
devicePixelRatio: @device_pixel_ratio,
|
|
47
|
+
f: @format,
|
|
48
|
+
}
|
|
49
|
+
if @key
|
|
50
|
+
params['key'] = @key
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
uri = URI('https://quickchart.io%s' % path)
|
|
54
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
|
55
|
+
https.use_ssl = true
|
|
56
|
+
req = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json')
|
|
57
|
+
req.body = params.to_json
|
|
58
|
+
|
|
59
|
+
return https.request(req)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def get_short_url
|
|
63
|
+
res = _http_post("/chart/create")
|
|
64
|
+
if (200..300).cover? res.code.to_i
|
|
65
|
+
return JSON.parse(res.body)['url']
|
|
66
|
+
else
|
|
67
|
+
raise 'Request error: %s' % res.body
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def to_blob
|
|
72
|
+
res = _http_post("/chart")
|
|
73
|
+
return res.body
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def to_file(path)
|
|
77
|
+
data = to_blob
|
|
78
|
+
File.open(path, "wb") {
|
|
79
|
+
|path| path.puts data
|
|
80
|
+
}
|
|
81
|
+
end
|
|
82
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: quickchart
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ian Webster
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-09-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Create chart images and embed them in emails, reports, and elsewhere.
|
|
14
|
+
email:
|
|
15
|
+
- support@quickchart.io
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/quickchart.rb
|
|
21
|
+
homepage: https://www.quickchart.io/
|
|
22
|
+
licenses:
|
|
23
|
+
- MIT
|
|
24
|
+
metadata:
|
|
25
|
+
bug_tracker_uri: https://github.com/typpo/quickchart-ruby/issues
|
|
26
|
+
documentation_uri: https://github.com/typpo/quickchart-ruby/README.md
|
|
27
|
+
homepage_uri: https://www.quickchart.io/
|
|
28
|
+
source_code_uri: https://github.com/typpo/quickchart-ruby/
|
|
29
|
+
post_install_message:
|
|
30
|
+
rdoc_options: []
|
|
31
|
+
require_paths:
|
|
32
|
+
- lib
|
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '0'
|
|
43
|
+
requirements: []
|
|
44
|
+
rubyforge_project:
|
|
45
|
+
rubygems_version: 2.5.2.3
|
|
46
|
+
signing_key:
|
|
47
|
+
specification_version: 4
|
|
48
|
+
summary: Official QuickChart API client library
|
|
49
|
+
test_files: []
|