Class: Monerorequest::Encoder
- Inherits:
-
Object
- Object
- Monerorequest::Encoder
- Defined in:
- lib/monerorequest/encoder.rb
Overview
class to Encode a Monerorequest hash
Defined Under Namespace
Classes: InvalidRequest
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#request ⇒ Object
Returns the value of attribute request.
Instance Method Summary collapse
- #encode(version) ⇒ Object
-
#initialize(request) ⇒ Encoder
constructor
A new instance of Encoder.
Constructor Details
#initialize(request) ⇒ Encoder
Returns a new instance of Encoder.
18 19 20 21 22 23 |
# File 'lib/monerorequest/encoder.rb', line 18 def initialize(request) @request = request @errors = [] validate! end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
16 17 18 |
# File 'lib/monerorequest/encoder.rb', line 16 def errors @errors end |
#request ⇒ Object
Returns the value of attribute request.
15 16 17 |
# File 'lib/monerorequest/encoder.rb', line 15 def request @request end |
Instance Method Details
#encode(version) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/monerorequest/encoder.rb', line 25 def encode(version) raise RequestVersionError, "Only Request Version 1 is supported." unless version == 1 json_str = @request.sort.to_h.to_json.force_encoding("ascii") compressed_data = StringIO.new gz = Zlib::GzipWriter.new(compressed_data, 9) gz.mtime = 0 gz.write(json_str) gz.close encoded_str = Base64.encode64(compressed_data.string).gsub("\n", "") "monero-request:1:#{encoded_str}" end |