marfa 0.6.0 → 0.6.1
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/marfa/configuration.rb +1 -0
 - data/lib/marfa/file_templates.rb +2 -0
 - data/lib/marfa/helpers/http/rest.rb +149 -0
 - data/lib/marfa/models/api_model.rb +4 -2
 - data/lib/marfa/version.rb +1 -1
 - data/lib/marfa.rb +1 -0
 - data/marfa.gemspec +1 -1
 - metadata +3 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 66e3877d2da115dc46d090bada41ff103f0d591d
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 19fb9b00540dd96495ce15b83a5075b6dc8c4c87
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 04a42c351d459acdb2866716851308c2d80960a3e1f191a042280309691c199912451055eb1287c5efbcce37840556734c8de648e45949474e3b486b2f0f01da
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 7c5e04ba7e8a2a42bbf1b629dc37520e72c30199c99706e2bd88ebfe977f06ada394a2dd15f8fc6084a72222f56199438d2fa44df5d680a00aa0216175338829
         
     | 
    
        data/lib/marfa/configuration.rb
    CHANGED
    
    
    
        data/lib/marfa/file_templates.rb
    CHANGED
    
    | 
         @@ -19,6 +19,8 @@ Marfa.configure do |cfg| 
     | 
|
| 
       19 
19 
     | 
    
         
             
              cfg.environment = :development
         
     | 
| 
       20 
20 
     | 
    
         
             
              # Request logging
         
     | 
| 
       21 
21 
     | 
    
         
             
              cfg.logging = true
         
     | 
| 
      
 22 
     | 
    
         
            +
              # 0 - disabled; 1 - small; 2 - all
         
     | 
| 
      
 23 
     | 
    
         
            +
              cfg.logging_level = 0
         
     | 
| 
       22 
24 
     | 
    
         
             
              # Show error page with backtrace
         
     | 
| 
       23 
25 
     | 
    
         
             
              cfg.show_exceptions = true
         
     | 
| 
       24 
26 
     | 
    
         
             
              # log exception backtraces to STDERR
         
     | 
| 
         @@ -0,0 +1,149 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'marfa/configuration'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Marfa
         
     | 
| 
      
 4 
     | 
    
         
            +
              # see Marfa
         
     | 
| 
      
 5 
     | 
    
         
            +
              module Helpers
         
     | 
| 
      
 6 
     | 
    
         
            +
                # HTTP helpers
         
     | 
| 
      
 7 
     | 
    
         
            +
                module HTTP
         
     | 
| 
      
 8 
     | 
    
         
            +
                  # Helpers to use Rest requests
         
     | 
| 
      
 9 
     | 
    
         
            +
                  class Rest
         
     | 
| 
      
 10 
     | 
    
         
            +
                    # GET request
         
     | 
| 
      
 11 
     | 
    
         
            +
                    # @param url [String] - url
         
     | 
| 
      
 12 
     | 
    
         
            +
                    # @param headers [Hash] - headers hash
         
     | 
| 
      
 13 
     | 
    
         
            +
                    # @example
         
     | 
| 
      
 14 
     | 
    
         
            +
                    #   response = Rest.get(url, headers)
         
     | 
| 
      
 15 
     | 
    
         
            +
                    # @return response [RestClient::Response]
         
     | 
| 
      
 16 
     | 
    
         
            +
                    def self.get(url, headers = {})
         
     | 
| 
      
 17 
     | 
    
         
            +
                      p "REST GET url = #{url}" if Marfa.config.logging_level > 0
         
     | 
| 
      
 18 
     | 
    
         
            +
                      p "REST GET headers = #{headers}" if Marfa.config.logging_level > 0
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                      response = RestClient.get(url, headers)
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                      p "REST GET code = #{response.code}" if Marfa.config.logging_level > 0
         
     | 
| 
      
 23 
     | 
    
         
            +
                      p response.body if Marfa.config.logging_level > 1
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                      response
         
     | 
| 
      
 26 
     | 
    
         
            +
                    end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                    # HEAD request
         
     | 
| 
      
 29 
     | 
    
         
            +
                    # @param url [String] - url
         
     | 
| 
      
 30 
     | 
    
         
            +
                    # @param headers [Hash] - headers hash
         
     | 
| 
      
 31 
     | 
    
         
            +
                    # @example
         
     | 
| 
      
 32 
     | 
    
         
            +
                    #   response = Rest.head(url)
         
     | 
| 
      
 33 
     | 
    
         
            +
                    # @return response [RestClient::Response]
         
     | 
| 
      
 34 
     | 
    
         
            +
                    def self.head(url, headers = {})
         
     | 
| 
      
 35 
     | 
    
         
            +
                      p "REST HEAD url = #{url}" if Marfa.config.logging_level > 0
         
     | 
| 
      
 36 
     | 
    
         
            +
                      p "REST HEAD headers = #{headers}" if Marfa.config.logging_level > 0
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                      response = RestClient.head(url, headers)
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                      p "REST HEAD code  = #{response.code}" if Marfa.config.logging_level > 0
         
     | 
| 
      
 41 
     | 
    
         
            +
                      p response.body if Marfa.config.logging_level > 1
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                      response
         
     | 
| 
      
 44 
     | 
    
         
            +
                    end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                    # POST request
         
     | 
| 
      
 47 
     | 
    
         
            +
                    # @param url [String] - url
         
     | 
| 
      
 48 
     | 
    
         
            +
                    # @param payload [String] - request body
         
     | 
| 
      
 49 
     | 
    
         
            +
                    # @param headers [Hash] - headers hash
         
     | 
| 
      
 50 
     | 
    
         
            +
                    # @param block [Proc] - block code to run
         
     | 
| 
      
 51 
     | 
    
         
            +
                    # @example
         
     | 
| 
      
 52 
     | 
    
         
            +
                    #   response = Rest.post(url, payload)
         
     | 
| 
      
 53 
     | 
    
         
            +
                    #   Rest.post(url, payload) do |response|
         
     | 
| 
      
 54 
     | 
    
         
            +
                    # @return response [RestClient::Response]
         
     | 
| 
      
 55 
     | 
    
         
            +
                    def self.post (url, payload, headers={}, &block)
         
     | 
| 
      
 56 
     | 
    
         
            +
                      p "REST POST url = #{url}" if Marfa.config.logging_level > 0
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                      if Marfa.config.logging_level > 0
         
     | 
| 
      
 59 
     | 
    
         
            +
                        p "REST POST headers= #{headers}"
         
     | 
| 
      
 60 
     | 
    
         
            +
                        p "REST POST payload= #{payload}"
         
     | 
| 
      
 61 
     | 
    
         
            +
                      end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                      if block.nil?
         
     | 
| 
      
 64 
     | 
    
         
            +
                        response = RestClient.post(url, payload, headers)
         
     | 
| 
      
 65 
     | 
    
         
            +
                        p "REST POST code = #{response.code}" if Marfa.config.logging_level > 0
         
     | 
| 
      
 66 
     | 
    
         
            +
                        p response.body if Marfa.config.logging_level > 1
         
     | 
| 
      
 67 
     | 
    
         
            +
                        return response
         
     | 
| 
      
 68 
     | 
    
         
            +
                      else
         
     | 
| 
      
 69 
     | 
    
         
            +
                        RestClient::Request.execute(
         
     | 
| 
      
 70 
     | 
    
         
            +
                          method: :post,
         
     | 
| 
      
 71 
     | 
    
         
            +
                          url: url,
         
     | 
| 
      
 72 
     | 
    
         
            +
                          payload: payload,
         
     | 
| 
      
 73 
     | 
    
         
            +
                          headers: headers
         
     | 
| 
      
 74 
     | 
    
         
            +
                        ) do |response|
         
     | 
| 
      
 75 
     | 
    
         
            +
                          p "REST POST code  = #{response.code}" if Marfa.config.logging_level > 0
         
     | 
| 
      
 76 
     | 
    
         
            +
                          p response.body if Marfa.config.logging_level > 1
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                          block.call(response)
         
     | 
| 
      
 79 
     | 
    
         
            +
                        end
         
     | 
| 
      
 80 
     | 
    
         
            +
                      end
         
     | 
| 
      
 81 
     | 
    
         
            +
                    end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                    # PUT request
         
     | 
| 
      
 84 
     | 
    
         
            +
                    # @param url [String] - url
         
     | 
| 
      
 85 
     | 
    
         
            +
                    # @param payload [String] - request body
         
     | 
| 
      
 86 
     | 
    
         
            +
                    # @param headers [Hash] - headers hash
         
     | 
| 
      
 87 
     | 
    
         
            +
                    # @param block [Proc] - block code to run
         
     | 
| 
      
 88 
     | 
    
         
            +
                    # @example
         
     | 
| 
      
 89 
     | 
    
         
            +
                    #   response = Rest.put(url, payload)
         
     | 
| 
      
 90 
     | 
    
         
            +
                    #   Rest.put(url, payload) do |response|
         
     | 
| 
      
 91 
     | 
    
         
            +
                    # @return response [RestClient::Response]
         
     | 
| 
      
 92 
     | 
    
         
            +
                    def self.put(url, payload, headers = {}, &block)
         
     | 
| 
      
 93 
     | 
    
         
            +
                      p "REST PUT url  = #{url}" if Marfa.config.logging_level > 0
         
     | 
| 
      
 94 
     | 
    
         
            +
                      if Marfa.config.logging_level > 0
         
     | 
| 
      
 95 
     | 
    
         
            +
                        p "REST PUT headers= #{headers}"
         
     | 
| 
      
 96 
     | 
    
         
            +
                        p "REST PUT payload= #{payload}"
         
     | 
| 
      
 97 
     | 
    
         
            +
                      end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                      if block.nil?
         
     | 
| 
      
 100 
     | 
    
         
            +
                        response = RestClient.put(url, payload, headers)
         
     | 
| 
      
 101 
     | 
    
         
            +
                        p "REST PUT code   = #{response.code}" if Marfa.config.logging_level > 0
         
     | 
| 
      
 102 
     | 
    
         
            +
                        p response.body if Marfa.config.logging_level > 1
         
     | 
| 
      
 103 
     | 
    
         
            +
                        return response
         
     | 
| 
      
 104 
     | 
    
         
            +
                      else
         
     | 
| 
      
 105 
     | 
    
         
            +
                        RestClient::Request.execute(
         
     | 
| 
      
 106 
     | 
    
         
            +
                          method: :put,
         
     | 
| 
      
 107 
     | 
    
         
            +
                          url: url,
         
     | 
| 
      
 108 
     | 
    
         
            +
                          payload: payload,
         
     | 
| 
      
 109 
     | 
    
         
            +
                          headers: headers
         
     | 
| 
      
 110 
     | 
    
         
            +
                        ) do |response|
         
     | 
| 
      
 111 
     | 
    
         
            +
                          p "REST PUT code   = #{response.code}" if Marfa.config.logging_level > 0
         
     | 
| 
      
 112 
     | 
    
         
            +
                          p response.body if Marfa.config.logging_level > 1
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                          block.call(response)
         
     | 
| 
      
 115 
     | 
    
         
            +
                        end
         
     | 
| 
      
 116 
     | 
    
         
            +
                      end
         
     | 
| 
      
 117 
     | 
    
         
            +
                    end
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                    # DELETE request
         
     | 
| 
      
 120 
     | 
    
         
            +
                    # @param url [String] - url
         
     | 
| 
      
 121 
     | 
    
         
            +
                    # @param payload [String] - request body
         
     | 
| 
      
 122 
     | 
    
         
            +
                    # @param headers [Hash] - headers hash
         
     | 
| 
      
 123 
     | 
    
         
            +
                    # @param block [Proc] - block code to run
         
     | 
| 
      
 124 
     | 
    
         
            +
                    # @example
         
     | 
| 
      
 125 
     | 
    
         
            +
                    #   Rest.delete(url, payload, headers) do |response|
         
     | 
| 
      
 126 
     | 
    
         
            +
                    # @return response [RestClient::Response]
         
     | 
| 
      
 127 
     | 
    
         
            +
                    def self.delete(url, payload, headers = {}, &block)
         
     | 
| 
      
 128 
     | 
    
         
            +
                      p "REST DELETE url    = #{url}" if Marfa.config.logging_level > 0
         
     | 
| 
      
 129 
     | 
    
         
            +
                      if Marfa.config.logging_level > 0
         
     | 
| 
      
 130 
     | 
    
         
            +
                        p "REST DELETE headers= #{headers}"
         
     | 
| 
      
 131 
     | 
    
         
            +
                        p "REST DELETE payload= #{payload}"
         
     | 
| 
      
 132 
     | 
    
         
            +
                      end
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
      
 134 
     | 
    
         
            +
                      RestClient::Request.execute(
         
     | 
| 
      
 135 
     | 
    
         
            +
                        method: :delete,
         
     | 
| 
      
 136 
     | 
    
         
            +
                        url: url,
         
     | 
| 
      
 137 
     | 
    
         
            +
                        payload: payload,
         
     | 
| 
      
 138 
     | 
    
         
            +
                        headers: headers
         
     | 
| 
      
 139 
     | 
    
         
            +
                      ) do |response|
         
     | 
| 
      
 140 
     | 
    
         
            +
                        p "REST DELETE code   = #{response.code}" if Marfa.config.logging_level > 0
         
     | 
| 
      
 141 
     | 
    
         
            +
                        p response.body if Marfa.config.logging_level > 1
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
                        block.call(response)
         
     | 
| 
      
 144 
     | 
    
         
            +
                      end
         
     | 
| 
      
 145 
     | 
    
         
            +
                    end
         
     | 
| 
      
 146 
     | 
    
         
            +
                  end
         
     | 
| 
      
 147 
     | 
    
         
            +
                end
         
     | 
| 
      
 148 
     | 
    
         
            +
              end
         
     | 
| 
      
 149 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -9,6 +9,8 @@ module Marfa 
     | 
|
| 
       9 
9 
     | 
    
         
             
                  # Base model error
         
     | 
| 
       10 
10 
     | 
    
         
             
                  class ModelError < StandardError; end
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
      
 12 
     | 
    
         
            +
                  include Marfa::Helpers::HTTP
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
       12 
14 
     | 
    
         
             
                  @aliases = {}
         
     | 
| 
       13 
15 
     | 
    
         | 
| 
       14 
16 
     | 
    
         
             
                  # Get data
         
     | 
| 
         @@ -45,7 +47,7 @@ module Marfa 
     | 
|
| 
       45 
47 
     | 
    
         
             
                      if Marfa.cache.exist?(cache_key)
         
     | 
| 
       46 
48 
     | 
    
         
             
                        result = JSON.parse(Marfa.cache.get(cache_key), symbolize_names: true)
         
     | 
| 
       47 
49 
     | 
    
         
             
                      else
         
     | 
| 
       48 
     | 
    
         
            -
                        response =  
     | 
| 
      
 50 
     | 
    
         
            +
                        response = Rest.get("#{Marfa.config.api_server}#{path}", { params: params[:query], headers: {} })
         
     | 
| 
       49 
51 
     | 
    
         
             
                        Marfa.cache.set(cache_key, response.body, params[:cache_time] || 7200)
         
     | 
| 
       50 
52 
     | 
    
         
             
                        result = JSON.parse(response.body, symbolize_names: true)
         
     | 
| 
       51 
53 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -72,7 +74,7 @@ module Marfa 
     | 
|
| 
       72 
74 
     | 
    
         
             
                      if Marfa.cache.exist?(cache_key)
         
     | 
| 
       73 
75 
     | 
    
         
             
                        result = JSON.parse(Marfa.cache.get(cache_key), symbolize_names: true)
         
     | 
| 
       74 
76 
     | 
    
         
             
                      else
         
     | 
| 
       75 
     | 
    
         
            -
                        response =  
     | 
| 
      
 77 
     | 
    
         
            +
                        response = Rest.get("#{Marfa.config.api_server}#{path}", { params: params[:query], headers: {} })
         
     | 
| 
       76 
78 
     | 
    
         
             
                        result[:data] = JSON.parse(response.body, symbolize_names: true)
         
     | 
| 
       77 
79 
     | 
    
         
             
                        result[:data_count] = response.headers[:x_count].to_i unless response.headers[:x_count].nil?
         
     | 
| 
       78 
80 
     | 
    
         
             
                        result[:data_pages] = response.headers[:x_pages].to_i unless response.headers[:x_pages].nil?
         
     | 
    
        data/lib/marfa/version.rb
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Version constant
         
     | 
| 
       2 
2 
     | 
    
         
             
            module Marfa
         
     | 
| 
       3 
3 
     | 
    
         
             
              # The version constant for the current version of Marfa
         
     | 
| 
       4 
     | 
    
         
            -
              VERSION = '0.6. 
     | 
| 
      
 4 
     | 
    
         
            +
              VERSION = '0.6.1'.freeze unless defined?(Marfa::VERSION)
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
              # The current Marfa version.
         
     | 
| 
       7 
7 
     | 
    
         
             
              # @return [String] The version number
         
     | 
    
        data/lib/marfa.rb
    CHANGED
    
    
    
        data/marfa.gemspec
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: marfa
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.6. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.6.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Max Krechetov
         
     | 
| 
         @@ -10,7 +10,7 @@ authors: 
     | 
|
| 
       10 
10 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       11 
11 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       12 
12 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       13 
     | 
    
         
            -
            date: 2017- 
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2017-08-10 00:00:00.000000000 Z
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies:
         
     | 
| 
       15 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       16 
16 
     | 
    
         
             
              name: haml
         
     | 
| 
         @@ -320,6 +320,7 @@ files: 
     | 
|
| 
       320 
320 
     | 
    
         
             
            - lib/marfa/helpers/classes/true_class.rb
         
     | 
| 
       321 
321 
     | 
    
         
             
            - lib/marfa/helpers/controller.rb
         
     | 
| 
       322 
322 
     | 
    
         
             
            - lib/marfa/helpers/email.rb
         
     | 
| 
      
 323 
     | 
    
         
            +
            - lib/marfa/helpers/http/rest.rb
         
     | 
| 
       323 
324 
     | 
    
         
             
            - lib/marfa/helpers/http/vary.rb
         
     | 
| 
       324 
325 
     | 
    
         
             
            - lib/marfa/helpers/sass_functions.rb
         
     | 
| 
       325 
326 
     | 
    
         
             
            - lib/marfa/helpers/scss.rb
         
     |