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")

Instance Method Summary collapse

Instance Method Details

#delete(path, query = {}, _options = {}) ⇒ Response

Examples:

Usage

client.delete("users/1")

Parameters:

  • path (String)

    URL path

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

    Query options to pass along with the request

Returns:



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/procore/requestable.rb', line 131

def delete(path, query = {}, _options = {})
  Util.log_info(
    "API Request Initiated",
    path: "#{base_api_path}/#{path}",
    method: "DELETE",
    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 = {}) ⇒ Response

Examples:

Usage

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

Parameters:

  • path (String)

    URL path

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

    Query options to pass along with the request

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/procore/requestable.rb', line 20

def get(path, query = {})
  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.merge(params: query),
      timeout: Procore.configuration.timeout,
    )
  end
end

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

TODO Add description for idempotency token

Examples:

Usage

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

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)

Returns:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/procore/requestable.rb', line 105

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

TODO Add description for idempotency key

Examples:

Usage

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

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)

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/procore/requestable.rb', line 48

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

TODO Add description for idempotency key

Examples:

Usage

client.put("dashboards/1/users", [1,2,3])

Parameters:

  • path (String)

    URL path

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

    Body parameters to send with the request

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

    Extra request options

Returns:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/procore/requestable.rb', line 76

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