Class: Songkick::Transport::Request
- Inherits:
-
Object
- Object
- Songkick::Transport::Request
- Defined in:
- lib/songkick/transport/request.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#error ⇒ Object
Returns the value of attribute error.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#response ⇒ Object
Returns the value of attribute response.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#verb ⇒ Object
(also: #http_method)
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
- #body ⇒ Object
- #duration ⇒ Object
- #headers ⇒ Object
-
#initialize(endpoint, verb, path, params, headers = {}, timeout = DEFAULT_TIMEOUT) ⇒ Request
constructor
A new instance of Request.
- #multipart? ⇒ Boolean
- #to_s ⇒ Object
- #url ⇒ Object
- #use_body? ⇒ Boolean
Constructor Details
#initialize(endpoint, verb, path, params, headers = {}, timeout = DEFAULT_TIMEOUT) ⇒ Request
Returns a new instance of Request.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/songkick/transport/request.rb', line 16 def initialize(endpoint, verb, path, params, headers = {}, timeout = DEFAULT_TIMEOUT) @endpoint = endpoint @verb = verb.to_s.downcase @path = path @headers = Headers.new(headers) @params = params @timeout = timeout @start_time = start_time || Time.now @multipart = Serialization.multipart?(params) if use_body? @headers['Content-Type'] ||= @multipart ? multipart_request[:content_type] : FORM_ENCODING end end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
5 6 7 |
# File 'lib/songkick/transport/request.rb', line 5 def endpoint @endpoint end |
#error ⇒ Object
Returns the value of attribute error.
5 6 7 |
# File 'lib/songkick/transport/request.rb', line 5 def error @error end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/songkick/transport/request.rb', line 5 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/songkick/transport/request.rb', line 5 def path @path end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/songkick/transport/request.rb', line 5 def response @response end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
5 6 7 |
# File 'lib/songkick/transport/request.rb', line 5 def start_time @start_time end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
5 6 7 |
# File 'lib/songkick/transport/request.rb', line 5 def timeout @timeout end |
#verb ⇒ Object (readonly) Also known as: http_method
Returns the value of attribute verb.
5 6 7 |
# File 'lib/songkick/transport/request.rb', line 5 def verb @verb end |
Instance Method Details
#body ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/songkick/transport/request.rb', line 58 def body return nil unless use_body? if @multipart multipart_request[:body] else Serialization.build_query_string(params) end end |
#duration ⇒ Object
41 42 43 44 |
# File 'lib/songkick/transport/request.rb', line 41 def duration return nil unless @end_time (@end_time.to_f - @start_time.to_f) * 1000 end |
#headers ⇒ Object
46 47 48 |
# File 'lib/songkick/transport/request.rb', line 46 def headers @headers.to_hash end |
#multipart? ⇒ Boolean
54 55 56 |
# File 'lib/songkick/transport/request.rb', line 54 def multipart? @multipart end |
#to_s ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/songkick/transport/request.rb', line 71 def to_s url = String === @endpoint ? Serialization.build_url(@verb, @endpoint, @path, @params, true) : @endpoint.to_s command = "#{@verb.upcase} '#{url}'" @headers.each do |key, value| value = Serialization::SANITIZED_VALUE if Serialization.sanitize?(key) command << " -H '#{key}: #{value}'" end return command unless use_body? query = Serialization.build_query_string(params, true, true) command << " -d '#{query}'" command end |
#url ⇒ Object
67 68 69 |
# File 'lib/songkick/transport/request.rb', line 67 def url Serialization.build_url(@verb, @endpoint, @path, @params) end |
#use_body? ⇒ Boolean
50 51 52 |
# File 'lib/songkick/transport/request.rb', line 50 def use_body? USE_BODY.include?(@verb) end |