netology-tasks_client 0.1.0 → 0.2.0
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/lib/netology_group/tasks_client.rb +3 -1
- data/lib/netology_group/tasks_client/client.rb +2 -2
- data/lib/netology_group/tasks_client/response.rb +1 -2
- data/lib/netology_group/tasks_client/task_response.rb +38 -0
- data/lib/netology_group/tasks_client/version.rb +1 -1
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 0cf94c9d49cfdf80e9eafc346fb01965e781c0e555e46bb0608b2854b59f6ec0
         | 
| 4 | 
            +
              data.tar.gz: a5ad538d0bbe04b0b46a70dbf3ac08e6cad79e03d95ffca6d6d13dac8350a437
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 1651ba2a09636a795a7542f1f6b5ee6b723e678073698adc76f891b5b388d699ae26253ab9bc56d9db8aa88d2b41f3d9734fec047f5de10c21810e7305ff9d74
         | 
| 7 | 
            +
              data.tar.gz: a74288b67627b20a11fede51b434d4a7f2942871c7b5b258f5dd36b7738ff13d5ece7aec1ee196ab3b872957d5f0372c95c5e45f887a189ef4dfbfa23b57e99a
         | 
| @@ -2,6 +2,7 @@ require 'netology_group/tasks_client/version' | |
| 2 2 | 
             
            require 'netology_group/tasks_client/config'
         | 
| 3 3 | 
             
            require 'netology_group/tasks_client/error'
         | 
| 4 4 | 
             
            require 'netology_group/tasks_client/response'
         | 
| 5 | 
            +
            require 'netology_group/tasks_client/task_response'
         | 
| 5 6 | 
             
            require 'netology_group/tasks_client/client'
         | 
| 6 7 |  | 
| 7 8 | 
             
            module NetologyGroup
         | 
| @@ -39,7 +40,8 @@ module NetologyGroup | |
| 39 40 | 
             
                  def find_task(task_id, options = {})
         | 
| 40 41 | 
             
                    params = {
         | 
| 41 42 | 
             
                      method: :get,
         | 
| 42 | 
            -
                      path: "/tasks/#{task_id}"
         | 
| 43 | 
            +
                      path: "/tasks/#{task_id}",
         | 
| 44 | 
            +
                      response_class: TaskResponse
         | 
| 43 45 | 
             
                    }
         | 
| 44 46 | 
             
                    client.request(params.merge(options))
         | 
| 45 47 | 
             
                  end
         | 
| @@ -5,7 +5,7 @@ module NetologyGroup | |
| 5 5 | 
             
                  end
         | 
| 6 6 |  | 
| 7 7 | 
             
                  # @return [Hash]
         | 
| 8 | 
            -
                  def request(method:, path:, body: nil, api_version: nil, query: nil, expects: [200, 201, 422])
         | 
| 8 | 
            +
                  def request(method:, path:, body: nil, api_version: nil, query: nil, response_class: Response, expects: [200, 201, 422])
         | 
| 9 9 | 
             
                    response =
         | 
| 10 10 | 
             
                      connection.request(
         | 
| 11 11 | 
             
                        method: method,
         | 
| @@ -14,7 +14,7 @@ module NetologyGroup | |
| 14 14 | 
             
                        query: query,
         | 
| 15 15 | 
             
                        expects: expects
         | 
| 16 16 | 
             
                      )
         | 
| 17 | 
            -
                     | 
| 17 | 
            +
                    response_class.new(response)
         | 
| 18 18 | 
             
                    # rescue Excon::Error
         | 
| 19 19 | 
             
                    #   raise Error
         | 
| 20 20 | 
             
                  end
         | 
| @@ -4,9 +4,8 @@ module NetologyGroup | |
| 4 4 | 
             
              module TasksClient
         | 
| 5 5 | 
             
                class Response
         | 
| 6 6 | 
             
                  attr_reader :excon_response, :status, :body
         | 
| 7 | 
            -
                  attr_reader :next_page_url, :previous_page_url
         | 
| 8 7 |  | 
| 9 | 
            -
                  # @param [Excon::Response]  | 
| 8 | 
            +
                  # @param [Excon::Response] excon_response
         | 
| 10 9 | 
             
                  def initialize(excon_response)
         | 
| 11 10 | 
             
                    @excon_response = excon_response
         | 
| 12 11 | 
             
                    @status = excon_response.status
         | 
| @@ -0,0 +1,38 @@ | |
| 1 | 
            +
            module NetologyGroup
         | 
| 2 | 
            +
              module TasksClient
         | 
| 3 | 
            +
                class TaskResponse < Response
         | 
| 4 | 
            +
                  attr_reader :original_body
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def initialize(_)
         | 
| 7 | 
            +
                    super
         | 
| 8 | 
            +
                    @original_body = body.deep_dup
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  # Скрыть правильные ответы и подсказки
         | 
| 12 | 
            +
                  def secure_answers
         | 
| 13 | 
            +
                    delete_correct_answers
         | 
| 14 | 
            +
                    set_hints_limit(0)
         | 
| 15 | 
            +
                    self
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  def hints_limit(limit)
         | 
| 19 | 
            +
                    set_hints_limit(limit)
         | 
| 20 | 
            +
                    self
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  private
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  def delete_correct_answers
         | 
| 26 | 
            +
                    body['questions'].each do |question|
         | 
| 27 | 
            +
                      question['answers'].each.with_index do |_, index|
         | 
| 28 | 
            +
                        question['answers'][index].delete('correct')
         | 
| 29 | 
            +
                      end
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  def set_hints_limit(limit)
         | 
| 34 | 
            +
                    body['hints'] = original_body['hints']&.take(limit)
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: netology-tasks_client
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Andrey Skuryatin
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2018-05- | 
| 11 | 
            +
            date: 2018-05-21 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: concurrent-ruby
         | 
| @@ -115,6 +115,7 @@ files: | |
| 115 115 | 
             
            - lib/netology_group/tasks_client/config.rb
         | 
| 116 116 | 
             
            - lib/netology_group/tasks_client/error.rb
         | 
| 117 117 | 
             
            - lib/netology_group/tasks_client/response.rb
         | 
| 118 | 
            +
            - lib/netology_group/tasks_client/task_response.rb
         | 
| 118 119 | 
             
            - lib/netology_group/tasks_client/version.rb
         | 
| 119 120 | 
             
            - netology-tasks_client.gemspec
         | 
| 120 121 | 
             
            homepage: https://netology-group.ru
         |