Class: Cryptopay::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/cryptopay/models/channel.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Channel

Initializes the object

Parameters:

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

    Model attributes in the form of hash



58
59
60
# File 'lib/cryptopay/models/channel.rb', line 58

def initialize(attributes = {})
  @attributes = ENCODER.sanitize(attributes)
end

Class Method Details

.build_from_hash(data) ⇒ Cryptopay::Channel

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:



51
52
53
54
# File 'lib/cryptopay/models/channel.rb', line 51

def self.build_from_hash(data)
  attributes = ENCODER.build_from_hash(data)
  new(attributes)
end

Instance Method Details

#addressObject

Channel description



92
93
94
# File 'lib/cryptopay/models/channel.rb', line 92

def address
  @attributes[:address]
end

#custom_idObject

The channel reference ID in your system



107
108
109
# File 'lib/cryptopay/models/channel.rb', line 107

def custom_id
  @attributes[:custom_id]
end

#customer_idObject

The reference ID of your customer



112
113
114
# File 'lib/cryptopay/models/channel.rb', line 112

def customer_id
  @attributes[:customer_id]
end

#descriptionObject

Channel description



77
78
79
# File 'lib/cryptopay/models/channel.rb', line 77

def description
  @attributes[:description]
end

#hosted_page_urlObject

Channel hosted page that renders channel details



122
123
124
# File 'lib/cryptopay/models/channel.rb', line 122

def hosted_page_url
  @attributes[:hosted_page_url]
end

#idObject

Channel ID



63
64
65
# File 'lib/cryptopay/models/channel.rb', line 63

def id
  @attributes[:id]
end

#inspectObject



172
173
174
# File 'lib/cryptopay/models/channel.rb', line 172

def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)}> JSON: " + JSON.pretty_generate(to_hash)
end

#invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/cryptopay/models/channel.rb', line 128

def invalid_properties
  properties = []

  properties.push('invalid value for "id", id cannot be nil.') if id.nil?

  properties.push('invalid value for "status", status cannot be nil.') if status.nil?

  if !status.nil? && !%w[enabled disabled].include?(status)
    properties.push('invalid value for status, must be one of "enabled", "disabled"')
  end

  properties.push('invalid value for "name", name cannot be nil.') if name.nil?

  properties.push('invalid value for "pay_currency", pay_currency cannot be nil.') if pay_currency.nil?

  if receiver_currency.nil?
    properties.push('invalid value for "receiver_currency", receiver_currency cannot be nil.')
  end

  properties.push('invalid value for "address", address cannot be nil.') if address.nil?

  properties.push('invalid value for "network", network cannot be nil.') if network.nil?

  properties.push('invalid value for "project_id", project_id cannot be nil.') if project_id.nil?

  properties.push('invalid value for "uri", uri cannot be nil.') if uri.nil?

  properties.push('invalid value for "hosted_page_url", hosted_page_url cannot be nil.') if hosted_page_url.nil?

  properties
end

#nameObject

Channel name



72
73
74
# File 'lib/cryptopay/models/channel.rb', line 72

def name
  @attributes[:name]
end

#networkObject

Cryptocurrency network



97
98
99
# File 'lib/cryptopay/models/channel.rb', line 97

def network
  @attributes[:network]
end

#pay_currencyObject

The cryptocurrency which you want to accept



82
83
84
# File 'lib/cryptopay/models/channel.rb', line 82

def pay_currency
  @attributes[:pay_currency]
end

#project_idObject

Project ID



102
103
104
# File 'lib/cryptopay/models/channel.rb', line 102

def project_id
  @attributes[:project_id]
end

#receiver_currencyObject

The currency which all incoming transactions will be converted to



87
88
89
# File 'lib/cryptopay/models/channel.rb', line 87

def receiver_currency
  @attributes[:receiver_currency]
end

#statusObject



67
68
69
# File 'lib/cryptopay/models/channel.rb', line 67

def status
  @attributes[:status]
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



168
169
170
# File 'lib/cryptopay/models/channel.rb', line 168

def to_hash
  ENCODER.to_hash(@attributes)
end

#uriObject

Channel URI. May be used for generating a QR code



117
118
119
# File 'lib/cryptopay/models/channel.rb', line 117

def uri
  @attributes[:uri]
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



162
163
164
# File 'lib/cryptopay/models/channel.rb', line 162

def valid?
  invalid_properties.empty?
end