Class: Tickethub::Request
- Inherits:
-
Object
- Object
- Tickethub::Request
- Defined in:
- lib/tickethub/request.rb
Instance Attribute Summary collapse
-
#auth_type ⇒ Object
Returns the value of attribute auth_type.
-
#body ⇒ Object
Returns the value of attribute body.
-
#follow_redirection ⇒ Object
Returns the value of attribute follow_redirection.
-
#format ⇒ Object
Returns the value of attribute format.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#max_attempts ⇒ Object
Returns the value of attribute max_attempts.
-
#method ⇒ Object
Returns the value of attribute method.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#params ⇒ Object
Returns the value of attribute params.
-
#password ⇒ Object
Returns the value of attribute password.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#retries ⇒ Object
Returns the value of attribute retries.
-
#ssl_options ⇒ Object
Returns the value of attribute ssl_options.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #encoded ⇒ Object
- #encoded? ⇒ Boolean
- #execute ⇒ Object
-
#initialize(url, options = {}) ⇒ Request
constructor
A new instance of Request.
- #path ⇒ Object
- #query_path ⇒ Object
- #uri ⇒ Object
- #uri_params ⇒ Object
Constructor Details
#initialize(url, options = {}) ⇒ Request
Returns a new instance of Request.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tickethub/request.rb', line 12 def initialize(url, = {}) @url = url.to_s @id = SecureRandom.uuid @retries = 6 @timeout = 10 @options = { :method => :get, :params => {}, :headers => {}, :format => :form, :max_attempts => 5, :follow_redirection => true }.merge() @options.each do |key, val| method = "#{key}=" send(method, val) if respond_to?(method) end end |
Instance Attribute Details
#auth_type ⇒ Object
Returns the value of attribute auth_type.
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def auth_type @auth_type end |
#body ⇒ Object
Returns the value of attribute body.
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def body @body end |
#follow_redirection ⇒ Object
Returns the value of attribute follow_redirection.
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def follow_redirection @follow_redirection end |
#format ⇒ Object
Returns the value of attribute format.
5 6 7 |
# File 'lib/tickethub/request.rb', line 5 def format @format end |
#headers ⇒ Object
Returns the value of attribute headers.
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def headers @headers end |
#max_attempts ⇒ Object
Returns the value of attribute max_attempts.
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def max_attempts @max_attempts end |
#method ⇒ Object
Returns the value of attribute method.
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def method @method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/tickethub/request.rb', line 5 def @options end |
#params ⇒ Object
Returns the value of attribute params.
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def params @params end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def password @password end |
#proxy ⇒ Object
Returns the value of attribute proxy.
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def proxy @proxy end |
#retries ⇒ Object
Returns the value of attribute retries.
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def retries @retries end |
#ssl_options ⇒ Object
Returns the value of attribute ssl_options.
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def @ssl_options end |
#timeout ⇒ Object
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def timeout @timeout end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/tickethub/request.rb', line 5 def url @url end |
#user ⇒ Object
Returns the value of attribute user.
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def user @user end |
Instance Method Details
#encoded ⇒ Object
79 80 81 |
# File 'lib/tickethub/request.rb', line 79 def encoded params.any? ? format.encode(params) : body end |
#encoded? ⇒ Boolean
75 76 77 |
# File 'lib/tickethub/request.rb', line 75 def encoded? [:post, :patch].include?(method) end |
#execute ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/tickethub/request.rb', line 83 def execute with_redirection do if encoded? result = connection.send(method, query_path, encoded, build_headers) else result = connection.send(method, query_path, build_headers) end Response.new(result, uri) end rescue ServerError, RequestError => err raise err if (@retries -= 1) == 0 execute end |
#path ⇒ Object
59 60 61 |
# File 'lib/tickethub/request.rb', line 59 def path uri.path end |
#query_path ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/tickethub/request.rb', line 63 def query_path query_path = path.dup query_params = uri_params.dup query_params.merge!(params) unless encoded? if query_params.any? query_path += '?' + Helpers.to_url_param(query_params) end query_path end |
#uri ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tickethub/request.rb', line 44 def uri return @uri if @uri url = @url.match(/\Ahttps?:\/\//) ? @url : "http://#{@url}" @uri = URI.parse(url) @uri.path = '/' if @uri.path.empty? @uri end |
#uri_params ⇒ Object
55 56 57 |
# File 'lib/tickethub/request.rb', line 55 def uri_params uri.query ? Helpers.from_param(uri.query) : {} end |