Class: TwelvedataRuby::Request

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/twelvedata_ruby/request.rb

Constant Summary collapse

DEFAULT_HTTP_VERB =
:get

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, **query_params) ⇒ Request

Returns a new instance of Request.



12
13
14
# File 'lib/twelvedata_ruby/request.rb', line 12

def initialize(name, **query_params)
  self.endpoint = Endpoint.new(name, **query_params)
end

Instance Attribute Details

#endpointObject

Returns the value of attribute endpoint.



10
11
12
# File 'lib/twelvedata_ruby/request.rb', line 10

def endpoint
  @endpoint
end

Instance Method Details

#fetchObject



17
18
19
# File 'lib/twelvedata_ruby/request.rb', line 17

def fetch
  Client.instance.fetch(self)
end

#full_urlObject



33
34
35
# File 'lib/twelvedata_ruby/request.rb', line 33

def full_url
  return_nil_unless_valid { "#{Client.origin[:origin]}/#{relative_url}" }
end

#http_verbObject



21
22
23
# File 'lib/twelvedata_ruby/request.rb', line 21

def http_verb
  return_nil_unless_valid { endpoint.definition[:http_verb] || DEFAULT_HTTP_VERB }
end

#paramsObject



25
26
27
# File 'lib/twelvedata_ruby/request.rb', line 25

def params
  {params: endpoint.query_params}
end

#relative_urlObject



29
30
31
# File 'lib/twelvedata_ruby/request.rb', line 29

def relative_url
  return_nil_unless_valid { name.to_s }
end

#to_aObject Also known as: build



41
42
43
# File 'lib/twelvedata_ruby/request.rb', line 41

def to_a
  return_nil_unless_valid { [http_verb, relative_url, params] }
end

#to_hObject



37
38
39
# File 'lib/twelvedata_ruby/request.rb', line 37

def to_h
  return_nil_unless_valid { {http_verb: http_verb, relative_url: relative_url}.merge(params: params) }
end