Class: Yandex360::ExternalContactsResource
- Includes:
- ParamBuilder
- Defined in:
- lib/yandex360/resources/external_contacts.rb
Overview
Shared contacts outside the organization.
See https://yandex.ru/dev/api360/doc/ru/ref/ExternalContactService/
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#create(org_id:, first_name:, last_name:, emails:, **params) ⇒ Object
emails must hold at least one entry; the API rejects a contact without one.
- #delete(org_id:, contact_id:) ⇒ Object
- #info(org_id:, contact_id:) ⇒ Object
- #list(org_id:, page: 1, per_page: 10) ⇒ Object
-
#update(org_id:, contact_id:, **params) ⇒ Object
PATCH, so only the fields given are touched.
-
#update_emails(org_id:, contact_id:, emails:) ⇒ Object
Replaces the address list entirely.
-
#update_phones(org_id:, contact_id:, phones:) ⇒ Object
Replaces the phone list entirely.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Yandex360::Resource
Instance Method Details
#create(org_id:, first_name:, last_name:, emails:, **params) ⇒ Object
emails must hold at least one entry; the API rejects a contact without one.
20 21 22 23 24 25 |
# File 'lib/yandex360/resources/external_contacts.rb', line 20 def create(org_id:, first_name:, last_name:, emails:, **params) required = {org_id: org_id, first_name: first_name, last_name: last_name, emails: emails} validate_required_params(required, %i[org_id first_name last_name emails]) body = build_params({firstName: first_name, lastName: last_name, emails: emails}, params) ExternalContact.new post("/directory/v1/org/#{org_id}/external_contacts", body: body).body end |
#delete(org_id:, contact_id:) ⇒ Object
41 42 43 44 |
# File 'lib/yandex360/resources/external_contacts.rb', line 41 def delete(org_id:, contact_id:) validate_required_params({org_id: org_id, contact_id: contact_id}, %i[org_id contact_id]) Response.new delete_request("/directory/v1/org/#{org_id}/external_contacts/#{contact_id}").body end |
#info(org_id:, contact_id:) ⇒ Object
27 28 29 30 |
# File 'lib/yandex360/resources/external_contacts.rb', line 27 def info(org_id:, contact_id:) validate_required_params({org_id: org_id, contact_id: contact_id}, %i[org_id contact_id]) ExternalContact.new get("/directory/v1/org/#{org_id}/external_contacts/#{contact_id}").body end |
#list(org_id:, page: 1, per_page: 10) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/yandex360/resources/external_contacts.rb', line 10 def list(org_id:, page: 1, per_page: 10) validate_required_params({org_id: org_id}, [:org_id]) resp = get("/directory/v1/org/#{org_id}/external_contacts", params: {page: page, perPage: per_page}) Collection.from_response(resp, key: "contacts", type: ExternalContact) do |next_page| list(org_id: org_id, page: next_page, per_page: per_page) end end |
#update(org_id:, contact_id:, **params) ⇒ Object
PATCH, so only the fields given are touched. Emails and phones are not editable here: they have their own endpoints below.
34 35 36 37 38 39 |
# File 'lib/yandex360/resources/external_contacts.rb', line 34 def update(org_id:, contact_id:, **params) validate_required_params({org_id: org_id, contact_id: contact_id}, %i[org_id contact_id]) body = build_params({}, params) resp = patch("/directory/v1/org/#{org_id}/external_contacts/#{contact_id}", body: body) ExternalContact.new resp.body end |
#update_emails(org_id:, contact_id:, emails:) ⇒ Object
Replaces the address list entirely. It cannot be empty and exactly one entry must carry main: true.
48 49 50 51 52 53 54 |
# File 'lib/yandex360/resources/external_contacts.rb', line 48 def update_emails(org_id:, contact_id:, emails:) required = {org_id: org_id, contact_id: contact_id, emails: emails} validate_required_params(required, %i[org_id contact_id emails]) resp = put("/directory/v1/org/#{org_id}/external_contacts/#{contact_id}/emails", body: {emails: emails}) ExternalContact.new resp.body end |
#update_phones(org_id:, contact_id:, phones:) ⇒ Object
Replaces the phone list entirely. At most one entry may carry main: true.
57 58 59 60 61 62 63 |
# File 'lib/yandex360/resources/external_contacts.rb', line 57 def update_phones(org_id:, contact_id:, phones:) required = {org_id: org_id, contact_id: contact_id, phones: phones} validate_required_params(required, %i[org_id contact_id phones]) resp = put("/directory/v1/org/#{org_id}/external_contacts/#{contact_id}/phones", body: {phones: phones}) ExternalContact.new resp.body end |