Class: PDFBucket::PDFBucket

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfbucket.rb

Overview

Main class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: ENV['PDF_BUCKET_API_KEY'], api_secret: ENV['PDF_BUCKET_API_SECRET'], api_host: ENV['PDF_BUCKET_API_HOST']) ⇒ PDFBucket

Returns a new instance of PDFBucket.



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pdfbucket.rb', line 34

def initialize(
  api_key:    ENV['PDF_BUCKET_API_KEY'],
  api_secret: ENV['PDF_BUCKET_API_SECRET'],
  api_host:   ENV['PDF_BUCKET_API_HOST'])

  fail 'bucket api_key is required' if api_key.nil? || api_key.strip.empty?
  fail 'bucket api_secret is required' if api_secret.nil? || api_secret.strip.empty?

  @api_host   = api_host || DEFAULT_HOST
  @api_key    = api_key
  @api_secret = api_secret
end

Instance Attribute Details

#api_hostObject (readonly)

Returns the value of attribute api_host.



32
33
34
# File 'lib/pdfbucket.rb', line 32

def api_host
  @api_host
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



32
33
34
# File 'lib/pdfbucket.rb', line 32

def api_key
  @api_key
end

#api_secretObject (readonly)

Returns the value of attribute api_secret.



32
33
34
# File 'lib/pdfbucket.rb', line 32

def api_secret
  @api_secret
end

Instance Method Details

#generate_plain_url(url, orientation, page_size, margin, zoom, expires_in = 0, pagination = false, position = nil, alignment = nil, cache = nil) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/pdfbucket.rb', line 63

def generate_plain_url(url, orientation, page_size, margin, zoom, expires_in = 0, pagination = false, position = nil, alignment = nil, cache = nil)
  signature = sign(api_secret, api_key, url, orientation, page_size, margin, zoom, pagination, position, alignment)

  params = {
    orientation:  ORIENTATIONS[orientation],
    page_size:    PAGE_SIZES[page_size],
    margin:       margin,
    zoom:         zoom,
    expires_in:   expires_in,
    api_key:      api_key,
    uri:          url,
    signature:    signature
  }
  set_optional_params(params, pagination, position, alignment, cache)
  build_uri(params)
end

#generate_url(url, orientation, page_size, margin, zoom, expires_in = 0, pagination = false, position = nil, alignment = nil, cache = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pdfbucket.rb', line 47

def generate_url(url, orientation, page_size, margin, zoom, expires_in = 0, pagination = false, position = nil, alignment = nil, cache = nil)
  encrypted_uri = encrypt(api_secret, url)

  params = {
    orientation:    ORIENTATIONS[orientation],
    page_size:      PAGE_SIZES[page_size],
    margin:         margin,
    zoom:           zoom,
    expires_in:     expires_in,
    api_key:        api_key,
    encrypted_uri:  encrypted_uri
  }
  set_optional_params(params, pagination, position, alignment, cache)
  build_uri(params)
end