Class: Skylight::Api Private

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

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

Instance Method Summary collapse

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

#configObject (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

#httpObject (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

#authenticationObject

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.

Raises:



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 (email, password)
  res = http.get('/me', 'X-Email' => email, 'X-Password' => password)

  if res && res.success?
    res.get('me.authentication_token')
  end
end

#validate_authenticationObject

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