A Ruby Client for Studyplus for School SYNC API
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
- Redirect Server Start: Case where the redirect server that receives authorization code is localhost
- Retrieve Authorization Code:
- If you start localhost, run it in a different terminal
- Authorize and receive the authorization code on the redirect server.
- Create/Refresh Token: Creating a token from authorization code
Redirect Server Start:
$ bundle exec studyplus_for_school_sync server
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
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}
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)
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.
- Fork it ( https://github.com/yshimada0330/studyplus_for_school_sync/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the StudyplusForSchoolSync project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.