lib/simple_twitter/client.rb in simple_twitter-2.2.0 vs lib/simple_twitter/client.rb in simple_twitter-2.2.1
- old
+ new
@@ -38,10 +38,11 @@
# @param url [String]
# @param params [Hash] Send this arg as a query string. (e.g. `?name1=value1&name2=value2`)
# @param json [Hash] Send this arg as JSON request body with `Content-Type: application/json` header
# @param form [Hash] Send this arg as form-data request body with `Content-Type: multipart/form-data` header
# @return [HTTP::Response]
+ # @see https://www.rubydoc.info/github/httprb/http/HTTP/Response HTTP::Response documentation
# @!method post(url, params: {}, json: {}, form: {})
# Call Twitter API with POST method
# @param url [String]
# @param params [Hash] Send this arg as a query string. (e.g. `?name1=value1&name2=value2`)
@@ -56,10 +57,11 @@
# @param url [String]
# @param params [Hash] Send this arg as a query string. (e.g. `?name1=value1&name2=value2`)
# @param json [Hash] Send this arg as JSON request body with `Content-Type: application/json` header
# @param form [Hash] Send this arg as form-data request body with `Content-Type: multipart/form-data` header
# @return [HTTP::Response]
+ # @see https://www.rubydoc.info/github/httprb/http/HTTP/Response HTTP::Response documentation
# @!method put(url, params: {}, json: {}, form: {})
# Call Twitter API with PUT method
# @param url [String]
# @param params [Hash] Send this arg as a query string. (e.g. `?name1=value1&name2=value2`)
@@ -74,10 +76,11 @@
# @param url [String]
# @param params [Hash] Send this arg as a query string. (e.g. `?name1=value1&name2=value2`)
# @param json [Hash] Send this arg as JSON request body with `Content-Type: application/json` header
# @param form [Hash] Send this arg as form-data request body with `Content-Type: multipart/form-data` header
# @return [HTTP::Response]
+ # @see https://www.rubydoc.info/github/httprb/http/HTTP/Response HTTP::Response documentation
# @!method delete(url, params: {}, json: {}, form: {})
# Call Twitter API with DELETE method
# @param url [String]
# @param params [Hash] Send this arg as a query string. (e.g. `?name1=value1&name2=value2`)
@@ -92,10 +95,11 @@
# @param url [String]
# @param params [Hash] Send this arg as a query string. (e.g. `?name1=value1&name2=value2`)
# @param json [Hash] Send this arg as JSON request body with `Content-Type: application/json` header
# @param form [Hash] Send this arg as form-data request body with `Content-Type: multipart/form-data` header
# @return [HTTP::Response]
+ # @see https://www.rubydoc.info/github/httprb/http/HTTP/Response HTTP::Response documentation
%i[get post put delete].each do |m|
class_eval <<~EOD
def #{m}(url, params: {}, json: {}, form: {})
res = #{m}_raw(url, params: params, json: json, form: form)
@@ -149,9 +153,10 @@
# @param res [HTTP::Response]
# @return [Hash] parsed json data
# @raise [SimpleTwitter::ClientError] Twitter API returned 4xx error
# @raise [SimpleTwitter::ServerError] Twitter API returned 5xx error
+ # @see https://www.rubydoc.info/github/httprb/http/HTTP/Response HTTP::Response documentation
def parse_response(res)
case res.code.to_i / 100
when 4
raise ClientError, res
when 5