class GDataPlus::Client

Attributes

authenticator[R]
default_gdata_version[R]

Public Class Methods

new(authenticator, default_gdata_version = "2.0") click to toggle source
# 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

Public Instance Methods

submit(request, options = {}) click to toggle source

FIXME detect infinite redirect

# File lib/gdata_plus/client.rb, line 13
def submit(request, options = {})
  options = ::GDataPlus::Util.prepare_options(options, [], [:gdata_version, :hydra, :no_redirect])
  hydra = options[:hydra] || Typhoeus::Hydra.hydra

  request.headers.merge!("GData-Version" => options[: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 && !options[:no_redirect] && (300..399).include?(response.code)
    response = submit ::Typhoeus::Request.new(response.headers_hash["Location"], :method => :get), options.merge(:no_redirect => true)
  end

  Util.raise_if_error(response)

  response
end