Module: Procore::Requestable

Included in:
Client
Defined in:
lib/procore/requestable.rb

Overview

Module which defines HTTP verbs GET, POST, PUT, PATCH and DELETE. Is included in Client. Has support for Idempotency Tokens on POST and PATCH.

Examples:

Using #get:

client.get("my_open_items", per_page: 5)

Using #post:

client.post("projects", name: "New Project")

Constant Summary collapse

HTTP_EXCEPTIONS =
[
  Errno::ECONNREFUSED,
  Errno::ECONNRESET,
  Procore::OAuthError,
  RestClient::Exceptions::Timeout,
  RestClient::ServerBrokeConnection,
].freeze

Instance Method Summary collapse

Instance Method Details

#delete(path, query: {}, options: {}) ⇒ Response

Examples:

Usage

client.delete("users/1", query: {}, options: {})

Parameters:

  • path (String) —

    URL path

  • query (Hash) (defaults to: {}) —

    Query options to pass along with the request

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

    a customizable set of options

Options Hash (options:):

  • :company_id (String)

Returns:



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/procore/requestable.rb', line 147

def delete(path, query: {}, options: {})
  Util.log_info(
    "API Request Initiated",
    path: "#{base_api_path}/#{path}",
    method: "DELETE",
    headers: headers(options),
    query: query.to_s,
  )

  with_response_handling do
    RestClient::Request.execute(
      method: :delete,
      url: "#{base_api_path}/#{path}",
      headers: headers.merge(params: query),
      timeout: Procore.configuration.timeout,
    )
  end
end

#get(path, query: {}, options: {}) ⇒ Response

Examples:

Usage

client.get("my_open_items", query: { per_page: 5, filter: {} })

Parameters:

  • path (String) —

    URL path

  • query (Hash) (defaults to: {}) —

    Query options to pass along with the request

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

    a customizable set of options

Options Hash (options:):

  • :company_id (Hash)

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/procore/requestable.rb', line 29

def get(path, query: {}, options: {})
  Util.log_info(
    "API Request Initiated",
    path: "#{base_api_path}/#{path}",
    method: "GET",
    query: query.to_s,
  )

  with_response_handling do
    RestClient::Request.execute(
      method: :get,
      url: "#{base_api_path}/#{path}",
      headers: headers(options).merge(params: query),
      timeout: Procore.configuration.timeout,
    )
  end
end

#patch(path, body: {}, options: {}) ⇒ Response

Examples:

Usage

client.patch(
  "users/1",
  body: { name: "Updated" },
  options: { idempotency_token: "key", company_id: 1 },
)

Parameters:

  • path (String) —

    URL path

  • body (Hash) (defaults to: {}) —

    Body parameters to send with the request

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

    Extra request options

Options Hash (options:):

  • :idempotency_token (String) —

    | :company_id

Returns:



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/procore/requestable.rb', line 120

def patch(path, body: {}, options: {})
  Util.log_info(
    "API Request Initiated",
    path: "#{base_api_path}/#{path}",
    method: "PATCH",
    body: body.to_s,
  )

  with_response_handling(request_body: body) do
    RestClient::Request.execute(
      method: :patch,
      url: "#{base_api_path}/#{path}",
      payload: payload(body),
      headers: headers(options),
      timeout: Procore.configuration.timeout,
    )
  end
end

#post(path, body: {}, options: {}) ⇒ Response

Examples:

Usage

client.post(
  "users",
  body: { name: "New User" },
  options: { idempotency_token: "key", company_id: 1 },
)

Parameters:

  • path (String) —

    URL path

  • body (Hash) (defaults to: {}) —

    Body parameters to send with the request

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

    Extra request options

Options Hash (options:):

  • :idempotency_token (String) —

    | :company_id

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/procore/requestable.rb', line 60

def post(path, body: {}, options: {})
  Util.log_info(
    "API Request Initiated",
    path: "#{base_api_path}/#{path}",
    method: "POST",
    body: body.to_s,
  )

  with_response_handling(request_body: body) do
    RestClient::Request.execute(
      method: :post,
      url: "#{base_api_path}/#{path}",
      payload: payload(body),
      headers: headers(options),
      timeout: Procore.configuration.timeout,
    )
  end
end

#put(path, body: {}, options: {}) ⇒ Response

Examples:

Usage

client.put("dashboards/1/users", body: [1,2,3], options: { company_id: 1 })

Parameters:

  • path (String) —

    URL path

  • body (Hash) (defaults to: {}) —

    Body parameters to send with the request

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

    Extra request options

Options Hash (options:):

  • :idempotency_token (String) —

    | :company_id

Returns:



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/procore/requestable.rb', line 88

def put(path, body: {}, options: {})
  Util.log_info(
    "API Request Initiated",
    path: "#{base_api_path}/#{path}",
    method: "PUT",
    body: body.to_s,
  )

  with_response_handling(request_body: body) do
    RestClient::Request.execute(
      method: :put,
      url: "#{base_api_path}/#{path}",
      payload: payload(body),
      headers: headers(options),
      timeout: Procore.configuration.timeout,
    )
  end
end