Class: TwelvedataRuby::Request
- Inherits:
-
Object
- Object
- TwelvedataRuby::Request
- Extended by:
- Forwardable
- Defined in:
- lib/twelvedata_ruby/request.rb
Constant Summary collapse
- DEFAULT_HTTP_VERB =
Default HTTP method for API requests
:get
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Check equality with another request.
-
#fetch ⇒ Response, ...
Send the request using the client.
-
#full_url ⇒ String?
Get the complete URL for this request.
-
#hash ⇒ Integer
Generate hash code for request.
-
#http_verb ⇒ Symbol?
Get the HTTP verb for this request.
-
#initialize(name, **query_params) ⇒ Request
constructor
Initialize a new request.
-
#inspect ⇒ String
Detailed inspection of the request.
-
#params ⇒ Hash?
Get request parameters formatted for HTTP client.
-
#relative_url ⇒ String?
Get the relative URL path for this request.
-
#to_a ⇒ Array?
(also: #build)
Convert request to array format for HTTPX.
-
#to_h ⇒ Hash?
Convert request to hash representation.
-
#to_s ⇒ String
String representation of the request.
Constructor Details
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
15 16 17 |
# File 'lib/twelvedata_ruby/request.rb', line 15 def endpoint @endpoint end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Check equality with another request
113 114 115 116 117 |
# File 'lib/twelvedata_ruby/request.rb', line 113 def ==(other) return false unless other.is_a?(self.class) name == other.name && query_params == other.query_params end |
#fetch ⇒ Response, ...
Send the request using the client
28 29 30 |
# File 'lib/twelvedata_ruby/request.rb', line 28 def fetch Client.instance.fetch(self) end |
#full_url ⇒ String?
Get the complete URL for this request
62 63 64 65 66 |
# File 'lib/twelvedata_ruby/request.rb', line 62 def full_url return nil unless valid? "#{Client::BASE_URL}/#{relative_url}" end |
#hash ⇒ Integer
Generate hash code for request
123 124 125 |
# File 'lib/twelvedata_ruby/request.rb', line 123 def hash [name, query_params].hash end |
#http_verb ⇒ Symbol?
Get the HTTP verb for this request
35 36 37 38 39 |
# File 'lib/twelvedata_ruby/request.rb', line 35 def http_verb return nil unless valid? endpoint.definition[:http_verb] || DEFAULT_HTTP_VERB end |
#inspect ⇒ String
Detailed inspection of the request
105 106 107 |
# File 'lib/twelvedata_ruby/request.rb', line 105 def inspect "#<#{self.class.name}:#{object_id} endpoint=#{name} valid=#{valid?} params=#{query_params.keys}>" end |
#params ⇒ Hash?
Get request parameters formatted for HTTP client
44 45 46 47 48 |
# File 'lib/twelvedata_ruby/request.rb', line 44 def params return nil unless valid? { params: endpoint.query_params } end |
#relative_url ⇒ String?
Get the relative URL path for this request
53 54 55 56 57 |
# File 'lib/twelvedata_ruby/request.rb', line 53 def relative_url return nil unless valid? name.to_s end |
#to_a ⇒ Array? Also known as: build
Convert request to array format for HTTPX
84 85 86 87 88 |
# File 'lib/twelvedata_ruby/request.rb', line 84 def to_a return nil unless valid? [http_verb.to_s.upcase, full_url, params] end |
#to_h ⇒ Hash?
Convert request to hash representation
71 72 73 74 75 76 77 78 79 |
# File 'lib/twelvedata_ruby/request.rb', line 71 def to_h return nil unless valid? { http_verb: http_verb, url: full_url, params: query_params, } end |
#to_s ⇒ String
String representation of the request
94 95 96 97 98 99 100 |
# File 'lib/twelvedata_ruby/request.rb', line 94 def to_s if valid? "#{http_verb.to_s.upcase} #{full_url} with params: #{query_params}" else "Invalid request for endpoint: #{name}" end end |