Class: StudyplusForSchoolSync::Client

Inherits:
Object
  • Object
show all
Includes:
Endpoint
Defined in:
lib/studyplus_for_school_sync/client.rb

Overview

Sync API Http Client

Constant Summary

Constants included from Endpoint

Endpoint::BASE_PAH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Endpoint::Student

#attach_student_tag, #create_passcode, #create_student_transfer, #create_study_record, #detach_student_tag, #inactivate_passcode, #student_tags, #student_transfer

Methods included from Endpoint::Partner

#create_partner, #create_student, #create_tag, #delete_tag, #tags, #update_tag

Methods included from Endpoint::LearningMaterial

#create_learning_material, #update_learning_material

Constructor Details

#initialize(base_url:, access_token: nil) ⇒ Client

Returns a new instance of Client.

Parameters:

  • base_url (String)

    API domain

  • access_token (String) (defaults to: nil)

    OAuth access token



16
17
18
19
20
21
22
23
24
# File 'lib/studyplus_for_school_sync/client.rb', line 16

def initialize(base_url:, access_token: nil)
  @base_url = base_url
  @access_token = access_token
  @conn = Faraday.new(headers: default_header) do |connection|
    connection.response :json
    connection.response :encoding
    connection.adapter Faraday.default_adapter
  end
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



12
13
14
# File 'lib/studyplus_for_school_sync/client.rb', line 12

def access_token
  @access_token
end

Instance Method Details

#delete(path:) ⇒ Hash

DELETE Http Request

Parameters:

  • path (String)

Returns:

  • (Hash)

    API response



69
70
71
# File 'lib/studyplus_for_school_sync/client.rb', line 69

def delete(path:)
  @conn.delete(build_url(path))
end

#get(path:, params: nil) ⇒ Hash

GET Http Request

Parameters:

  • path (String)
  • params (Hash) (defaults to: nil)

Returns:

  • (Hash)

    API response



30
31
32
33
34
# File 'lib/studyplus_for_school_sync/client.rb', line 30

def get(path:, params: nil)
  @conn.get(build_url(path)) do |req|
    req.params = params if params
  end
end

#patch(path:, params: nil) ⇒ Hash

PATCH Http Request

Parameters:

  • path (String)
  • params (Hash) (defaults to: nil)

Returns:

  • (Hash)

    API response



60
61
62
63
64
# File 'lib/studyplus_for_school_sync/client.rb', line 60

def patch(path:, params: nil)
  @conn.patch(build_url(path)) do |req|
    req.body = params.to_json if params
  end
end

#post(path:, params: nil) ⇒ Hash

POST Http Request

Parameters:

  • path (String)
  • params (Hash) (defaults to: nil)

Returns:

  • (Hash)

    API response



40
41
42
43
44
# File 'lib/studyplus_for_school_sync/client.rb', line 40

def post(path:, params: nil)
  @conn.post(build_url(path)) do |req|
    req.body = params.to_json if params
  end
end

#put(path:, params: nil) ⇒ Hash

PUT Http Request

Parameters:

  • path (String)
  • params (Hash) (defaults to: nil)

Returns:

  • (Hash)

    API response



50
51
52
53
54
# File 'lib/studyplus_for_school_sync/client.rb', line 50

def put(path:, params: nil)
  @conn.put(build_url(path)) do |req|
    req.body = params.to_json if params
  end
end