sferik / twitter-ruby

A Ruby interface to the Twitter API.
http://www.rubydoc.info/gems/twitter
MIT License
4.58k stars 1.31k forks source link

handle json post requests #900

Closed shmargum closed 4 years ago

shmargum commented 6 years ago

This adds basic support for sending authenticated JSON post requests. Resolves #862 Also resolves #869

Example usage:

    Twitter::REST::Request.new(
      client, # Twitter::REST::Client instance
      :json_post, # <-- this is important
      '/1.1/the-endpoint.json',
      {
        some_key: "some value",
      }
    ).perform
shmargum commented 6 years ago

Just leaving an explanation behind this PR: We need to be able to send authenticated requests with a JSON (string) payload, with the correct header application/json

For the correct oauth headers, we must not include the JSON payload in the signature. In order to get the underlying HTTP client to send the proper application/json header, we need to send the options under the key :json : https://github.com/httprb/http/blob/d09394c5dcf9cc28b4858a78dc071091bcce4b54/lib/http/client.rb#L176

shmargum commented 6 years ago

@sferik hoping you can have a look at this

bobber205 commented 6 years ago

I can confirm this allows me to create welcome messages easily!

clarkbab commented 6 years ago

@shmargum @sferik Any movement on getting this merged? I believe that the old DM endpoints will cease to work on June 19th. Not long!

bobber205 commented 6 years ago

FWIW the pull request is missing a put equivalent (I added a PR for it) https://github.com/shmargum/twitter/pull/1

sferik commented 6 years ago

@shmargum I recently merged https://github.com/sferik/twitter/pull/927. Does this solve your problem? If so, can this PR be closed?