Class: EDIS::Client
- Inherits:
-
Object
- Object
- EDIS::Client
- Defined in:
- lib/edis_client.rb
Instance Method Summary collapse
-
#download_attachment(options = {}) ⇒ Object
Fetch a document.
-
#find_attachments(options = {}) ⇒ Object
Fetch a document’s attachments.
-
#find_documents(options = {}) ⇒ Object
Fetch document metadata.
-
#find_investigations(options = {}) ⇒ Object
Find investigations.
-
#gen_digest(username, password, retain = true) ⇒ Object
Generates a digest for api usage.
-
#initialize(config = {}) ⇒ Client
constructor
Construct a new instance.
Constructor Details
#initialize(config = {}) ⇒ Client
Construct a new instance. The following options are available:
-
:proxy_uri
-
:proxy_user
-
:proxy_pass
-
:timeout - Defaults to 10s
Example:
'require 'edis_client'
edis = EDIS::Client.new({
timeout: 5s,
proxy: {
uri: 'https://my.domain.com',
user: 'matz',
password: 'changeit'
}
})
34 35 36 37 38 39 40 41 |
# File 'lib/edis_client.rb', line 34 def initialize(config = {}) config[:timeout] = 10 unless config[:timeout] if config[:proxy] config[:proxy][:uri] = URI.parse(config[:proxy][:uri]) end @config = config end |
Instance Method Details
#download_attachment(options = {}) ⇒ Object
Fetch a document. The result is streamed and therefore clients must provide a block to read each chunk of the response. The following options are available:
-
:document_id - the document id [REQUIRED]
-
:attachment_id - the actual attachment id [REQUIRED]
-
:digest - the authorization digest returned from gen_digest [REQUIRED]
133 134 135 136 137 138 |
# File 'lib/edis_client.rb', line 133 def ( = {}) raise ArgumentError, "Missing block." unless block_given? validate_download path = build_path '/download', , download_paths stream_resource(path, ) { |chunk| yield chunk } end |
#find_attachments(options = {}) ⇒ Object
Fetch a document’s attachments. Returns a hash rooted at the rest API’s results node. Accepts an hash for the following options:
-
:document_id - the document id [REQUIRED]
-
:digest - The authorization digest returned from gen_digest
119 120 121 122 |
# File 'lib/edis_client.rb', line 119 def ( = {}) validate_presence_of [:document_id], get_resource "/attachment/#{[:document_id]}", end |
#find_documents(options = {}) ⇒ Object
Fetch document metadata. The following options are available:
-
:document_id - the document id.
-
:security_level - the security level name.
-
:investigation_number - the investigation number.
-
:investigation_phase - the name of the investigation phase.
-
:document_type - the document type
-
:official_received_date - the document’s official received date comparision. this should be a hash of the following keys:
:type => :between, :before, :after or :exact when the type is :exact, :before, :after then the hash must also contain :date for :between the hash must contain the 2 following keys :from_date, :to_date
-
:modified_date - the docuemnt’s last modified date comparision.
this should be a hash of the following keys: :comparision_type => :between, :before, :after or :exact when the type is :exact, :before, :after then the hash must also contain :date for :between the hash must contain the 2 following keys :from_date, :to_date
-
:firm_org - the firm that filed the doc
-
:page - the page number for result pagination.
-
:digest - the authorization digest returned from gen_digest
105 106 107 108 109 110 |
# File 'lib/edis_client.rb', line 105 def find_documents( = {}) path = build_path '/document', , [:document_id] params = build_params(, document_params).merge \ build_date_params , document_date_params get_resource path, , params end |
#find_investigations(options = {}) ⇒ Object
Find investigations. The following options are available:
-
:investigation_number - the investigation number.
-
:investigation_phase - the name of the investigation phase. :investgation_number is required when using this option
-
:investigation_type - the name of the investigation type
-
:investigation_status - the name of the investigation status
-
:page - the page number for result pagination.
-
:digest - the authorization digest returned from gen_digest
73 74 75 76 77 78 |
# File 'lib/edis_client.rb', line 73 def find_investigations( = {}) path = build_path '/investigation', , investigation_paths params = build_params , investigation_params get_resource path, params, end |
#gen_digest(username, password, retain = true) ⇒ Object
Generates a digest for api usage. Users must be preregistered with the edis app. The digest can be retained (default) for the life of this instance (session), ensuring all subseqent api calls pass the digest to the endpoint. In this mode clients need not worry about retaining and passing this to other api calls.
-
:username - your EDIS registered username [REQUIRED]
-
:password - your EDIS registered password [REQUIRED]
-
:retain - retain your digest for subsequent api calls [Defaults to true]
54 55 56 57 58 59 60 61 |
# File 'lib/edis_client.rb', line 54 def gen_digest(username, password, retain = true) results = post_resource "/secretKey/#{username}", { password: password } raise ArgumentError, results.errors if results.errors secret_key = results.results.secretKey digest = Base64.strict_encode64 "#{username}:#{secret_key}" @config[:digest] = digest if retain digest end |