Class: Eversign::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



14
15
16
17
18
19
20
21
22
23
# File 'lib/eversign/client.rb', line 14

def initialize()
	self.base_uri = (Eversign.configuration && Eversign.configuration.api_base) ? Eversign.configuration.api_base : 'https://api.eversign.com'
	access_key = Eversign.configuration.access_key
	if access_key.start_with?('Bearer ')
        self.set_oauth_access_token(access_key)
    else
		self.access_key = access_key
	end
	self.business_id = Eversign.configuration.business_id
end

Instance Attribute Details

#access_keyObject

Returns the value of attribute access_key.



12
13
14
# File 'lib/eversign/client.rb', line 12

def access_key
  @access_key
end

#base_uriObject

Returns the value of attribute base_uri.



12
13
14
# File 'lib/eversign/client.rb', line 12

def base_uri
  @base_uri
end

#business_idObject

Returns the value of attribute business_id.



12
13
14
# File 'lib/eversign/client.rb', line 12

def business_id
  @business_id
end

#tokenObject

Returns the value of attribute token.



12
13
14
# File 'lib/eversign/client.rb', line 12

def token
  @token
end

Instance Method Details

#cancel_document(document_hash) ⇒ Object



128
129
130
131
# File 'lib/eversign/client.rb', line 128

def cancel_document(document_hash)
	path = "/api/document?access_key=#{access_key}&business_id=#{business_id}&document_hash=#{document_hash}&cancel=1"
	delete(path, document_hash)
end

#create_document(document) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/eversign/client.rb', line 103

def create_document(document)
	if document.files
		for file in document.files
       if file.file_url
         file_response = self.upload_file(file.file_url)
         file.file_url = nil
         file.file_id = file_response.file_id
       end
     end
   end
 	path = "/api/document?access_key=#{access_key}&business_id=#{business_id}"
    data = Eversign::Mappings::Document.representation_for(document)
	response = execute_request(:post, path, data)
	extract_response(response.body, Eversign::Mappings::Document)
end

#create_document_from_template(template) ⇒ Object



119
120
121
# File 'lib/eversign/client.rb', line 119

def create_document_from_template(template)
	create_document(template)
end

#delete_document(document_hash) ⇒ Object



123
124
125
126
# File 'lib/eversign/client.rb', line 123

def delete_document(document_hash)
 	path = "/api/document?access_key=#{access_key}&business_id=#{business_id}&document_hash=#{document_hash}"
	delete(path, document_hash)
end

#download_final_document_to_path(document_hash, path, audit_trail = 1) ⇒ Object



138
139
140
141
# File 'lib/eversign/client.rb', line 138

def download_final_document_to_path(document_hash, path, audit_trail=1)
	sub_uri = "/api/download_raw_document?access_key=#{access_key}&business_id=#{business_id}&document_hash=#{document_hash}&audit_trail=#{audit_trail}"
	download(sub_uri, path)
end

#download_raw_document_to_path(document_hash, path) ⇒ Object



133
134
135
136
# File 'lib/eversign/client.rb', line 133

def download_raw_document_to_path(document_hash, path)
	sub_uri = "/api/download_raw_document?access_key=#{access_key}&business_id=#{business_id}&document_hash=#{document_hash}"
	download(sub_uri, path)
end

#generate_oauth_authorization_url(options) ⇒ Object



34
35
36
37
38
# File 'lib/eversign/client.rb', line 34

def generate_oauth_authorization_url(options)
  check_arguments(['client_id', 'state'], options)
  template = Addressable::Template.new(Eversign.configuration.oauth_base + '/authorize{?clinet_id,state}')
  return template.partial_expand(clinet_id: options['client_id'], state: options['state']).pattern
end

#get_action_required_documentsObject



77
78
79
# File 'lib/eversign/client.rb', line 77

def get_action_required_documents
 	get_documents('my_action_required')
end

#get_all_documentsObject



61
62
63
# File 'lib/eversign/client.rb', line 61

def get_all_documents
 	get_documents('all')
end

#get_archived_templatesObject



89
90
91
# File 'lib/eversign/client.rb', line 89

def get_archived_templates
 	get_documents('templates_archived')
end

#get_buisnessesObject



56
57
58
59
# File 'lib/eversign/client.rb', line 56

def get_buisnesses
	response = execute_request(:get, "/api/business?access_key=#{access_key}")
 	extract_response(response.body, Eversign::Mappings::Business)
end

#get_cancelled_documentsObject



73
74
75
# File 'lib/eversign/client.rb', line 73

def get_cancelled_documents
 	get_documents('cancelled')
end

#get_completed_documentsObject



65
66
67
# File 'lib/eversign/client.rb', line 65

def get_completed_documents
 	get_documents('completed')
end

#get_document(document_hash) ⇒ Object



97
98
99
100
101
# File 'lib/eversign/client.rb', line 97

def get_document(document_hash)
 	path = "/api/document?access_key=#{access_key}&business_id=#{business_id}&document_hash=#{document_hash}"
 	response = execute_request(:get, path)
 	extract_response(response.body, Eversign::Mappings::Document)
end

#get_draft_documentsObject



69
70
71
# File 'lib/eversign/client.rb', line 69

def get_draft_documents
 	get_documents('draft')
end

#get_draft_templatesObject



93
94
95
# File 'lib/eversign/client.rb', line 93

def get_draft_templates
 	get_documents('template_draft')
end

#get_templatesObject



85
86
87
# File 'lib/eversign/client.rb', line 85

def get_templates
 	get_documents('templates')
end

#get_waiting_for_others_documentsObject



81
82
83
# File 'lib/eversign/client.rb', line 81

def get_waiting_for_others_documents
 	get_documents('waiting_for_others')
end

#request_oauth_token(options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/eversign/client.rb', line 40

def request_oauth_token(options)
  check_arguments(['client_id', 'client_secret', 'code', 'state'], options)

  req = execute_request(:post, '/token', options)
  if req.status == 200
    response_obj = JSON.parse(req.body)

    if response_obj.key?('success')
      raise response_obj['message']
    else
      return response_obj['access_token']
    end
  end
  raise 'no success'
end

#send_reminder_for_document(document_hash, signer_id) ⇒ Object



150
151
152
153
154
# File 'lib/eversign/client.rb', line 150

def send_reminder_for_document(document_hash, signer_id)
	path = "/api/send_reminder?access_key=#{access_key}&business_id=#{business_id}"
	response = execute_request(:post, path, {document_hash: document_hash, signer_id: signer_id}.to_json)
	eval(response.body)[:success] ? true : extract_response(response.body)
end

#set_oauth_access_token(oauthtoken) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/eversign/client.rb', line 25

def set_oauth_access_token(oauthtoken)
	if oauthtoken.startswith('Bearer ')
      self.token = oauthtoken
    else
      self.token = 'Bearer ' + oauthtoken
    end
    self.get_businesses()
end

#upload_file(file_path) ⇒ Object



143
144
145
146
147
148
# File 'lib/eversign/client.rb', line 143

def upload_file(file_path)
	payload = { upload: Faraday::UploadIO.new(file_path, 'text/plain') }
	path = "/api/file?access_key=#{access_key}&business_id=#{business_id}"
	response = execute_request(:post, path, payload, true)
	extract_response(response.body, Eversign::Mappings::File)
end