Class: Skylight::Api Private
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: CreateFailed
Instance Attribute Summary collapse
- #config ⇒ Object readonly private
- #http ⇒ Object readonly private
Instance Method Summary collapse
- #authentication ⇒ Object private
- #authentication=(token) ⇒ Object private
- #create_app(name, token = nil) ⇒ Object private
-
#initialize(config, service = :auth) ⇒ Api
constructor
private
A new instance of Api.
- #login(email, password) ⇒ Object private
- #validate_authentication ⇒ Object private
Constructor Details
#initialize(config, service = :auth) ⇒ Api
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Api.
32 33 34 35 |
# File 'lib/skylight/api.rb', line 32 def initialize(config, service = :auth) @config = config @http = Util::HTTP.new(config, service) end |
Instance Attribute Details
#config ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
6 7 8 |
# File 'lib/skylight/api.rb', line 6 def config @config end |
#http ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
6 7 8 |
# File 'lib/skylight/api.rb', line 6 def http @http end |
Instance Method Details
#authentication ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 |
# File 'lib/skylight/api.rb', line 37 def authentication @http.authentication end |
#authentication=(token) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/skylight/api.rb', line 41 def authentication=(token) @http.authentication = token end |
#create_app(name, token = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 73 74 75 76 |
# File 'lib/skylight/api.rb', line 70 def create_app(name, token=nil) params = { app: { name: name } } params[:token] = token if token res = @http.post('/apps', params) raise CreateFailed, res unless res.success? res end |
#login(email, password) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 65 66 67 68 |
# File 'lib/skylight/api.rb', line 62 def login(email, password) res = http.get('/me', 'X-Email' => email, 'X-Password' => password) if res && res.success? res.get('me.authentication_token') end end |
#validate_authentication ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/skylight/api.rb', line 45 def validate_authentication url = URI.parse(config[:auth_url]) res = @http.get(url.path) case res.status when 200...300 :ok when 400...500 :invalid else :unknown end rescue :unknown end |