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.

Direct Known Subclasses

Mock::Client

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

#company_nameString?

Returns the business the client is, where the client is a business.

Returns:

  • (String, nil)

    the business the client is, where the client is a business.



32
# File 'lib/jbr/client.rb', line 32

def company_name = @node['companyName']

#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:



52
53
54
# File 'lib/jbr/client.rb', line 52

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

#emailString?

Returns the address to write to.

Returns:

  • (String, nil)

    the address to write to.



39
# File 'lib/jbr/client.rb', line 39

def email = @node['email']

#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:



59
60
61
62
# File 'lib/jbr/client.rb', line 59

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

#first_nameString?

Returns what the client is called.

Returns:

  • (String, nil)

    what the client is called.



27
# File 'lib/jbr/client.rb', line 27

def first_name = @node['firstName']

#last_nameObject



29
# File 'lib/jbr/client.rb', line 29

def last_name = @node['lastName']

#nameString

Jobber files nobody without one name or the other, so there is always one to call them.

Returns:

  • (String)

    the person's first name, or the business's name.



36
# File 'lib/jbr/client.rb', line 36

def name = first_name || company_name

#phoneString?

The number to reach them on, without its country code.

Returns:

  • (String, nil)

    ten digits, or nil where Jobber holds none we can dial.



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

def phone = Phone.from(@node['phones'])