marfa 0.4.0 → 0.4.3
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/helpers/controller.rb +15 -2
- data/lib/marfa/models/api_model.rb +41 -6
- data/lib/marfa/version.rb +1 -1
- data/marfa.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf0393e4cc01dbc36e6b34ddebe89f9f400e0824
|
4
|
+
data.tar.gz: c7844ca68f4144af82d0358ba888a884e2ae16a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40ee5fcaf70cc12dd9376bc412c4a2dfa63279aeda149779b6d76e5ce9d7b8bde14972412d7bf677da767d08fa81f9aa00539f94e3eea9cb844848d1e7d96e5e
|
7
|
+
data.tar.gz: efd735356fd54a436ddacbb8be4388f61b8ffc86a34cea8600dd42f528591bfbe56e502b3432a3c2dae1669cb6e28cb478e81cf8e142f3d7221c49e4b4a2d812
|
@@ -3,7 +3,12 @@ require 'marfa/configuration'
|
|
3
3
|
module Marfa
|
4
4
|
module Helpers
|
5
5
|
module Controller
|
6
|
-
|
6
|
+
# Render content
|
7
|
+
# @param path [String] - URL
|
8
|
+
# @param data [Hash] - options hash
|
9
|
+
# @example
|
10
|
+
# render_content('some_key', 'path/url', {})
|
11
|
+
# @return [String] rendered content
|
7
12
|
def render_content(path, data)
|
8
13
|
haml :"#{path}", locals: data
|
9
14
|
end
|
@@ -137,7 +142,6 @@ module Marfa
|
|
137
142
|
# @example
|
138
143
|
# get_html({ path: 'index', tags: ['tag1', 'tag2'], data: {} })
|
139
144
|
# @return [String] HTML
|
140
|
-
# def get_html(path, tags, data, cache_time = Marfa.config.cache[:expiration_time])
|
141
145
|
def get_html(options)
|
142
146
|
cache_time = options[:cache_time] || Marfa.config.cache[:expiration_time]
|
143
147
|
|
@@ -153,6 +157,15 @@ module Marfa
|
|
153
157
|
html
|
154
158
|
end
|
155
159
|
|
160
|
+
# Render pagination panel
|
161
|
+
# @param data [Hash] - pages info data
|
162
|
+
# @param _template [String] - template to render
|
163
|
+
# @return [String] HTML
|
164
|
+
def render_pagination(data, _template=nil)
|
165
|
+
template = _template || Marfa.config.pagination_template
|
166
|
+
haml :"#{template}", locals: data
|
167
|
+
end
|
168
|
+
|
156
169
|
alias_method :render_component, :render_block
|
157
170
|
alias_method :render_static_component, :render_static_block
|
158
171
|
end
|
@@ -20,6 +20,15 @@ module Marfa
|
|
20
20
|
get_raw_data(params)
|
21
21
|
end
|
22
22
|
|
23
|
+
# Get data w/pagination headers x_count / x_pages
|
24
|
+
# @param params [Hash] options hash
|
25
|
+
# @example
|
26
|
+
# BaseModel.get_data({ path: 'category/list' })
|
27
|
+
# @return [Hash] data from API
|
28
|
+
def self.get_data_with_pagination(params)
|
29
|
+
get_raw_data_with_pagination(params)
|
30
|
+
end
|
31
|
+
|
23
32
|
# "Raw" data getting
|
24
33
|
# @param params [Hash] - options hash
|
25
34
|
# @example
|
@@ -34,17 +43,43 @@ module Marfa
|
|
34
43
|
result = JSON.parse(response.body, symbolize_names: true)
|
35
44
|
rescue => exception
|
36
45
|
if [:development, :test].include? Marfa.config.environment
|
37
|
-
|
38
|
-
p "Path: #{Marfa.config.api_server}#{path}"
|
39
|
-
p 'Params:'
|
40
|
-
p params
|
41
|
-
p "#{exception.message} (#{exception.class})"
|
42
|
-
p '=================================================='
|
46
|
+
_log_exception(exception, path, params)
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
46
50
|
result
|
47
51
|
end
|
52
|
+
|
53
|
+
# "Raw" data getting w/pagination headers x_count / x_pages
|
54
|
+
# @param params [Hash] - options hash
|
55
|
+
# @return [Hash]
|
56
|
+
def self.get_raw_data_with_pagination(params)
|
57
|
+
result = {}
|
58
|
+
path = params[:path]
|
59
|
+
|
60
|
+
begin
|
61
|
+
response = RestClient.get("#{Marfa.config.api_server}#{path}", { params: params[:query], headers: {} })
|
62
|
+
result[:data] = JSON.parse(response.body, symbolize_names: true)
|
63
|
+
result[:data_count] = response.headers[:x_count].to_i unless response.headers[:x_count].nil?
|
64
|
+
result[:data_pages] = response.headers[:x_pages].to_i unless response.headers[:x_pages].nil?
|
65
|
+
rescue => exception
|
66
|
+
if [:development, :test].include? Marfa.config.environment
|
67
|
+
_log_exception(exception, path, params)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
result
|
72
|
+
end
|
73
|
+
|
74
|
+
# Log exceptions to console
|
75
|
+
def self._log_exception(e, path, params)
|
76
|
+
p '========== Exception while making request: =========='
|
77
|
+
p "Path: #{Marfa.config.api_server}#{path}"
|
78
|
+
p 'Params:'
|
79
|
+
p params
|
80
|
+
p "#{e.message} (#{e.class})"
|
81
|
+
p '=================================================='
|
82
|
+
end
|
48
83
|
end
|
49
84
|
end
|
50
85
|
end
|
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.4.
|
4
|
+
VERSION = '0.4.3' unless defined?(Marfa::VERSION)
|
5
5
|
|
6
6
|
# The current Marfa version.
|
7
7
|
# @return [String] The version number
|
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.4.
|
4
|
+
version: 0.4.3
|
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-05-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: haml
|