marfa 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 862d25196c6c383de5233b33b119ffa32fccee35
4
- data.tar.gz: 80654b3ddd051ec3912e81b0cebd2d90b6910005
3
+ metadata.gz: 077740413761a2332ab3064d01571c536a9debcc
4
+ data.tar.gz: 8a76c2df9d05d1e7f94f977cc95ae94f52c890cc
5
5
  SHA512:
6
- metadata.gz: 02f586bb240842d4be8c39eb4c9d5990f22bec4942513bf466fccb00a3a7abd7d56e4438e8b7601df2ad42141f26852ae4101958bf9661851e966a22c94c2997
7
- data.tar.gz: cf2ae9b244b64b4d11a19e14c3ab141ae0180fc45b64fde37ebc7c5520690c7a921273e2e1a36c57c3fb321c1f1554350c2e96e35a18c7cf5fe5e804b20e62a8
6
+ metadata.gz: 8798bc436b7e58f5a781f94dab28dd7610345a0b5cef10e2d964309f1fd4962341f6abbd755050f75c10a9bb2bb326697b506186989c5c5b05e645e3db96a7fb
7
+ data.tar.gz: 0c7674862463f5e124ed654178d05d452bd781692b44b42cc694c6989573fedf5bebee39323dd042b7a00c05005eb7b051a0bdd0a243e00c95cdd0c30ea1d371
@@ -4,6 +4,7 @@ require 'device_detector'
4
4
  require 'marfa/helpers/controller'
5
5
  require 'marfa/helpers/http/vary'
6
6
  require 'marfa/css_version'
7
+ require 'marfa/exceptions'
7
8
 
8
9
  # Extending Marfa
9
10
  module Marfa
@@ -11,6 +12,8 @@ module Marfa
11
12
  module Controllers
12
13
  # base controller
13
14
  class BaseController < Sinatra::Base
15
+ include Marfa::Exceptions
16
+
14
17
  before do
15
18
  if Marfa.config.device_detector[:enabled]
16
19
  client = DeviceDetector.new(request.user_agent)
@@ -0,0 +1,15 @@
1
+ # Extending Marfa
2
+ module Marfa
3
+ # Marfa Exceptions
4
+ module Exceptions
5
+ # Pages range error
6
+ class PagesRangeError < StandardError
7
+ attr_reader :redirect_page_to
8
+
9
+ def initialize(msg = 'Page is out of range', redirect_page_to = 1)
10
+ @redirect_page_to = redirect_page_to
11
+ super(msg)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,6 +1,7 @@
1
1
  require 'rest-client'
2
2
  require 'json'
3
3
  require 'marfa/configuration'
4
+ require 'marfa/exceptions'
4
5
 
5
6
  module Marfa
6
7
  # Extend Models
@@ -11,6 +12,7 @@ module Marfa
11
12
  class ModelError < StandardError; end
12
13
 
13
14
  include Marfa::Helpers::HTTP
15
+ include Marfa::Exceptions
14
16
 
15
17
  @aliases = {}
16
18
 
@@ -69,6 +71,8 @@ module Marfa
69
71
  # @return [Hash]
70
72
  def self.get_raw_data_with_pagination(params)
71
73
  params[:query] = params[:query].delete_if { |_, v| v.nil? } unless params[:query].nil?
74
+ params[:query][:page] = 1 if params[:query][:page].blank?
75
+
72
76
  path = params[:path]
73
77
  cache_key = params[:cache_key]
74
78
 
@@ -83,7 +87,14 @@ module Marfa
83
87
  Marfa.cache.set(cache_key, result.to_json, params[:cache_time] || Marfa.config.cache[:expiration_time])
84
88
 
85
89
  return result
90
+ # Avoid range errors
91
+ rescue RestClient::RangeNotSatisfiable
92
+ params[:query][:page] = 1
93
+
94
+ # try to get x_pages
95
+ res = _get_request_result_with_headers(params)
86
96
 
97
+ raise PagesRangeError.new('Page is out of range', res[:data_pages])
87
98
  rescue => exception
88
99
  if [:development, :test].include? Marfa.config.environment
89
100
  _log_exception(exception, path, params)
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.10.0'.freeze unless defined?(Marfa::VERSION)
4
+ VERSION = '0.10.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
@@ -2,6 +2,7 @@ require 'sinatra/base'
2
2
  require 'marfa/configuration'
3
3
  require 'marfa/cache'
4
4
  require 'marfa/version'
5
+ require 'marfa/exceptions'
5
6
  require 'marfa/helpers/http/rest'
6
7
  require 'marfa/helpers/controller'
7
8
  require 'marfa/helpers/http/vary'
data/marfa.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'marfa'
6
- s.version = '0.10.0'
6
+ s.version = '0.10.1'
7
7
  s.required_ruby_version = '>= 2.5.0'
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.date = Time.now.strftime('%Y-%m-%d')
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.10.0
4
+ version: 0.10.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: 2018-02-06 00:00:00.000000000 Z
13
+ date: 2018-02-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: haml
@@ -253,6 +253,7 @@ files:
253
253
  - lib/marfa/controllers/base_controller.rb
254
254
  - lib/marfa/controllers/css_controller.rb
255
255
  - lib/marfa/css_version.rb
256
+ - lib/marfa/exceptions.rb
256
257
  - lib/marfa/file_templates.rb
257
258
  - lib/marfa/helpers/classes/array.rb
258
259
  - lib/marfa/helpers/classes/false_class.rb