Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable wallet activity events support for webhooks at wallet level #189

Open
wants to merge 8 commits into
base: v0.7.0
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions lib/coinbase/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
Coinbase::Client.autoload :WebhookEventFilter, 'coinbase/client/models/webhook_event_filter'
Coinbase::Client.autoload :WebhookEventType, 'coinbase/client/models/webhook_event_type'
Coinbase::Client.autoload :WebhookList, 'coinbase/client/models/webhook_list'
Coinbase::Client.autoload :WebhookEventTypeFilter, 'coinbase/client/models/webhook_event_type_filter'
Coinbase::Client.autoload :WebhookWalletActivityFilter, 'coinbase/client/models/webhook_wallet_activity_filter'

# APIs
Coinbase::Client.autoload :AddressesApi, 'coinbase/client/api/addresses_api'
Expand Down
11 changes: 10 additions & 1 deletion lib/coinbase/client/models/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Webhook

attr_accessor :event_type

attr_accessor :event_type_filter

# Webhook will monitor all events that matches any one of the event filters.
attr_accessor :event_filters

Expand Down Expand Up @@ -67,6 +69,7 @@ def self.attribute_map
:'id' => :'id',
:'network_id' => :'network_id',
:'event_type' => :'event_type',
:'event_type_filter' => :'event_type_filter',
:'event_filters' => :'event_filters',
:'notification_uri' => :'notification_uri',
:'created_at' => :'created_at',
Expand All @@ -86,6 +89,7 @@ def self.openapi_types
:'id' => :'String',
:'network_id' => :'String',
:'event_type' => :'WebhookEventType',
:'event_type_filter' => :'WebhookEventTypeFilter',
:'event_filters' => :'Array<WebhookEventFilter>',
:'notification_uri' => :'String',
:'created_at' => :'Time',
Expand Down Expand Up @@ -127,6 +131,10 @@ def initialize(attributes = {})
self.event_type = attributes[:'event_type']
end

if attributes.key?(:'event_type_filter')
self.event_type_filter = attributes[:'event_type_filter']
end

if attributes.key?(:'event_filters')
if (value = attributes[:'event_filters']).is_a?(Array)
self.event_filters = value
Expand Down Expand Up @@ -173,6 +181,7 @@ def ==(o)
id == o.id &&
network_id == o.network_id &&
event_type == o.event_type &&
event_type_filter == o.event_type_filter &&
event_filters == o.event_filters &&
notification_uri == o.notification_uri &&
created_at == o.created_at &&
Expand All @@ -189,7 +198,7 @@ def eql?(o)
# Calculates hash code according to all attributes.
# @return [Integer] Hash code
def hash
[id, network_id, event_type, event_filters, notification_uri, created_at, updated_at, signature_header].hash
[id, network_id, event_type, event_type_filter, event_filters, notification_uri, created_at, updated_at, signature_header].hash
end

# Builds the object from hash
Expand Down
3 changes: 2 additions & 1 deletion lib/coinbase/client/models/webhook_event_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ class WebhookEventType
UNSPECIFIED = "unspecified".freeze
ERC20_TRANSFER = "erc20_transfer".freeze
ERC721_TRANSFER = "erc721_transfer".freeze
WALLET_ACTIVITY = "wallet_activity".freeze
UNKNOWN_DEFAULT_OPEN_API = "unknown_default_open_api".freeze

def self.all_vars
@all_vars ||= [UNSPECIFIED, ERC20_TRANSFER, ERC721_TRANSFER, UNKNOWN_DEFAULT_OPEN_API].freeze
@all_vars ||= [UNSPECIFIED, ERC20_TRANSFER, ERC721_TRANSFER, WALLET_ACTIVITY, UNKNOWN_DEFAULT_OPEN_API].freeze
end

# Builds the enum from string
Expand Down
105 changes: 105 additions & 0 deletions lib/coinbase/client/models/webhook_event_type_filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
=begin
#Coinbase Platform API

#This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.

The version of the OpenAPI document: 0.0.1-alpha

Generated by: https://openapi-generator.tech
Generator version: 7.8.0

=end

require 'date'
require 'time'

module Coinbase::Client
# The event_type_filter parameter specifies the criteria to filter events based on event type.
module WebhookEventTypeFilter
class << self
# List of class defined in oneOf (OpenAPI v3)
def openapi_one_of
[
:'WebhookWalletActivityFilter'
]
end

# Builds the object
# @param [Mixed] Data to be matched against the list of oneOf items
# @return [Object] Returns the model or the data itself
def build(data)
# Go through the list of oneOf items and attempt to identify the appropriate one.
# Note:
# - We do not attempt to check whether exactly one item matches.
# - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
# due to the way the deserialization is made in the base_object template (it just casts without verifying).
# - TODO: scalar values are de facto behaving as if they were nullable.
# - TODO: logging when debugging is set.
openapi_one_of.each do |klass|
begin
next if klass == :AnyType # "nullable: true"
typed_data = find_and_cast_into_type(klass, data)
return typed_data if typed_data
rescue # rescue all errors so we keep iterating even if the current item lookup raises
end
end

openapi_one_of.include?(:AnyType) ? data : nil
end

private

SchemaMismatchError = Class.new(StandardError)

# Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
def find_and_cast_into_type(klass, data)
return if data.nil?

case klass.to_s
when 'Boolean'
return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
when 'Float'
return data if data.instance_of?(Float)
when 'Integer'
return data if data.instance_of?(Integer)
when 'Time'
return Time.parse(data)
when 'Date'
return Date.parse(data)
when 'String'
return data if data.instance_of?(String)
when 'Object' # "type: object"
return data if data.instance_of?(Hash)
when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
if data.instance_of?(Array)
sub_type = Regexp.last_match[:sub_type]
return data.map { |item| find_and_cast_into_type(sub_type, item) }
end
when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
sub_type = Regexp.last_match[:sub_type]
return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
end
else # model
const = Coinbase::Client.const_get(klass)
if const
if const.respond_to?(:openapi_one_of) # nested oneOf model
model = const.build(data)
return model if model
else
# raise if data contains keys that are not known to the model
raise if const.respond_to?(:acceptable_attributes) && !(data.keys - const.acceptable_attributes).empty?
model = const.build_from_hash(data)
return model if model
end
end
end

raise # if no match by now, raise
rescue
raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
end
end
end

end
Loading
Loading