Class: GDataPlus::Client
- Inherits:
-
Object
- Object
- GDataPlus::Client
- Defined in:
- lib/gdata_plus/client.rb
Instance Attribute Summary collapse
-
#authenticator ⇒ Object
readonly
Returns the value of attribute authenticator.
-
#default_gdata_version ⇒ Object
readonly
Returns the value of attribute default_gdata_version.
Instance Method Summary collapse
-
#initialize(authenticator, default_gdata_version = "2.0") ⇒ Client
constructor
A new instance of Client.
-
#submit(request, options = {}) ⇒ Object
FIXME detect infinite redirect.
Constructor Details
#initialize(authenticator, default_gdata_version = "2.0") ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/gdata_plus/client.rb', line 7 def initialize(authenticator, default_gdata_version = "2.0") @authenticator = authenticator @default_gdata_version = default_gdata_version end |
Instance Attribute Details
#authenticator ⇒ Object (readonly)
Returns the value of attribute authenticator.
5 6 7 |
# File 'lib/gdata_plus/client.rb', line 5 def authenticator @authenticator end |
#default_gdata_version ⇒ Object (readonly)
Returns the value of attribute default_gdata_version.
5 6 7 |
# File 'lib/gdata_plus/client.rb', line 5 def default_gdata_version @default_gdata_version end |
Instance Method Details
#submit(request, options = {}) ⇒ Object
FIXME detect infinite redirect
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gdata_plus/client.rb', line 13 def submit(request, = {}) = ::GDataPlus::Util.(, [], [:gdata_version, :hydra, :no_redirect]) hydra = [:hydra] || Typhoeus::Hydra.hydra request.headers.merge!("GData-Version" => [:gdata_version] || default_gdata_version) @authenticator.sign_request(request) # add "If-Match: *" header if there is not already a conditional header unless request.headers.keys.any? { |key| key =~ /^If-/ } request.headers.merge!("If-Match" => "*") end hydra.queue(request) hydra.run response = request.response # automatically follow redirects since some GData APIs (like Calendar) redirect GET requests if request.method.to_sym == :get && ![:no_redirect] && (300..399).include?(response.code) response = submit ::Typhoeus::Request.new(response.headers_hash["Location"], :method => :get), .merge(:no_redirect => true) end Util.raise_if_error(response) response end |