adobe_doc_api 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fa70ac6119400a1d4e5f9f945b58d2c087221a6f94ce31f9a7e073450e021118
4
+ data.tar.gz: 1941e4e7f1c4ec3b57a504bb92be4c3faaa3d7c4f4148987458e422822ff69a5
5
+ SHA512:
6
+ metadata.gz: 381363a1c7b89c72d42f7c3847b0857489b23428b768451f507259e49c2ad6bb0399a12e10e435a19f5c029347332ca21ccd7ca5ebc37741ecb32dde06dea704
7
+ data.tar.gz: 554a83e571dbe3d4844d250694c07cf8bfa0d545e290ed8e465c56c0f0a3df198ad94f1a6900a9fae5e43b681c344efb04e1ebd82cee168107234b1ca06003b3
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-12-28
4
+
5
+ - Initial release
@@ -0,0 +1,133 @@
1
+
2
+ # Contributor Covenant Code of Conduct
3
+
4
+ ## Our Pledge
5
+
6
+ We as members, contributors, and leaders pledge to make participation in our
7
+ community a harassment-free experience for everyone, regardless of age, body
8
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
9
+ identity and expression, level of experience, education, socio-economic status,
10
+ nationality, personal appearance, race, religion, or sexual identity
11
+ and orientation.
12
+
13
+ We pledge to act and interact in ways that contribute to an open, welcoming,
14
+ diverse, inclusive, and healthy community.
15
+
16
+ ## Our Standards
17
+
18
+ Examples of behavior that contributes to a positive environment for our
19
+ community include:
20
+
21
+ * Demonstrating empathy and kindness toward other people
22
+ * Being respectful of differing opinions, viewpoints, and experiences
23
+ * Giving and gracefully accepting constructive feedback
24
+ * Accepting responsibility and apologizing to those affected by our mistakes,
25
+ and learning from the experience
26
+ * Focusing on what is best not just for us as individuals, but for the
27
+ overall community
28
+
29
+ Examples of unacceptable behavior include:
30
+
31
+ * The use of sexualized language or imagery, and sexual attention or
32
+ advances of any kind
33
+ * Trolling, insulting or derogatory comments, and personal or political attacks
34
+ * Public or private harassment
35
+ * Publishing others' private information, such as a physical or email
36
+ address, without their explicit permission
37
+ * Other conduct which could reasonably be considered inappropriate in a
38
+ professional setting
39
+
40
+ ## Enforcement Responsibilities
41
+
42
+ Community leaders are responsible for clarifying and enforcing our standards of
43
+ acceptable behavior and will take appropriate and fair corrective action in
44
+ response to any behavior that they deem inappropriate, threatening, offensive,
45
+ or harmful.
46
+
47
+ Community leaders have the right and responsibility to remove, edit, or reject
48
+ comments, commits, code, wiki edits, issues, and other contributions that are
49
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
50
+ decisions when appropriate.
51
+
52
+ ## Scope
53
+
54
+ This Code of Conduct applies within all community spaces, and also applies when
55
+ an individual is officially representing the community in public spaces.
56
+ Examples of representing our community include using an official e-mail address,
57
+ posting via an official social media account, or acting as an appointed
58
+ representative at an online or offline event.
59
+
60
+ ## Enforcement
61
+
62
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
63
+ reported to the community leaders responsible for enforcement at
64
+ christopher.sonnier[at]gmail.
65
+ All complaints will be reviewed and investigated promptly and fairly.
66
+
67
+ All community leaders are obligated to respect the privacy and security of the
68
+ reporter of any incident.
69
+
70
+ ## Enforcement Guidelines
71
+
72
+ Community leaders will follow these Community Impact Guidelines in determining
73
+ the consequences for any action they deem in violation of this Code of Conduct:
74
+
75
+ ### 1. Correction
76
+
77
+ **Community Impact**: Use of inappropriate language or other behavior deemed
78
+ unprofessional or unwelcome in the community.
79
+
80
+ **Consequence**: A private, written warning from community leaders, providing
81
+ clarity around the nature of the violation and an explanation of why the
82
+ behavior was inappropriate. A public apology may be requested.
83
+
84
+ ### 2. Warning
85
+
86
+ **Community Impact**: A violation through a single incident or series
87
+ of actions.
88
+
89
+ **Consequence**: A warning with consequences for continued behavior. No
90
+ interaction with the people involved, including unsolicited interaction with
91
+ those enforcing the Code of Conduct, for a specified period of time. This
92
+ includes avoiding interactions in community spaces as well as external channels
93
+ like social media. Violating these terms may lead to a temporary or
94
+ permanent ban.
95
+
96
+ ### 3. Temporary Ban
97
+
98
+ **Community Impact**: A serious violation of community standards, including
99
+ sustained inappropriate behavior.
100
+
101
+ **Consequence**: A temporary ban from any sort of interaction or public
102
+ communication with the community for a specified period of time. No public or
103
+ private interaction with the people involved, including unsolicited interaction
104
+ with those enforcing the Code of Conduct, is allowed during this period.
105
+ Violating these terms may lead to a permanent ban.
106
+
107
+ ### 4. Permanent Ban
108
+
109
+ **Community Impact**: Demonstrating a pattern of violation of community
110
+ standards, including sustained inappropriate behavior, harassment of an
111
+ individual, or aggression toward or disparagement of classes of individuals.
112
+
113
+ **Consequence**: A permanent ban from any sort of public interaction within
114
+ the community.
115
+
116
+ ## Attribution
117
+
118
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119
+ version 2.0, available at
120
+ [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
121
+
122
+ Community Impact Guidelines were inspired by
123
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
124
+
125
+ For answers to common questions about this code of conduct, see the FAQ at
126
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available
127
+ at [https://www.contributor-covenant.org/translations][translations].
128
+
129
+ [homepage]: https://www.contributor-covenant.org
130
+ [v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
131
+ [Mozilla CoC]: https://github.com/mozilla/diversity
132
+ [FAQ]: https://www.contributor-covenant.org/faq
133
+ [translations]: https://www.contributor-covenant.org/translations
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in adobe_doc_api.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Chris Sonnier
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # AdobeDocApi
2
+
3
+ This is still a work in progress. Use at your own risk.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'adobe_doc_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install adobe_doc_api
20
+
21
+ ## Required ENV variables
22
+ ```ruby
23
+ ENV['adobe_org_id']
24
+ ENV['adobe_tech_account_id']
25
+ ENV['adobe_client_id']
26
+ ENV['adobe_client_secret']
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```ruby
32
+ key_path = "../full_path_to/private.key"
33
+ doc_path = "../full_path_to/disclosure.docx"
34
+ destination = "../full_path_to_output/output.docx"
35
+ json_data = { 'DocTag': 'Value', 'DocTag2': 'Value2'}
36
+ client = AdobeDocApi::Client.new(private_key_path: key_path, destination_path: destination)
37
+ client.submit(json: json_data, disclosure_file_path: doc_path)
38
+ ```
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/c-sonnier/adobe_doc_api.
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "adobe_doc_api"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,116 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'jwt'
4
+ require 'openssl'
5
+
6
+ module AdobeDocApi
7
+ class Client
8
+ JWT_URL = 'https://ims-na1.adobelogin.com/ims/exchange/jwt/'.freeze
9
+ API_ENDPOINT_URL = 'https://cpf-ue1.adobe.io'.freeze
10
+ attr_reader :access_token, :output_ext, :output_format, :poll_url, :content_request
11
+
12
+ def initialize(private_key_path:, destination_path:)
13
+ @destination_path = destination_path
14
+ @output_ext = File.extname(destination_path)
15
+ @output_format = @output_ext =~ /docx/ ? 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' : 'application/pdf'
16
+
17
+ jwt_payload = {
18
+ 'iss' => ENV['adobe_org_id'],
19
+ 'sub' => ENV['adobe_tech_account_id'],
20
+ 'https://ims-na1.adobelogin.com/s/ent_documentcloud_sdk' => true,
21
+ 'aud' => "https://ims-na1.adobelogin.com/c/#{ENV['adobe_client_id']}",
22
+ 'exp' => (Time.now.utc + 500).to_i
23
+ }
24
+
25
+ rsa_private = OpenSSL::PKey::RSA.new File.read(private_key_path)
26
+ jwt_token = JWT.encode jwt_payload, rsa_private, 'RS256'
27
+
28
+ connection = Faraday.new do |conn|
29
+ conn.response :json, content_type: 'application/json'
30
+ end
31
+
32
+ response = connection.post JWT_URL do |req|
33
+ req.params['client_id'] = ENV['adobe_client_id']
34
+ req.params['client_secret'] = ENV['adobe_client_secret']
35
+ req.params['jwt_token'] = jwt_token
36
+ end
37
+
38
+ @access_token = response.body['access_token']
39
+
40
+ end
41
+
42
+ def submit(json:, disclosure_file_path:)
43
+ @content_request = {
44
+ "cpf:engine": {
45
+ "repo:assetId": 'urn:aaid:cpf:Service-52d5db6097ed436ebb96f13a4c7bf8fb'
46
+ },
47
+ "cpf:inputs": {
48
+ "documentIn": {
49
+ "dc:format": 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
50
+ "cpf:location": 'InputFile0'
51
+ },
52
+ "params": {
53
+ "cpf:inline": {
54
+ "outputFormat": @output_ext.delete('.'),
55
+ "jsonDataForMerge": json
56
+ }
57
+ }
58
+ },
59
+ "cpf:outputs": {
60
+ "documentOut": {
61
+ "dc:format": @output_format.to_s,
62
+ "cpf:location": 'multipartLabel'
63
+ }
64
+ }
65
+ }.to_json
66
+
67
+ connection = Faraday.new API_ENDPOINT_URL do |conn|
68
+ conn.request :authorization, 'Bearer', @access_token
69
+ conn.headers['x-api-key'] = ENV['adobe_client_id']
70
+ conn.request :multipart
71
+ conn.request :url_encoded
72
+ conn.response :json, content_type: 'application/json'
73
+ end
74
+
75
+ payload = {'contentAnalyzerRequests' => content_request}
76
+ payload[:InputFile0] = Faraday::FilePart.new(disclosure_file_path, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')
77
+ res = connection.post('/ops/:create', payload)
78
+ @poll_url = res.headers['location']
79
+ poll_for_file(@poll_url)
80
+ end
81
+
82
+ def poll_for_file(url)
83
+ poll = Faraday.new do |conn|
84
+ conn.request :authorization, 'Bearer', @access_token
85
+ conn.headers['x-api-key'] = ENV['adobe_client_id']
86
+ end
87
+ counter = 0
88
+ loop do
89
+ sleep(6)
90
+ poll_response = poll.get(url)
91
+ counter += 1
92
+ if poll_response.body.include?('"cpf:status":{"completed":true,"type":"","status":200}')
93
+ write_to_file(poll_response)
94
+ break
95
+ end
96
+ break if counter > 10
97
+ rescue StandardError => e
98
+ # Here we can log if there is a failure from Adobe's response i.e. "Failed to complete"
99
+ raise(e)
100
+ end
101
+ end
102
+
103
+ def write_to_file(response)
104
+ temp_file = Tempfile.new([Time.now.to_i.to_s, @output_ext])
105
+ temp_file.write response.body
106
+ temp_file.rewind
107
+ # Read in the raw response and remove the
108
+ my_array = IO.readlines(temp_file.path)
109
+ my_array.pop
110
+ array = my_array.drop(9)
111
+ arry = array.join('')
112
+ File.open(@destination_path, 'wb') { |f| f.write arry.chomp}
113
+ temp_file.close!
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,3 @@
1
+ module AdobeDocApi
2
+ class Error < StandardError; end
3
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AdobeDocApi
4
+ VERSION = "0.1.1"
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "adobe_doc_api/version"
4
+
5
+ module AdobeDocApi
6
+ autoload :Client, "adobe_doc_api/client"
7
+ autoload :Error, "adobe_doc_api/error"
8
+
9
+ # Your code goes here...
10
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adobe_doc_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Sonnier
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jwt
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: openssl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.2.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.2.1
69
+ description: Ruby interface for Adobe PDF Services API Document Generation
70
+ email:
71
+ - christopher.sonnier@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - CHANGELOG.md
77
+ - CODE_OF_CONDUCT.md
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/adobe_doc_api.rb
85
+ - lib/adobe_doc_api/client.rb
86
+ - lib/adobe_doc_api/error.rb
87
+ - lib/adobe_doc_api/version.rb
88
+ homepage: https://github.com/c-sonnier/adobe_doc_api
89
+ licenses:
90
+ - MIT
91
+ metadata:
92
+ homepage_uri: https://github.com/c-sonnier/adobe_doc_api
93
+ changelog_uri: https://github.com/c-sonnier/adobe_doc_api/blob/master/CHANGELOG.md
94
+ bug_tracker_uri: https://github.com/c-sonnier/adobe_doc_api/issues
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 2.6.0
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubygems_version: 3.2.32
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Ruby interface for Adobe PDF Services API Document Generation
114
+ test_files: []