konduto-ruby 2.1.1 → 2.1.2

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
  SHA256:
3
- metadata.gz: 3ed318163f8a657f5717e5ffcf9b8052ddcba8580bce2d610b4cd8334395f9fb
4
- data.tar.gz: 3f6c9674cd5b62a5096a45a1735b21a5cdabe92b7b16c7548a73ad6c6e4f47fb
3
+ metadata.gz: ec1ca77129c269d4fde4b050cf435ea9ac0b0b32505c631677f49432bdf08f09
4
+ data.tar.gz: 1da2a417aa8806fbd456231f901a98a07f3080f4c1258aa74ff3434d9322570e
5
5
  SHA512:
6
- metadata.gz: 45b3265d4196188e8795c56b8f63225d94495dd8fe659208c88b059af86f84a4fb1bd159d0114b18b3ef2d01d623dd9cf50210823cedce4fcba0b1477fe50229
7
- data.tar.gz: c6002c33f9afbfc95fc105691096288698a3af378cd0c86882acdf7f74f110f9859712856edc2ea70895a04347a25e0bf27d7df59e17a6245b0577fa27d5e22c
6
+ metadata.gz: e3db33a75125fa3849aebf4b7c8f10f3f76a19f323f983f8c1cf2de3f7e6fe9dd1975286c8a9b7cead9a034cfdb82698266cc0eb9b3a4faac219de203239ccea
7
+ data.tar.gz: c8ad6cebe2be3175652ddba10dca045da749825b3acb5caa0c081909febac638cb97e9814f17d107e60e5b71be82b9778a3a23158ce7f23b51067e3f87bd9f70
@@ -5,7 +5,7 @@ module Konduto
5
5
  name = options[:alias] || model
6
6
 
7
7
  self.send(:define_method, name) do
8
- instance_variable_get("@#{name}")
8
+ instance_variable_get("@#{name}") if instance_variable_defined?("@#{name}")
9
9
  end
10
10
 
11
11
  self.send(:define_method, "#{name}=".to_sym) do |value|
@@ -25,7 +25,7 @@ module Konduto
25
25
  name = options[:alias] || model
26
26
 
27
27
  self.send(:define_method, name) do
28
- instance_variable_get("@#{name}")
28
+ instance_variable_get("@#{name}") if instance_variable_defined?("@#{name}")
29
29
  end
30
30
 
31
31
  self.send(:define_method, "#{name}=".to_sym) do |arr|
@@ -6,6 +6,8 @@ module Konduto
6
6
  klass = attribute.values[0].to_s.gsub(/_/, ' ').split.map(&:capitalize).join('')
7
7
  type = Object::const_get(klass)
8
8
  name = attribute.keys[0]
9
+
10
+ define_strftime_pattern(self, name, attribute[:strftime_pattern]) if attribute.has_key?(:strftime_pattern)
9
11
  else
10
12
  name = attribute
11
13
  end
@@ -22,11 +24,17 @@ module Konduto
22
24
  end
23
25
 
24
26
  self.send(:define_method, name) do
25
- instance_variable_get("@#{name.to_s.gsub(/[?|!]$/, '')}")
27
+ instance_variable_get("@#{name.to_s.gsub(/[?|!]$/, '')}") if instance_variable_defined?("@#{name.to_s.gsub(/[?|!]$/, '')}")
26
28
  end
27
29
  end
28
30
  end
29
31
 
30
32
  alias :attribute :attributes
33
+
34
+ def define_strftime_pattern(klass, name, value)
35
+ klass.send(:define_method, "#{name.to_s.gsub(/[?|!]$/, '')}_strftime_pattern") do
36
+ value
37
+ end
38
+ end
31
39
  end
32
40
  end
@@ -28,11 +28,17 @@ class KondutoBase
28
28
  instance_variables.map do |name|
29
29
  value = instance_variable_get(name)
30
30
 
31
+ strftime_pattern = defined_strftime_pattern(name) if defined_strftime_pattern?(name)
32
+
31
33
  if value.respond_to? :each
32
34
  value = value.map {|v| v.to_hash }
33
35
  elsif !value.instance_variables.empty?
34
36
  value = value.to_hash
35
- elsif value.is_a?(Date) || value.is_a?(Symbol)
37
+ elsif value.is_a?(DateTime)
38
+ value = value.strftime(strftime_pattern || '%Y-%m-%dT%H:%MZ')
39
+ elsif value.is_a?(Date)
40
+ value = value.strftime(strftime_pattern || '%Y-%m-%d')
41
+ elsif value.is_a?(Symbol)
36
42
  value = value.to_s
37
43
  end
38
44
 
@@ -53,4 +59,12 @@ class KondutoBase
53
59
 
54
60
  true
55
61
  end
62
+
63
+ def defined_strftime_pattern?(attr)
64
+ respond_to? "#{attr.to_s.gsub(/^@/, '')}_strftime_pattern"
65
+ end
66
+
67
+ def defined_strftime_pattern(attr)
68
+ send("#{attr.to_s.gsub(/^@/, '')}_strftime_pattern")
69
+ end
56
70
  end
@@ -1,4 +1,4 @@
1
- class KondutoNavigationInfo < KondutoBase
1
+ class KondutoNavigation < KondutoBase
2
2
  attributes :session_time, :referrer, :time_site_1d, :new_accounts_1d, :password_resets_1d, :sales_declined_1d,\
3
3
  :sessions_1d, :time_since_last_sale, :time_site_7d, :time_per_page_7d, :new_accounts_7d, \
4
4
  :password_resets_7d, :checkout_count_7d, :sales_declined_7d, :sessions_7d
@@ -15,8 +15,8 @@ class KondutoOrder < KondutoBase
15
15
  attributes :id, :visitor, :timestamp, :total_amount, :tax_amount, :currency, :installments,
16
16
  :ip, :score, :analyze, :messages_exchanged, :shipping_amount
17
17
 
18
- attribute first_message: :date_time
19
- attribute purchased_at: :date_time
18
+ attribute first_message: :date_time, strftime_pattern: '%Y-%m-%dT%H:%M:%SZ'
19
+ attribute purchased_at: :date_time, strftime_pattern: '%Y-%m-%dT%H:%M:%SZ'
20
20
  attribute status: :symbol
21
21
  attribute recommendation: :symbol
22
22
 
@@ -2,6 +2,6 @@ class KondutoOrderStatus < KondutoBase
2
2
  attributes :status, :comments
3
3
 
4
4
  def self.allowed_status
5
- %w(APPROVED DECLINED NOT_AUTHORIZED CANCELED FRAUD)
5
+ %w(APPROVED DECLINED NOT_AUTHORIZED CANCELLED FRAUD)
6
6
  end
7
7
  end
@@ -1,5 +1,5 @@
1
1
  class KondutoTravelLeg < KondutoBase
2
2
  attributes :number_of_connections, :fare_basis
3
- attribute date: :date
3
+ attribute date: :date_time
4
4
  attribute klass: :symbol
5
5
  end
@@ -1,14 +1,16 @@
1
- module ClassMethods
2
- def validates_presence_of(*attributes)
3
- self.send(:define_method, :required_attr) do
4
- attributes
1
+ module Konduto
2
+ module ClassMethods
3
+ def validates_presence_of(*attributes)
4
+ self.send(:define_method, :required_attr) do
5
+ attributes
6
+ end
5
7
  end
6
- end
7
8
 
8
- def validates(*attributes, &block)
9
- if block_given?
10
- self.send(:define_method, :custom_validations) do
11
- { Proc.new(&block) => attributes }
9
+ def validates(*attributes, &block)
10
+ if block_given?
11
+ self.send(:define_method, :custom_validations) do
12
+ { Proc.new(&block) => attributes }
13
+ end
12
14
  end
13
15
  end
14
16
  end
@@ -4,7 +4,7 @@ module Konduto
4
4
  module Validations
5
5
  def self.included(base)
6
6
  base.class_eval do
7
- extend ClassMethods
7
+ extend Konduto::ClassMethods
8
8
  end
9
9
  end
10
10
 
data/lib/konduto-ruby.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'json'
2
+ require 'date'
2
3
  require 'konduto-ruby/konduto_base'
4
+ require 'konduto-ruby/konduto_travel_leg'
5
+
3
6
  Dir[__dir__ + '/konduto-ruby/*.rb'].each { |file| require file }
4
7
 
5
8
  class KondutoRuby
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: konduto-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Custodio
@@ -46,7 +46,7 @@ files:
46
46
  - lib/konduto-ruby/konduto_geolocation.rb
47
47
  - lib/konduto-ruby/konduto_item.rb
48
48
  - lib/konduto-ruby/konduto_loyalty.rb
49
- - lib/konduto-ruby/konduto_navigation_info.rb
49
+ - lib/konduto-ruby/konduto_navigation.rb
50
50
  - lib/konduto-ruby/konduto_order.rb
51
51
  - lib/konduto-ruby/konduto_order_status.rb
52
52
  - lib/konduto-ruby/konduto_passenger.rb
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []
80
- rubygems_version: 3.2.15
80
+ rubygems_version: 3.0.8
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: ''