Class: Scro::Auth::Request
- Inherits:
-
Object
- Object
- Scro::Auth::Request
- Defined in:
- lib/scro/auth.rb
Direct Known Subclasses
Instance Method Summary collapse
- #endpoint ⇒ Object
- #get(path) ⇒ Object
-
#initialize(token) ⇒ Request
constructor
A new instance of Request.
- #post(path, params) ⇒ Object
- #uri_for(path) ⇒ Object
Constructor Details
#initialize(token) ⇒ Request
Returns a new instance of Request.
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
#endpoint ⇒ Object
36 37 38 |
# File 'lib/scro/auth.rb', line 36 def endpoint "#{Scro::Auth.endpoint_host}#{Scro::Auth.endpoint_path}" end |
#get(path) ⇒ Object
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
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 |