Class: GroupDocs::Signature::Contact

Inherits:
Api::Entity show all
Defined in:
lib/groupdocs/signature/contact.rb

Constant Summary collapse

INTEGRATION_PROVIDERS =
{
  :local     => 0,
  :groupdocs => 1,
  :google    => 2,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Api::Entity

#initialize, #inspect, #to_hash

Methods included from Api::Helpers::Accessor

#alias_accessor

Constructor Details

This class inherits a constructor from GroupDocs::Api::Entity

Instance Attribute Details

#emailObject



116
117
118
# File 'lib/groupdocs/signature/contact.rb', line 116

def email
  @email
end

#firstNameObject



110
111
112
# File 'lib/groupdocs/signature/contact.rb', line 110

def firstName
  @firstName
end

#idObject



108
109
110
# File 'lib/groupdocs/signature/contact.rb', line 108

def id
  @id
end

#lastNameObject



112
113
114
# File 'lib/groupdocs/signature/contact.rb', line 112

def lastName
  @lastName
end

#nicknameObject



114
115
116
# File 'lib/groupdocs/signature/contact.rb', line 114

def nickname
  @nickname
end

#providerObject



118
119
120
# File 'lib/groupdocs/signature/contact.rb', line 118

def provider
  @provider
end

Class Method Details

.add_integration!(integration, access = {}) ⇒ Object

Adds contact integration.

Examples:

Add Google contacts integration

integration = {
  provider:                :google,
  refresh_token:           'token',
  access_token:            'token',
  access_token_expiration: '2014-12-12'
}

Parameters:

  • integration (Hash)
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (integration):

  • provider (Symbol)

    One of :local, :groupdocs or :google

  • refresh_token (String)
  • access_token (String)
  • access_token_exipration (String)

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/groupdocs/signature/contact.rb', line 91

def self.add_integration!(integration, access = {})
  payload = {
    :provider              => INTEGRATION_PROVIDERS[integration[:provider]],
    :refreshToken          => integration[:refresh_token],
    :accessToken           => integration[:access_token],
    :accessTokenExpiration => integration[:access_token_expiration],
  }

  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :POST
    request[:path] = '/signature/{{client_id}}/integration'
    request[:request_body] = payload
  end.execute!
end

.get!(options = {}, access = {}) ⇒ Array<GroupDocs::Signature::Contact>

Returns a list of all contacts.

Parameters:

  • options (Hash) (defaults to: {})

    Hash of options

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (options):

  • :page (Integer)

    Page to start with

  • :records (Integer)

    How many items to list

  • :firstName (String)

    Filter by first name

  • :lastName (String)

    Filter by last name

  • :email (String)

    Filter by last name

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/groupdocs/signature/contact.rb', line 24

def self.get!(options = {}, access = {})
  api = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :GET
    request[:path] = '/signature/{{client_id}}/contacts'
  end
  api.add_params(options)
  json = api.execute!

  json[:contacts].map do |contact|
    new(contact)
  end
end

.import!(contacts, access = {}) ⇒ Object

Imports array of contacts.

Examples:

contact_one = GroupDocs::Signature::Contact.new
contact_one.first_name = 'John'
contact_one.last_name = 'Smith'
contact_one.email = '[email protected]'
contact_two = GroupDocs::Signature::Contact.new
contact_two.first_name = 'Carla'
contact_two.last_name = 'Smith'
contact_two.email = '[email protected]'
GroupDocs::Signature::Contact.import!([contact_one, contact_two])

Parameters:

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/groupdocs/signature/contact.rb', line 57

def self.import!(contacts, access = {})
  contacts.is_a?(Array) or raise ArgumentError, "Contacts should be array, received: #{contacts.inspect}"
  contacts.each do |contact|
    contact.is_a?(GroupDocs::Signature::Contact) or raise ArgumentError, "Contact should be GroupDocs::Signature::Contact, received: #{contact.inspect}"
  end

  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :POST
    request[:path] = '/signature/{{client_id}}/contacts'
    request[:request_body] = contacts.map { |contact| contact.to_hash }
  end.execute!
end

Instance Method Details

#add!(access = {}) ⇒ Object

Adds contact.

Examples:

contact = GroupDocs::Signature::Contact.new
contact.first_name = 'John'
contact.last_name = 'Smith'
contact.email = '[email protected]'
contact.add!

Parameters:

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


138
139
140
141
142
143
144
145
146
147
# File 'lib/groupdocs/signature/contact.rb', line 138

def add!(access = {})
  json = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :POST
    request[:path] = '/signature/{{client_id}}/contact'
    request[:request_body] = to_hash
  end.execute!

  self.id = json[:contact][:id]
end

#delete!(access = {}) ⇒ Object

Deletes contact.

Parameters:

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


172
173
174
175
176
177
178
# File 'lib/groupdocs/signature/contact.rb', line 172

def delete!(access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :DELETE
    request[:path] = "/signature/{{client_id}}/contacts/#{id}"
  end.execute!
end

#update!(access = {}) ⇒ Object

Updates contact.

Parameters:

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


156
157
158
159
160
161
162
163
# File 'lib/groupdocs/signature/contact.rb', line 156

def update!(access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :POST
    request[:path] = "/signature/{{client_id}}/contacts/#{id}"
    request[:request_body] = to_hash
  end.execute!
end