lingutest_client 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 75545303557e78cc13f1aff77d1236a60e96a64450bbe3b028109fa27c9125bb
4
+ data.tar.gz: d4536b69d79b552326ab302d19cca72d4192530c7fb438997e8156ecaa9a00dc
5
+ SHA512:
6
+ metadata.gz: e0c0bb5293aeda8932acc6bb867af5ca4295a0d632d1addb04756de6061150fe72465f14a8356a22b9eb1655f7dd385c56ecdf126c45b7ea8ba265b965e38d45
7
+ data.tar.gz: a251fb5e341b92ddc6b106053fd7cce1eaa6f9c74c03fafa5f5bf438409fbfaec1b48a74d4a4b727d4671ff266f05bcd9558897c6d60ef9e6b7368305c41e873
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.idea/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ Style/Documentation:
2
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.4
@@ -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/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in lingutest_client.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,98 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lingutest_client (0.1.4)
5
+ dry-configurable (~> 0.9.0)
6
+ dry-schema (~> 1.4.3)
7
+ dry-struct (~> 1.2.0)
8
+ dry-types (~> 1.2.2)
9
+ faraday
10
+ faraday_middleware
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ ast (2.4.0)
16
+ concurrent-ruby (1.1.5)
17
+ diff-lcs (1.3)
18
+ dry-configurable (0.9.0)
19
+ concurrent-ruby (~> 1.0)
20
+ dry-core (~> 0.4, >= 0.4.7)
21
+ dry-container (0.7.2)
22
+ concurrent-ruby (~> 1.0)
23
+ dry-configurable (~> 0.1, >= 0.1.3)
24
+ dry-core (0.4.9)
25
+ concurrent-ruby (~> 1.0)
26
+ dry-equalizer (0.3.0)
27
+ dry-inflector (0.2.0)
28
+ dry-initializer (3.0.3)
29
+ dry-logic (1.0.5)
30
+ concurrent-ruby (~> 1.0)
31
+ dry-core (~> 0.2)
32
+ dry-equalizer (~> 0.2)
33
+ dry-schema (1.4.3)
34
+ concurrent-ruby (~> 1.0)
35
+ dry-configurable (~> 0.8, >= 0.8.3)
36
+ dry-core (~> 0.4)
37
+ dry-equalizer (~> 0.2)
38
+ dry-initializer (~> 3.0)
39
+ dry-logic (~> 1.0)
40
+ dry-types (~> 1.2)
41
+ dry-struct (1.2.0)
42
+ dry-core (~> 0.4, >= 0.4.3)
43
+ dry-equalizer (~> 0.3)
44
+ dry-types (~> 1.0)
45
+ ice_nine (~> 0.11)
46
+ dry-types (1.2.2)
47
+ concurrent-ruby (~> 1.0)
48
+ dry-container (~> 0.3)
49
+ dry-core (~> 0.4, >= 0.4.4)
50
+ dry-equalizer (~> 0.3)
51
+ dry-inflector (~> 0.1, >= 0.1.2)
52
+ dry-logic (~> 1.0, >= 1.0.2)
53
+ faraday (0.17.3)
54
+ multipart-post (>= 1.2, < 3)
55
+ faraday_middleware (0.14.0)
56
+ faraday (>= 0.7.4, < 1.0)
57
+ ice_nine (0.11.2)
58
+ jaro_winkler (1.5.4)
59
+ multipart-post (2.1.1)
60
+ parallel (1.19.1)
61
+ parser (2.7.0.2)
62
+ ast (~> 2.4.0)
63
+ rainbow (3.0.0)
64
+ rake (12.3.3)
65
+ rspec (3.9.0)
66
+ rspec-core (~> 3.9.0)
67
+ rspec-expectations (~> 3.9.0)
68
+ rspec-mocks (~> 3.9.0)
69
+ rspec-core (3.9.1)
70
+ rspec-support (~> 3.9.1)
71
+ rspec-expectations (3.9.0)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.9.0)
74
+ rspec-mocks (3.9.1)
75
+ diff-lcs (>= 1.2.0, < 2.0)
76
+ rspec-support (~> 3.9.0)
77
+ rspec-support (3.9.2)
78
+ rubocop (0.79.0)
79
+ jaro_winkler (~> 1.5.1)
80
+ parallel (~> 1.10)
81
+ parser (>= 2.7.0.1)
82
+ rainbow (>= 2.2.2, < 4.0)
83
+ ruby-progressbar (~> 1.7)
84
+ unicode-display_width (>= 1.4.0, < 1.7)
85
+ ruby-progressbar (1.10.1)
86
+ unicode-display_width (1.6.1)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ lingutest_client!
93
+ rake (~> 12.0)
94
+ rspec (~> 3.0)
95
+ rubocop (~> 0.79.0)
96
+
97
+ BUNDLED WITH
98
+ 1.17.3
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # LingutestClient
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/lingutest_client`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'lingutest_client', github: 'AdeptLMS/lingutest_client', branch: :master
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ 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).
28
+
29
+ ## Contributing
30
+
31
+ 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).
32
+
33
+
34
+ ## Code of Conduct
35
+
36
+ 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).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'lingutest_client'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.dirname(__FILE__)
4
+
5
+ module LingutestClient
6
+ autoload :API, 'lingutest_client/api'
7
+ autoload :Base, 'lingutest_client/base'
8
+ autoload :Candidate, 'lingutest_client/candidate'
9
+ autoload :Configuration, 'lingutest_client/configuration'
10
+ autoload :Connection, 'lingutest_client/connection'
11
+ autoload :CandidateList, 'lingutest_client/candidate_list'
12
+ autoload :Exam, 'lingutest_client/exam'
13
+ autoload :ExamList, 'lingutest_client/exam_list'
14
+ autoload :Examination, 'lingutest_client/examination'
15
+ autoload :ExaminationList, 'lingutest_client/examination_list'
16
+ autoload :Types, 'lingutest_client/types'
17
+ autoload :VERSION, 'lingutest_client/version'
18
+
19
+ include Configuration
20
+
21
+ class ValidationError < StandardError; end
22
+
23
+ class Client
24
+ include LingutestClient::Connection
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LingutestClient
4
+ module API
5
+ autoload :Resource, 'lingutest_client/api/resource'
6
+ autoload :Operations, 'lingutest_client/api/operations'
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LingutestClient
4
+ module API
5
+ module Operations
6
+ autoload :Create, 'lingutest_client/api/operations/create'
7
+ autoload :Delete, 'lingutest_client/api/operations/delete'
8
+ autoload :Find, 'lingutest_client/api/operations/find'
9
+ autoload :List, 'lingutest_client/api/operations/list'
10
+ autoload :Update, 'lingutest_client/api/operations/update'
11
+ end
12
+ end
13
+ end
@@ -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) # rubocop:disable Metrics/AbcSize
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,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LingutestClient
4
+ module API
5
+ module Operations
6
+ module List
7
+ class << self
8
+ def module(list_type)
9
+ Module.new do
10
+ class_methods_module = Module.new
11
+ class_methods_module.define_method :list do
12
+ list_type.new(Client.get(resource_url).body)
13
+ end
14
+ define_singleton_method :included do |base|
15
+ base.extend class_methods_module
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ 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) # rubocop:disable Metrics/AbcSize
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,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+ require 'dry-struct'
5
+ require 'dry-schema'
6
+
7
+ module LingutestClient
8
+ class Base < Dry::Struct
9
+ extend Forwardable
10
+
11
+ def_delegator :to_hash, :to_json
12
+
13
+ def to_hash(object = self, type = self.class) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
14
+ type.schema.each_with_object({}) do |key, res|
15
+ name = key.name
16
+ attr = key.type
17
+ if array?(attr)
18
+ values = ::Array.wrap(object.public_send(name))
19
+ res[name] = values.map do |value_item|
20
+ serialize(value_item, attr.member)
21
+ end
22
+ elsif bool?(attr)
23
+ value = object.public_send("#{name}?")
24
+ res[name] = value
25
+ else
26
+ value = object.public_send(name)
27
+ res[name] = serialize(value, attr)
28
+ end
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def serialize(object, type)
35
+ complex?(type) ? to_hash(object, type) : object
36
+ end
37
+
38
+ def complex?(attribute)
39
+ attribute.respond_to?(:<) && attribute < Base
40
+ end
41
+
42
+ def bool?(attribute)
43
+ attribute.primitive?(true)
44
+ end
45
+
46
+ def array?(attribute)
47
+ attribute.primitive?([])
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri/mailto'
4
+
5
+ module LingutestClient
6
+ class Candidate < Base
7
+ CreateSchema = Dry::Schema.Params do
8
+ required(:fname).filled(:string)
9
+ required(:lname).filled(:string)
10
+ required(:email).filled(:string, format?: URI::MailTo::EMAIL_REGEXP)
11
+ optional(:locale).filled(:string)
12
+ optional(:mobile).filled(:string)
13
+ optional(:gender).filled(Types::Gender)
14
+ optional(:ssn).filled(:string, format?: /\A([\d]{10,11}|[\d]{5,6}|^$)\z/i)
15
+ end
16
+ UpdateSchema = Dry::Schema.Params do
17
+ optional(:fname).filled(:string)
18
+ optional(:lname).filled(:string)
19
+ optional(:email).filled(:string, format?: URI::MailTo::EMAIL_REGEXP)
20
+ optional(:locale).filled(:string)
21
+ optional(:mobile).filled(:string)
22
+ optional(:gender).filled(Types::Gender)
23
+ optional(:ssn).filled(:string, format?: /\A([\d]{10,11}|[\d]{5,6}|^$)\z/i)
24
+ end
25
+
26
+ OBJECT_NAME = :candidate
27
+
28
+ include API::Resource
29
+ include API::Operations::List.module(CandidateList)
30
+ include API::Operations::Create
31
+ include API::Operations::Find
32
+ include API::Operations::Delete
33
+ include API::Operations::Update
34
+
35
+ attribute :id, Types::Coercible::Integer.default(0)
36
+ attribute :email, Types::Coercible::String.default('')
37
+ attribute :fname, Types::Coercible::String.default('')
38
+ attribute :lname, Types::Coercible::String.default('')
39
+ attribute :mobile, Types::Coercible::String.default('')
40
+ attribute :locale, Types::Coercible::String.default('')
41
+ attribute :ssn, Types::Coercible::String.default('')
42
+ attribute :gender,
43
+ Types::String.optional.enum('unknown', 'male', 'female')
44
+ end
45
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LingutestClient
4
+ class CandidateList < Base
5
+ include Enumerable
6
+ delegate %i[each size last] => :candidates
7
+
8
+ attribute :candidates, Types::Array.of(Candidate)
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-configurable'
4
+
5
+ module LingutestClient
6
+ module Configuration
7
+ def self.included(base)
8
+ base.extend Dry::Configurable
9
+ base.class_eval do
10
+ setting(:api_base,
11
+ 'https://test.lingu.com/api/v1/',
12
+ reader: true) do |value|
13
+ URI.parse(value)
14
+ end
15
+ setting(:api_key, reader: true, &:to_s)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
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,15 @@
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
+ attribute :id, Types::Coercible::Integer.optional.default(0)
11
+ attribute :name, Types::Coercible::String.optional.default('')
12
+ attribute :description, Types::Coercible::String.optional.default('')
13
+ attribute :updated_at, Types::DateTime.optional.default(nil)
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LingutestClient
4
+ class ExamList < Base
5
+ include Enumerable
6
+ delegate %i[each size last] => :exams
7
+
8
+ attribute :exams, Types::Array.of(Exam)
9
+ end
10
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LingutestClient
4
+ class Examination < Base
5
+ CreateSchema = Dry::Schema.Params do
6
+ required(:exam_id).filled(Types::Coercible::Integer)
7
+ required(:candidate_id).filled(Types::Coercible::Integer)
8
+ required(:expires_at).filled(Types::DateTime)
9
+ optional(:redirect_url).filled(:string, format?: %r{\Ahttps?://.+\z}i)
10
+ end
11
+
12
+ OBJECT_NAME = :examination
13
+
14
+ include API::Resource
15
+ include API::Operations::List.module(ExaminationList)
16
+ include API::Operations::Create
17
+ include API::Operations::Find
18
+
19
+ attribute :id, Types::Integer.optional
20
+ attribute :exam, Exam.optional.default(nil)
21
+ attribute :candidate, Candidate.optional.default(nil)
22
+ attribute :total_score, Types::Integer.optional.default(0)
23
+ attribute :total_time_spent, Types::Integer.optional.default(0)
24
+ attribute :code, Types::String.optional.default('')
25
+ attribute :redirect_url, Types::String.optional
26
+
27
+ attribute :status, Types::Integer.optional.default(0).enum(
28
+ 0 => 'pending',
29
+ 1 => 'in_progress',
30
+ 2 => 'completed',
31
+ 3 => 'pending_review',
32
+ 4 => 'reviewed'
33
+ )
34
+
35
+ attribute :expires_at, Types::Time.optional.default(nil)
36
+ attribute :created_at, Types::Time.optional.default(nil)
37
+ attribute :updated_at, Types::Time.optional.default(nil)
38
+
39
+ def url
40
+ URI.join(LingutestClient.config.api_base.to_s, "/#{code}").to_s
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LingutestClient
4
+ class ExaminationList < Base
5
+ include Enumerable
6
+ delegate %i[each size last] => :examinations
7
+
8
+ attribute :examinations, Types::Array.of(Examination)
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-types'
4
+
5
+ module LingutestClient
6
+ module Types
7
+ include Dry.Types()
8
+
9
+ DateTime = Strict::Date | JSON::Date | Strict::Time
10
+ Time = Strict::Time | Types::JSON::Time
11
+ Gender = Types::String.enum('unknown', 'male', 'female')
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module LingutestClient
2
+ VERSION = '0.1.4'
3
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './lib/lingutest_client/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'lingutest_client'
7
+ spec.version = LingutestClient::VERSION
8
+ spec.authors = ['Anatolii Didukh']
9
+ spec.email = ['railsme7@gmail.com']
10
+
11
+ spec.summary = 'Write a short summary, because RubyGems requires one.'
12
+ spec.description = 'Write a longer description or delete this line.'
13
+ # spec.homepage = "Put your gem's website or public repo URL here."
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
15
+
16
+ # spec.metadata['allowed_push_host'] = "Set to 'http://mygemserver.com'"
17
+
18
+ # spec.metadata["homepage_uri"] = spec.homepage
19
+ # spec.metadata["source_code_uri"] = "Put your gem's public repo URL here."
20
+ # spec.metadata["changelog_uri"] = "Put your gem's CHANGELOG.md URL here."
21
+
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`
24
+ .split("\x0")
25
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+ spec.add_dependency 'dry-configurable', '~> 0.9.0'
31
+ spec.add_dependency 'dry-schema', '~> 1.4.3'
32
+ spec.add_dependency 'dry-struct', '~> 1.2.0'
33
+ spec.add_dependency 'dry-types', '~> 1.2.2'
34
+
35
+ spec.add_dependency 'faraday'
36
+ spec.add_dependency 'faraday_middleware'
37
+ spec.add_development_dependency 'rubocop', '~> 0.79.0'
38
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lingutest_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Anatolii Didukh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-configurable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-schema
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.4.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-struct
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: dry-types
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '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: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.79.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.79.0
111
+ description: Write a longer description or delete this line.
112
+ email:
113
+ - railsme7@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".rubocop.yml"
121
+ - ".travis.yml"
122
+ - CODE_OF_CONDUCT.md
123
+ - Gemfile
124
+ - Gemfile.lock
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - lib/lingutest_client.rb
130
+ - lib/lingutest_client/api.rb
131
+ - lib/lingutest_client/api/operations.rb
132
+ - lib/lingutest_client/api/operations/create.rb
133
+ - lib/lingutest_client/api/operations/delete.rb
134
+ - lib/lingutest_client/api/operations/find.rb
135
+ - lib/lingutest_client/api/operations/list.rb
136
+ - lib/lingutest_client/api/operations/update.rb
137
+ - lib/lingutest_client/api/resource.rb
138
+ - lib/lingutest_client/base.rb
139
+ - lib/lingutest_client/candidate.rb
140
+ - lib/lingutest_client/candidate_list.rb
141
+ - lib/lingutest_client/configuration.rb
142
+ - lib/lingutest_client/connection.rb
143
+ - lib/lingutest_client/exam.rb
144
+ - lib/lingutest_client/exam_list.rb
145
+ - lib/lingutest_client/examination.rb
146
+ - lib/lingutest_client/examination_list.rb
147
+ - lib/lingutest_client/types.rb
148
+ - lib/lingutest_client/version.rb
149
+ - lingutest_client.gemspec
150
+ homepage:
151
+ licenses: []
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: 2.3.0
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubygems_version: 3.1.2
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Write a short summary, because RubyGems requires one.
172
+ test_files: []