Module: DocxManagerClient::Connection
- Defined in:
- lib/docx_manager_client/connection.rb
Defined Under Namespace
Classes: ConfigMissing
Class Method Summary collapse
- .docx_manager_api_key ⇒ Object
- .docx_manager_server_path ⇒ Object
- .docx_manager_token ⇒ Object
- .docx_server_api(method, path, body = {}) ⇒ Object
- .docx_server_api_multipart(method, path, payload) ⇒ Object
- .docx_server_headers ⇒ Object
- .docx_server_json ⇒ Object
- .docx_server_multipart ⇒ Object
Class Method Details
.docx_manager_api_key ⇒ Object
52 53 54 55 56 57 |
# File 'lib/docx_manager_client/connection.rb', line 52 def self.docx_manager_api_key exist = ENV['DOCX_MANAGER_API_KEY'] || Rails.application.secrets[:docx_manager_api_key] raise ConfigMissing.new("ENV['DOCX_MANAGER_API_KEY'] or Rails.application.secrets[:docx_manager_api_key] not exist") if exist.blank? exist.to_s end |
.docx_manager_server_path ⇒ Object
45 46 47 48 49 50 |
# File 'lib/docx_manager_client/connection.rb', line 45 def self.docx_manager_server_path exist = ENV['DOCX_MANAGER_SERVER_PATH'] || Rails.application.secrets[:docx_manager_server_path] raise ConfigMissing.new("ENV['DOCX_MANAGER_SERVER_PATH'] or Rails.application.secrets[:docx_manager_server_path] not exist") if exist.blank? exist.to_s end |
.docx_manager_token ⇒ Object
59 60 61 62 63 64 |
# File 'lib/docx_manager_client/connection.rb', line 59 def self.docx_manager_token exist = ENV['DOCX_MANAGER_TOKEN'] || Rails.application.secrets[:docx_manager_token] raise ConfigMissing.new("ENV['DOCX_MANAGER_TOKEN'] or Rails.application.secrets[:docx_manager_token] not exist") if exist.blank? exist.to_s end |
.docx_server_api(method, path, body = {}) ⇒ Object
8 9 10 11 |
# File 'lib/docx_manager_client/connection.rb', line 8 def self.docx_server_api(method, path, body = {}) response = docx_server_json.send(method, path, body) [response.status, Hashie::Mash.new(response.body)] end |
.docx_server_api_multipart(method, path, payload) ⇒ Object
13 14 15 16 |
# File 'lib/docx_manager_client/connection.rb', line 13 def self.docx_server_api_multipart(method, path, payload) response = docx_server_multipart.send(method, path, payload) [response.status, Hashie::Mash.new(response.body)] end |
.docx_server_headers ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/docx_manager_client/connection.rb', line 18 def self.docx_server_headers { 'client' => docx_manager_api_key, 'Authorization' => docx_manager_token, 'User-Agent' => "DocxManagerClient #{DocxManagerClient::VERSION}" } end |
.docx_server_json ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/docx_manager_client/connection.rb', line 26 def self.docx_server_json @docx_server_json ||= Faraday.new(url: "#{docx_manager_server_path}/api/v1", headers: docx_server_headers) do |f| f.request :json f.use :instrumentation f.response :json f.adapter :net_http end end |
.docx_server_multipart ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/docx_manager_client/connection.rb', line 35 def self.docx_server_multipart @docx_server_multipart ||= Faraday.new(url: "#{docx_manager_server_path}/api/v1", headers: docx_server_headers) do |f| f.request :multipart f.request :url_encoded f.use :instrumentation f.response :json f.adapter :net_http end end |