Search code examples
rubyoauth-2.0google-oauthfaradayfaraday-oauth

Attempting a PUT to Google Groups API using OAuth2 gem and Ruby


I'm trying to do a PUT call on a Google Groups API using Ruby and the OAuth2 GEM. I've managed to authenticate OK, and the GET call works properly, but I can't seem to get the call to use the PUT method. I thought the following would work, since OAuth2 uses Faraday, but I just keep getting the 400 message back, with an indication that something's "required":

data = access_token.put('https://www.googleapis.com/groups/v1/groups/{email address}?alt=json').parsed do |request|
  request.params['email'] = "{email address}"
end

Has anyone got a working example of passing parameters to a PUT request?


Solution

  • OK. Looks like the ".parsed" was interfering with the call here's what works, with some additions to the request object:

    response = access_token.put('https://www.googleapis.com/groups/v1/groups/{email address}') do |request|
      request.headers['Content-Type'] = 'application/json'
      request.body='{"email": "{email address}"}'
    end
    # check this
    puts response.status
    # works if it's 200