Class: Jbr::Request

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

Constant Summary collapse

CREATE =
<<~GRAPHQL.freeze
  mutation($input: RequestCreateInput!) {
    requestCreate(input: $input) { request { 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

#client_idObject (readonly)

Returns the value of attribute client_id.



9
10
11
# File 'lib/jbr/request.rb', line 9

def client_id
  @client_id
end

Instance Method Details

#create(params = {}) ⇒ String

Create a lead in Jobber associated to a new or existing client, matched by phone.

Parameters:

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

    the attributes of the lead

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

  • :title (String)

    the reason why the lead is created

  • :instructions (String)

    a comment about the lead

Returns:

  • (String)

    the ID of the newly created lead.



20
21
22
23
24
25
26
# File 'lib/jbr/request.rb', line 20

def create(params = {})
  @client_id = @oauth.clients.create_with(params).find_or_create_by(phone: params[:phone]).id
  input = { clientId: @client_id, title: params[:title], assessment: { instructions: params[:instructions] } }
  output = @oauth.query CREATE, variables: { input: input }
  @id = output.dig 'requestCreate', 'request', 'id'
  self
end