Sha256: d91a669de007743e85dcb95819c59b2066a54490592d98efc9c3c5dc430c48a3

Contents?: true

Size: 733 Bytes

Versions: 1

Compression:

Stored size: 733 Bytes

Contents

require 'faraday'

module LearnConfig
  class LearnWebInteractor
    attr_reader :token, :conn, :silent_output

    LEARN_URL = 'https://learn.co'
    API_ROOT  = '/api/v1'

    def initialize(token, silent_output: false)
      @token = token
      @silent_output = silent_output
      @conn = Faraday.new(url: LEARN_URL) do |faraday|
        faraday.adapter Faraday.default_adapter
      end
    end

    def me_endpoint
      "#{API_ROOT}/users/me"
    end

    def me
      response = @conn.get do |req|
        req.url me_endpoint
        req.headers['Authorization'] = "Bearer #{token}"
      end

      LearnConfig::Me.new(response, silent_output: silent_output)
    end

    def valid_token?
      !!me.data
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
learn-config-0.0.2 lib/learn_config/learn_web_interactor.rb