docmago_client 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5df904a82dddce585c9927218db5a45226b97629
4
- data.tar.gz: 7c008e9db440b2f55cfe81f38c7d0144bc62ad50
3
+ metadata.gz: 427cde4f1b93bca32ad2f0a36ba35a07d480eabc
4
+ data.tar.gz: aba13394543c749323a9ac856a65d017db54c33e
5
5
  SHA512:
6
- metadata.gz: 87e960d40a0bc8f861fa7e1cdd97efb184d6608d3c197204132436b432fa18f4f43c416d039ecfadcffa3e8256ea9c215728ea1ae06a4969bd202f0003857d9d
7
- data.tar.gz: 51534f2bdaf7ad87e4d83053011ba6ba20c77226d8de9b680a207cea481343ff1509d7c46f58fa91ab833db474fe1f558cc50e076dd99da8501e28bb879c5a04
6
+ metadata.gz: d176c4ee995dfb48aa7f19b4c6902666a110ebce5ebd45a8f55766aa96d71acc9a109c470fd3c362df5bde26be6acf17b8bec97aa6a0d4d31e37a38819565122
7
+ data.tar.gz: 86a8a5c31c85516d14da1a74bdadb05e2853a224fab66fd58e9dc9f8f64b43a84ea95fec918f85fd3b8ea86dba3de8eea8aee227c75561b3e3ef2b0b6dd4ea33
@@ -31,14 +31,13 @@ module DocmagoClient
31
31
  options = default_options.merge(options)
32
32
  options[:content] ||= render_to_string(options)
33
33
 
34
- docmago_response = DocmagoClient.create(options)
35
- logger.info "Docmago response - status: #{docmago_response.code}; size: #{docmago_response.body.size}"
34
+ res = DocmagoClient.create(options)
35
+ logger.info "Docmago response - status: #{res.code}; size: #{res.body.size}"
36
36
 
37
- if docmago_response.code == 200
38
- response.headers['Content-Length'] = docmago_response.body.size.to_s
39
- send_data docmago_response, filename: "#{options[:name]}.pdf", type: 'application/pdf', disposition: 'attachment'
37
+ if res.code == 200
38
+ send_data res.body, filename: "#{options[:name]}.pdf", type: 'application/pdf', disposition: 'attachment'
40
39
  else
41
- render inline: docmago_response.body, status: docmago_response.code
40
+ render inline: res.body, status: res.code
42
41
  end
43
42
  end
44
43
  end
@@ -1,3 +1,3 @@
1
1
  module DocmagoClient
2
- VERSION = '0.4.2'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
@@ -1,4 +1,4 @@
1
- require 'httmultiparty'
1
+ require 'typhoeus'
2
2
  require 'tempfile'
3
3
 
4
4
  require 'docmago_client/version'
@@ -15,31 +15,21 @@ if defined?(Rails)
15
15
  end
16
16
 
17
17
  module DocmagoClient
18
- include HTTMultiParty
19
-
20
- base_uri ENV['DOCMAGO_URL'] || 'https://docmago.com/api'
21
-
22
18
  class << self
19
+ attr_accessor :base_uri, :api_key
23
20
  attr_writer :logger
24
21
 
25
22
  def logger
26
23
  @logger ||= Logger.new($stdout)
27
24
  end
28
- end
29
25
 
30
- def self.base_uri(uri = nil)
31
- default_options[:base_uri] = uri ? uri : default_options[:base_uri] || ENV['DOCMAGO_URL']
32
- default_options[:base_uri]
33
- end
34
-
35
- def self.api_key(key = nil)
36
- default_options[:api_key] = key ? key : default_options[:api_key] || ENV['DOCMAGO_API_KEY']
37
- default_options[:api_key] || raise(DocmagoClient::Error::NoApiKeyProvidedError.new('No API key provided'))
38
- end
26
+ def base_uri
27
+ @base_uri || ENV['DOCMAGO_URL'] || 'https://docmago.com/api'
28
+ end
39
29
 
40
- def self.create!(options = {})
41
- raise ArgumentError, 'please pass in an options hash' unless options.is_a? Hash
42
- create options.merge(raise_exception_on_failure: true)
30
+ def api_key
31
+ @api_key || ENV['DOCMAGO_API_KEY']
32
+ end
43
33
  end
44
34
 
45
35
  # when given a block, hands the block a TempFile of the resulting document
@@ -58,8 +48,6 @@ module DocmagoClient
58
48
  }
59
49
 
60
50
  options = default_options.merge(options)
61
- raise_exception_on_failure = options[:raise_exception_on_failure]
62
- options.delete :raise_exception_on_failure
63
51
 
64
52
  if options[:zip_resources]
65
53
  tmp_dir = Dir.mktmpdir
@@ -68,16 +56,18 @@ module DocmagoClient
68
56
  options[:content] = File.new(resource_archiver.create_zip("#{tmp_dir}/document.zip"))
69
57
  options.delete :assets
70
58
 
71
- response = post('/documents', body: { document: options }, basic_auth: { username: api_key })
59
+ response = Typhoeus.post "#{base_uri}/documents", body: {
60
+ auth_token: api_key,
61
+ document: { content: options[:content] }
62
+ }
72
63
  ensure
73
64
  FileUtils.remove_entry_secure tmp_dir
74
65
  end
75
66
  else
76
- response = post('/documents', body: { document: options }, basic_auth: { username: api_key })
77
- end
78
-
79
- if raise_exception_on_failure && !response.success?
80
- raise DocmagoClient::Exception::DocumentCreationFailure.new response.body, response.code
67
+ response = Typhoeus.post "#{base_uri}/documents", body: {
68
+ auth_token: api_key,
69
+ document: options
70
+ }
81
71
  end
82
72
 
83
73
  if block_given?
@@ -94,28 +84,4 @@ module DocmagoClient
94
84
  response
95
85
  end
96
86
  end
97
-
98
- def self.list_docs!(options = {})
99
- raise ArgumentError, 'please pass in an options hash' unless options.is_a? Hash
100
- list_docs options.merge(raise_exception_on_failure: true)
101
- end
102
-
103
- def self.list_docs(options = {})
104
- raise ArgumentError, 'please pass in an options hash' unless options.is_a? Hash
105
- default_options = {
106
- page: 1,
107
- per_page: 100,
108
- raise_exception_on_failure: false
109
- }
110
- options = default_options.merge(options)
111
- raise_exception_on_failure = options[:raise_exception_on_failure]
112
- options.delete :raise_exception_on_failure
113
-
114
- response = get('/documents', query: options, basic_auth: { username: api_key })
115
- if raise_exception_on_failure && !response.success?
116
- raise DocmagoClient::Exception::DocumentListingFailure.new response.body, response.code
117
- end
118
-
119
- response
120
- end
121
87
  end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docmago_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Habermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-03 00:00:00.000000000 Z
11
+ date: 2016-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: httparty
14
+ name: typhoeus
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.13.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 0.13.0
27
- - !ruby/object:Gem::Dependency
28
- name: httmultiparty
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.3.10
19
+ version: '1.0'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: 0.3.10
26
+ version: '1.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rubyzip
43
29
  requirement: !ruby/object:Gem::Requirement