Class: Rails::Contact::Google::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/contact/google/client.rb

Constant Summary collapse

PEOPLE_API_BASE =
"https://people.googleapis.com/v1".freeze
UPDATE_MASK_FIELDS =

Fields allowed in updatePersonFields (People API field mask); excludes Person metadata keys.

%w[names emailAddresses phoneNumbers addresses biographies].freeze

Instance Method Summary collapse

Constructor Details

#initialize(access_token:) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
18
# File 'lib/rails/contact/google/client.rb', line 12

def initialize(access_token:)
  @connection = Faraday.new(url: PEOPLE_API_BASE) do |faraday|
    faraday.request :retry, max: 3, interval: 0.5, backoff_factor: 2
    faraday.response :raise_error
  end
  @access_token = access_token
end

Instance Method Details

#create_contact(payload) ⇒ Object



20
21
22
# File 'lib/rails/contact/google/client.rb', line 20

def create_contact(payload)
  post("/people:createContact", payload)
end

#delete_contact(resource_name) ⇒ Object



31
32
33
# File 'lib/rails/contact/google/client.rb', line 31

def delete_contact(resource_name)
  @connection.delete("/#{resource_name}") { |request| request.headers = headers }
end

#update_contact(resource_name, payload) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
29
# File 'lib/rails/contact/google/client.rb', line 24

def update_contact(resource_name, payload)
  mask = update_person_fields_mask(payload)
  raise ArgumentError, "updatePersonFields must not be empty" if mask.blank?

  patch("/#{resource_name}:updateContact", payload, { "updatePersonFields" => mask })
end