Class: Naviance

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

Defined Under Namespace

Classes: AccessToken, MockSession, School, Session, Staff, Student, Subscription

Constant Summary

API_VERSION =

The version of the NAviance API we are using

'v1'

Class Method Summary (collapse)

Class Method Details

+ (Object) base_host(env)

:nodoc:



36
37
38
39
40
41
42
43
44
45
# File 'lib/naviance/naviance.rb', line 36

def self.base_host(env) # :nodoc:
  case env
    when 'production', 'prod'
      'https://services.naviance.com'
    when 'sandbox', 'development', 'staging', 'test'
      'https://nav-services-sandbox-01.naviance.com'
    else
      raise "Invalid or missing environment (#{env.inspect})"
  end
end

+ (Object) base_url(env)

:nodoc:



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/naviance/naviance.rb', line 23

def self.base_url(env) # :nodoc:
  base_url = base_host(env)

  case env
    when 'production', 'prod'
      "#{base_url}/api/rest/#{API_VERSION}"
    when 'sandbox', 'development', 'staging', 'test'
      base_url
    else
      raise "Invalid or missing environment (#{env.inspect})"
  end
end

+ (Object) error(resp)

:nodoc:



19
20
21
# File 'lib/naviance/naviance.rb', line 19

def self.error(resp) # :nodoc:
  raise resp.parsed_response['error_description']
end

+ (Object) fetch(env, access_token, id, resource)

:nodoc:



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/naviance/naviance.rb', line 5

def self.fetch(env, access_token, id, resource) # :nodoc:
  resp = HTTParty.get("#{Naviance.base_url(env)}/#{resource}/#{id}?access_token=#{access_token}")

  if 200 == resp.code
    if 'student' == resource
      Naviance::Student.new(resp.parsed_response)
    elsif 'staff' == resource
      Naviance::Staff.new(resp.parsed_response)
    end
  else
    Naviance.error(resp)
  end
end