Class: Jbr::Client

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

Constant Summary collapse

LOOKUP =
<<~GRAPHQL.freeze
  query($searchTerm: String!) {
    clientPhones(first: 1, searchTerm: $searchTerm) { nodes {
      client { id updatedAt clientProperties { nodes { id address { street city province postalCode } }} }
    } }
  }
GRAPHQL
CREATE =
<<~GRAPHQL.freeze
  mutation($input: ClientCreateInput!) {
    clientCreate(input: $input) {
      client { id clientProperties(first: 1) { nodes { id } } }
      userErrors { message }
    }
  }
GRAPHQL
CREATE_PROPERTY =
<<~GRAPHQL.freeze
  mutation propertyCreateMutation($clientId: EncodedId!, $input: PropertyCreateInput!) {
    propertyCreate(clientId: $clientId, input: $input) {
      properties { 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_idObject (readonly)

Returns the value of attribute property_id.



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

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:



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

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

#find_or_create_by(phone:) ⇒ Object



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

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