filepreviews 1.2.0 → 2.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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -1
- data/Changelog.md +13 -0
- data/README.md +23 -19
- data/lib/filepreviews.rb +8 -4
- data/lib/filepreviews/cli.rb +7 -2
- data/lib/filepreviews/config.rb +6 -4
- data/lib/filepreviews/http.rb +26 -8
- data/lib/filepreviews/response.rb +17 -8
- data/lib/filepreviews/utils.rb +14 -1
- data/lib/filepreviews/version.rb +1 -1
- data/spec/filepreviews/config_spec.rb +13 -1
- data/spec/filepreviews/filepreviews_spec.rb +29 -6
- data/spec/filepreviews/http_spec.rb +11 -5
- data/spec/filepreviews/utils_spec.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 546e8d302d532f3d59e47303370a194f098095be
|
4
|
+
data.tar.gz: 5e68cfdc503bb10fd36b0ed7f7e87f55c99093f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebd3b87732db306fc5849a5009bbe6855fe70a0efba217fddf01846006a63368e39ac7fa1df5c43d444d8e7e352362b388b954cda471c119e7941e8f3797dd33
|
7
|
+
data.tar.gz: 484ac6d498dffd8444f4d701d9ee5ec4d935bce614e814978b341560c2126299acaa4a8bda8700627623712a510578dd49d123e2922dd4984184c8f46e8e674d
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
2
3
|
rvm:
|
3
4
|
- 2.1.1
|
4
5
|
- 2.0.0
|
@@ -12,4 +13,5 @@ notifications:
|
|
12
13
|
- irc.freenode.org#rubyonadhd
|
13
14
|
env:
|
14
15
|
global:
|
15
|
-
|
16
|
+
- secure: ksz/xSq5EkiWQfclYHh5gj32IjqH5uTXacYqFGZdpZWPtkxGscSVeBzAvGtY9IQddkEuobVEW8TBqPo2rZ+7sT6ZfLQOuNM9Vtw5jDbAifyHLivZ5/acnW7m5BcmkxttKrel4DfRexzvGW6SAweE+fC07BLfPjzyKoIyjKnV4Y8=
|
17
|
+
- secure: lYcTOY21MNhFAvd3mCNj0CBoMJYMLGy+PsNcuLvhNcQHw/+ulkzQITJFo9IaAOl8TXv+ETAfay0eXfzVC8hE8DTeq3QovdocciMa+otCpVQWRzDwfc+mfUqutdgn96CjAmkvGYHwkDf/X4LBRaDhI2beKeaGO/BGQZw+NMEBFzo=
|
data/Changelog.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# Filepreviews Changelog
|
2
2
|
|
3
|
+
## 2.0.0
|
4
|
+
|
5
|
+
Released Sept 17, 2015 ([2.0.0](https://github.com/jonahoffline/filepreviews-ruby/tree/v2.0.0)).
|
6
|
+
|
7
|
+
* Change API base url
|
8
|
+
* Add `generate_auth_key` for generating Authorization header
|
9
|
+
* Remove `:metadata` options: `all`
|
10
|
+
* Add `:pages` validator
|
11
|
+
* Add default `:pages` (`1`) and `:metadata` (`exif`)
|
12
|
+
* Update README to include new `secret_key` options for `lib` and `cli`
|
13
|
+
* Update encrypted `api key` and add `secret key` for Travis-CI.
|
14
|
+
* Update version to 2.0.0
|
15
|
+
|
3
16
|
## 1.2.0
|
4
17
|
|
5
18
|
Released Jun 26, 2014 ([1.2.0](https://github.com/jonahoffline/filepreviews-ruby/tree/v1.2.0)).
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
[](https://gitter.im/jonahoffline/filepreviews-ruby)
|
7
7
|
[](http://inch-ci.org/github/jonahoffline/filepreviews-ruby)
|
8
8
|
|
9
|
-
This is the ruby client library for the
|
9
|
+
This is the ruby client library for the [FilePreviews.io](http://filepreviews.io) API. A lot more to come very soon.
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
|
@@ -23,12 +23,12 @@ Or install it yourself as:
|
|
23
23
|
$ gem install filepreviews
|
24
24
|
|
25
25
|
## Usage
|
26
|
-
You can currently use the Filepreviews.io API through this gem without registering your application. However, this may change anytime in the future.
|
26
|
+
You can currently use the Filepreviews.io API through this gem without registering your application. However, this may change anytime in the future.
|
27
27
|
|
28
|
-
For additional features and greater customization, register your application for an API key at [Filepreviews.io](http://bit.ly/filepreviews-signup)
|
28
|
+
For additional features and greater customization, register your application for an API key at [Filepreviews.io](http://bit.ly/filepreviews-signup)
|
29
29
|
|
30
30
|
### Configuration
|
31
|
-
To configure the gem to use your newly-registered `
|
31
|
+
To configure the gem to use your newly-registered `api + secret keys`, you can use one of the two configuration styles:
|
32
32
|
|
33
33
|
Block style:
|
34
34
|
```ruby
|
@@ -36,14 +36,16 @@ require 'filepreviews'
|
|
36
36
|
|
37
37
|
Filepreviews.configure do |config|
|
38
38
|
config.api_key = 'YOUR_API_KEY'
|
39
|
+
config.secret_key = 'YOUR_SECRET_KEY'
|
39
40
|
end
|
40
41
|
```
|
41
42
|
|
42
|
-
Simpler style:
|
43
|
+
Simpler style:
|
43
44
|
```ruby
|
44
45
|
require 'filepreviews'
|
45
46
|
|
46
47
|
Filepreviews.api_key = 'YOUR_API_KEY'
|
48
|
+
Filepreviews.config.secret_key = 'YOUR_SECRET_KEY'
|
47
49
|
```
|
48
50
|
|
49
51
|
### Basic Example Code
|
@@ -53,9 +55,9 @@ require 'filepreviews'
|
|
53
55
|
url = 'http://pixelhipsters.com/images/pixelhipster_cat.png'
|
54
56
|
result = Filepreviews.generate(url)
|
55
57
|
|
56
|
-
result.
|
57
|
-
result.
|
58
|
-
result.metadata
|
58
|
+
result.url
|
59
|
+
result.status
|
60
|
+
result.metadata # fetches metadata
|
59
61
|
```
|
60
62
|
|
61
63
|
#### Web Page Screencaptures
|
@@ -63,8 +65,8 @@ result.metadata
|
|
63
65
|
url = 'http://pixelhipsters.com'
|
64
66
|
result = Filepreviews.generate(url)
|
65
67
|
|
66
|
-
result.
|
67
|
-
result.
|
68
|
+
result.url
|
69
|
+
result.status
|
68
70
|
result.metadata
|
69
71
|
```
|
70
72
|
|
@@ -80,24 +82,26 @@ conf = {
|
|
80
82
|
height: 999
|
81
83
|
},
|
82
84
|
# supported: 'exif', 'ocr', 'psd', 'checksum', 'multimedia',
|
83
|
-
|
84
|
-
metadata: ['exif', 'ocr', 'psd'],
|
85
|
+
metadata: ['exif'],
|
85
86
|
|
86
87
|
# supported: 'jpg', 'jpeg', 'png'
|
87
|
-
format: 'jpg'
|
88
|
+
format: 'jpg',
|
89
|
+
|
90
|
+
# supported: '1', '1-3', '1,3,5', '1-3', 'all'
|
91
|
+
pages: '1-3'
|
88
92
|
}
|
89
93
|
}
|
90
94
|
|
91
|
-
result =
|
92
|
-
result.
|
93
|
-
result.metadata_url
|
95
|
+
result = Filepreviews.generate(url, conf)
|
96
|
+
result.url
|
94
97
|
result.metadata
|
95
98
|
```
|
96
99
|
|
97
100
|
### Command-Line Application
|
98
101
|
Options:
|
99
102
|
|
100
|
-
* -k, --api_key
|
103
|
+
* -k, --api_key [key] - use API key from Filepreviews.io
|
104
|
+
* -s, --secret_key [key] - use secret key from Filepreviews.io
|
101
105
|
* -m, --metadata - load metadata response
|
102
106
|
* -v, --version - display the version
|
103
107
|
* -h, --help - print help
|
@@ -108,12 +112,12 @@ Options:
|
|
108
112
|
$ filepreviews http://www.pixelhipsters.com
|
109
113
|
|
110
114
|
#### With an API Key
|
111
|
-
$ filepreviews --api_key YOUR_API_KEY_HERE http://www.pixelhipsters.com
|
115
|
+
$ filepreviews --api_key YOUR_API_KEY_HERE --secret_key YOUR_SECRET_KEY_HERE http://www.pixelhipsters.com
|
112
116
|
|
113
117
|
#### Autoload Full (metadata) Response
|
114
118
|
$ filepreviews -m http://pixelhipsters.com/images/pixelhipster_cat.png
|
115
119
|
|
116
|
-
**Note**: This will return a full metadata response, instead of the API's original
|
120
|
+
**Note**: This will return a full metadata response, instead of the API's original response that only returns the `url` and `status` of the request.
|
117
121
|
|
118
122
|
|
119
123
|
## Author
|
data/lib/filepreviews.rb
CHANGED
@@ -10,6 +10,7 @@ require 'ostruct'
|
|
10
10
|
# Main module for FilePreviews.io library
|
11
11
|
module Filepreviews
|
12
12
|
include Filepreviews::Config
|
13
|
+
include Filepreviews::Utils
|
13
14
|
|
14
15
|
# Facade method to call API response
|
15
16
|
# @param url [String] image url to convert
|
@@ -36,25 +37,28 @@ module Filepreviews
|
|
36
37
|
# Default options to be used in API request
|
37
38
|
# @return [Hash<symbol>] default options
|
38
39
|
def self.default_options
|
39
|
-
{ debug: false,
|
40
|
+
{ debug: false, pages: '1' }
|
40
41
|
end
|
41
42
|
|
42
43
|
# Merges metadata options with supported formats
|
43
44
|
# @param options [Hash<symbol>] metadata and optional size
|
44
45
|
def self.merge_options(options)
|
45
|
-
metadata = (options.fetch(:metadata) & metadata_formats)
|
46
|
-
options.store(:metadata, metadata)
|
46
|
+
metadata = (options.fetch(:metadata, ['exif']) & metadata_formats)
|
47
|
+
options.store(:metadata, metadata) unless metadata.empty?
|
47
48
|
|
48
49
|
image = (options.fetch(:format) if image_formats.include?(options[:format]))
|
49
50
|
options.store(:format, image)
|
50
51
|
|
52
|
+
pages = (options.fetch(:pages, '1'))
|
53
|
+
options.store(:pages, validate_pages(pages))
|
54
|
+
|
51
55
|
default_options.merge(options)
|
52
56
|
end
|
53
57
|
|
54
58
|
# Supported (image) formats in metadata
|
55
59
|
# @return [Array] image file extensions
|
56
60
|
def self.metadata_formats
|
57
|
-
%w(
|
61
|
+
%w(exif ocr psd checksum multimedia)
|
58
62
|
end
|
59
63
|
|
60
64
|
# Supported extracted (image) thumbnail formats
|
data/lib/filepreviews/cli.rb
CHANGED
@@ -25,8 +25,13 @@ MSG
|
|
25
25
|
opts.set_program_name 'Filepreviews.io'
|
26
26
|
|
27
27
|
opts.on('-k', '--api_key [key]', String,
|
28
|
-
'use API key from Filepreviews.io') do |
|
29
|
-
Filepreviews.api_key =
|
28
|
+
'use API key from Filepreviews.io') do |api_key|
|
29
|
+
Filepreviews.api_key = api_key
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on('-s', '--secret_key [key]', String,
|
33
|
+
'use Secret key from Filepreviews.io') do |secret_key|
|
34
|
+
Filepreviews.secret_key = secret_key
|
30
35
|
end
|
31
36
|
|
32
37
|
opts.on('-m', '--metadata', 'load metadata response') do
|
data/lib/filepreviews/config.rb
CHANGED
@@ -6,20 +6,22 @@ module Filepreviews
|
|
6
6
|
base.extend(self)
|
7
7
|
end
|
8
8
|
|
9
|
-
# @!attribute api_key
|
10
|
-
# @return [String] API key to be used
|
11
|
-
attr_accessor :api_key
|
9
|
+
# @!attribute api_key, :secret_key
|
10
|
+
# @return [String] API/Secret key to be used
|
11
|
+
attr_accessor :api_key, :secret_key
|
12
12
|
|
13
13
|
# Configures api_key and options
|
14
14
|
# Usage example:
|
15
15
|
# Filepreviews.configure do |config|
|
16
16
|
# config.api_key = 'your_api_key_here'
|
17
|
+
# config.secret_key = 'your_api_key_here'
|
17
18
|
# end
|
18
19
|
#
|
19
20
|
# Alternate way:
|
20
21
|
# Filepreviews.api_key = ENV['YOUR_API_KEY']
|
22
|
+
# Filepreviews.secret_key = ENV['YOUR_SECRET_KEY']
|
21
23
|
#
|
22
|
-
# @param <api_key> [String] api key to use
|
24
|
+
# @param <api_key> [String] api/secret key to use
|
23
25
|
def configure
|
24
26
|
yield self if block_given?
|
25
27
|
end
|
data/lib/filepreviews/http.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'base64'
|
2
3
|
require 'faraday'
|
3
4
|
require 'typhoeus'
|
4
5
|
require 'typhoeus/adapters/faraday'
|
@@ -7,7 +8,7 @@ module Filepreviews
|
|
7
8
|
# @author Jonah Ruiz <jonah@pixelhipsters.com>
|
8
9
|
# Contains http helper module
|
9
10
|
module HTTP
|
10
|
-
|
11
|
+
BASE_URL = 'https://api.filepreviews.io'
|
11
12
|
USER_AGENT = "Filepreviews-Rubygem/#{Filepreviews::VERSION}"
|
12
13
|
|
13
14
|
include Filepreviews::Utils
|
@@ -18,7 +19,7 @@ module Filepreviews
|
|
18
19
|
# @param url [String] API url to be used as base
|
19
20
|
# @param debug [Boolean] flag to log responses into STDOUT
|
20
21
|
# @return [Typhoeus::Connection] configured http client for requests to API
|
21
|
-
def default_connection(url =
|
22
|
+
def default_connection(url = BASE_URL, debug = false)
|
22
23
|
Faraday.new(url: url) do |conn|
|
23
24
|
conn.adapter :typhoeus
|
24
25
|
conn.headers[:user_agent] = USER_AGENT
|
@@ -28,12 +29,25 @@ module Filepreviews
|
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
32
|
+
# Returns API Keys status
|
33
|
+
# @return [Boolean] for when API keys are configured
|
34
|
+
def api_keys?
|
35
|
+
!!(Filepreviews.api_key && Filepreviews.secret_key)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Configures API HTTP Basic Authentication
|
39
|
+
# @return [String] HTTP Auth string for header
|
40
|
+
def generate_auth_key
|
41
|
+
key = Base64.encode64("#{Filepreviews.api_key}:#{Filepreviews.secret_key}").gsub(/\n/, '')
|
42
|
+
"Basic #{key}"
|
43
|
+
end
|
44
|
+
|
31
45
|
# Configures API Authentication header
|
32
46
|
# @param connection_headers [Faraday::Connection] header block
|
33
|
-
# @return [Faraday::Connection] '
|
47
|
+
# @return [Faraday::Connection] 'Authorization' header
|
34
48
|
def configure_api_auth_header(connection_headers)
|
35
|
-
if
|
36
|
-
connection_headers['
|
49
|
+
if api_keys?
|
50
|
+
connection_headers['Authorization'] = generate_auth_key
|
37
51
|
end
|
38
52
|
end
|
39
53
|
|
@@ -55,10 +69,14 @@ module Filepreviews
|
|
55
69
|
|
56
70
|
# Returns parsed response from API
|
57
71
|
# @return [Filepreviews::Response] json response as callable methods
|
58
|
-
def fetch(params)
|
72
|
+
def fetch(params, endpoint_path = 'previews')
|
59
73
|
options = prepare_request(params)
|
60
|
-
response = default_connection(
|
61
|
-
.post
|
74
|
+
response = default_connection(BASE_URL, params.debug)
|
75
|
+
.post do |req|
|
76
|
+
req.url("/v2/#{endpoint_path}/")
|
77
|
+
req.body = JSON.generate(options)
|
78
|
+
end
|
79
|
+
|
62
80
|
parse(response.body)
|
63
81
|
end
|
64
82
|
|
@@ -7,6 +7,18 @@ module Filepreviews
|
|
7
7
|
# @return [Filepreviews::Response] inherited/hack version of OpenStruct
|
8
8
|
# @see OpenStruct#initialize
|
9
9
|
def initialize(hash = nil)
|
10
|
+
responsify(hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Magical method to give OpenStruct-like class deep nesting capability
|
14
|
+
def to_h
|
15
|
+
@hash_table
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param hash [Hash<symbol>] JSON response body
|
19
|
+
# @return [Filepreviews::Response] inherited/hack version of OpenStruct
|
20
|
+
# @see OpenStruct#initialize
|
21
|
+
def responsify(hash = nil)
|
10
22
|
@table, @hash_table = {}, {}
|
11
23
|
|
12
24
|
if hash
|
@@ -18,19 +30,16 @@ module Filepreviews
|
|
18
30
|
end
|
19
31
|
end
|
20
32
|
|
21
|
-
#
|
22
|
-
def to_h
|
23
|
-
@hash_table
|
24
|
-
end
|
25
|
-
|
26
|
-
# Returns metadata response using the metadata_url from first response
|
33
|
+
# Returns metadata response using the url from first response
|
27
34
|
# flag is used to share this method with the CLI version (puerco, I know)
|
28
35
|
# @param js [Boolean] flag to enable json response
|
29
36
|
# @return [Filepreviews::Response] api response object
|
30
37
|
def metadata(js: false)
|
31
|
-
url = send(:
|
38
|
+
url = send(:url)
|
32
39
|
response = Filepreviews::HTTP.default_connection(url).get(nil)
|
33
|
-
|
40
|
+
json = JSON.parse(response.body)
|
41
|
+
|
42
|
+
js ? json : self.responsify(json)
|
34
43
|
end
|
35
44
|
end
|
36
45
|
end
|
data/lib/filepreviews/utils.rb
CHANGED
@@ -13,7 +13,20 @@ module Filepreviews
|
|
13
13
|
# @param metadata [Array] image formats
|
14
14
|
# @return [String] metadata url parameters
|
15
15
|
def extract_metadata(metadata)
|
16
|
-
metadata.
|
16
|
+
if metadata.class.eql?(Array)
|
17
|
+
metadata.join(',')
|
18
|
+
else
|
19
|
+
metadata
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Validates page parameters
|
24
|
+
# @param pages [Array] page parameters
|
25
|
+
# @return [String] page thumbnail parameters
|
26
|
+
def validate_pages(pages)
|
27
|
+
if !!(pages =~ /,/) || !!(pages =~ /-/) || pages.eql?('all') || pages =~ /\d/
|
28
|
+
pages
|
29
|
+
end
|
17
30
|
end
|
18
31
|
|
19
32
|
# Extracts the desired image size attributes
|
data/lib/filepreviews/version.rb
CHANGED
@@ -15,10 +15,22 @@ describe Filepreviews::Config do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
describe '.secret_key' do
|
19
|
+
it 'sets secret key' do
|
20
|
+
config.secret_key = '666'
|
21
|
+
expect(config.secret_key).to eq('666')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
18
25
|
describe '.configure' do
|
19
26
|
it 'sets the api_key when used with a block' do
|
20
|
-
config.configure
|
27
|
+
config.configure do |conf|
|
28
|
+
conf.api_key = 'kawaii!'
|
29
|
+
conf.secret_key = 'not-kawaii!'
|
30
|
+
end
|
31
|
+
|
21
32
|
expect(config.api_key).to eq('kawaii!')
|
33
|
+
expect(config.secret_key).to eq('not-kawaii!')
|
22
34
|
end
|
23
35
|
end
|
24
36
|
end
|
@@ -13,11 +13,14 @@ describe Filepreviews do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'includes configurable methods from Filepreviews::Config' do
|
16
|
-
expect(file_previews.methods).to include(:api_key, :configure)
|
16
|
+
expect(file_previews.methods).to include(:api_key, :secret_key, :configure)
|
17
17
|
end
|
18
18
|
|
19
19
|
describe '.generate' do
|
20
|
-
before(:each)
|
20
|
+
before(:each) do
|
21
|
+
Filepreviews.api_key = nil
|
22
|
+
Filepreviews.secret_key = nil
|
23
|
+
end
|
21
24
|
|
22
25
|
context 'when used without an api key' do
|
23
26
|
it 'returns a Filepreviews::Response instance' do
|
@@ -29,10 +32,11 @@ describe Filepreviews do
|
|
29
32
|
context 'when used with an api key' do
|
30
33
|
it 'returns a Filepreviews::Response instance' do
|
31
34
|
Filepreviews.api_key = ENV['FILEPREVIEWS_API_KEY']
|
35
|
+
Filepreviews.secret_key = ENV['FILEPREVIEWS_SECRET_KEY']
|
32
36
|
response = file_previews.generate(sample_img)
|
33
37
|
|
34
|
-
expect(response.
|
35
|
-
expect(response.
|
38
|
+
expect(response.url).to_not be_nil
|
39
|
+
expect(response.id).to_not be_nil
|
36
40
|
expect(response).to be_an_instance_of(Filepreviews::Response)
|
37
41
|
end
|
38
42
|
end
|
@@ -40,11 +44,30 @@ describe Filepreviews do
|
|
40
44
|
context 'when used with an incorrect api key' do
|
41
45
|
it 'returns a Filepreviews::Response instance with an error msg' do
|
42
46
|
Filepreviews.api_key = '666'
|
47
|
+
Filepreviews.secret_key = '777'
|
43
48
|
response = file_previews.generate(sample_img)
|
44
49
|
|
45
50
|
expect(response).to respond_to(:error)
|
46
|
-
expect(response.error).to respond_to(:
|
47
|
-
expect(response.error
|
51
|
+
expect(response.error).to respond_to(:message)
|
52
|
+
expect(response.error).to respond_to(:type)
|
53
|
+
|
54
|
+
expect(response.error.message).to eq('Invalid API Key provided.')
|
55
|
+
expect(response.error.type).to eq('invalid_request_error')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when used with incomplete keys' do
|
60
|
+
it 'returns a Filepreviews::Response instance with an error msg' do
|
61
|
+
Filepreviews.api_key = '666'
|
62
|
+
# Filepreviews.secret_key = nil
|
63
|
+
response = file_previews.generate(sample_img)
|
64
|
+
|
65
|
+
expect(response).to respond_to(:error)
|
66
|
+
expect(response.error).to respond_to(:message)
|
67
|
+
expect(response.error).to respond_to(:type)
|
68
|
+
|
69
|
+
expect(response.error.message).to eq('Authentication credentials were not provided.')
|
70
|
+
expect(response.error.type).to eq('invalid_request_error')
|
48
71
|
end
|
49
72
|
end
|
50
73
|
end
|
@@ -22,22 +22,28 @@ describe Filepreviews::HTTP do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
describe 'configure_api_auth_header' do
|
25
|
-
before(:each)
|
25
|
+
before(:each) do
|
26
|
+
Filepreviews.api_key = nil
|
27
|
+
Filepreviews.secret_key = nil
|
28
|
+
end
|
29
|
+
|
26
30
|
header = {
|
27
31
|
'User-Agent' => "Filepreviews-Rubygem/#{Filepreviews::VERSION}",
|
28
32
|
'Content-Type' => 'application/json'
|
29
33
|
}
|
30
34
|
|
31
35
|
context 'when api_key is set' do
|
32
|
-
it 'configures the
|
36
|
+
it 'configures the Authorization header' do
|
33
37
|
Filepreviews.api_key = '666'
|
34
|
-
|
38
|
+
Filepreviews.secret_key = '000'
|
39
|
+
expect(http.default_connection.headers['Authorization'])
|
40
|
+
.to eq(Filepreviews::HTTP.generate_auth_key)
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
38
44
|
context 'when api_key is not present' do
|
39
|
-
it 'does not add the
|
40
|
-
expect(http.default_connection.headers['
|
45
|
+
it 'does not add the Authorization header' do
|
46
|
+
expect(http.default_connection.headers['Authorization']).to be_nil
|
41
47
|
expect(http.default_connection.headers).to eq(header)
|
42
48
|
end
|
43
49
|
end
|
@@ -24,4 +24,26 @@ describe Filepreviews::Utils do
|
|
24
24
|
expect(Kawaii.new.extract_size(size)).to eq('320x240')
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
describe '.validate_pages' do
|
29
|
+
context 'when called with range parameters (1-3)' do
|
30
|
+
it 'validates page parameters' do
|
31
|
+
expect(Kawaii.new.validate_pages('1-3'))
|
32
|
+
.to eq('1-3')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when called with specific pages' do
|
37
|
+
it 'validates page parameters' do
|
38
|
+
expect(Kawaii.new.validate_pages('1,3,5'))
|
39
|
+
.to eq('1,3,5')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when called with specific pages' do
|
44
|
+
it 'validates page parameters' do
|
45
|
+
expect(Kawaii.new.validate_pages('all')).to eq('all')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
27
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filepreviews
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonah Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|