Class: Scro::Auth::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/scro/auth.rb

Direct Known Subclasses

Repository, User

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Request

Returns a new instance of Request.

Raises:



15
16
17
18
# File 'lib/scro/auth.rb', line 15

def initialize(token)
  raise RequestError, "Token not configured" if token.nil? || token.empty?
  @token = token
end

Instance Method Details

#endpointObject



36
37
38
# File 'lib/scro/auth.rb', line 36

def endpoint
  "#{Scro::Auth.endpoint_host}#{Scro::Auth.endpoint_path}"
end

#get(path) ⇒ Object

Raises:



20
21
22
23
24
# File 'lib/scro/auth.rb', line 20

def get(path)
  response = RestClient.get(uri_for(path), {:accept => :json})
  raise RequestError, response.inspect unless response.code == 200
  JSON.parse(response.to_s)
end

#post(path, params) ⇒ Object

Raises:



26
27
28
29
30
# File 'lib/scro/auth.rb', line 26

def post(path, params)
  response = RestClient.post(uri_for(path), params.to_json, {:content_type => :json, :accept => :json})
  raise RequestError, response.inspect unless response.code == 200
  JSON.parse(response.to_s)
end

#uri_for(path) ⇒ Object



32
33
34
# File 'lib/scro/auth.rb', line 32

def uri_for(path)
  "#{endpoint}#{path}?access_token=#{@token}"
end