Class: Pdf4me::Client

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = Configuration.default) ⇒ Client

Returns a new instance of Client.



6
7
8
# File 'lib/pdf4me/client.rb', line 6

def initialize(config = Configuration.default)
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/pdf4me/client.rb', line 3

def config
  @config
end

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/pdf4me/client.rb', line 4

def logger
  @logger
end

Class Method Details

.defaultObject



10
11
12
# File 'lib/pdf4me/client.rb', line 10

def self.default
  @@default ||= Client.new
end

Instance Method Details

#multipart_post(path, params) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pdf4me/client.rb', line 22

def multipart_post(path, params)
  request = multipart_request(path, params)

  if block_given?
   yield request
  end

  request.run.tap do |response|
    validate_response!(response)
  end
end

#post(path, params) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pdf4me/client.rb', line 34

def post(path, params)
  request = Typhoeus::Request.new(
    request_url(path),
    method: :post,
    body: params,
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
      'Authorization': "Basic #{config.token}",
      'User-Agent': "Pdf4me/ruby/#{VERSION}"
    },
    timeout: 0,
    ssl_verifypeer: true,
    ssl_verifyhost: 2,
    verbose: config.debugging
  )

  request.run.tap do |response|
    validate_response!(response)
  end
end

#request_url(path) ⇒ Object



18
19
20
# File 'lib/pdf4me/client.rb', line 18

def request_url(path)
  URI.join(config.base_url, path)
end