Module: PostDeleteTweets
- Included in:
- TweetTop::User
- Defined in:
- lib/post_delete_tweets.rb
Instance Method Summary collapse
Instance Method Details
#delete_tweet(tweet_id) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/post_delete_tweets.rb', line 33 def delete_tweet(tweet_id) url = "https://api.twitter.com/2/tweets/#{tweet_id}" = { :method => :delete, headers: { "content-type": "application/json" } } access_token = @credentials oauth_params = {:consumer => @client, :token => access_token} request = Typhoeus::Request.new(url, ) oauth_helper = OAuth::Client::Helper.new(request, oauth_params.merge(:request_uri => url)) request.[:headers].merge!({"Authorization" => oauth_helper.header}) response = request.run return response.code end |
#post_tweet(text) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/post_delete_tweets.rb', line 7 def post_tweet(text) url = "https://api.twitter.com/2/tweets" @json_payload = {"text": text} = { :method => :post, headers: { "content-type": "application/json" }, body: JSON.dump(@json_payload) } access_token = @credentials oauth_params = {:consumer => @client, :token => access_token} request = Typhoeus::Request.new(url, ) oauth_helper = OAuth::Client::Helper.new(request, oauth_params.merge(:request_uri => url)) request.[:headers].merge!({"Authorization" => oauth_helper.header}) response = request.run return response.code, JSON.pretty_generate(JSON.parse(response.body)) end |