konduto-ruby 2.0.1 → 2.1.0

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
- SHA1:
3
- metadata.gz: 9f999d7311ada5064ed73af20e309798dc200c88
4
- data.tar.gz: e3c0a388cbee50a7b4fae5d6b1e9878b48dbc33d
2
+ SHA256:
3
+ metadata.gz: 2979ec6a852c1d1aec13ff2fee745918d33ccd68dc60b8a3fb59902cdcc0d12c
4
+ data.tar.gz: 18724ed8955265a9ee632454d3bc6fe4a1277d268de87d5d86a81318d2b0e53d
5
5
  SHA512:
6
- metadata.gz: 2c7b2601218b470b752f55d9a72c9c1994f7c51f6a01a47752819243b7b74f1d65fc112ee72303ffe321a39bfe38865db6628c1e2804a6294ab46dabd836a964
7
- data.tar.gz: 5fc2b0b07ac1bae002e008773d1fa114990ec7ab57ba8739fe2cca7febedb3265618e4051008d7d2e417aa795edbf2bb2bc3b0d27c8dd130266458006c585a45
6
+ metadata.gz: adbba6bf4810427c18a3aff47ae11526ca32bc9cef0a09f44920cc71bca4d4b11d56e651c8d1d85197d9f1dba71dffd3265169596254bc39c56a0a1083bf5ca9
7
+ data.tar.gz: edabb1c41aa2d930240e5897c204f65df269e8a065a8e11d267b20ecd97e543f6d0c007759d0615dc26187289dd25a8ae3e8b808c9966028a77cf57633e03226
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## Hey there,
2
2
 
3
- This document is a rubyist adaptation of the original README file made for the Java API version. You can get access to it by clicking [here](https://github.com/konduto/java-sdk/blob/master/README.md). **Konduto is a trademark, all rights reserved**. This project has no intention beyond helping ruby users to get easy access to Konduto's API through a simplified interface.
3
+ This document is a rubyist adaptation of the original README file made for the Java API version. You can get access to it by clicking [here](https://github.com/konduto/java-sdk/blob/master/README.md). **Konduto is a trademark, all rights reserved**. This project has no intention beyond helping ruby users to get easy access to Konduto's API through a simplified interface.
4
4
 
5
5
  ## Intro
6
6
 
@@ -10,9 +10,13 @@ Our service uses the visitor's behavior to analyze browsing patterns and detect
10
10
 
11
11
  This document refers to the **Ruby SDK** used for our API.
12
12
 
13
+ ## Migration from 1.0 to 2.0
14
+
15
+ NavigationInfo class is now Navigation and validation methods are now scopped by Konduto module.
16
+
13
17
  ## Requirements
14
18
 
15
- * This API was tested with Ruby MRI version 2.
19
+ - This API was tested with Ruby MRI version 2.
16
20
 
17
21
  ## Installation
18
22
 
@@ -30,7 +34,6 @@ When a customer makes a purchase you must send the order information to us so we
30
34
 
31
35
  While many of the parameters we accept are optional we recommend you send all you can, because every data point matters for the analysis. The **billing address** and **credit card information** are specially important, though we understand there are cases where you don't have that information.
32
36
 
33
-
34
37
  ## Set your API key
35
38
 
36
39
  You will need an API key to authenticate the requests. Luckily for you the examples below have been populated with a working key, so you can just copy and paste to see how it works.
@@ -53,7 +56,8 @@ order = KondutoOrder.new({
53
56
  totalAmount: 123.4,
54
57
  customer: customer # customer is an instance of KondutoCustomer
55
58
  })
56
- ```
59
+ ```
60
+
57
61
  One can also use the more conventional set-based approach as seen below.
58
62
 
59
63
  ```ruby
@@ -63,105 +67,98 @@ order.total_amount = 123.4
63
67
  order.customer = customer
64
68
  ```
65
69
 
66
- >
67
- **NOTICE**: the order created above is really, really simple. The more detail you provide, more accurate Konduto's analysis will be.
68
- >
70
+ > **NOTICE**: the order created above is really, really simple. The more detail you provide, more accurate Konduto's analysis will be.
69
71
 
70
72
  ### Order parameters
71
73
 
72
- Parameter | Description
73
- --- | ---
74
- id | _(required)_ Unique identifier for each order.
75
- visitor | _(required)_ Visitor identifier obtained from our JavaScript snippet.
76
- total_amount | _(required)_ Total order amount.
77
- shipping_amount | _(optional)_ Shipping and handling amount.
78
- tax_amount | _(optional)_ Taxes amount.
79
- currency | _(optional)_ Currency code with 3 letters (ISO-4712).
80
- installments | _(optional)_ Number of installments in the payment plan.
81
- ip | _(optional)_ Customer's IPv4 address.
82
- customer | _(required)_ Object containing the customer details.
83
- payment | _(optional)_ Array containing the payment methods.
84
- billing | _(optional)_ Object containing the billing information.
85
- shipping | _(optional)_ Object containing the shipping information.
86
- shopping_cart | _(optional)_ Array containing the items purchased.
87
- analyze | _(optional)_ A boolean indicating if the order should be analyzed. Defaults to **true**.
88
- first_message | _(optional)_ Time when the first message was exchanged between customer and seller.
89
- messages_exchanged | _(optional)_ Number of messages exchanged between customer and seller.
90
- purchased_at | _(optional)_ Time when the customer purchased from the seller.
74
+ | Parameter | Description |
75
+ | ------------------ | ---------------------------------------------------------------------------------------- |
76
+ | id | _(required)_ Unique identifier for each order. |
77
+ | visitor | _(required)_ Visitor identifier obtained from our JavaScript snippet. |
78
+ | total_amount | _(required)_ Total order amount. |
79
+ | shipping_amount | _(optional)_ Shipping and handling amount. |
80
+ | tax_amount | _(optional)_ Taxes amount. |
81
+ | currency | _(optional)_ Currency code with 3 letters (ISO-4712). |
82
+ | installments | _(optional)_ Number of installments in the payment plan. |
83
+ | ip | _(optional)_ Customer's IPv4 address. |
84
+ | customer | _(required)_ Object containing the customer details. |
85
+ | payment | _(optional)_ Array containing the payment methods. |
86
+ | billing | _(optional)_ Object containing the billing information. |
87
+ | shipping | _(optional)_ Object containing the shipping information. |
88
+ | shopping_cart | _(optional)_ Array containing the items purchased. |
89
+ | analyze | _(optional)_ A boolean indicating if the order should be analyzed. Defaults to **true**. |
90
+ | first_message | _(optional)_ Time when the first message was exchanged between customer and seller. |
91
+ | messages_exchanged | _(optional)_ Number of messages exchanged between customer and seller. |
92
+ | purchased_at | _(optional)_ Time when the customer purchased from the seller. |
91
93
 
92
94
  #### Customer information
93
95
 
94
- Parameter | Description
95
- --- | ---
96
- id | _(required)_ **Unique** identifier for each customer. Can be anything you like (counter, id, e-mail address) as long as it's consistent in future orders.
97
- name | _(required)_ Customer's full name.
98
- email | _(required)_ Customer's e-mail address
99
- tax_id | _(optional)_ Customer's tax id.
100
- phone1 | _(optional)_ Customer's primary phone number
101
- phone 2 | _(optional)_ Customer's secondary phone number
102
- new | _(optional)_ Boolean indicating if the customer is using a newly created account for this purchase.
103
- vip | _(optional)_ Boolean indicating if the customer is a VIP or frequent buyer.
104
- created_at | _(optional)_ Date when customer was created.
105
-
96
+ | Parameter | Description |
97
+ | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
98
+ | id | _(required)_ **Unique** identifier for each customer. Can be anything you like (counter, id, e-mail address) as long as it's consistent in future orders. |
99
+ | name | _(required)_ Customer's full name. |
100
+ | email | _(required)_ Customer's e-mail address |
101
+ | tax_id | _(optional)_ Customer's tax id. |
102
+ | phone1 | _(optional)_ Customer's primary phone number |
103
+ | phone 2 | _(optional)_ Customer's secondary phone number |
104
+ | new | _(optional)_ Boolean indicating if the customer is using a newly created account for this purchase. |
105
+ | vip | _(optional)_ Boolean indicating if the customer is a VIP or frequent buyer. |
106
+ | created_at | _(optional)_ Date when customer was created. |
106
107
 
107
108
  #### Payment information
108
109
 
109
- Parameter | Description
110
- --- | ---
111
- status | _(required)_ The status of the transaction returned by the payment processor. Accepts `approved`, `declined` or `pending` if the payment wasn't been processed yet.
112
- bin | _(optional)_ First six digits of the customer's credit card. Used to identify the type of card being sent.
113
- last4 | _(optional)_ Four last digits of the customer's credit card number.
114
- expiration_date | _(optional)_ Card's expiration date under MMYYYY format.
115
-
110
+ | Parameter | Description |
111
+ | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
112
+ | status | _(required)_ The status of the transaction returned by the payment processor. Accepts `approved`, `declined` or `pending` if the payment wasn't been processed yet. |
113
+ | bin | _(optional)_ First six digits of the customer's credit card. Used to identify the type of card being sent. |
114
+ | last4 | _(optional)_ Four last digits of the customer's credit card number. |
115
+ | expiration_date | _(optional)_ Card's expiration date under MMYYYY format. |
116
116
 
117
117
  #### Billing address
118
118
 
119
- Parameter | Description
120
- --- | ---
121
- name | _(optional)_ Cardholder's full name.
122
- address1 | _(optional)_ Cardholder's billing address on file with the bank.
123
- address2 | _(optional)_ Additional cardholder address information.
124
- city | _(optional)_ Cardholder's city.
125
- state | _(optional)_ Cardholder's state.
126
- zip | _(optional)_ Cardholder's ZIP code.
127
- country | _(optional)_ Cardholder's country code (ISO 3166-2)
128
-
119
+ | Parameter | Description |
120
+ | --------- | ---------------------------------------------------------------- |
121
+ | name | _(optional)_ Cardholder's full name. |
122
+ | address1 | _(optional)_ Cardholder's billing address on file with the bank. |
123
+ | address2 | _(optional)_ Additional cardholder address information. |
124
+ | city | _(optional)_ Cardholder's city. |
125
+ | state | _(optional)_ Cardholder's state. |
126
+ | zip | _(optional)_ Cardholder's ZIP code. |
127
+ | country | _(optional)_ Cardholder's country code (ISO 3166-2) |
129
128
 
130
129
  #### Shipping address
131
130
 
132
- Parameter | Description
133
- --- | ---
134
- name | _(optional)_ Recipient's full name.
135
- address1 | _(optional)_ Recipient's shipping address.
136
- address2 | _(optional)_ Additional recipient address information.
137
- city | _(optional)_ Recipient's city.
138
- state | _(optional)_ Recipient's state.
139
- zip | _(optional)_ Recipient's ZIP code.
140
- country | _(optional)_ Recipient's country code (ISO 3166-2)
141
-
131
+ | Parameter | Description |
132
+ | --------- | ------------------------------------------------------ |
133
+ | name | _(optional)_ Recipient's full name. |
134
+ | address1 | _(optional)_ Recipient's shipping address. |
135
+ | address2 | _(optional)_ Additional recipient address information. |
136
+ | city | _(optional)_ Recipient's city. |
137
+ | state | _(optional)_ Recipient's state. |
138
+ | zip | _(optional)_ Recipient's ZIP code. |
139
+ | country | _(optional)_ Recipient's country code (ISO 3166-2) |
142
140
 
143
141
  #### Shopping cart
144
142
 
145
- Parameter | Description
146
- --- | ---
147
- sku | _(optional)_ Product or service's SKU or inventory id.
148
- product_code | _(optional)_ Product or service's UPC, barcode or secondary id.
149
- category | _(optional)_ Category code for the item purchased. [See here](http://docs.konduto.com/#n-tables) for the list.
150
- name | _(optional)_ Name of the product or service.
151
- description | _(optional)_ Detailed description of the item.
152
- unit_cost | _(optional)_ Cost of a single unit of this item.
153
- quantity | _(optional)_ Number of units purchased.
154
- discount | _(optional)_ Discounted amount for this item.
155
- created_at | _(optional)_ Date when this item was created.
143
+ | Parameter | Description |
144
+ | ------------ | -------------------------------------------------------------------------------------------------------------- |
145
+ | sku | _(optional)_ Product or service's SKU or inventory id. |
146
+ | product_code | _(optional)_ Product or service's UPC, barcode or secondary id. |
147
+ | category | _(optional)_ Category code for the item purchased. [See here](http://docs.konduto.com/#n-tables) for the list. |
148
+ | name | _(optional)_ Name of the product or service. |
149
+ | description | _(optional)_ Detailed description of the item. |
150
+ | unit_cost | _(optional)_ Cost of a single unit of this item. |
151
+ | quantity | _(optional)_ Number of units purchased. |
152
+ | discount | _(optional)_ Discounted amount for this item. |
153
+ | created_at | _(optional)_ Date when this item was created. |
156
154
 
157
155
  ### Seller
158
156
 
159
- Parameter | Description
160
- --- | ---
161
- id | _(required)_ Seller's id
162
- name | _(optional)_ Sellers's name
163
- created_at | _(optional)_ Date when the seller was created
164
-
157
+ | Parameter | Description |
158
+ | ---------- | --------------------------------------------- |
159
+ | id | _(required)_ Seller's id |
160
+ | name | _(optional)_ Sellers's name |
161
+ | created_at | _(optional)_ Date when the seller was created |
165
162
 
166
163
  ## Sending an order for analysis.
167
164
 
@@ -205,12 +202,13 @@ order = konduto.get_order order_id # orderId is a String
205
202
  konduto.update_order_status(order, new_status, 'some comments');
206
203
  ```
207
204
 
208
- Parameter | Description
209
- --- | ---
210
- status | _(required)_ New status for this transaction. Either `approved`, `declined` or `fraud`, when you have identified a fraud or chargeback.
211
- comments | _(required)_ Reason or comments about the status update.
205
+ | Parameter | Description |
206
+ | --------- | --------------------------------------------------------------------------------------------------------------------------------------- |
207
+ | status | _(required)_ New status for this transaction. Either `approved`, `declined` or `fraud`, when you have identified a fraud or chargeback. |
208
+ | comments | _(required)_ Reason or comments about the status update. |
212
209
 
213
210
  ## Sending requests through a proxy
211
+
214
212
  To send requests through a proxy just build a new Konduto instance and set the proxy host passing the proxy url as parameters of `proxy=` method. If the proxy requires username and password, just set then at the proxy url you'll pass to `proxy=` method.
215
213
 
216
214
  ```ruby
@@ -1,6 +1,7 @@
1
1
  require 'json'
2
2
  require 'konduto-ruby/konduto_base'
3
3
  require 'konduto-ruby/konduto_travel_leg'
4
+
4
5
  Dir[__dir__ + '/konduto-ruby/*.rb'].each { |file| require file }
5
6
 
6
7
  class KondutoRuby
@@ -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,9 +25,7 @@ module Konduto
25
25
  name = options[:alias] || model
26
26
 
27
27
  self.send(:define_method, name) do
28
- instance_variable_set("@#{name}", []) if instance_variable_get("@#{name}").nil?
29
-
30
- instance_variable_get("@#{name}")
28
+ instance_variable_get("@#{name}") if instance_variable_defined?("@#{name}")
31
29
  end
32
30
 
33
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
@@ -14,8 +14,8 @@ class KondutoOrder < KondutoBase
14
14
  attributes :id, :visitor, :timestamp, :total_amount, :tax_amount, :currency, :installments,
15
15
  :ip, :score, :analyze, :messages_exchanged, :shipping_amount
16
16
 
17
- attribute first_message: :date_time
18
- attribute purchased_at: :date_time
17
+ attribute first_message: :date_time, strftime_pattern: '%Y-%m-%dT%H:%M:%SZ'
18
+ attribute purchased_at: :date_time, strftime_pattern: '%Y-%m-%dT%H:%M:%SZ'
19
19
  attribute status: :symbol
20
20
  attribute recommendation: :symbol
21
21
 
@@ -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
 
@@ -12,7 +12,6 @@ module Konduto
12
12
  if respond_to? :required_attr
13
13
  required_attr.each do |attr|
14
14
  return false if send(attr).nil?
15
- return false if send(attr).is_a?(Array) && send(attr).empty?
16
15
  end
17
16
  end
18
17
 
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.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Custodio
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-15 00:00:00.000000000 Z
12
+ date: 2018-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: factory_girl
15
+ name: factory_bot
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '4.7'
20
+ version: '4.10'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '4.7'
27
+ version: '4.10'
28
28
  description: A wrapper for konduto antifraud API
29
29
  email:
30
30
  - gcmartins93@gmail.com jonathancardosodecampos@gmail.com
@@ -45,7 +45,7 @@ files:
45
45
  - lib/konduto-ruby/konduto_geolocation.rb
46
46
  - lib/konduto-ruby/konduto_item.rb
47
47
  - lib/konduto-ruby/konduto_loyalty.rb
48
- - lib/konduto-ruby/konduto_navigation_info.rb
48
+ - lib/konduto-ruby/konduto_navigation.rb
49
49
  - lib/konduto-ruby/konduto_order.rb
50
50
  - lib/konduto-ruby/konduto_order_status.rb
51
51
  - lib/konduto-ruby/konduto_passenger.rb
@@ -77,9 +77,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  requirements: []
79
79
  rubyforge_project:
80
- rubygems_version: 2.4.8
80
+ rubygems_version: 2.7.7
81
81
  signing_key:
82
82
  specification_version: 4
83
- summary: This project aims to help ruby users of konduto API by offering a easy to
84
- use interface
83
+ summary: Konduto Ruby SDK
85
84
  test_files: []