Sha256: 9e6ac245fc013fceec9854e82eeb4f1f54f27ea08887baec3644f273c6ac8048

Contents?: true

Size: 765 Bytes

Versions: 8

Compression:

Stored size: 765 Bytes

Contents

class ExvoAuth::Autonomous::Consumer < ExvoAuth::Autonomous::Base
  include ExvoAuth::Autonomous::Http

  def initialize(params = {})
    super
    validate_params!(:app_id)
  end

  def base_uri
    authorization["url"]
  end

  def username
    Exvo::Helpers.auth_client_id
  end

  def password
    authorization["access_token"]
  end

  def authorization
    @@cache.fetch(params) do
      authorization!
    end
  end

  def authorization!
    response = auth.get("/apps/consumer/authorizations/#{URI.escape(params[:app_id])}.json")

    if response["authorization"]
      @@cache.write(params, response["authorization"])
    else
      raise "Authorization not found. You need an auhorization to contact provider app (#{ params[:app_id] })"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
exvo_auth-0.16.5 lib/exvo_auth/autonomous/consumer.rb
exvo_auth-0.16.4 lib/exvo_auth/autonomous/consumer.rb
exvo_auth-0.16.3 lib/exvo_auth/autonomous/consumer.rb
exvo_auth-0.16.2 lib/exvo_auth/autonomous/consumer.rb
exvo_auth-0.16.1 lib/exvo_auth/autonomous/consumer.rb
exvo_auth-0.16.0 lib/exvo_auth/autonomous/consumer.rb
exvo_auth-0.15.1 lib/exvo_auth/autonomous/consumer.rb
exvo_auth-0.15.0 lib/exvo_auth/autonomous/consumer.rb