Class: Prismic::API::OAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/prismic/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initiate, token, http_client) ⇒ OAuth

Returns a new instance of OAuth.



305
306
307
308
309
# File 'lib/prismic/api.rb', line 305

def initialize(initiate, token, http_client)
  @http_client = http_client
  @initiate = initiate
  @token = token
end

Instance Attribute Details

#http_clientObject (readonly)

Returns the value of attribute http_client.



304
305
306
# File 'lib/prismic/api.rb', line 304

def http_client
  @http_client
end

#initiateObject (readonly)

Returns the value of attribute initiate.



304
305
306
# File 'lib/prismic/api.rb', line 304

def initiate
  @initiate
end

#tokenObject (readonly)

Returns the value of attribute token.



304
305
306
# File 'lib/prismic/api.rb', line 304

def token
  @token
end

Instance Method Details

#check_token(params) ⇒ Object



317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/prismic/api.rb', line 317

def check_token(params)
  res = http_client.post(token, params)
  if res.code == '200'
    begin
      JSON.load(res.body)['access_token']
    rescue Exception => e
      raise PrismicWSConnectionError.new(res, e)
    end
  else
    raise PrismicWSConnectionError, res
  end
end

#initiate_url(opts) ⇒ Object



310
311
312
313
314
315
316
# File 'lib/prismic/api.rb', line 310

def initiate_url(opts)
  initiate + '?' + {
    'client_id' => opts.fetch(:client_id),
    'redirect_uri' => opts.fetch(:redirect_uri),
    'scope' => opts.fetch(:scope),
  }.map{|kv| kv.map{|e| CGI.escape(e) }.join('=') }.join('&')
end