Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions lib/purple/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def callback(&block)
end
end

def callback_params(*args)
if args.empty?
@callback_params ||= []
else
@callback_params = args
end
end

def path(name, method: :get, is_param: false)
path = Path.new(name:, parent: @parent_path, method:, client: self, is_param:)

Expand Down
11 changes: 10 additions & 1 deletion lib/purple/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,16 @@ def execute(params = {}, args = {})
{}
end

client.callback&.call(url, params, headers, JSON.parse(response.body))
if client.callback
callback_args = [url, params, headers, JSON.parse(response.body)]
callback_args.concat(client.callback_params) if client.respond_to?(:callback_params)

if client.callback.lambda? && client.callback.arity >= 0
callback_args = callback_args.first(client.callback.arity)
end

client.callback.call(*callback_args)
end

if block_given?
yield(resp_structure.status, object)
Expand Down