nard-appi 0.1.5 → 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/nard/appi.rb +1 -7
- data/lib/nard/appi/api_ext/client.rb +2 -2
- data/lib/nard/appi/base.rb +60 -0
- data/lib/nard/appi/client.rb +74 -14
- data/lib/nard/appi/response/body.rb +54 -0
- data/lib/nard/appi/version.rb +1 -1
- metadata +4 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 4f846be2fa546d1e2c860e19bf8b4d79a2e68d9b
         | 
| 4 | 
            +
              data.tar.gz: 6624e51eeaef3f96de7ed3fe1c32999909dc313a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: bf8dd8602da13ad5f9cde0471fecbf038b94347690ff850e8f74cb10ee4dcf6ffde7ba30c5cd0ea085825dc976f6aeb4bd2aa195d880b5137a0aa4c2333512b3
         | 
| 7 | 
            +
              data.tar.gz: 539fc89634579c6c8cc4ebb76b536764386954f194332e9141197bdc5f2913e49fff2a11ee8fc21ac4b77212d3ac9ae882780cc31243f9dba9ee6ad7df13f2fd
         | 
    
        data/lib/nard/appi.rb
    CHANGED
    
    | @@ -1,13 +1,7 @@ | |
| 1 1 | 
             
            require 'nard/appi/version'
         | 
| 2 2 |  | 
| 3 | 
            -
            require 'nard/appi/ | 
| 4 | 
            -
            require 'nard/appi/api_ext/version'
         | 
| 5 | 
            -
            require 'nard/appi/api_ext/configuration'
         | 
| 6 | 
            -
            require 'nard/appi/api_ext/initializer'
         | 
| 7 | 
            -
            require 'nard/appi/api_ext/environment'
         | 
| 8 | 
            -
             | 
| 3 | 
            +
            require 'nard/appi/base'
         | 
| 9 4 | 
             
            require 'nard/appi/api_ext/default_configuration'
         | 
| 10 5 |  | 
| 11 | 
            -
             | 
| 12 6 | 
             
            require 'nard/appi/client'
         | 
| 13 7 | 
             
            require 'nard/appi/client/util/base_normalizer'
         | 
| @@ -0,0 +1,60 @@ | |
| 1 | 
            +
            require 'active_support'
         | 
| 2 | 
            +
            require 'active_support/concern'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            require 'nard/appi/api_ext/version'
         | 
| 5 | 
            +
            require 'nard/appi/api_ext/client'
         | 
| 6 | 
            +
            require 'nard/appi/api_ext/configuration'
         | 
| 7 | 
            +
            require 'nard/appi/api_ext/environment'
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            require 'nard/appi/api_ext/initializer'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            module Nard
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              module Appi
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                module Base
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  extend ActiveSupport::Concern
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  included do
         | 
| 20 | 
            +
                    class << self
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                      include ActiveSupport::Callbacks
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                      define_callbacks :default_config
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                      set_callback :default_config, :before, :before_default_config
         | 
| 27 | 
            +
                      set_callback :default_config, :after, :after_default_config
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                      private
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                      def before_default_config
         | 
| 32 | 
            +
                        include Nard::Appi::ApiExt::Version
         | 
| 33 | 
            +
                        include Nard::Appi::ApiExt::Client
         | 
| 34 | 
            +
                        include Nard::Appi::ApiExt::Configuration
         | 
| 35 | 
            +
                        include Nard::Appi::ApiExt::Environment
         | 
| 36 | 
            +
                      end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                      def after_default_config
         | 
| 39 | 
            +
                        include Nard::Appi::ApiExt::Initializer
         | 
| 40 | 
            +
                      end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                    end
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  module ClassMethods
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                    # 標準設定のモジュールを include するメソッド
         | 
| 48 | 
            +
                    # @param namespace [Module] 標準設定のモジュールが定義されている名前空間
         | 
| 49 | 
            +
                    # @return [Class] namespace に指定した名前空間
         | 
| 50 | 
            +
                    def default_config( namespace )
         | 
| 51 | 
            +
                      run_callbacks :default_config do
         | 
| 52 | 
            +
                        include namespace
         | 
| 53 | 
            +
                      end
         | 
| 54 | 
            +
                    end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
            end
         | 
    
        data/lib/nard/appi/client.rb
    CHANGED
    
    | @@ -9,32 +9,92 @@ module Nard | |
| 9 9 |  | 
| 10 10 | 
             
                  include Nard::Appi::ClientExt::Request
         | 
| 11 11 |  | 
| 12 | 
            -
                   | 
| 13 | 
            -
                    options_keys = gem_top_namespace::OPTIONS_KEYS
         | 
| 12 | 
            +
                  # @!group Methods for DSL
         | 
| 14 13 |  | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 14 | 
            +
                  def self.client_for( namespace )
         | 
| 15 | 
            +
                    set_top_namespace( namespace )
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  def self.concerns( *namespaces, under: nil )
         | 
| 19 | 
            +
                    raise ArgumentError unless under.present?
         | 
| 20 | 
            +
                    namespaces.each do | namespace |
         | 
| 21 | 
            +
                      include_concerned_module( namespace, under )
         | 
| 17 22 | 
             
                    end
         | 
| 23 | 
            +
                  end
         | 
| 18 24 |  | 
| 19 | 
            -
             | 
| 25 | 
            +
                  # @!endgroup
         | 
| 20 26 |  | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 27 | 
            +
                  class << self
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                    include ActiveSupport::Callbacks
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    attr_reader :top_namespace
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    private
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                    # @!group Private methods for DSL
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                    def set_top_namespace( top_namespace )
         | 
| 38 | 
            +
                      @top_namespace = top_namespace
         | 
| 23 39 | 
             
                    end
         | 
| 24 | 
            -
                  end
         | 
| 25 40 |  | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 41 | 
            +
                    def include_concerned_module( namespace, under )
         | 
| 42 | 
            +
                      require "#{ under }/#{ namespace.to_s.downcase }"
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                      module_name = under.classify
         | 
| 45 | 
            +
                                         .constantize
         | 
| 46 | 
            +
                                         .const_get( namespace.to_s.capitalize )
         | 
| 28 47 |  | 
| 29 | 
            -
             | 
| 48 | 
            +
                      # puts "#{ module_name } is included."
         | 
| 49 | 
            +
                      include module_name
         | 
| 50 | 
            +
                    end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                    # @!endgroup
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                    def set_attr_accessor( option_key )
         | 
| 30 55 | 
             
                      getter_method = option_key.to_sym
         | 
| 31 56 | 
             
                      setter_method = "#{ option_key }=".to_sym
         | 
| 32 57 | 
             
                      writer = option_key.to_sym
         | 
| 33 | 
            -
                      attr_reader getter_method unless getter_method.in?(  | 
| 34 | 
            -
                      attr_writer writer unless setter_method.in?(  | 
| 58 | 
            +
                      attr_reader getter_method unless getter_method.in?( instance_methods )
         | 
| 59 | 
            +
                      attr_writer writer unless setter_method.in?( instance_methods )
         | 
| 35 60 | 
             
                    end
         | 
| 36 61 |  | 
| 37 | 
            -
             | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  def initialize( options = {} )
         | 
| 65 | 
            +
                    set_attr_accessors
         | 
| 66 | 
            +
                    set_option_values( options )
         | 
| 67 | 
            +
                  end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                  private
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                  def set_attr_accessors
         | 
| 72 | 
            +
                    top_namespace = self.class.top_namespace
         | 
| 73 | 
            +
                    options_keys = top_namespace::OPTIONS_KEYS
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                    self.class.instance_eval do
         | 
| 76 | 
            +
                      return if @_attr_accessors_defined
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                      options_keys.each do | option_key |
         | 
| 79 | 
            +
                        set_attr_accessor( option_key )
         | 
| 80 | 
            +
                      end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                      @_attr_accessors_defined = true
         | 
| 83 | 
            +
                    end
         | 
| 84 | 
            +
                  end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                  def set_option_values( options )
         | 
| 87 | 
            +
                    options_keys = self.class.top_namespace::OPTIONS_KEYS
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                    options = self.class
         | 
| 90 | 
            +
                                  .top_namespace
         | 
| 91 | 
            +
                                  .options
         | 
| 92 | 
            +
                                  .merge( options )
         | 
| 93 | 
            +
                                  .with_indifferent_access
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                    options_keys.each do | key |
         | 
| 96 | 
            +
                      send( "#{ key }=", options[ key ] )
         | 
| 97 | 
            +
                    end
         | 
| 38 98 | 
             
                  end
         | 
| 39 99 |  | 
| 40 100 | 
             
                end
         | 
| @@ -0,0 +1,54 @@ | |
| 1 | 
            +
            module Nard
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              module Appi
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                module Response
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                  class Body
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                    def initialize( h, client, path, options )
         | 
| 10 | 
            +
                      @h = h
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                      @client = client
         | 
| 13 | 
            +
                      @path = path
         | 
| 14 | 
            +
                      @options = options
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                      raise_error_if_needed
         | 
| 17 | 
            +
                    end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    # @return [URI::HTTPS or URI::Generic]
         | 
| 20 | 
            +
                    def path( full: true )
         | 
| 21 | 
            +
                      options = @options.dup.merge( full: full )
         | 
| 22 | 
            +
                      @client.path( @path, options )
         | 
| 23 | 
            +
                    end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    def method_missing( method_name, *args, &block )
         | 
| 26 | 
            +
                      return super unless @h.respond_to?( method_name )
         | 
| 27 | 
            +
                      @h.send( method, *args, &block )
         | 
| 28 | 
            +
                    rescue NoMethodError => e
         | 
| 29 | 
            +
                      rescue_method_missing(e)
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                    def respond_to?( method, include_all = true )
         | 
| 33 | 
            +
                      return @h.respond_to?( method, include_all ) || super
         | 
| 34 | 
            +
                    end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                    private
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                    def rescue_method_missing(e)
         | 
| 39 | 
            +
                      raise NotImplementedError
         | 
| 40 | 
            +
                    end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                    def raise_error_if_needed
         | 
| 43 | 
            +
                      nil
         | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                    def rescue_method_missing(e)
         | 
| 47 | 
            +
                      raise NotImplementedError
         | 
| 48 | 
            +
                    end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
            end
         | 
    
        data/lib/nard/appi/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: nard-appi
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Shu Fujita
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016-12- | 
| 11 | 
            +
            date: 2016-12-16 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         | 
| @@ -125,6 +125,7 @@ files: | |
| 125 125 | 
             
            - lib/nard/appi/api_ext/environment.rb
         | 
| 126 126 | 
             
            - lib/nard/appi/api_ext/initializer.rb
         | 
| 127 127 | 
             
            - lib/nard/appi/api_ext/version.rb
         | 
| 128 | 
            +
            - lib/nard/appi/base.rb
         | 
| 128 129 | 
             
            - lib/nard/appi/client.rb
         | 
| 129 130 | 
             
            - lib/nard/appi/client/util/args_normalizer.rb
         | 
| 130 131 | 
             
            - lib/nard/appi/client/util/base_normalizer.rb
         | 
| @@ -133,6 +134,7 @@ files: | |
| 133 134 | 
             
            - lib/nard/appi/client/util/module/path_normalizer.rb
         | 
| 134 135 | 
             
            - lib/nard/appi/client_ext/request.rb
         | 
| 135 136 | 
             
            - lib/nard/appi/environment.rb
         | 
| 137 | 
            +
            - lib/nard/appi/response/body.rb
         | 
| 136 138 | 
             
            - lib/nard/appi/version.rb
         | 
| 137 139 | 
             
            - nard-appi.gemspec
         | 
| 138 140 | 
             
            homepage: https://github.com/nard-tech/nard-appi
         |