Class: OpenStax::Exchange::RealClient
- Inherits:
-
Object
- Object
- OpenStax::Exchange::RealClient
- Includes:
- ClientInstance
- Defined in:
- lib/openstax/exchange/real_client/real_client.rb
Instance Method Summary collapse
- #create_identifier ⇒ Object
-
#initialize(exchange_configuration) ⇒ RealClient
constructor
A new instance of RealClient.
- #is_real_client? ⇒ Boolean
- #record_multiple_choice_answer(identifier, resource, trial, answer) ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(exchange_configuration) ⇒ RealClient
Returns a new instance of RealClient.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/openstax/exchange/real_client/real_client.rb', line 9 def initialize(exchange_configuration) @platform_id = exchange_configuration.client_platform_id @platform_secret = exchange_configuration.client_platform_secret @server_url = exchange_configuration.client_server_url @api_version = exchange_configuration.client_api_version @oauth_client = OAuth2::Client.new( @platform_id, @platform_secret, site: @server_url) @oauth_token = @oauth_client.client_credentials.get_token end |
Instance Method Details
#create_identifier ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/openstax/exchange/real_client/real_client.rb', line 31 def create_identifier = {} add_accept_header! response = @oauth_token.request( :post, "#{@server_url}/api/identifiers", ) return JSON.parse(response.body)['identifier'] end |
#is_real_client? ⇒ Boolean
23 24 25 |
# File 'lib/openstax/exchange/real_client/real_client.rb', line 23 def is_real_client? true end |
#record_multiple_choice_answer(identifier, resource, trial, answer) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/openstax/exchange/real_client/real_client.rb', line 43 def record_multiple_choice_answer(identifier, resource, trial, answer) = {} add_accept_header! [:body] = { identifier: identifier, resource: resource, trial: trial, answer: answer }.to_json response = @oauth_token.request( :post, "#{@server_url}/api/events/platforms/multiple_choices", ) return JSON.parse(response.body) end |
#token ⇒ Object
27 28 29 |
# File 'lib/openstax/exchange/real_client/real_client.rb', line 27 def token @oauth_token.token end |