Module: MixinBot::API::Collectible

Included in:
MixinBot::API
Defined in:
lib/mixin_bot/api/collectible.rb

Constant Summary collapse

NFT_ASSET_MIXIN_ID =
'1700941284a95f31b25ec8c546008f208f88eee4419ccdcdbe6e3195e60128ca'
COLLECTABLE_REQUEST_ACTIONS =
%i[sign unlock].freeze

Instance Method Summary collapse

Instance Method Details

#cancel_collectible_request(request_id, pin) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'lib/mixin_bot/api/collectible.rb', line 79

def cancel_collectible_request(request_id, pin)
  path = format('/collectibles/requests/%<request_id>s/cancel', request_id: request_id)
  payload = {
    pin: encrypt_pin(pin)
  }
  access_token ||= access_token('POST', path, payload.to_json)
  authorization = format('Bearer %<access_token>s', access_token: access_token)
  client.post(path, headers: { 'Authorization': authorization }, json: payload)
end

#collectible(id, access_token: nil) ⇒ Object



8
9
10
11
12
13
# File 'lib/mixin_bot/api/collectible.rb', line 8

def collectible(id, access_token: nil)
  path = "/collectibles/tokens/#{id}"
  access_token ||= access_token('GET', path, '')
  authorization = format('Bearer %<access_token>s', access_token: access_token)
  client.get(path, headers: { 'Authorization': authorization })
end

#collectible_outputs(**kwargs) ⇒ Object Also known as: collectibles



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mixin_bot/api/collectible.rb', line 15

def collectible_outputs(**kwargs)
  limit = kwargs[:limit] || 100
  offset = kwargs[:offset] || ''
  state = kwargs[:state] || ''
  members = kwargs[:members] || [client_id]
  threshold = kwargs[:threshold] || 1
  access_token = kwargs[:access_token]
  members = SHA3::Digest::SHA256.hexdigest(members&.sort&.join)

  path = format(
    '/collectibles/outputs?limit=%<limit>s&offset=%<offset>s&state=%<state>s&members=%<members>s&threshold=%<threshold>s',
    limit: limit,
    offset: offset,
    state: state,
    members: members,
    threshold: threshold
  )
  access_token ||= access_token('GET', path, '')
  authorization = format('Bearer %<access_token>s', access_token: access_token)
  client.get(path, headers: { 'Authorization': authorization })
end

#create_collectible_request(action, raw, access_token: nil) ⇒ Object

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mixin_bot/api/collectible.rb', line 39

def create_collectible_request(action, raw, access_token: nil)
  raise ArgumentError, "request action is limited in #{COLLECTABLE_REQUEST_ACTIONS.join(', ')}" unless COLLECTABLE_REQUEST_ACTIONS.include? action.to_sym
  path = '/collectibles/requests'
  payload = {
    action: action,
    raw: raw
  }
  access_token ||= access_token('POST', path, payload.to_json)
  authorization = format('Bearer %<access_token>s', access_token: access_token)
  client.post(path, headers: { 'Authorization': authorization }, json: payload)
end

#create_sign_collectible_request(raw, access_token: nil) ⇒ Object



51
52
53
# File 'lib/mixin_bot/api/collectible.rb', line 51

def create_sign_collectible_request(raw, access_token: nil)
  create_collectible_request 'sign', raw, access_token: access_token
end

#create_unlock_collectible_request(raw, access_token: nil) ⇒ Object



55
56
57
# File 'lib/mixin_bot/api/collectible.rb', line 55

def create_unlock_collectible_request(raw, access_token: nil)
  create_collectible_request 'unlock', raw, access_token: access_token
end

#sign_collectible_request(request_id, pin) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/mixin_bot/api/collectible.rb', line 59

def sign_collectible_request(request_id, pin)
  path = format('/collectibles/requests/%<request_id>s/sign', request_id: request_id)
  payload = {
    pin: encrypt_pin(pin)
  }
  access_token ||= access_token('POST', path, payload.to_json)
  authorization = format('Bearer %<access_token>s', access_token: access_token)
  client.post(path, headers: { 'Authorization': authorization }, json: payload)
end

#unlock_collectible_request(request_id, pin) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/mixin_bot/api/collectible.rb', line 69

def unlock_collectible_request(request_id, pin)
  path = format('/collectibles/requests/%<request_id>s/unlock', request_id: request_id)
  payload = {
    pin: encrypt_pin(pin)
  }
  access_token ||= access_token('POST', path, payload.to_json)
  authorization = format('Bearer %<access_token>s', access_token: access_token)
  client.post(path, headers: { 'Authorization': authorization }, json: payload)
end