lib/groupme/client.rb in groupme-api-0.8.0 vs lib/groupme/client.rb in groupme-api-0.9.0

- old
+ new

@@ -10,15 +10,10 @@ def initialize(args = {}) @access_token = args[:access_token] || GroupMe.configuration.access_token @client = HTTPClient.new(base_url: API_BASE_URL, default_header: API_DEFAULT_HEADER) end - def request(method, path, query: {}, body: nil) - response = @client.request(method, path, { token: @access_token }.merge(query), body&.to_json) - [parse_response_body(response), response.status] - end - def get(path, query = {}) request(:get, path, query: query) end def post(path, body = {}) @@ -27,28 +22,32 @@ def delete(path, query = {}) request(:delete, path, query: query) end + def request(method, path, query: {}, body: nil) + response = @client.request(method, path, { token: @access_token }.merge(query), body&.to_json) + [parse_response_body(response), response.status] + end + private def parse_response_body(response) return response.reason unless response.ok? + return if blank?(response.body) - unless blank?(response.body) - JSON.parse(response.body, symbolize_names: true).fetch(:response) - end + JSON.parse(response.body, symbolize_names: true).fetch(:response) end def blank?(string) string =~ /\A[[:space:]]*\z/ end end - def self.client - @client ||= Client.new - end - def self.client=(client) @client = client + end + + def self.client + @client ||= Client.new end end