Class: Prismic::API::OAuth
- Inherits:
-
Object
- Object
- Prismic::API::OAuth
- Defined in:
- lib/prismic/api.rb
Instance Attribute Summary collapse
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
-
#initiate ⇒ Object
readonly
Returns the value of attribute initiate.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #check_token(params) ⇒ Object
-
#initialize(initiate, token, http_client) ⇒ OAuth
constructor
A new instance of OAuth.
- #initiate_url(opts) ⇒ Object
Constructor Details
#initialize(initiate, token, http_client) ⇒ OAuth
Returns a new instance of OAuth
283 284 285 286 287 |
# File 'lib/prismic/api.rb', line 283 def initialize(initiate, token, http_client) @http_client = http_client @initiate = initiate @token = token end |
Instance Attribute Details
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client
282 283 284 |
# File 'lib/prismic/api.rb', line 282 def http_client @http_client end |
#initiate ⇒ Object (readonly)
Returns the value of attribute initiate
282 283 284 |
# File 'lib/prismic/api.rb', line 282 def initiate @initiate end |
#token ⇒ Object (readonly)
Returns the value of attribute token
282 283 284 |
# File 'lib/prismic/api.rb', line 282 def token @token end |
Instance Method Details
#check_token(params) ⇒ Object
295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/prismic/api.rb', line 295 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
288 289 290 291 292 293 294 |
# File 'lib/prismic/api.rb', line 288 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 |