blazingdocs 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +12 -0
- data/LICENSE +21 -0
- data/README.md +56 -0
- data/blazingdocs.gemspec +51 -0
- data/lib/blazingdocs/blazing_client.rb +152 -0
- data/lib/blazingdocs/configuration.rb +19 -0
- data/lib/blazingdocs/errors/blazing_error.rb +41 -0
- data/lib/blazingdocs/models/account_model.rb +42 -0
- data/lib/blazingdocs/models/base_model.rb +9 -0
- data/lib/blazingdocs/models/file_model.rb +36 -0
- data/lib/blazingdocs/models/operation_model.rb +23 -0
- data/lib/blazingdocs/models/operation_type_model.rb +7 -0
- data/lib/blazingdocs/models/plan_model.rb +11 -0
- data/lib/blazingdocs/models/template_model.rb +6 -0
- data/lib/blazingdocs/models/usage_model.rb +9 -0
- data/lib/blazingdocs/parameters/merge_parameters.rb +43 -0
- data/lib/blazingdocs/utils/hash_utils.rb +82 -0
- data/lib/blazingdocs/version.rb +3 -0
- data/lib/blazingdocs.rb +19 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b91b8015b41363e73016f083c266037b25d78cdc36aaa3b7b8e7cd5625ecadfe
|
4
|
+
data.tar.gz: d0135b8cfc006264cae8ce41f4247dd22745103009aec6055a5828ceb6d08ea3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e467a216544d7632643b97e693e381c8c4479d462f8792f2d36408b150f35f78a175af1f3725ec88b010d0526a1015aee48555b932bd93ca5b23425a513c0089
|
7
|
+
data.tar.gz: fb03c1237a1a534ed97eb2deb7d50da7883503bb5bc0288085a8fdff4a1ae0abd6d1083323f93a0a17da88cc432c0505624d901124d9d536130c56aac46817b9
|
data/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gem 'multipart-post'
|
data/Gemfile.lock
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 BlazingDocs
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# BlazingDocs Ruby client
|
2
|
+
High-performance document generation API. Generate documents and reports from СSV, JSON, XML with 99,9% uptime and 24/7 monitoring.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'blazingdocs'
|
10
|
+
```
|
11
|
+
## Integration basics
|
12
|
+
|
13
|
+
### Setup
|
14
|
+
|
15
|
+
You can get your API Key at https://app.blazingdocs.com
|
16
|
+
```ruby
|
17
|
+
client = BlazingDocs.create_client('api-key')
|
18
|
+
```
|
19
|
+
### Getting account info
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
account = client.get_account
|
23
|
+
```
|
24
|
+
|
25
|
+
### Getting merge templates list
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
templates = client.get_templates
|
29
|
+
|
30
|
+
# with parent folder path
|
31
|
+
templates = client.get_templates('parentfolder')
|
32
|
+
```
|
33
|
+
|
34
|
+
### Getting usage info
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
usage = client.get_usage
|
38
|
+
```
|
39
|
+
|
40
|
+
### Executing merge
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
data = File.open('PO-Template.json').read
|
44
|
+
template = File.open('PO-Template.docx')
|
45
|
+
|
46
|
+
merge_parameters = BlazingDocs::MergeParameters.new
|
47
|
+
merge_parameters.sequence = false # data is object
|
48
|
+
merge_parameters.data_source_type = 'json' # data in json format
|
49
|
+
merge_parameters.strict = true # keep json types
|
50
|
+
|
51
|
+
merge_result = client.merge(data, 'output.pdf', merge_parameters, template)
|
52
|
+
```
|
53
|
+
|
54
|
+
## Documentation
|
55
|
+
|
56
|
+
See more details here https://docs.blazingdocs.com
|
data/blazingdocs.gemspec
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'blazingdocs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'blazingdocs'
|
8
|
+
spec.version = BlazingDocs::VERSION
|
9
|
+
spec.authors = ['Mentalstack']
|
10
|
+
spec.email = ['hello@blazingdocs.com']
|
11
|
+
|
12
|
+
spec.summary = 'BlazingDocs Ruby client'
|
13
|
+
spec.description = 'BlazingDocs Ruby client. High-performance document generation API. Generate documents and reports from СSV, JSON, XML with 99,9% uptime and 24/7 monitoring'
|
14
|
+
spec.homepage = 'https://blazingdocs.com'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
spec.metadata = {
|
17
|
+
"bug_tracker_uri" => "https://github.com/blazingdocs/blazingdocs-ruby/issues",
|
18
|
+
"changelog_uri" => "https://github.com/blazingdocs/blazingdocs-ruby/blob/master/CHANGELOG.md",
|
19
|
+
"documentation_uri" => "https://docs.blazingdocs.com",
|
20
|
+
"homepage_uri" => spec.homepage,
|
21
|
+
"source_code_uri" => "https://github.com/blazingdocs/blazingdocs-ruby"
|
22
|
+
}
|
23
|
+
|
24
|
+
ignored = Regexp.union(
|
25
|
+
/\.editorconfig/,
|
26
|
+
/\.git/,
|
27
|
+
/\.vscode/,
|
28
|
+
/^test/,
|
29
|
+
/^examples/,
|
30
|
+
/^templates/
|
31
|
+
)
|
32
|
+
spec.files = `git ls-files`.split("\n").reject { |f| ignored.match(f) }
|
33
|
+
puts(spec.files)
|
34
|
+
#spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
35
|
+
# f.match(%r{^(test|spec|features|examples|templates)/})
|
36
|
+
#end
|
37
|
+
#spec.files.reject! { |fn| fn.include? "gitignore" }
|
38
|
+
|
39
|
+
spec.bindir = 'exe'
|
40
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
41
|
+
spec.require_paths = ['lib']
|
42
|
+
|
43
|
+
spec.extra_rdoc_files = Dir["README.md", "CHANGELOG.md", "LICENSE.txt"]
|
44
|
+
spec.rdoc_options += [
|
45
|
+
"--title", "BlazingDocs Ruby client",
|
46
|
+
"--main", "README.md",
|
47
|
+
"--line-numbers",
|
48
|
+
"--inline-source",
|
49
|
+
"--quiet"
|
50
|
+
]
|
51
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'uri'
|
3
|
+
require 'cgi'
|
4
|
+
require 'json'
|
5
|
+
require 'net/http/post/multipart'
|
6
|
+
require 'blazingdocs/utils/hash_utils'
|
7
|
+
require 'blazingdocs/models/account_model'
|
8
|
+
require 'blazingdocs/models/usage_model'
|
9
|
+
require 'blazingdocs/models/template_model'
|
10
|
+
require 'blazingdocs/models/operation_model'
|
11
|
+
require 'blazingdocs/parameters/merge_parameters'
|
12
|
+
require 'blazingdocs/errors/blazing_error'
|
13
|
+
|
14
|
+
module BlazingDocs
|
15
|
+
class BlazingClient
|
16
|
+
API_KEY_HEADER ||= 'X-API-Key'
|
17
|
+
|
18
|
+
DEFAULT_HEADERS ||= {
|
19
|
+
'Accept' => 'application/json'
|
20
|
+
}
|
21
|
+
|
22
|
+
def initialize(api_key, config)
|
23
|
+
raise TypeError, 'api_key expects a string' unless api_key.kind_of?(String)
|
24
|
+
|
25
|
+
@configuration = config.nil? ? Configuration.new : config.clone
|
26
|
+
@configuration.api_key = api_key
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_account
|
30
|
+
hash = get('/account')
|
31
|
+
AccountModel.new(to_snake_keys(hash))
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_templates(path = nil)
|
35
|
+
hashes = get("/templates/#{path or ''}")
|
36
|
+
hashes.map { |hash| TemplateModel.new(to_snake_keys(hash)) }
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_usage
|
40
|
+
hash = get('/usage')
|
41
|
+
UsageModel.new(to_snake_keys(hash))
|
42
|
+
end
|
43
|
+
|
44
|
+
def merge(data, file_name, merge_parameters, template)
|
45
|
+
form_data = {}
|
46
|
+
|
47
|
+
raise ArgumentError, 'data is not provided' if data.nil?
|
48
|
+
raise ArgumentError, 'data expects a string' unless data.kind_of?(String)
|
49
|
+
|
50
|
+
form_data['Data'] = data
|
51
|
+
|
52
|
+
raise ArgumentError, 'file_name is not provided' if file_name.nil?
|
53
|
+
|
54
|
+
form_data['OutputName'] = file_name
|
55
|
+
|
56
|
+
raise ArgumentError, 'merge_parameters is not provided' if merge_parameters.nil?
|
57
|
+
|
58
|
+
if merge_parameters.is_a?(Hash)
|
59
|
+
form_data['MergeParameters'] = to_camel_keys(merge_parameters).to_json
|
60
|
+
elsif merge_parameters.is_a?(BlazingDocs::MergeParameters)
|
61
|
+
form_data['MergeParameters'] = to_camel_keys(to_hash(merge_parameters)).to_json
|
62
|
+
else
|
63
|
+
raise ArgumentError, 'merge_parameters expects Hash or MergeParameters'
|
64
|
+
end
|
65
|
+
|
66
|
+
raise ArgumentError, 'template is not provided' if template.nil?
|
67
|
+
|
68
|
+
options = default_options
|
69
|
+
if template.is_a?(File)
|
70
|
+
form_data['Template'] = UploadIO.new(template, 'application/octet-stream', File.basename(template))
|
71
|
+
options = upload_options
|
72
|
+
elsif template.is_a?(String)
|
73
|
+
form_data['Template'] = template
|
74
|
+
end
|
75
|
+
|
76
|
+
hash = multipart_post('/operation/merge', form_data, options)
|
77
|
+
OperationModel.new(to_snake_keys(hash))
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
include BlazingDocs::Utils
|
83
|
+
|
84
|
+
attr_accessor :configuration
|
85
|
+
|
86
|
+
def get(path, params = {}, options = {})
|
87
|
+
handle_response do
|
88
|
+
headers = DEFAULT_HEADERS.merge({ API_KEY_HEADER => @configuration.api_key })
|
89
|
+
request = Net::HTTP::Get.new(request_uri(path, params), headers)
|
90
|
+
|
91
|
+
http(options).request(request)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def multipart_post(path, form_data, options = {})
|
96
|
+
handle_response do
|
97
|
+
headers = DEFAULT_HEADERS.merge({ API_KEY_HEADER => @configuration.api_key })
|
98
|
+
request = Net::HTTP::Post::Multipart.new(path, form_data, headers)
|
99
|
+
|
100
|
+
http(options).request(request)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def handle_response
|
105
|
+
response = yield
|
106
|
+
status = response.code.to_i
|
107
|
+
|
108
|
+
if status != 200
|
109
|
+
raise(
|
110
|
+
BlazingError,
|
111
|
+
status: status,
|
112
|
+
body: response.body,
|
113
|
+
headers: response.each_header.to_h,
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
JSON.parse(response.body)
|
118
|
+
end
|
119
|
+
|
120
|
+
def http(options = {})
|
121
|
+
options = default_options if options.empty?
|
122
|
+
|
123
|
+
http = Net::HTTP.new(base_uri.host, base_uri.port)
|
124
|
+
http.open_timeout = options.fetch(:open_timeout)
|
125
|
+
http.read_timeout = options.fetch(:read_timeout)
|
126
|
+
http.use_ssl = base_uri.scheme == 'https'
|
127
|
+
# http.set_debug_output $stderr
|
128
|
+
http
|
129
|
+
end
|
130
|
+
|
131
|
+
def request_uri(path, params = {})
|
132
|
+
query = URI.encode_www_form(params)
|
133
|
+
base_uri.path + path + '?' + query
|
134
|
+
end
|
135
|
+
|
136
|
+
def base_uri
|
137
|
+
@configuration.base_uri
|
138
|
+
end
|
139
|
+
|
140
|
+
def default_options
|
141
|
+
options = { read_timeout: @configuration.read_timeout }
|
142
|
+
options[:open_timeout] = @configuration.connect_timeout if RUBY_VERSION > '2.2.0'
|
143
|
+
options
|
144
|
+
end
|
145
|
+
|
146
|
+
def upload_options
|
147
|
+
options = default_options
|
148
|
+
options[:read_timeout] = @configuration.upload_timeout
|
149
|
+
options
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module BlazingDocs
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :api_key
|
6
|
+
attr_accessor :connect_timeout
|
7
|
+
attr_accessor :read_timeout
|
8
|
+
attr_accessor :upload_timeout
|
9
|
+
|
10
|
+
attr_reader :base_uri
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@base_uri = URI('https://api.blazingdocs.com')
|
14
|
+
@connect_timeout = 5
|
15
|
+
@read_timeout = 60
|
16
|
+
@upload_timeout = 1800
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module BlazingDocs
|
2
|
+
class BlazingError < StandardError
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
@response = response
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
return "the server responded with status #{http_status}" unless json?
|
11
|
+
|
12
|
+
"Status: #{http_status}. Error message: #{error_message}. Errors: #{errors}".strip
|
13
|
+
end
|
14
|
+
|
15
|
+
def error_message
|
16
|
+
response_json['message']
|
17
|
+
end
|
18
|
+
|
19
|
+
def errors
|
20
|
+
response_json['errors']
|
21
|
+
end
|
22
|
+
|
23
|
+
def http_status
|
24
|
+
response[:status]
|
25
|
+
end
|
26
|
+
|
27
|
+
def response_json
|
28
|
+
@response_json ||= begin
|
29
|
+
JSON.parse(response[:body])
|
30
|
+
rescue JSON::ParserError
|
31
|
+
{}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def json?
|
38
|
+
response[:headers]['content-type'] =~ /json/
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'blazingdocs/models/base_model'
|
3
|
+
require 'blazingdocs/models/plan_model'
|
4
|
+
|
5
|
+
module BlazingDocs
|
6
|
+
class AccountModel < BaseModel
|
7
|
+
attr_accessor :id
|
8
|
+
attr_accessor :api_key
|
9
|
+
attr_accessor :obsolete_api_key
|
10
|
+
attr_accessor :name
|
11
|
+
attr_accessor :is_disabled
|
12
|
+
|
13
|
+
attr_reader :plan
|
14
|
+
attr_reader :created_at
|
15
|
+
attr_reader :last_synced_at
|
16
|
+
attr_reader :updated_at
|
17
|
+
|
18
|
+
def plan=(plan_hash)
|
19
|
+
@plan = PlanModel.new(plan_hash)
|
20
|
+
end
|
21
|
+
|
22
|
+
def created_at=(created_at_str)
|
23
|
+
@created_at = DateTime.iso8601(created_at_str)
|
24
|
+
end
|
25
|
+
|
26
|
+
def last_synced_at=(last_synced_at_str)
|
27
|
+
@last_synced_at = if !last_synced_at_str.nil?
|
28
|
+
DateTime.iso8601(last_synced_at_str)
|
29
|
+
else
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def updated_at=(updated_at_str)
|
35
|
+
@updated_at = if !updated_at_str.nil?
|
36
|
+
DateTime.iso8601(updated_at_str)
|
37
|
+
else
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'blazingdocs/models/base_model'
|
3
|
+
|
4
|
+
module BlazingDocs
|
5
|
+
class FileModel < BaseModel
|
6
|
+
attr_accessor :id
|
7
|
+
attr_accessor :name
|
8
|
+
attr_accessor :content_type
|
9
|
+
attr_accessor :download_url
|
10
|
+
attr_accessor :length
|
11
|
+
|
12
|
+
attr_reader :created_at
|
13
|
+
attr_reader :last_modified_at
|
14
|
+
attr_reader :last_accessed_at
|
15
|
+
|
16
|
+
def created_at=(created_at_str)
|
17
|
+
@created_at = DateTime.iso8601(created_at_str)
|
18
|
+
end
|
19
|
+
|
20
|
+
def last_modified_at=(last_modified_at_str)
|
21
|
+
@last_modified_at = if !last_modified_at_str.nil?
|
22
|
+
DateTime.iso8601(last_modified_at_str)
|
23
|
+
else
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def last_accessed_at=(last_accessed_at_str)
|
29
|
+
@last_accessed_at = if !last_accessed_at_str.nil?
|
30
|
+
DateTime.iso8601(last_accessed_at_str)
|
31
|
+
else
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'blazingdocs/models/base_model'
|
2
|
+
require 'blazingdocs/models/file_model'
|
3
|
+
require 'blazingdocs/models/operation_type_model'
|
4
|
+
|
5
|
+
module BlazingDocs
|
6
|
+
class OperationModel < BaseModel
|
7
|
+
attr_accessor :id
|
8
|
+
attr_accessor :page_count
|
9
|
+
attr_accessor :elapsed_milliseconds
|
10
|
+
attr_accessor :remote_ip_address
|
11
|
+
|
12
|
+
attr_reader :files
|
13
|
+
attr_reader :type
|
14
|
+
|
15
|
+
def files=(file_hashes)
|
16
|
+
@files = file_hashes.map { |hash| FileModel.new(hash) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def type=(type_hash)
|
20
|
+
@type = OperationTypeModel.new(type_hash)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module BlazingDocs
|
2
|
+
DATA_SOURCE_TYPES ||= {
|
3
|
+
'csv' => 'Csv',
|
4
|
+
'json' => 'Json',
|
5
|
+
'xml' => 'Xml'
|
6
|
+
}
|
7
|
+
|
8
|
+
class MergeParameters
|
9
|
+
attr_accessor :data_source_name
|
10
|
+
attr_accessor :parse_columns
|
11
|
+
attr_accessor :sequence
|
12
|
+
attr_accessor :data_source_type
|
13
|
+
attr_accessor :strict
|
14
|
+
|
15
|
+
def initialize(sequence = false, data_source_type = 'json', strict = false, data_source_name = 'data', parse_columns = false)
|
16
|
+
@data_source_name = data_source_name
|
17
|
+
|
18
|
+
if !!sequence == sequence
|
19
|
+
@sequence = sequence
|
20
|
+
else
|
21
|
+
raise TypeError, 'sequence expects to be boolean'
|
22
|
+
end
|
23
|
+
|
24
|
+
if !DATA_SOURCE_TYPES[data_source_type.downcase].nil?
|
25
|
+
@data_source_type = DATA_SOURCE_TYPES[data_source_type.downcase]
|
26
|
+
else
|
27
|
+
raise TypeError, 'data_source_type expects csv, json or xml'
|
28
|
+
end
|
29
|
+
|
30
|
+
if !!strict == strict
|
31
|
+
@strict = strict
|
32
|
+
else
|
33
|
+
raise TypeError, 'strict expects to be boolean'
|
34
|
+
end
|
35
|
+
|
36
|
+
if !!parse_columns == parse_columns
|
37
|
+
@parse_columns = parse_columns
|
38
|
+
else
|
39
|
+
raise TypeError, 'parse_columns expects to be boolean'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module BlazingDocs
|
2
|
+
module Utils
|
3
|
+
|
4
|
+
def to_snake_keys(value = {})
|
5
|
+
case value
|
6
|
+
when Array
|
7
|
+
value.map { |v| to_snake_keys(v) }
|
8
|
+
when Hash
|
9
|
+
snake_hash(value)
|
10
|
+
else
|
11
|
+
value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_camel_keys(value = {})
|
16
|
+
case value
|
17
|
+
when Array
|
18
|
+
value.map { |v| to_camel_keys(v) }
|
19
|
+
when Hash
|
20
|
+
camel_hash(value)
|
21
|
+
else
|
22
|
+
value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_hash(obj)
|
27
|
+
hash = {}
|
28
|
+
obj.instance_variables.each { |var| hash[var.to_s.delete('@')] = obj.instance_variable_get(var) }
|
29
|
+
hash
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def snake_hash(value)
|
35
|
+
value.map { |k, v| [underscore_key(k), to_snake_keys(v)] }.to_h
|
36
|
+
end
|
37
|
+
|
38
|
+
def underscore_key(key)
|
39
|
+
case key
|
40
|
+
when Symbol
|
41
|
+
underscore(key.to_s).to_sym
|
42
|
+
when String
|
43
|
+
underscore(key)
|
44
|
+
else
|
45
|
+
key
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def underscore(string)
|
50
|
+
@__memoize_underscore ||= {}
|
51
|
+
|
52
|
+
return @__memoize_underscore[string] if @__memoize_underscore[string]
|
53
|
+
|
54
|
+
@__memoize_underscore[string] =
|
55
|
+
string.tr("::", "/")
|
56
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
57
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
58
|
+
.tr("-", "_")
|
59
|
+
.downcase
|
60
|
+
@__memoize_underscore[string]
|
61
|
+
end
|
62
|
+
|
63
|
+
def camel_hash(value)
|
64
|
+
value.map { |k, v| [camel_case_key(k), to_camel_keys(v)] }.to_h
|
65
|
+
end
|
66
|
+
|
67
|
+
def camel_case_key(key)
|
68
|
+
case key
|
69
|
+
when Symbol
|
70
|
+
camel_case_lower(key.to_s).to_sym
|
71
|
+
when String
|
72
|
+
camel_case_lower(key)
|
73
|
+
else
|
74
|
+
key
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def camel_case_lower(string)
|
79
|
+
string.split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/blazingdocs.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'blazingdocs/version'
|
2
|
+
require 'blazingdocs/configuration'
|
3
|
+
require 'blazingdocs/blazing_client'
|
4
|
+
|
5
|
+
module BlazingDocs
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def configure
|
9
|
+
yield(config)
|
10
|
+
end
|
11
|
+
|
12
|
+
def config
|
13
|
+
@config ||= Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_client(api_key)
|
17
|
+
BlazingClient.new(api_key, config)
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blazingdocs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mentalstack
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: BlazingDocs Ruby client. High-performance document generation API. Generate
|
14
|
+
documents and reports from СSV, JSON, XML with 99,9% uptime and 24/7 monitoring
|
15
|
+
email:
|
16
|
+
- hello@blazingdocs.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files:
|
20
|
+
- README.md
|
21
|
+
files:
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- blazingdocs.gemspec
|
27
|
+
- lib/blazingdocs.rb
|
28
|
+
- lib/blazingdocs/blazing_client.rb
|
29
|
+
- lib/blazingdocs/configuration.rb
|
30
|
+
- lib/blazingdocs/errors/blazing_error.rb
|
31
|
+
- lib/blazingdocs/models/account_model.rb
|
32
|
+
- lib/blazingdocs/models/base_model.rb
|
33
|
+
- lib/blazingdocs/models/file_model.rb
|
34
|
+
- lib/blazingdocs/models/operation_model.rb
|
35
|
+
- lib/blazingdocs/models/operation_type_model.rb
|
36
|
+
- lib/blazingdocs/models/plan_model.rb
|
37
|
+
- lib/blazingdocs/models/template_model.rb
|
38
|
+
- lib/blazingdocs/models/usage_model.rb
|
39
|
+
- lib/blazingdocs/parameters/merge_parameters.rb
|
40
|
+
- lib/blazingdocs/utils/hash_utils.rb
|
41
|
+
- lib/blazingdocs/version.rb
|
42
|
+
homepage: https://blazingdocs.com
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata:
|
46
|
+
bug_tracker_uri: https://github.com/blazingdocs/blazingdocs-ruby/issues
|
47
|
+
changelog_uri: https://github.com/blazingdocs/blazingdocs-ruby/blob/master/CHANGELOG.md
|
48
|
+
documentation_uri: https://docs.blazingdocs.com
|
49
|
+
homepage_uri: https://blazingdocs.com
|
50
|
+
source_code_uri: https://github.com/blazingdocs/blazingdocs-ruby
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- "--title"
|
54
|
+
- BlazingDocs Ruby client
|
55
|
+
- "--main"
|
56
|
+
- README.md
|
57
|
+
- "--line-numbers"
|
58
|
+
- "--inline-source"
|
59
|
+
- "--quiet"
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubygems_version: 3.2.22
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: BlazingDocs Ruby client
|
77
|
+
test_files: []
|