Class: Jbr::Client

Inherits:
Resource show all
Defined in:
lib/jbr/client.rb

Overview

A person a Jobber user works for, and the property the work happens at.

Constant Summary collapse

LOOKUP =

The query that finds a client by phone, with the properties already on file.

<<~GRAPHQL
  query($searchTerm: String!) {
    clientPhones(first: 1, searchTerm: $searchTerm) { nodes {
      client { id updatedAt clientProperties { nodes { id address { #{Property::SELECTION} } }} }
    } }
  }
GRAPHQL
CREATE =

The mutation that opens a client, with a first property when an address is given.

<<~GRAPHQL
  mutation($input: ClientCreateInput!) {
    clientCreate(input: $input) {
      client { id clientProperties(first: 1) { nodes { id } } }
      userErrors { message }
    }
  }
GRAPHQL

Instance Attribute Summary collapse

Attributes inherited from Resource

#id

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Jbr::Resource

Instance Attribute Details

#property_idString? (readonly)

Returns the property the work happens at.

Returns:

  • (String, nil)

    the property the work happens at.



24
25
26
# File 'lib/jbr/client.rb', line 24

def property_id
  @property_id
end

Instance Method Details

#create_with(params = {}) ⇒ Client

Create a client instance with the provided attributes.

Parameters:

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

    the attributes of the client

Options Hash (params):

  • :first_name (String)

    the client’s first name

  • :last_name (String)

    the client’s last name

  • :phone (String)

    the client’s phone number

  • :email (<String, nil>)

    the client’s email address

Returns:



33
34
35
# File 'lib/jbr/client.rb', line 33

def create_with(params = {})
  self.tap { @create_params = params }
end

#find_or_create_by(phone:) ⇒ Client

Reach the client behind a phone number, opening one if Jobber has none.

Parameters:

  • phone (String)

    the number to match on.

Returns:



40
41
42
43
# File 'lib/jbr/client.rb', line 40

def find_or_create_by(phone:)
  find_by_phone(phone) || create
  self
end