Skip to content

yshimada0330/studyplus_for_school_sync

Repository files navigation

StudyplusForSchoolSync

Gem Version Build Status Maintainability Test Coverage GitHub code size in bytes Inline docs GitHub

A Ruby Client for Studyplus for School SYNC API

logo

Installation

Add this line to your application's Gemfile:

gem 'studyplus_for_school_sync'

And then execute:

$ bundle

Or install it yourself as:

$ gem install studyplus_for_school_sync

Usage

Authorization

  1. Redirect Server Start: Case where the redirect server that receives authorization code is localhost
  2. Retrieve Authorization Code:
    1. If you start localhost, run it in a different terminal
    2. Authorize and receive the authorization code on the redirect server.
  3. Create/Refresh Token: Creating a token from authorization code

Redirect Server Start:

$ bundle exec studyplus_for_school_sync server

=> https://localhost:8080/

If to get a token with a form

$ BASE_URL=[BASE_URL] bundle exec studyplus_for_school_sync server

If you want to change the port

$ bundle exec studyplus_for_school_sync server --port 3000

=> https://localhost:3000/

Retrieve Authorization Code:

$ bundle exec studyplus_for_school_sync authorize [BASE_URL] [CLIENT_ID]

Create/Refresh Token:

base_url = "https://sandbox.fs-lms.studyplus.co.jp" # SYNC API URL
client_id = "sample_id" # YOUR CLIENT_ID
client_secret = "sample_pass" # YOUR CLIENT SECRET
authorization_code = "xxx" # Retrieve Authorization Code
token = StudyplusForSchoolSync::Token.new(base_url: base_url, client_id: client_id, client_secret: client_secret)
response = token.create(authorization_code: authorization_code, redirect_uri: "https://localhost:8080")
response.status # => 200
response.body # => {"access_token"=>"xxx", "token_type"=>"Bearer", "expires_in"=>86399, "refresh_token"=>"xxxx", "scope"=>"learning_material_supplier lms_passcode_issue", "created_at"=>1621558627}

# Refresh token
response = token.refresh(response.body["refresh_token"])
response.status # => 200
response.body # => {"access_token"=>"xxx", "token_type"=>"Bearer", "expires_in"=>86399, "refresh_token"=>"xxx", "scope"=>"learning_material_supplier lms_passcode_issue", "created_at"=>1621558753}

Resource Access

access_token is the value obtained from Authorization flow.

client = StudyplusForSchoolSync::Client.new(base_url: base_url, access_token: access_token)
response = client.create_partner(school_name: "school A")
response.status # => 200
response.body # => {"public_id"=>"12345abcde"}

response = client.create_student(
  partner_public_id: response.body["public_id"],
  last_name: "山田",
  first_name: "太郎",
  last_name_kana: "ヤマダ",
  first_name_kana: "タロウ"
)
response.status #=> 200
response.body # => {"public_id"=>"xxxx"}
student_public_id = response.body["public_id"]

response = client.create_learning_material(name: "text A")
learning_material_public_id = response.body["public_id"]
response = client.update_learning_material(learning_material_public_id: learning_material_public_id, name: "text B")

response = client.create_study_record(
  learning_material_public_id: learning_material_public_id,
  student_public_id: student_public_id,
  recorded_at: "2020/03/01 09:30:10",
  number_of_seconds: 600
)

response = client.create_passcode(student_public_id)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/yshimada0330/studyplus_for_school_sync. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

  1. Fork it ( https://github.com/yshimada0330/studyplus_for_school_sync/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the StudyplusForSchoolSync project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.