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.



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

def initialize()
  self.base_uri = 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.



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

def access_key
  @access_key
end

#base_uriObject

Returns the value of attribute base_uri.



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

def base_uri
  @base_uri
end

#business_idObject

Returns the value of attribute business_id.



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

def business_id
  @business_id
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

Instance Method Details

#cancel_document(document_hash) ⇒ Object



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

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, isFromTemplate = false) ⇒ Object



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

def create_document(document, isFromTemplate = false)
  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, isFromTemplate)
  response = execute_request(:post, path, data)
  extract_response(response.body, Eversign::Mappings::Document)
end

#create_document_from_template(template) ⇒ Object



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

def create_document_from_template(template)
  create_document(template, true)
end

#delete_document(document_hash) ⇒ Object



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

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



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

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



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

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



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

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



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

def get_action_required_documents
  get_documents("my_action_required")
end

#get_all_documentsObject



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

def get_all_documents
  get_documents("all")
end

#get_archived_templatesObject



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

def get_archived_templates
  get_documents("templates_archived")
end

#get_buisnessesObject



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

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

#get_cancelled_documentsObject



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

def get_cancelled_documents
  get_documents("cancelled")
end

#get_completed_documentsObject



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

def get_completed_documents
  get_documents("completed")
end

#get_document(document_hash) ⇒ Object



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

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



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

def get_draft_documents
  get_documents("draft")
end

#get_draft_templatesObject



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

def get_draft_templates
  get_documents("template_draft")
end

#get_templatesObject



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

def get_templates
  get_documents("templates")
end

#get_waiting_for_others_documentsObject



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

def get_waiting_for_others_documents
  get_documents("waiting_for_others")
end

#request_oauth_token(options) ⇒ Object



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

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



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

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



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

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



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

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