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.
-
#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.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/tickethub/request.rb', line 9 def initialize(url, = {}) @url = url.to_s @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
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def auth_type @auth_type end |
#body ⇒ Object
Returns the value of attribute body.
4 5 6 |
# File 'lib/tickethub/request.rb', line 4 def body @body end |
#format ⇒ Object
Returns the value of attribute format.
3 4 5 |
# File 'lib/tickethub/request.rb', line 3 def format @format end |
#headers ⇒ Object
Returns the value of attribute headers.
4 5 6 |
# File 'lib/tickethub/request.rb', line 4 def headers @headers end |
#method ⇒ Object
Returns the value of attribute method.
4 5 6 |
# File 'lib/tickethub/request.rb', line 4 def method @method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/tickethub/request.rb', line 3 def @options end |
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/tickethub/request.rb', line 4 def params @params end |
#password ⇒ Object
Connection options
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def password @password end |
#proxy ⇒ Object
Connection options
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def proxy @proxy end |
#ssl_options ⇒ Object
Connection options
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def @ssl_options end |
#timeout ⇒ Object
Connection options
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def timeout @timeout end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/tickethub/request.rb', line 3 def url @url end |
#user ⇒ Object
Connection options
7 8 9 |
# File 'lib/tickethub/request.rb', line 7 def user @user end |
Instance Method Details
#execute ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/tickethub/request.rb', line 55 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 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
51 52 53 |
# File 'lib/tickethub/request.rb', line 51 def path uri.path end |
#uri ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tickethub/request.rb', line 35 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 |