Module: IntercodeClient

Defined in:
lib/intercode_client.rb,
lib/intercode_client/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

HTTP =
GraphQL::Client::HTTP.new("#{IntercodeClient.intercode_url}/graphql") do
  def headers(context)
    context[:headers] || {}
  end
end
Schema =
GraphQL::Client.load_schema(
  File.expand_path('../intercode_schema.json', __FILE__)
)
Client =
GraphQL::Client.new(schema: Schema, execute: HTTP)
VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.decode_jwt(jwt) ⇒ Object



25
26
27
# File 'lib/intercode_client.rb', line 25

def self.decode_jwt(jwt)
  JSON::JWT.decode(jwt, IntercodeClient.jwk_set)
end

.intercode_urlObject



11
12
13
# File 'lib/intercode_client.rb', line 11

def self.intercode_url
  ENV['INTERCODE_URL'] || 'https://www.neilhosting.net'
end

.jwk_responseObject



33
34
35
36
37
38
39
40
# File 'lib/intercode_client.rb', line 33

def self.jwk_response
  if !@jwk_response_last_fetched || @jwk_response_last_fetched < Time.now.to_i - 3600
    @jwk_response_last_fetched = Time.now.to_i
    @jwk_response = Net::HTTP.get(URI("#{IntercodeClient.intercode_url}/oauth/discovery/keys"))
  end

  @jwk_response
end

.jwk_setObject



29
30
31
# File 'lib/intercode_client.rb', line 29

def self.jwk_set
  JSON::JWK::Set.new(JSON.parse(jwk_response))
end