select_pdf_api 0.0.2 → 0.0.3
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/README.md +52 -28
- data/config/select-pdf-config.yml +1 -0
- data/lib/select_pdf_api.rb +40 -16
- data/lib/select_pdf_api/env_config.rb +40 -0
- data/lib/select_pdf_api/exceptions.rb +3 -0
- data/lib/select_pdf_api/version.rb +2 -1
- data/lib/select_pdf_api/yaml_config.rb +40 -0
- data/select_pdf_api.gemspec +2 -0
- data/test/fixtures/vcr/download_no_url.yml +44 -0
- data/test/fixtures/vcr/download_pdf.yml +2205 -0
- data/test/minitest_helper.rb +11 -1
- data/test/test_select_pdf_api/test_api.rb +18 -5
- data/test/test_select_pdf_api/test_env_config.rb +28 -0
- data/test/test_select_pdf_api/{test_yaml_file_config.rb → test_yaml_config.rb} +7 -7
- metadata +53 -5
- data/lib/select_pdf_api/yaml_file_config.rb +0 -24
data/test/minitest_helper.rb
CHANGED
@@ -1,3 +1,13 @@
|
|
1
1
|
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
|
2
3
|
require 'select_pdf_api'
|
3
|
-
require 'minitest/autorun'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'webmock/minitest'
|
6
|
+
require 'vcr'
|
7
|
+
|
8
|
+
VCR.configure do |c|
|
9
|
+
c.filter_sensitive_data('<KEY>') { ENV['SELECT_PDF_KEY'] }
|
10
|
+
|
11
|
+
c.cassette_library_dir = "test/fixtures/vcr"
|
12
|
+
c.hook_into :webmock
|
13
|
+
end
|
@@ -3,11 +3,14 @@ require './test/minitest_helper'
|
|
3
3
|
# API test
|
4
4
|
describe SelectPdfApi do
|
5
5
|
let(:fixtures) {"../test/fixtures"}
|
6
|
-
let(:minimum_config) {"#{fixtures}/minimum-config
|
7
|
-
let(:maximum_config) {"#{fixtures}/all-config
|
8
|
-
let(:blank_config) {"#{fixtures}/blank-config
|
6
|
+
let(:minimum_config) {"#{fixtures}/minimum-config"}
|
7
|
+
let(:maximum_config) {"#{fixtures}/all-config"}
|
8
|
+
let(:blank_config) {"#{fixtures}/blank-config"}
|
9
9
|
|
10
|
-
let(:select_pdf) {SelectPdfApi.new({
|
10
|
+
let(:select_pdf) {SelectPdfApi.new({
|
11
|
+
url: 'http://www.google.com',
|
12
|
+
config: SelectPdfApi::YamlConfig.new(minimum_config)
|
13
|
+
})}
|
11
14
|
|
12
15
|
before do
|
13
16
|
select_pdf.config.load_config(minimum_config)
|
@@ -54,7 +57,17 @@ describe SelectPdfApi do
|
|
54
57
|
end
|
55
58
|
|
56
59
|
def test_it_fails_without_a_url
|
57
|
-
|
60
|
+
VCR.use_cassette('download_no_url') do
|
61
|
+
-> {select_pdf.download}.must_raise SelectPdfApi::DownloadError
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_downloads_a_pdf
|
66
|
+
VCR.use_cassette('download_pdf') do
|
67
|
+
select_pdf.config.options['key'] = ENV["SELECT_PDF_KEY"]
|
68
|
+
select_pdf.download
|
69
|
+
select_pdf.success?.must_equal true
|
70
|
+
end
|
58
71
|
end
|
59
72
|
end
|
60
73
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require './test/minitest_helper'
|
2
|
+
|
3
|
+
# Config test
|
4
|
+
describe SelectPdfApi::EnvConfig do
|
5
|
+
let(:select_pdf) {SelectPdfApi.new({
|
6
|
+
url: "http://www.google.com",
|
7
|
+
config: SelectPdfApi::EnvConfig.new
|
8
|
+
})}
|
9
|
+
|
10
|
+
def test_it_exists
|
11
|
+
select_pdf.must_be_instance_of SelectPdfApi
|
12
|
+
select_pdf.config.must_be_instance_of SelectPdfApi::EnvConfig
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_key_is_loaded_from_env
|
16
|
+
env_key = ENV['SELECT_PDF_KEY']
|
17
|
+
select_pdf.config.options['key'].must_equal env_key
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_options_must_be_changable
|
21
|
+
original_key = ENV['SELECT_PDF_KEY']
|
22
|
+
modified_key = "modified-key-123"
|
23
|
+
|
24
|
+
select_pdf.config.options['key'].must_equal original_key
|
25
|
+
select_pdf.config.options['key'] = modified_key
|
26
|
+
select_pdf.config.options['key'].must_equal modified_key
|
27
|
+
end
|
28
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require './test/minitest_helper'
|
2
2
|
|
3
3
|
# Config test
|
4
|
-
describe SelectPdfApi::
|
4
|
+
describe SelectPdfApi::YamlConfig do
|
5
5
|
let(:fixtures) {"../test/fixtures"}
|
6
6
|
|
7
|
-
let(:blank_config) {SelectPdfApi::
|
8
|
-
let(:minimum_config) {SelectPdfApi::
|
9
|
-
let(:maximum_config) {SelectPdfApi::
|
10
|
-
let(:invalid_config) {SelectPdfApi::
|
7
|
+
let(:blank_config) {SelectPdfApi::YamlConfig.new("#{fixtures}/blank-config")}
|
8
|
+
let(:minimum_config) {SelectPdfApi::YamlConfig.new("#{fixtures}/minimum-config")}
|
9
|
+
let(:maximum_config) {SelectPdfApi::YamlConfig.new("#{fixtures}/all-config")}
|
10
|
+
let(:invalid_config) {SelectPdfApi::YamlConfig.new('invalid_config')}
|
11
11
|
|
12
12
|
def test_it_should_fail_with_an_invalid_config
|
13
13
|
-> {invalid_config}.must_raise SelectPdfApi::ConfigError
|
@@ -31,9 +31,9 @@ describe SelectPdfApi::YamlFileConfig do
|
|
31
31
|
original = {"key"=>"random-valid-api-123abc-345dbc"}
|
32
32
|
modified = {"key"=>"valid-key-123-67ad", "page_size"=>"Letter", "page_orientation"=>"Landscape", "margin_right"=>"2pt", "margin_bottom"=>"2pt", "margin_left"=>"1.25pt", "user_password"=>"user123", "owner_password"=>"owner567"}
|
33
33
|
|
34
|
-
config = SelectPdfApi::
|
34
|
+
config = SelectPdfApi::YamlConfig.new("#{fixtures}/minimum-config")
|
35
35
|
config.options.must_equal original
|
36
|
-
config.load_config("#{fixtures}/all-config
|
36
|
+
config.load_config("#{fixtures}/all-config")
|
37
37
|
config.options.must_equal modified
|
38
38
|
end
|
39
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: select_pdf_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arian Amador
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,46 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: vcr
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.9'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 2.9.3
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '2.9'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.9.3
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: webmock
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.20'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.20.4
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.20'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.20.4
|
41
81
|
- !ruby/object:Gem::Dependency
|
42
82
|
name: minitest
|
43
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,17 +125,22 @@ files:
|
|
85
125
|
- LICENSE.txt
|
86
126
|
- README.md
|
87
127
|
- Rakefile
|
128
|
+
- config/select-pdf-config.yml
|
88
129
|
- lib/select_pdf_api.rb
|
130
|
+
- lib/select_pdf_api/env_config.rb
|
89
131
|
- lib/select_pdf_api/exceptions.rb
|
90
132
|
- lib/select_pdf_api/version.rb
|
91
|
-
- lib/select_pdf_api/
|
133
|
+
- lib/select_pdf_api/yaml_config.rb
|
92
134
|
- select_pdf_api.gemspec
|
93
135
|
- test/fixtures/all-config.yml
|
94
136
|
- test/fixtures/blank-config.yml
|
95
137
|
- test/fixtures/minimum-config.yml
|
138
|
+
- test/fixtures/vcr/download_no_url.yml
|
139
|
+
- test/fixtures/vcr/download_pdf.yml
|
96
140
|
- test/minitest_helper.rb
|
97
141
|
- test/test_select_pdf_api/test_api.rb
|
98
|
-
- test/test_select_pdf_api/
|
142
|
+
- test/test_select_pdf_api/test_env_config.rb
|
143
|
+
- test/test_select_pdf_api/test_yaml_config.rb
|
99
144
|
homepage: https://www.github.com/arian-amador/select_pdf_api
|
100
145
|
licenses:
|
101
146
|
- MIT
|
@@ -124,6 +169,9 @@ test_files:
|
|
124
169
|
- test/fixtures/all-config.yml
|
125
170
|
- test/fixtures/blank-config.yml
|
126
171
|
- test/fixtures/minimum-config.yml
|
172
|
+
- test/fixtures/vcr/download_no_url.yml
|
173
|
+
- test/fixtures/vcr/download_pdf.yml
|
127
174
|
- test/minitest_helper.rb
|
128
175
|
- test/test_select_pdf_api/test_api.rb
|
129
|
-
- test/test_select_pdf_api/
|
176
|
+
- test/test_select_pdf_api/test_env_config.rb
|
177
|
+
- test/test_select_pdf_api/test_yaml_config.rb
|
@@ -1,24 +0,0 @@
|
|
1
|
-
class SelectPdfApi
|
2
|
-
class YamlFileConfig
|
3
|
-
|
4
|
-
def initialize(filename)
|
5
|
-
@data = {}
|
6
|
-
load_config filename
|
7
|
-
end
|
8
|
-
|
9
|
-
def load_config(filename)
|
10
|
-
config_file = File.join(File.expand_path(File.join('config')), filename)
|
11
|
-
|
12
|
-
raise SelectPdfApi::ConfigError, "Config file #{config_file} does not exist." unless
|
13
|
-
File.exist? config_file
|
14
|
-
|
15
|
-
@data = YAML::load_file(config_file)
|
16
|
-
|
17
|
-
raise SelectPdfApi::ConfigError, "Error loading values from #{config_file}" unless @data
|
18
|
-
end
|
19
|
-
|
20
|
-
def options
|
21
|
-
@data
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|