Skip to content

Commit

Permalink
Merge pull request #3 from ARPC/getting-started
Browse files Browse the repository at this point in the history
Rearrange to make it work like a real gem.
  • Loading branch information
jbosse authored Aug 31, 2022
2 parents 7dc1146 + 3615379 commit 5ac981b
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 52 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ An Adobe PDF Services Ruby SDK provides APIs for creating, combining, exporting

To use the gem in your project Gemfile:
1. Generate an OAuth token for GitHub
```terminal
curl -u 'username' -d '{"scopes":["repo"],"note":"Gemfile Token"}' https://api.github.com/authorizations
```

2. Add the token as an environment variable:
```terminal
$ export GITHUB_TOKEN=your_token
$ export BUNDLE_GITHUB__COM=your_token
```

3. Add the gem to your gemfile:
```terminal
gem "pdfservices", git: "https://#{ENV['GITHUB_TOKEN']}:x-oauth-basic@github.com/arpc/pdfservices-ruby-sdk.git'
gem "pdfservices", git: "https://github.com/arpc/pdfservices-ruby-sdk.git'
```

## Usage
Expand Down
16 changes: 16 additions & 0 deletions lib/pdfservices.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require "http"
require "json"
require "jwt"
require "multipart_parser/reader"
require "pdfservices/document_merge/operation"
require "pdfservices/document_merge/result"
require "pdfservices/credentials_builder"
require "pdfservices/credentials"
require "pdfservices/jwt_provider"
require "pdfservices/version"
require "yaml"

module PdfServices
end
2 changes: 1 addition & 1 deletion lib/credentials.rb → lib/pdfservices/credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "json"

module PdfServicesSdk
module PdfServices
class Credentials
attr_accessor :client_id, :client_secret, :organization_id, :account_id, :private_key

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

require "json"
require "credentials"
require "pdfservices/credentials"

module PdfServicesSdk
module PdfServices
class CredentialsBuilder
def initialize
@client_id = nil
Expand Down Expand Up @@ -50,7 +50,7 @@ def from_file(file_path)
end

def build
::PdfServicesSdk::Credentials.new(
::PdfServices::Credentials.new(
client_id: @client_id,
client_secret: @client_secret,
organization_id: @organization_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require "jwt_provider"
require "http"
require "document_merge/result"
require "jwt_provider"
require "pdfservices/document_merge/result"
require "yaml"

module PdfServicesSdk
module PdfServices
module DocumentMerge
class Operation
ENDPOINT = "https://cpf-ue1.adobe.io/ops/:create?respondWith=%7B%22reltype%22%3A%20%22http%3A%2F%2Fns.adobe.com%2Frel%2Fprimary%22%7D"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "multipart_parser/reader"
require "json"
require "multipart_parser/reader"

module PdfServicesSdk
module PdfServices
module DocumentMerge
class Result
attr_accessor :document, :error
Expand Down
12 changes: 7 additions & 5 deletions lib/jwt_provider.rb → lib/pdfservices/jwt_provider.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
require "jwt"
# frozen_string_literal: true

require "http"
require "json"
require "jwt"
require "yaml"

module PdfServicesSdk
module PdfServices
class JwtProvider
ROOT = "https://ims-na1.adobelogin.com/".freeze
ENDPOINT = "#{ROOT}ims/exchange/jwt/".freeze
SCOPE = "#{ROOT}s/ent_documentcloud_sdk".freeze
ROOT = "https://ims-na1.adobelogin.com/"
ENDPOINT = "#{ROOT}ims/exchange/jwt/"
SCOPE = "#{ROOT}s/ent_documentcloud_sdk"

def self.get_jwt(credentials)
payload = {
Expand Down
5 changes: 5 additions & 0 deletions lib/pdfservices/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module PdfServices
VERSION = "0.1.1"
end
5 changes: 0 additions & 5 deletions lib/version.rb

This file was deleted.

8 changes: 6 additions & 2 deletions pdfservices-ruby-sdk.gemspec
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

require_relative "lib/version"
require_relative "lib/pdfservices/version"

Gem::Specification.new do |spec|
spec.name = "pdfservices"
spec.version = PdfServicesSdk::VERSION
spec.version = PdfServices::VERSION
spec.authors = ["Jimmy Bosse"]
spec.email = ["[email protected]"]

Expand All @@ -31,6 +31,10 @@ Gem::Specification.new do |spec|

# Uncomment to register a new dependency of your gem
# spec.add_dependency "example-gem", "~> 1.0"
spec.add_dependency "json", "~> 2.6"
spec.add_dependency "jwt", "~> 2.5"
spec.add_dependency "http", "~> 5.1"
spec.add_dependency "multipart-parser", "~> 0.1"

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
Expand Down
3 changes: 1 addition & 2 deletions test/pdf_services_sdk/test_credentials.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# frozen_string_literal: true

require "test_helper"
require "credentials"

class CredentialsTest < Minitest::Test
def test_it_has_the_fields
credentials = ::PdfServicesSdk::Credentials.new(
credentials = ::PdfServices::Credentials.new(
client_id: "client_id",
client_secret: "client_secret",
organization_id: "organization_id",
Expand Down
17 changes: 8 additions & 9 deletions test/pdf_services_sdk/test_credentials_builder.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# frozen_string_literal: true

require "test_helper"
require "credentials_builder"

class CredentialsBuildTest < Minitest::Test
def test_it_is_empty_when_initialized
builder = ::PdfServicesSdk::CredentialsBuilder.new
builder = ::PdfServices::CredentialsBuilder.new

assert builder.instance_variable_get(:@client_id).nil?
assert builder.instance_variable_get(:@client_secret).nil?
Expand All @@ -15,37 +14,37 @@ def test_it_is_empty_when_initialized
end

def test_with_client_id_sets_client_id
builder = ::PdfServicesSdk::CredentialsBuilder.new.with_client_id("123someclientid")
builder = ::PdfServices::CredentialsBuilder.new.with_client_id("123someclientid")

assert builder.instance_variable_get(:@client_id) == "123someclientid"
end

def test_with_client_secret_sets_client_secret
builder = ::PdfServicesSdk::CredentialsBuilder.new.with_client_secret("123someclientsecret")
builder = ::PdfServices::CredentialsBuilder.new.with_client_secret("123someclientsecret")

assert builder.instance_variable_get(:@client_secret) == "123someclientsecret"
end

def test_with_organization_id_sets_organization_id
builder = ::PdfServicesSdk::CredentialsBuilder.new.with_organization_id("123someorganizationid")
builder = ::PdfServices::CredentialsBuilder.new.with_organization_id("123someorganizationid")

assert builder.instance_variable_get(:@organization_id) == "123someorganizationid"
end

def test_with_account_id_sets_account_id
builder = ::PdfServicesSdk::CredentialsBuilder.new.with_account_id("123someaccountid")
builder = ::PdfServices::CredentialsBuilder.new.with_account_id("123someaccountid")

assert builder.instance_variable_get(:@account_id) == "123someaccountid"
end

def test_with_private_key_sets_private_key
builder = ::PdfServicesSdk::CredentialsBuilder.new.with_private_key("123someprivatekey")
builder = ::PdfServices::CredentialsBuilder.new.with_private_key("123someprivatekey")

assert builder.instance_variable_get(:@private_key) == "123someprivatekey"
end

def test_from_file_sets_all_fields
builder = ::PdfServicesSdk::CredentialsBuilder.new.from_file("test/fixtures/files/pdfservices-api-credentials.json")
builder = ::PdfServices::CredentialsBuilder.new.from_file("test/fixtures/files/pdfservices-api-credentials.json")

assert builder.instance_variable_get(:@client_id) == "123someclientid"
assert builder.instance_variable_get(:@client_secret) == "123-somesecret!"
Expand All @@ -55,7 +54,7 @@ def test_from_file_sets_all_fields
end

def test_chaining_method
builder = ::PdfServicesSdk::CredentialsBuilder.new
builder = ::PdfServices::CredentialsBuilder.new
.with_client_id("123someclientid")
.with_client_secret("123someclientsecret")
.with_organization_id("123someorganizationid")
Expand Down
7 changes: 3 additions & 4 deletions test/pdf_services_sdk/test_integration.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "test_helper"
require "json"
require "credentials_builder"
require "document_merge/operation"

class IntegrationTest < Minitest::Test
def test_it_works
Expand All @@ -17,7 +16,7 @@ def test_it_works
# template source file
template_path = File.join(Dir.pwd, "test", "fixtures", "files", "sample_template.docx")

operation = ::PdfServicesSdk::DocumentMerge::Operation.new(
operation = ::PdfServices::DocumentMerge::Operation.new(
credentials,
template_path,
json_data_for_merge,
Expand Down
11 changes: 5 additions & 6 deletions test/pdf_services_sdk/test_jwt_provider.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# frozen_string_literal: true

require "test_helper"
require "credentials_builder"
require "http"
require "jwt_provider"

class JwtProviderTest < Minitest::Test
def test_it_returns_a_jwt_token
stub_valid_response
jwt = ::PdfServicesSdk::JwtProvider.get_jwt(valid_credentials)
jwt = ::PdfServices::JwtProvider.get_jwt(valid_credentials)
assert_equal "fake1.fake2.fake3", jwt
end

def test_it_raises_an_error_if_other_than_200
stub_invalid_response
error = assert_raises RuntimeError do
_jwt = ::PdfServicesSdk::JwtProvider.get_jwt(valid_credentials)
_jwt = ::PdfServices::JwtProvider.get_jwt(valid_credentials)
end
assert_equal "The JWT subject is invalid", error.message
end
Expand All @@ -33,6 +32,6 @@ def stub_invalid_response
end

def valid_credentials
::PdfServicesSdk::CredentialsBuilder.new.from_file("test/fixtures/files/pdfservices-api-credentials.json").build
::PdfServices::CredentialsBuilder.new.from_file("test/fixtures/files/pdfservices-api-credentials.json").build
end
end
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# frozen_string_literal: true

require "test_helper"
require "version"

class PdfServicesSdkTest < Minitest::Test
class PdfServicesTest < Minitest::Test
def test_that_it_has_a_version_number
refute_nil ::PdfServicesSdk::VERSION
refute_nil ::PdfServices::VERSION
end
end
3 changes: 2 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "minitest/autorun"
require "webmock/minitest"
require "pdfservices"

def json_fixture(name)
path = File.join(Dir.pwd, "test", "fixtures", "#{name}.json")
Expand All @@ -20,5 +21,5 @@ def file_fixture(file_name)
end

def valid_credentials
::PdfServicesSdk::CredentialsBuilder.new.from_file("test/fixtures/files/pdfservices-api-credentials.json").build
::PdfServices::CredentialsBuilder.new.from_file("test/fixtures/files/pdfservices-api-credentials.json").build
end

0 comments on commit 5ac981b

Please sign in to comment.