Class: Phantasma::API::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/phantasma/API/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, api_version: 'v1', debug: false) ⇒ Request

Returns a new instance of Request.



13
14
15
16
17
18
# File 'lib/phantasma/API/request.rb', line 13

def initialize(url:, api_version: 'v1', debug: false)
  @url = url
  @api_version = api_version
  @debug = debug
  @allowed_methods_hash = Phantasma::API.allowed_methods_hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/phantasma/API/request.rb', line 24

def method_missing(method_name, *args, &block)
  return super(method_name, *args, &block) unless @allowed_methods_hash.include?(method_name.to_s)
  self.class.send(:define_method, method_name) do |*method_args|
    build_request(method_name, method_args)
  end
  self.send(method_name, *args, &block)
end

Instance Attribute Details

#api_versionObject

Returns the value of attribute api_version.



11
12
13
# File 'lib/phantasma/API/request.rb', line 11

def api_version
  @api_version
end

#debugObject

Returns the value of attribute debug.



11
12
13
# File 'lib/phantasma/API/request.rb', line 11

def debug
  @debug
end

#urlObject

Returns the value of attribute url.



11
12
13
# File 'lib/phantasma/API/request.rb', line 11

def url
  @url
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/phantasma/API/request.rb', line 20

def respond_to_missing?(method_name, include_private = false)
  @allowed_methods_hash.include?(method_name.to_s) || super
end