Class: Tickethub::Request
- Inherits:
-
Object
- Object
- Tickethub::Request
- Defined in:
- lib/tickethub/request.rb
Constant Summary collapse
- SAFE_TO_RETRY =
[408, 502, 503, 504].freeze
- MAXIMUM_RETRIES =
3.freeze
Instance Attribute Summary collapse
-
#auth_type ⇒ Object
Connection options.
-
#body ⇒ Object
Returns the value of attribute body.
-
#format ⇒ Object
Returns the value of attribute format.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#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
Connection options.
-
#proxy ⇒ Object
Connection options.
-
#ssl_options ⇒ Object
Connection options.
-
#timeout ⇒ Object
Connection options.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user ⇒ Object
Connection options.
Instance Method Summary collapse
- #execute(retries = 0) ⇒ Object
-
#initialize(url, options = {}) ⇒ Request
constructor
A new instance of Request.
- #path ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(url, options = {}) ⇒ Request
Returns a new instance of Request.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tickethub/request.rb', line 15 def initialize(url, = {}) @url = url.to_s @id = SecureRandom.uuid @options = @options.each do |key, val| method = "#{key}=" send(method, val) if respond_to?(method) end self.method ||= :get self.params ||= {} self.headers ||= {} self.format ||= :form end |
Instance Attribute Details
#auth_type ⇒ Object
Connection options
13 14 15 |
# File 'lib/tickethub/request.rb', line 13 def auth_type @auth_type end |
#body ⇒ Object
Returns the value of attribute body.
10 11 12 |
# File 'lib/tickethub/request.rb', line 10 def body @body end |
#format ⇒ Object
Returns the value of attribute format.
9 10 11 |
# File 'lib/tickethub/request.rb', line 9 def format @format end |
#headers ⇒ Object
Returns the value of attribute headers.
10 11 12 |
# File 'lib/tickethub/request.rb', line 10 def headers @headers end |
#method ⇒ Object
Returns the value of attribute method.
10 11 12 |
# File 'lib/tickethub/request.rb', line 10 def method @method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/tickethub/request.rb', line 9 def @options end |
#params ⇒ Object
Returns the value of attribute params.
10 11 12 |
# File 'lib/tickethub/request.rb', line 10 def params @params end |
#password ⇒ Object
Connection options
13 14 15 |
# File 'lib/tickethub/request.rb', line 13 def password @password end |
#proxy ⇒ Object
Connection options
13 14 15 |
# File 'lib/tickethub/request.rb', line 13 def proxy @proxy end |
#ssl_options ⇒ Object
Connection options
13 14 15 |
# File 'lib/tickethub/request.rb', line 13 def @ssl_options end |
#timeout ⇒ Object
Connection options
13 14 15 |
# File 'lib/tickethub/request.rb', line 13 def timeout @timeout end |
#url ⇒ Object
Returns the value of attribute url.
9 10 11 |
# File 'lib/tickethub/request.rb', line 9 def url @url end |
#user ⇒ Object
Connection options
13 14 15 |
# File 'lib/tickethub/request.rb', line 13 def user @user end |
Instance Method Details
#execute(retries = 0) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/tickethub/request.rb', line 62 def execute(retries = 0) if encoded? result = connection.send(method, path, encoded, build_headers) else result = connection.send(method, query_path, build_headers) end Response.new(result) rescue TimeoutError => err raise if retries == MAXIMUM_RETRIES - 1 execute retries + 1 rescue ConnectionError => err raise if ! SAFE_TO_RETRY.member?(err.response.code) || retries == MAXIMUM_RETRIES - 1 execute retries + 1 rescue Redirection => error raise error unless error.response['Location'] location = URI.parse(error.response['Location']) # Path is relative unless location.host location = URI.join(uri, location) end self.url = location.to_s execute end |
#path ⇒ Object
58 59 60 |
# File 'lib/tickethub/request.rb', line 58 def path uri.path end |
#uri ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tickethub/request.rb', line 42 def uri return @uri if @uri url = @url.match(/\Ahttps?:\/\//) ? @url : "http://#{@url}" @uri = URI.parse(url) @uri.path = '/' if @uri.path.empty? if @uri.query @params.merge!(Helpers.from_param(@uri.query)) @uri.query = nil end @uri end |