lingutest_client 0.2.7 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/README.md +57 -0
- data/lib/lingutest_client/api/operations/create.rb +28 -0
- data/lib/lingutest_client/api/operations/delete.rb +32 -0
- data/lib/lingutest_client/api/operations/find.rb +26 -0
- data/lib/lingutest_client/api/operations/list.rb +44 -0
- data/lib/lingutest_client/api/operations/update.rb +42 -0
- data/lib/lingutest_client/api/resource.rb +19 -0
- data/lib/lingutest_client/base.rb +46 -0
- data/lib/lingutest_client/candidate.rb +50 -0
- data/lib/lingutest_client/candidate_list.rb +10 -0
- data/lib/lingutest_client/client.rb +7 -0
- data/lib/lingutest_client/connection.rb +43 -0
- data/lib/lingutest_client/exam.rb +27 -0
- data/lib/lingutest_client/exam_list.rb +10 -0
- data/lib/lingutest_client/examination.rb +84 -0
- data/lib/lingutest_client/examination_list.rb +17 -0
- data/lib/lingutest_client/types.rb +17 -0
- data/lib/lingutest_client/validation_error.rb +6 -0
- data/lib/lingutest_client/version.rb +5 -0
- data/lib/lingutest_client.rb +25 -0
- metadata +27 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa427fd6672aba7265e90baca7b8ef3bb4b02a4d99792492f382dba1f8862835
|
4
|
+
data.tar.gz: d32e97f7336d6afb72a73041e830eaf4b8f3bea2560cd21c5c1a1484ab9eea2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4863da3deb7d87511ca69572e28c664e9731501319d206f7e91b84f397cddc13212cfbdf41af71e2f65a948e8f98c9f4b7c5f41f3eed48304ae31a25c244ed37
|
7
|
+
data.tar.gz: 9a7db9e9e754d263626f26952620b653abc3930dae2dd051187a680db5e52d440a4b4a406167e4098efc30829ae2c7c1fff56640889e4d184e41e2dacdffdb20
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at railsme7@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# LingutestClient
|
2
|
+
|
3
|
+
This library will allow you to communicate with Lingu Test API. You can create examinations for client, and receive examination results. You need API token from Lingu Test to use this gem. Check [documentation](https://test.lingu.com/documentation) for API calls.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'lingutest_client'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle install
|
17
|
+
|
18
|
+
## Configuration
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
# config/initializers/lingutest_client.rb
|
22
|
+
|
23
|
+
LingutestClient.configure do |config|
|
24
|
+
config.api_base = 'https://test.lingu.com/api/v1/'
|
25
|
+
config.api_key = 'yourLinguTestApiKey'
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
LingutestClient::Exam.list
|
33
|
+
|
34
|
+
LingutestClient::Candidate.list
|
35
|
+
LingutestClient::Candidate.find(id)
|
36
|
+
LingutestClient::Candidate.create(fname:, lname:, email:, ssn:, gender:, mobile:)
|
37
|
+
LingutestClient::Candidate.update(fname:, lname:, email:, ssn:, gender:, mobile:)
|
38
|
+
|
39
|
+
LingutestClient::Examination.list
|
40
|
+
LingutestClient::Examination.find(id)
|
41
|
+
LingutestClient::Examination.create(candidate_id:, exam_id:, expires_at:)
|
42
|
+
```
|
43
|
+
|
44
|
+
## Development
|
45
|
+
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
47
|
+
|
48
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/AdeptLMS/lingutest_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/AdeptLMS/lingutest_client/blob/master/CODE_OF_CONDUCT.md).
|
53
|
+
|
54
|
+
|
55
|
+
## Code of Conduct
|
56
|
+
|
57
|
+
Everyone interacting in the LingutestClient project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/AdeptLMS/lingutest_client/blob/master/CODE_OF_CONDUCT.md).
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LingutestClient
|
4
|
+
module Api
|
5
|
+
module Operations
|
6
|
+
module Create
|
7
|
+
module ClassMethods
|
8
|
+
def create(**params)
|
9
|
+
schema = const_get(:CreateSchema).call(params)
|
10
|
+
unless schema.success?
|
11
|
+
raise ValidationError,
|
12
|
+
schema.errors.to_h.to_a.first.flatten.join(' ')
|
13
|
+
end
|
14
|
+
|
15
|
+
response = Client.post(
|
16
|
+
resource_url, self::OBJECT_NAME => schema.to_h
|
17
|
+
)
|
18
|
+
new(response.body[self::OBJECT_NAME])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.included(base)
|
23
|
+
base.extend ClassMethods
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LingutestClient
|
4
|
+
module Api
|
5
|
+
module Operations
|
6
|
+
module Delete
|
7
|
+
module ClassMethods
|
8
|
+
def delete(id)
|
9
|
+
Client.delete(member_resource_url(id)).body && nil
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def member_resource_url(id)
|
15
|
+
"#{resource_url}/#{id}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module InstanceMethods
|
20
|
+
def delete
|
21
|
+
self.class.delete(id)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.included(base)
|
26
|
+
base.extend ClassMethods
|
27
|
+
base.send(:include, InstanceMethods)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LingutestClient
|
4
|
+
module Api
|
5
|
+
module Operations
|
6
|
+
module Find
|
7
|
+
module ClassMethods
|
8
|
+
def find(id)
|
9
|
+
new(Client.get("#{resource_url}/#{id}").body[self::OBJECT_NAME])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module InstanceMethods
|
14
|
+
def reload
|
15
|
+
self.class.find(id)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.included(base)
|
20
|
+
base.extend ClassMethods
|
21
|
+
base.send(:include, InstanceMethods)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LingutestClient
|
4
|
+
module Api
|
5
|
+
module Operations
|
6
|
+
module List
|
7
|
+
DELEGATED_METHODS = %i[
|
8
|
+
each
|
9
|
+
empty?
|
10
|
+
find
|
11
|
+
first
|
12
|
+
last
|
13
|
+
map
|
14
|
+
reject
|
15
|
+
select
|
16
|
+
size
|
17
|
+
].freeze
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def module(list_type, params_schema = nil) # rubocop:disable Metrics/MethodLength
|
21
|
+
Module.new do
|
22
|
+
class_methods_module = Module.new
|
23
|
+
|
24
|
+
class_methods_module.define_method :list do |**options|
|
25
|
+
params = options.dup
|
26
|
+
if params_schema
|
27
|
+
result = params_schema.call(options)
|
28
|
+
raise ArgumentError, result.errors if result.failure?
|
29
|
+
|
30
|
+
params = result.to_h
|
31
|
+
end
|
32
|
+
list_type.new(Client.get(resource_url, **params).body)
|
33
|
+
end
|
34
|
+
|
35
|
+
define_singleton_method :included do |base|
|
36
|
+
base.extend class_methods_module
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LingutestClient
|
4
|
+
module Api
|
5
|
+
module Operations
|
6
|
+
module Update
|
7
|
+
module ClassMethods
|
8
|
+
def update(id, **params)
|
9
|
+
schema = const_get(:UpdateSchema).call(params)
|
10
|
+
unless schema.success?
|
11
|
+
raise ValidationError,
|
12
|
+
schema.errors.to_h.to_a.first.flatten.join(' ')
|
13
|
+
end
|
14
|
+
|
15
|
+
new(
|
16
|
+
Client.put(
|
17
|
+
member_resource_url(id), self::OBJECT_NAME => schema.to_h
|
18
|
+
).body[self::OBJECT_NAME]
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def member_resource_url(id)
|
25
|
+
"#{resource_url}/#{id}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module InstanceMethods
|
30
|
+
def update(**params)
|
31
|
+
self.class.update(id, params)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.included(base)
|
36
|
+
base.extend ClassMethods
|
37
|
+
base.send(:include, InstanceMethods)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module LingutestClient
|
6
|
+
module Api
|
7
|
+
module Resource
|
8
|
+
module ClassMethods
|
9
|
+
def resource_url
|
10
|
+
"/api/v1/#{self::OBJECT_NAME.to_s.downcase.tr('.', '/')}s"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.included(base)
|
15
|
+
base.extend ClassMethods
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LingutestClient
|
4
|
+
class Base < Dry::Struct
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def_delegator :to_hash, :to_json
|
8
|
+
|
9
|
+
def to_hash(object = self, type = self.class) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
10
|
+
type.schema.each_with_object({}) do |key, res|
|
11
|
+
name = key.name
|
12
|
+
attr = key.type
|
13
|
+
if array?(attr)
|
14
|
+
values = ::Array.wrap(object.public_send(name))
|
15
|
+
res[name] = values.map do |value_item|
|
16
|
+
serialize(value_item, attr.member)
|
17
|
+
end
|
18
|
+
elsif bool?(attr)
|
19
|
+
value = object.public_send("#{name}?")
|
20
|
+
res[name] = value
|
21
|
+
else
|
22
|
+
value = object.public_send(name)
|
23
|
+
res[name] = serialize(value, attr)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def serialize(object, type)
|
31
|
+
complex?(type) ? to_hash(object, type) : object
|
32
|
+
end
|
33
|
+
|
34
|
+
def complex?(attribute)
|
35
|
+
attribute.respond_to?(:<) && attribute < Base
|
36
|
+
end
|
37
|
+
|
38
|
+
def bool?(attribute)
|
39
|
+
attribute.primitive?(true)
|
40
|
+
end
|
41
|
+
|
42
|
+
def array?(attribute)
|
43
|
+
attribute.primitive?([])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LingutestClient
|
4
|
+
class Candidate < Base
|
5
|
+
CreateSchema = Dry::Schema.Params do
|
6
|
+
required(:fname).filled(:string)
|
7
|
+
required(:lname).filled(:string)
|
8
|
+
required(:email).filled(Types::Email)
|
9
|
+
optional(:locale).filled(:string)
|
10
|
+
optional(:mobile).filled(:string)
|
11
|
+
optional(:gender).filled(Types::Gender)
|
12
|
+
optional(:ssn).filled(Types::Ssn)
|
13
|
+
end
|
14
|
+
UpdateSchema = Dry::Schema.Params do
|
15
|
+
optional(:fname).filled(:string)
|
16
|
+
optional(:lname).filled(:string)
|
17
|
+
optional(:email).filled(Types::Email)
|
18
|
+
optional(:locale).filled(:string)
|
19
|
+
optional(:mobile).filled(:string)
|
20
|
+
optional(:gender).filled(Types::Gender)
|
21
|
+
optional(:ssn).filled(Types::Ssn)
|
22
|
+
end
|
23
|
+
|
24
|
+
FilterSchema = Dry::Schema.Params do
|
25
|
+
optional(:page)
|
26
|
+
optional(:per_page)
|
27
|
+
optional(:email_eq).filled(Types::Email)
|
28
|
+
optional(:fname_eq).filled(:string)
|
29
|
+
optional(:lname_eq).filled(:string)
|
30
|
+
end
|
31
|
+
|
32
|
+
OBJECT_NAME = :candidate
|
33
|
+
|
34
|
+
include Api::Resource
|
35
|
+
include Api::Operations::List.module(CandidateList, FilterSchema)
|
36
|
+
include Api::Operations::Create
|
37
|
+
include Api::Operations::Find
|
38
|
+
include Api::Operations::Delete
|
39
|
+
include Api::Operations::Update
|
40
|
+
|
41
|
+
attribute :id, Types::Coercible::Integer.default(0)
|
42
|
+
attribute :email, Types::Coercible::String.default('')
|
43
|
+
attribute :fname, Types::Coercible::String.default('')
|
44
|
+
attribute :lname, Types::Coercible::String.default('')
|
45
|
+
attribute :mobile, Types::Coercible::String.default('')
|
46
|
+
attribute :locale, Types::Coercible::String.default('')
|
47
|
+
attribute :ssn, Types::Coercible::String.default('')
|
48
|
+
attribute :gender, Types::Gender
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
|
5
|
+
module LingutestClient
|
6
|
+
module Connection
|
7
|
+
module ClassMethods
|
8
|
+
def client
|
9
|
+
Thread.current[:lingutest_client] ||= connection
|
10
|
+
end
|
11
|
+
|
12
|
+
def connection # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
13
|
+
Thread.current[:lingutest_default_connection] ||=
|
14
|
+
Faraday.new(url: LingutestClient.config.api_base) do |c|
|
15
|
+
c.request :json
|
16
|
+
c.response :raise_error
|
17
|
+
c.response :json,
|
18
|
+
content_type: /\bjson$/,
|
19
|
+
parser_options: { symbolize_names: true }
|
20
|
+
c.headers['X-Api-Token'] =
|
21
|
+
format('Token token="%<key>s"',
|
22
|
+
key: LingutestClient.config.api_key)
|
23
|
+
c.headers[:user_agent] = 'Lingutest Ruby Client'
|
24
|
+
c.headers['Content-Type'] = 'application/json'
|
25
|
+
c.headers['Accept'] = 'application/json'
|
26
|
+
c.adapter Faraday.default_adapter
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.included(base)
|
32
|
+
base.extend ClassMethods
|
33
|
+
base.extend Forwardable
|
34
|
+
base.class_eval do
|
35
|
+
def_delegators :connection, :get, :post, :delete, :put, :patch
|
36
|
+
end
|
37
|
+
base.singleton_class.extend Forwardable
|
38
|
+
base.singleton_class.class_eval do
|
39
|
+
def_delegators :client, :get, :post, :delete, :put, :patch
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LingutestClient
|
4
|
+
class Exam < Base
|
5
|
+
OBJECT_NAME = :exam
|
6
|
+
|
7
|
+
include Api::Resource
|
8
|
+
include Api::Operations::List.module(ExamList)
|
9
|
+
|
10
|
+
FilterSchema = Dry::Schema.Params do
|
11
|
+
config.validate_keys = true
|
12
|
+
optional(:page).filled(Types::Coercible::Integer)
|
13
|
+
optional(:per_page).filled(Types::Coercible::Integer)
|
14
|
+
|
15
|
+
optional(:locale_eq).filled(Types::Coercible::String)
|
16
|
+
optional(:price_gt).filled(Types::Coercible::Integer)
|
17
|
+
end
|
18
|
+
|
19
|
+
attribute :id, Types::Coercible::Integer.optional.default(0)
|
20
|
+
attribute :name, Types::Coercible::String.optional.default('')
|
21
|
+
attribute :locale, Types::Coercible::String.optional.default('')
|
22
|
+
attribute :description, Types::Coercible::String.optional.default('')
|
23
|
+
attribute :price, Types::Coercible::Decimal.optional.default(0)
|
24
|
+
attribute :updated_at, Types::DateTime.optional.default(nil)
|
25
|
+
attribute :created_at, Types::DateTime.optional.default(nil)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LingutestClient
|
4
|
+
class Examination < Base
|
5
|
+
OBJECT_NAME = :examination
|
6
|
+
|
7
|
+
STATUSES = %w[
|
8
|
+
pending
|
9
|
+
in_progress
|
10
|
+
completed
|
11
|
+
pending_review
|
12
|
+
reviewed
|
13
|
+
].freeze
|
14
|
+
|
15
|
+
CreateSchema = Dry::Schema.Params do
|
16
|
+
required(:exam_id).filled(Types::Coercible::Integer)
|
17
|
+
required(:candidate_id).filled(Types::Coercible::Integer)
|
18
|
+
required(:expires_at).filled(Types::DateTime)
|
19
|
+
optional(:redirect_url).filled(Types::Url)
|
20
|
+
|
21
|
+
optional(:team_id).filled(Types::Coercible::String)
|
22
|
+
optional(:team_group_id).filled(Types::Coercible::String)
|
23
|
+
optional(:student_id).filled(Types::Coercible::String)
|
24
|
+
end
|
25
|
+
|
26
|
+
FilterSchema = Dry::Schema.Params do
|
27
|
+
config.validate_keys = true
|
28
|
+
optional(:page).filled(Types::Coercible::Integer)
|
29
|
+
optional(:per_page).filled(Types::Coercible::Integer)
|
30
|
+
|
31
|
+
optional(:team_id_eq).filled(Types::Coercible::String)
|
32
|
+
optional(:team_group_id_eq).filled(Types::Coercible::String)
|
33
|
+
optional(:student_id_eq).filled(Types::Coercible::String)
|
34
|
+
|
35
|
+
optional(:price_gteq).filled(Types::Coercible::Integer)
|
36
|
+
optional(:created_at_gteq).filled(Types::DateTime)
|
37
|
+
optional(:created_at_lteq).filled(Types::DateTime)
|
38
|
+
optional(:completed_at_gteq).filled(Types::DateTime)
|
39
|
+
optional(:completed_at_lteq).filled(Types::DateTime)
|
40
|
+
optional(:status_eq).filled(Types::Coercible::String)
|
41
|
+
end
|
42
|
+
|
43
|
+
include Api::Resource
|
44
|
+
include Api::Operations::List.module(ExaminationList, FilterSchema)
|
45
|
+
include Api::Operations::Create
|
46
|
+
include Api::Operations::Find
|
47
|
+
|
48
|
+
attribute :id, Types::Integer.optional
|
49
|
+
attribute :exam, Exam.optional.default(nil)
|
50
|
+
attribute :candidate, Candidate.optional.default(nil)
|
51
|
+
attribute :total_score, Types::Integer.optional.default(0)
|
52
|
+
attribute :max_score, Types::Integer.optional.default(0)
|
53
|
+
attribute :tasks_limit, Types::Integer.optional.default(0)
|
54
|
+
attribute :total_time_spent, Types::Integer.optional.default(0)
|
55
|
+
attribute :code, Types::String.optional.default('')
|
56
|
+
attribute :redirect_url, Types::String.optional
|
57
|
+
attribute :price, Types::Coercible::Decimal.optional.default(0)
|
58
|
+
|
59
|
+
attribute :team_id, Types::String.optional.default(nil)
|
60
|
+
attribute :team_group_id, Types::String.optional.default(nil)
|
61
|
+
attribute :student_id, Types::String.optional.default(nil)
|
62
|
+
|
63
|
+
attribute :status, Types::String.optional.enum(*STATUSES)
|
64
|
+
|
65
|
+
attribute :expires_at, Types::Time.optional.default(nil)
|
66
|
+
attribute :created_at, Types::Time.optional.default(nil)
|
67
|
+
attribute :completed_at, Types::Time.optional.default(nil)
|
68
|
+
attribute :updated_at, Types::Time.optional.default(nil)
|
69
|
+
|
70
|
+
def url
|
71
|
+
URI.join(LingutestClient.config.api_base.to_s, "/#{code}").to_s
|
72
|
+
end
|
73
|
+
|
74
|
+
def result_url
|
75
|
+
URI.join(LingutestClient.config.api_base.to_s, "/examinations/#{code}").to_s
|
76
|
+
end
|
77
|
+
|
78
|
+
STATUSES.each do |status|
|
79
|
+
define_method "#{status}?" do
|
80
|
+
self.status == status
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LingutestClient
|
4
|
+
class ExaminationList < Base
|
5
|
+
include Enumerable
|
6
|
+
delegate ::LingutestClient::Api::Operations::List::DELEGATED_METHODS => :examinations
|
7
|
+
|
8
|
+
attribute :examinations, Types::Array.of(Examination)
|
9
|
+
|
10
|
+
attribute :limit_value, Types::Coercible::Integer
|
11
|
+
attribute :current_page, Types::Coercible::Integer
|
12
|
+
attribute :total_pages, Types::Coercible::Integer
|
13
|
+
attribute :total_count, Types::Coercible::Integer
|
14
|
+
attribute :per_page, Types::Coercible::Integer
|
15
|
+
attribute :page, Types::Coercible::Integer
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-types'
|
4
|
+
require 'uri/mailto'
|
5
|
+
|
6
|
+
module LingutestClient
|
7
|
+
module Types
|
8
|
+
include Dry.Types()
|
9
|
+
|
10
|
+
DateTime = Strict::Date | JSON::Date | Strict::Time
|
11
|
+
Time = Strict::Time | Types::JSON::Time
|
12
|
+
Gender = Types::String.enum('unknown', 'male', 'female')
|
13
|
+
Email = Types::String.constrained(format: URI::MailTo::EMAIL_REGEXP)
|
14
|
+
Ssn = Types::String.constrained(format: /\A(\d{10,11}|\d{5,6}|^$)\z/i)
|
15
|
+
Url = Types::String.constrained(format: %r{\Ahttps?://.+\z}i)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
4
|
+
require 'uri'
|
5
|
+
require 'dry-configurable'
|
6
|
+
require 'dry-schema'
|
7
|
+
require 'dry-struct'
|
8
|
+
require 'dry-types'
|
9
|
+
require 'forwardable'
|
10
|
+
require 'zeitwerk'
|
11
|
+
|
12
|
+
Zeitwerk::Loader.for_gem.setup
|
13
|
+
|
14
|
+
module LingutestClient
|
15
|
+
extend Dry::Configurable
|
16
|
+
|
17
|
+
setting :api_base,
|
18
|
+
default: 'https://test.lingu.com/api/v1/',
|
19
|
+
constructor: proc { |value| URI.parse(value) },
|
20
|
+
reader: true
|
21
|
+
|
22
|
+
setting :api_key,
|
23
|
+
constructor: proc { |value| value.to_s },
|
24
|
+
reader: true
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lingutest_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anatolii Didukh
|
@@ -72,28 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 1.10.0
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: faraday_middleware
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 1.2.0
|
75
|
+
version: '2.9'
|
90
76
|
type: :runtime
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
82
|
+
version: '2.9'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: zeitwerk
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,7 +106,29 @@ email:
|
|
120
106
|
executables: []
|
121
107
|
extensions: []
|
122
108
|
extra_rdoc_files: []
|
123
|
-
files:
|
109
|
+
files:
|
110
|
+
- CHANGELOG.md
|
111
|
+
- CODE_OF_CONDUCT.md
|
112
|
+
- README.md
|
113
|
+
- lib/lingutest_client.rb
|
114
|
+
- lib/lingutest_client/api/operations/create.rb
|
115
|
+
- lib/lingutest_client/api/operations/delete.rb
|
116
|
+
- lib/lingutest_client/api/operations/find.rb
|
117
|
+
- lib/lingutest_client/api/operations/list.rb
|
118
|
+
- lib/lingutest_client/api/operations/update.rb
|
119
|
+
- lib/lingutest_client/api/resource.rb
|
120
|
+
- lib/lingutest_client/base.rb
|
121
|
+
- lib/lingutest_client/candidate.rb
|
122
|
+
- lib/lingutest_client/candidate_list.rb
|
123
|
+
- lib/lingutest_client/client.rb
|
124
|
+
- lib/lingutest_client/connection.rb
|
125
|
+
- lib/lingutest_client/exam.rb
|
126
|
+
- lib/lingutest_client/exam_list.rb
|
127
|
+
- lib/lingutest_client/examination.rb
|
128
|
+
- lib/lingutest_client/examination_list.rb
|
129
|
+
- lib/lingutest_client/types.rb
|
130
|
+
- lib/lingutest_client/validation_error.rb
|
131
|
+
- lib/lingutest_client/version.rb
|
124
132
|
homepage: https://github.com/AdeptLMS/lingutest_client
|
125
133
|
licenses: []
|
126
134
|
metadata:
|
@@ -135,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
143
|
requirements:
|
136
144
|
- - ">="
|
137
145
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
146
|
+
version: 3.0.0
|
139
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
148
|
requirements:
|
141
149
|
- - ">="
|