Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions lib/namely/resource_gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ def json_index_paged
end

attr_reader :access_token, :subdomain, :paged


def default_headers
{
accept: :json,
authorization: "Bearer #{access_token}"
}
end

def resource_name
endpoint.split("/").last
end
Expand All @@ -82,31 +89,31 @@ def with_retry
raise
end

def get(path, params = {})
JSON.parse(RestClient.get(url(path), accept: :json, params: params, authorization: "Bearer #{access_token}"))
def get(path, params = {}, headers: {})
headers = default_headers.merge(headers)
JSON.parse(RestClient.get(url(path), params: params, **headers))
end

def head(path, params = {})
RestClient.head(url(path), accept: :json, params: params, authorization: "Bearer #{access_token}")
def head(path, params = {}, headers: {})
headers = default_headers.merge(headers)
RestClient.head(url(path), params: params, **headers)
end

def post(path, params)
def post(path, params, headers: {})
headers = default_headers.merge(content_type: :json).merge(headers)
RestClient.post(
url(path),
params.to_json,
accept: :json,
content_type: :json,
authorization: "Bearer #{access_token}"
**headers
)
end

def put(path, params)
def put(path, params, headers={})
headers = default_headers.merge(content_type: :json).merge(headers)
RestClient.put(
url(path),
params.to_json,
accept: :json,
content_type: :json,
authorization: "Bearer #{access_token}"
**headers
)
end
end
Expand Down