Class: RailsSso::Client
- Inherits:
-
Object
- Object
- RailsSso::Client
- Defined in:
- lib/rails_sso/client.rb
Class Method Summary collapse
Instance Method Summary collapse
- #delete(url, params = {}) ⇒ Object
- #get(url, params = {}) ⇒ Object
-
#initialize(adapter) ⇒ Client
constructor
A new instance of Client.
- #patch(url, params = {}) ⇒ Object
- #post(url, params = {}) ⇒ Object
- #put(url, params = {}) ⇒ Object
- #token!(token) ⇒ Object
Constructor Details
#initialize(adapter) ⇒ Client
Returns a new instance of Client.
46 47 48 |
# File 'lib/rails_sso/client.rb', line 46 def initialize(adapter) @connection = adapter end |
Class Method Details
.build(url, &block) ⇒ Object
6 7 8 9 |
# File 'lib/rails_sso/client.rb', line 6 def self.build(url, &block) adapter = Faraday.new(url, &block) new(adapter) end |
.build_fake(url) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rails_sso/client.rb', line 25 def self.build_fake(url) build(url) do |conn| conn.adapter :test do |stub| RailsSso.config.profile_mocks.each do |token, profile| headers = { "Content-Type" => "application/json", "Authorization" => "Bearer #{token}" } stub.get(RailsSso.config.provider_profile_path, headers) do |env| if profile.nil? [401, { "Content-Type" => "application/json" }, ""] else [200, { "Content-Type" => "application/json" }, profile.to_json] end end end end end end |
.build_real(url) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rails_sso/client.rb', line 11 def self.build_real(url) build(url) do |conn| if RailsSso.config.use_cache conn.use :http_cache, store: Rails.cache, logger: Rails.logger, serializer: Marshal, shared_cache: false end conn.adapter Faraday.default_adapter end end |
Instance Method Details
#delete(url, params = {}) ⇒ Object
68 69 70 |
# File 'lib/rails_sso/client.rb', line 68 def delete(url, params = {}) request(:delete, url, params) end |
#get(url, params = {}) ⇒ Object
56 57 58 |
# File 'lib/rails_sso/client.rb', line 56 def get(url, params = {}) request(:get, url, params) end |
#patch(url, params = {}) ⇒ Object
72 73 74 |
# File 'lib/rails_sso/client.rb', line 72 def patch(url, params = {}) request(:patch, url, params) end |
#post(url, params = {}) ⇒ Object
60 61 62 |
# File 'lib/rails_sso/client.rb', line 60 def post(url, params = {}) request(:post, url, params) end |
#put(url, params = {}) ⇒ Object
64 65 66 |
# File 'lib/rails_sso/client.rb', line 64 def put(url, params = {}) request(:put, url, params) end |
#token!(token) ⇒ Object
50 51 52 53 54 |
# File 'lib/rails_sso/client.rb', line 50 def token!(token) @token = token self end |