Class: Tickethub::Request
- Inherits:
-
Object
- Object
- Tickethub::Request
- Defined in:
- lib/tickethub/request.rb
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.
-
#retries ⇒ 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 ⇒ 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.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tickethub/request.rb', line 12 def initialize(url, = {}) @url = url.to_s @id = SecureRandom.uuid @retries = 3 @timeout = 10 @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
10 11 12 |
# File 'lib/tickethub/request.rb', line 10 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 |
#format ⇒ Object
Returns the value of attribute format.
6 7 8 |
# File 'lib/tickethub/request.rb', line 6 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 |
#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.
6 7 8 |
# File 'lib/tickethub/request.rb', line 6 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
Connection options
10 11 12 |
# File 'lib/tickethub/request.rb', line 10 def password @password end |
#proxy ⇒ Object
Connection options
10 11 12 |
# File 'lib/tickethub/request.rb', line 10 def proxy @proxy end |
#retries ⇒ Object
Connection options
10 11 12 |
# File 'lib/tickethub/request.rb', line 10 def retries @retries end |
#ssl_options ⇒ Object
Connection options
10 11 12 |
# File 'lib/tickethub/request.rb', line 10 def @ssl_options end |
#timeout ⇒ Object
Connection options
10 11 12 |
# File 'lib/tickethub/request.rb', line 10 def timeout @timeout end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/tickethub/request.rb', line 6 def url @url end |
#user ⇒ Object
Connection options
10 11 12 |
# File 'lib/tickethub/request.rb', line 10 def user @user end |
Instance Method Details
#execute ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/tickethub/request.rb', line 61 def execute 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, ServerError => err raise err if (@retries -= 1) == 0 execute 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
57 58 59 |
# File 'lib/tickethub/request.rb', line 57 def path uri.path end |
#uri ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/tickethub/request.rb', line 41 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 |