toptranslation_api 2.3.0 → 2.4.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/toptranslation/client.rb +8 -0
 - data/lib/toptranslation/connection.rb +18 -16
 - data/lib/toptranslation/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 28238cfa869293329560fd7c6c0830b828fe409a8135fe018951ef48c0b54fbd
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8b803d37c0a170b10fdc427afc7da23902e876d2af07e47270de9e755995dc37
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 9e2702875480b453b4647e23068001e6b009fdbe609861c89d15b6ea36892be6b32302184db5a575f3db25385d99bb93ea32d44f667d16a27d3cc4f8bf70bfc2
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: db9565bbfd58e063f5826aa5f3639577ab596526b4181ea59a64496824d6b8665e867e75f1c3a51c65164592eceaa668e1bb0fa386db6cd50ce1c99355fa27b1
         
     | 
| 
         @@ -19,5 +19,13 @@ module Toptranslation 
     | 
|
| 
       19 
19 
     | 
    
         
             
                def locales(options = {})
         
     | 
| 
       20 
20 
     | 
    
         
             
                  @locale_list ||= Resource::LocaleList.new(@connection, options)
         
     | 
| 
       21 
21 
     | 
    
         
             
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                def sign_in!(options)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @connection.sign_in!(options)
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                def access_token=(token)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  @connection.access_token = token
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
       22 
30 
     | 
    
         
             
              end
         
     | 
| 
       23 
31 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,12 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Toptranslation
         
     | 
| 
       2 
2 
     | 
    
         
             
              class Connection # rubocop:disable Metrics/ClassLength
         
     | 
| 
       3 
     | 
    
         
            -
                attr_accessor :upload_token, :verbose
         
     | 
| 
      
 3 
     | 
    
         
            +
                attr_accessor :upload_token, :verbose, :access_token
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
                def initialize(options = {})
         
     | 
| 
       6 
6 
     | 
    
         
             
                  @base_url = options[:base_url] || 'https://api.toptranslation.com'
         
     | 
| 
       7 
7 
     | 
    
         
             
                  @files_url = options[:files_url] || 'https://files.toptranslation.com'
         
     | 
| 
       8 
     | 
    
         
            -
                  @access_token = options[:access_token] 
     | 
| 
      
 8 
     | 
    
         
            +
                  @access_token = options[:access_token]
         
     | 
| 
       9 
9 
     | 
    
         
             
                  @verbose = options[:verbose] || false
         
     | 
| 
      
 10 
     | 
    
         
            +
                  sign_in!(options) if @access_token.nil? && options.values_at(:email, :password).all?
         
     | 
| 
       10 
11 
     | 
    
         
             
                end
         
     | 
| 
       11 
12 
     | 
    
         | 
| 
       12 
13 
     | 
    
         
             
                def get(path, options = {})
         
     | 
| 
         @@ -33,6 +34,21 @@ module Toptranslation 
     | 
|
| 
       33 
34 
     | 
    
         
             
                  upload_file(file, type, uri, &block)
         
     | 
| 
       34 
35 
     | 
    
         
             
                end
         
     | 
| 
       35 
36 
     | 
    
         | 
| 
      
 37 
     | 
    
         
            +
                def sign_in!(options)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  return if @access_token
         
     | 
| 
      
 39 
     | 
    
         
            +
                  sign_in_options = {
         
     | 
| 
      
 40 
     | 
    
         
            +
                    email: options[:email],
         
     | 
| 
      
 41 
     | 
    
         
            +
                    password: options[:password],
         
     | 
| 
      
 42 
     | 
    
         
            +
                    application_id: 'pollux'
         
     | 
| 
      
 43 
     | 
    
         
            +
                  }.merge(options)
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  @access_token = post('/auth/sign_in', sign_in_options.merge(version: 2))['access_token']
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                  puts "# Requested access token #{@access_token}" if @verbose
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                  @access_token
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
       36 
52 
     | 
    
         
             
                private
         
     | 
| 
       37 
53 
     | 
    
         | 
| 
       38 
54 
     | 
    
         
             
                  def version(options)
         
     | 
| 
         @@ -60,20 +76,6 @@ module Toptranslation 
     | 
|
| 
       60 
76 
     | 
    
         
             
                    token
         
     | 
| 
       61 
77 
     | 
    
         
             
                  end
         
     | 
| 
       62 
78 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
                  def sign_in(options)
         
     | 
| 
       64 
     | 
    
         
            -
                    sign_in_options = {
         
     | 
| 
       65 
     | 
    
         
            -
                      email: options[:email],
         
     | 
| 
       66 
     | 
    
         
            -
                      password: options[:password],
         
     | 
| 
       67 
     | 
    
         
            -
                      application_id: 'pollux'
         
     | 
| 
       68 
     | 
    
         
            -
                    }.merge!(options)
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
                    access_token = post('/auth/sign_in', sign_in_options)['access_token']
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
                    puts "# Requested access token #{access_token}" if @verbose
         
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
                    access_token
         
     | 
| 
       75 
     | 
    
         
            -
                  end
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
79 
     | 
    
         
             
                  def transform_response(response, options)
         
     | 
| 
       78 
80 
     | 
    
         
             
                    puts response if @verbose
         
     | 
| 
       79 
81 
     | 
    
         
             
                    parsed = JSON.parse(response)
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: toptranslation_api
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.4.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Toptranslation GmbH
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2018-06- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2018-06-22 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: json
         
     |