antbird 0.2.2 → 0.3.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/.github/workflows/build.yml +1 -1
 - data/lib/antbird/client.rb +44 -5
 - data/lib/antbird/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: 8d6972953a2ec1f37d057b6a9dd477593fc06a11b7f343f8c57d0f0fa9e31ee1
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: bd672bd59f69c2c6d77f90714da1112f441a8d6372d1ce3a9ae641778e2ee2f6
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: b2fea4c7232a0b7209a4c4729ee4ffcd7c4a985de2bf9ec718919b8c01577528fba618ea68a4811aebea5ec47c964baf6b8e0c668327afcf15679d84ee3a3bbc
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 04c28e273287890b585b500ce7733399057602a8ff52f8924445317d25d680134b944fbcfdc2950a0648bf8425e2e89fb06ae3255dc25683a670ad4babe560a1
         
     | 
    
        data/.github/workflows/build.yml
    CHANGED
    
    
    
        data/lib/antbird/client.rb
    CHANGED
    
    | 
         @@ -26,7 +26,7 @@ module Antbird 
     | 
|
| 
       26 
26 
     | 
    
         
             
                end
         
     | 
| 
       27 
27 
     | 
    
         
             
                attr_reader :scope, :url, :version
         
     | 
| 
       28 
28 
     | 
    
         
             
                attr_reader :read_timeout, :open_timeout, :adapter
         
     | 
| 
       29 
     | 
    
         
            -
                attr_reader :api_specs
         
     | 
| 
      
 29 
     | 
    
         
            +
                attr_reader :api_specs, :last_request
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
                def scoped(new_scope = {})
         
     | 
| 
       32 
32 
     | 
    
         
             
                  Client.new(
         
     | 
| 
         @@ -43,11 +43,13 @@ module Antbird 
     | 
|
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
                  body   = extract_body(params)
         
     | 
| 
       45 
45 
     | 
    
         
             
                  scopes = extract_scopes(params)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  forced_method = extract_method(params)
         
     | 
| 
       46 
47 
     | 
    
         | 
| 
       47 
48 
     | 
    
         
             
                  # Greedy match
         
     | 
| 
       48 
49 
     | 
    
         
             
                  api_path = nil
         
     | 
| 
      
 50 
     | 
    
         
            +
                  api_path_template = nil
         
     | 
| 
       49 
51 
     | 
    
         
             
                  path_methods = nil
         
     | 
| 
       50 
     | 
    
         
            -
                  api_spec['url']['paths']. 
     | 
| 
      
 52 
     | 
    
         
            +
                  sort_url_paths(api_spec['url']['paths']).each do |path|
         
     | 
| 
       51 
53 
     | 
    
         
             
                    if path.is_a?(Hash)
         
     | 
| 
       52 
54 
     | 
    
         
             
                      path_methods = path['methods']
         
     | 
| 
       53 
55 
     | 
    
         
             
                      path = path['path']
         
     | 
| 
         @@ -57,19 +59,40 @@ module Antbird 
     | 
|
| 
       57 
59 
     | 
    
         
             
                      scopes[$1.to_sym] || @scope[$1.to_sym] || match
         
     | 
| 
       58 
60 
     | 
    
         
             
                    end
         
     | 
| 
       59 
61 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
                     
     | 
| 
      
 62 
     | 
    
         
            +
                    unless embeded.include?('{')
         
     | 
| 
      
 63 
     | 
    
         
            +
                      api_path_template = path
         
     | 
| 
      
 64 
     | 
    
         
            +
                      api_path = embeded
         
     | 
| 
      
 65 
     | 
    
         
            +
                      break
         
     | 
| 
      
 66 
     | 
    
         
            +
                    end
         
     | 
| 
       61 
67 
     | 
    
         
             
                  end
         
     | 
| 
       62 
68 
     | 
    
         | 
| 
       63 
69 
     | 
    
         
             
                  unless api_path
         
     | 
| 
       64 
70 
     | 
    
         
             
                    raise "API path not found: paths: #{api_spec['url']['paths']}, scope: #{@scope}"
         
     | 
| 
       65 
71 
     | 
    
         
             
                  end
         
     | 
| 
       66 
72 
     | 
    
         | 
| 
       67 
     | 
    
         
            -
                  methods = ( 
     | 
| 
       68 
     | 
    
         
            -
                  method = 
     | 
| 
      
 73 
     | 
    
         
            +
                  methods = (path_methods || api_spec['methods']).map { |m| m.downcase.to_sym }
         
     | 
| 
      
 74 
     | 
    
         
            +
                  method =
         
     | 
| 
      
 75 
     | 
    
         
            +
                    if forced_method
         
     | 
| 
      
 76 
     | 
    
         
            +
                      forced_method
         
     | 
| 
      
 77 
     | 
    
         
            +
                    elsif methods.include?(:put)
         
     | 
| 
      
 78 
     | 
    
         
            +
                      :put
         
     | 
| 
      
 79 
     | 
    
         
            +
                    elsif methods.include?(:post)
         
     | 
| 
      
 80 
     | 
    
         
            +
                      :post
         
     | 
| 
      
 81 
     | 
    
         
            +
                    else
         
     | 
| 
      
 82 
     | 
    
         
            +
                      methods.first
         
     | 
| 
      
 83 
     | 
    
         
            +
                    end
         
     | 
| 
       69 
84 
     | 
    
         | 
| 
       70 
85 
     | 
    
         
             
                  read_timeout = params.delete(:read_timeout)
         
     | 
| 
       71 
86 
     | 
    
         
             
                  params.reject! { |_, v| v.nil? }
         
     | 
| 
       72 
87 
     | 
    
         | 
| 
      
 88 
     | 
    
         
            +
                  @last_request = {
         
     | 
| 
      
 89 
     | 
    
         
            +
                    method: method,
         
     | 
| 
      
 90 
     | 
    
         
            +
                    forced_method: forced_method,
         
     | 
| 
      
 91 
     | 
    
         
            +
                    api_path: api_path,
         
     | 
| 
      
 92 
     | 
    
         
            +
                    api_path_template: api_path_template,
         
     | 
| 
      
 93 
     | 
    
         
            +
                    params: params
         
     | 
| 
      
 94 
     | 
    
         
            +
                  }
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
       73 
96 
     | 
    
         
             
                  response =
         
     | 
| 
       74 
97 
     | 
    
         
             
                    case method
         
     | 
| 
       75 
98 
     | 
    
         
             
                    when :head
         
     | 
| 
         @@ -116,6 +139,10 @@ module Antbird 
     | 
|
| 
       116 
139 
     | 
    
         
             
                  response.body
         
     | 
| 
       117 
140 
     | 
    
         
             
                end
         
     | 
| 
       118 
141 
     | 
    
         | 
| 
      
 142 
     | 
    
         
            +
                def extract_method(params)
         
     | 
| 
      
 143 
     | 
    
         
            +
                  params.delete(:method)&.to_sym
         
     | 
| 
      
 144 
     | 
    
         
            +
                end
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
       119 
146 
     | 
    
         
             
                def extract_scopes(params)
         
     | 
| 
       120 
147 
     | 
    
         
             
                  scopes = {}
         
     | 
| 
       121 
148 
     | 
    
         
             
                  [:index, :type, :id].each do |s|
         
     | 
| 
         @@ -165,6 +192,18 @@ module Antbird 
     | 
|
| 
       165 
192 
     | 
    
         | 
| 
       166 
193 
     | 
    
         
             
                private
         
     | 
| 
       167 
194 
     | 
    
         | 
| 
      
 195 
     | 
    
         
            +
                # NOTE: stable sort
         
     | 
| 
      
 196 
     | 
    
         
            +
                def sort_url_paths(url_paths)
         
     | 
| 
      
 197 
     | 
    
         
            +
                  i = 0
         
     | 
| 
      
 198 
     | 
    
         
            +
                  url_paths.sort_by do |path|
         
     | 
| 
      
 199 
     | 
    
         
            +
                    if path.is_a?(Hash)
         
     | 
| 
      
 200 
     | 
    
         
            +
                      [-path['path'].count('{'), (path['deprecated'] ? 1 : 0), i += 1]
         
     | 
| 
      
 201 
     | 
    
         
            +
                    else
         
     | 
| 
      
 202 
     | 
    
         
            +
                      [-path.count('{'), i += 1]
         
     | 
| 
      
 203 
     | 
    
         
            +
                    end
         
     | 
| 
      
 204 
     | 
    
         
            +
                  end
         
     | 
| 
      
 205 
     | 
    
         
            +
                end
         
     | 
| 
      
 206 
     | 
    
         
            +
             
     | 
| 
       168 
207 
     | 
    
         
             
                def handle_errors!(response)
         
     | 
| 
       169 
208 
     | 
    
         
             
                  if response.status >= 500
         
     | 
| 
       170 
209 
     | 
    
         
             
                    raise ServerError, response
         
     | 
    
        data/lib/antbird/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: antbird
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - fukayatsu
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2020-12- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-12-19 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: faraday
         
     |