|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +class Clickwrap::Eg006EmbedClickwrapService |
| 4 | + attr_reader :args |
| 5 | + |
| 6 | + def initialize(args) |
| 7 | + @args = args |
| 8 | + end |
| 9 | + |
| 10 | + def worker |
| 11 | + # Step 2. Construct your API headers |
| 12 | + configuration = DocuSign_Click::Configuration.new |
| 13 | + configuration.host = args[:base_path] |
| 14 | + |
| 15 | + api_client = DocuSign_Click::ApiClient.new configuration |
| 16 | + api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}") |
| 17 | + api_client.config.debugging = true; |
| 18 | + |
| 19 | + # document_data = DocuSign_Click::DocumentData.new({ |
| 20 | + # full_name: args[:full_name], |
| 21 | + # email: args[:email], |
| 22 | + # company: args[:company], |
| 23 | + # title: args[:title], |
| 24 | + # date: args[:date] |
| 25 | + # }) |
| 26 | + |
| 27 | + document_data = { |
| 28 | + "fullName" => args[:full_name], |
| 29 | + "email" => args[:email], |
| 30 | + "company" => args[:company], |
| 31 | + "title" => args[:title], |
| 32 | + "date" => args[:date] |
| 33 | + } |
| 34 | + |
| 35 | + |
| 36 | + userAgreementRequest = DocuSign_Click::UserAgreementRequest.new({ |
| 37 | + clientUserId: args[:email], |
| 38 | + documentData: document_data |
| 39 | + }) |
| 40 | + |
| 41 | + accounts_api = DocuSign_Click::AccountsApi.new(api_client) |
| 42 | + |
| 43 | + response = accounts_api.create_has_agreed(args[:account_id], args[:clickwrap_id], userAgreementRequest) |
| 44 | + |
| 45 | + response.as_json |
| 46 | + end |
| 47 | + |
| 48 | + def get_active_clickwraps |
| 49 | + configuration = DocuSign_Click::Configuration.new |
| 50 | + configuration.host = args[:ds_base_path] |
| 51 | + |
| 52 | + api_client = DocuSign_Click::ApiClient.new configuration |
| 53 | + api_client.set_default_header('Authorization', "Bearer #{args[:ds_access_token]}") |
| 54 | + |
| 55 | + accounts_api = DocuSign_Click::AccountsApi.new(api_client) |
| 56 | + |
| 57 | + options = DocuSign_Click::GetClickwrapsOptions.new |
| 58 | + options.status = 'active' |
| 59 | + |
| 60 | + results = accounts_api.get_clickwraps( |
| 61 | + args[:ds_account_id], |
| 62 | + options |
| 63 | + ) |
| 64 | + puts results.as_json['clickwraps'] |
| 65 | + results.as_json['clickwraps'] |
| 66 | + end |
| 67 | + |
| 68 | + def get_inactive_clickwraps |
| 69 | + configuration = DocuSign_Click::Configuration.new |
| 70 | + configuration.host = args[:ds_base_path] |
| 71 | + |
| 72 | + api_client = DocuSign_Click::ApiClient.new configuration |
| 73 | + api_client.set_default_header('Authorization', "Bearer #{args[:ds_access_token]}") |
| 74 | + |
| 75 | + accounts_api = DocuSign_Click::AccountsApi.new(api_client) |
| 76 | + |
| 77 | + options = DocuSign_Click::GetClickwrapsOptions.new |
| 78 | + options.status = 'inactive' |
| 79 | + |
| 80 | + results = accounts_api.get_clickwraps( |
| 81 | + args[:ds_account_id], |
| 82 | + options |
| 83 | + ) |
| 84 | + results.as_json['clickwraps'] |
| 85 | + end |
| 86 | +end |
0 commit comments