Class: Procore::Client

Inherits:
Object
  • Object
show all
Includes:
Requestable
Defined in:
lib/procore/client.rb

Overview

Main class end users interact with. An instance of a client can call out the Procore API using methods matching standard HTTP verbs #get, #post, #put, #patch, #delete.

Examples:

Creating a new client:

store = Procore::Auth::Stores::Session.new(session: session)
client = Procore::Client.new(
  client_id: Rails.application.secrets.procore_client_id,
  client_secret: Rails.application.secrets.procore_secret_id,
  store: store
)

client.get("me").body #=> { id: 5, email: "[email protected]" }

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Requestable

#delete, #get, #patch, #post, #put

Constructor Details

#initialize(client_id:, client_secret:, store:, options: {}) ⇒ Client

Returns a new instance of Client.

Parameters:

  • client_id (String)

    Client ID issued from Procore

  • client_secret (String)

    Client Secret issued from Procore

  • store (Auth::Store)

    A store to use for saving, updating and refreshing tokens

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

    options to configure the client with

Options Hash (options:):

  • :host (String)

    Endpoint to use for the API. Defaults to Configuration.host

  • :user_agent (String)

    User Agent string to send along with the request. Defaults to Configuration.user_agent



31
32
33
34
35
36
37
38
39
# File 'lib/procore/client.rb', line 31

def initialize(client_id:, client_secret:, store:, options: {})
  @options = Procore::Defaults::client_options.merge(options)
  @credentials = Procore::Auth::AccessTokenCredentials.new(
    client_id: client_id,
    client_secret: client_secret,
    host: @options[:host],
  )
  @store = store
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



20
21
22
# File 'lib/procore/client.rb', line 20

def options
  @options
end

#storeObject (readonly)

Returns the value of attribute store.



20
21
22
# File 'lib/procore/client.rb', line 20

def store
  @store
end