Sha256: d544c713903f07893b36b2767385011179e8e2f9301251b25360c6fbbda741c4

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 KB

Contents

require 'oauth2'
require 'path-builder'

module SecondStep::APIRequests
  class Request
    attr_writer :token_cache
    class <<self
      def client
        @@client ||= OAuth2::Client.new(config.client_id, config.client_secret, site: config.base_uri)
      end
      def token(type=@token_type, auth_code: nil)
        case type
        when :auth_code
          client.auth_code.get_token auth_code, redirect_uri: config.redirect_uri
        when :client_credentials
          client.client_credentials.get_token
        end
      end
      def auth_url
        client.auth_code.authorize_url redirect_uri: config.redirect_uri
      end
      def token_type(type)
        @token_type = type
      end
      def path(*args)
        PathBuilder.new(*args)
      end
    end
    def path(*args)
      PathBuilder.new(*args)
    end
    def token_cache
      @token_cache ||= {}
    end
    def token_cache_args(args)
      token_cache[args] ||= {}
    end
    def token(*args, **opts)
      token_cache_args(args)[opts] ||= self.class.token(*args, **opts)
    end
    def token!(*args, **opts)
      token_cache_args(args)[opts] = self.class.token(*args, **opts)
    end
  end
end

Version data entries

5 entries across 4 versions & 1 rubygems

Version Path
second_step-0.2.0 lib/second_step/api_requests/request.rb
second_step-0.1.4 lib/second_step/api_requests/request.rb
second_step-0.1.3 lib/second_step/api_requests/request.rb
second_step-0.1.2 lib/second_step/api_requests/request.rb
second_step-0.1.2 secondstep-notify-1.0.0-osx/lib/ruby/lib/ruby/gems/2.2.0/gems/second_step-0.1.1/lib/second_step/api_requests/request.rb