lib/schoology_client/client.rb in strongmind-schoology-client-0.1.2 vs lib/schoology_client/client.rb in strongmind-schoology-client-0.1.3

- old
+ new

@@ -1,9 +1,9 @@ # frozen_string_literal: true require 'faraday' require 'faraday_middleware' -require 'oauth' +require 'simple_oauth' module SchoologyClient class Client attr_reader :adapter, :oauth_consumer_key, :oauth_consumer_secret, :url, :stubs @@ -20,36 +20,21 @@ def group GroupResource.new(self) end def connection + # setup faraday connection using 2-legged oauth 1.0 + connection = Faraday.new(url: @url) do |faraday| + faraday.request :json + faraday.request :oauth, { + consumer_key: @oauth_consumer_key, + consumer_secret: @oauth_consumer_secret + } - # Set up the OAuth 1.0 consumer - consumer = OAuth::Consumer.new( - @oauth_consumer_key, - @oauth_consumer_secret, - site: @url, - scheme: :header, - signature_method: 'PLAINTEXT', - realm: 'Schoology API' - ) - - # Set up the Faraday connection - connection = Faraday.new("#{@url}") do |conn| - conn.request :url_encoded - conn.request :json - - conn.response :dates - conn.response :json, content_type: "application/json" - - if @stubs - conn.adapter adapter, @stubs - else - conn.adapter adapter - end + faraday.response :json + faraday.adapter @adapter, @stubs end - - return connection + connection end end end