appdirect_integration 0.0.1 → 1.0.0
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f01e227540090b6cfbb952f07fe04e04a69662cb
|
4
|
+
data.tar.gz: d45eddf596ce7365da9d2684d19665165c66262b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d33b387174292a04cdd0034925dc70c06a90876b4d88bb06c2cbadc0b1720d739d0be189a73047e54eb1caca9602cd715ff946e5f6e4b12ffc49d2cd8b63cc4
|
7
|
+
data.tar.gz: c31baa2d5f9d39e7e4650c890b0becef130f82337704bcfc8a3e03040205dadd79b997bf786772792a8127d876e0db32b6ec1769a82a045418f0279cd10f737f
|
data/.gitignore
CHANGED
@@ -7,10 +7,14 @@ doc/
|
|
7
7
|
pkg/
|
8
8
|
spec/reports/
|
9
9
|
tmp/
|
10
|
-
log
|
10
|
+
log/
|
11
11
|
spec/dummy/db/*.sqlite3
|
12
12
|
spec/dummy/db/*.sqlite3-journal
|
13
|
-
spec/dummy/log
|
13
|
+
spec/dummy/log/
|
14
14
|
spec/dummy/tmp/
|
15
15
|
spec/dummy/.sass-cache
|
16
16
|
.DS_Store
|
17
|
+
*~
|
18
|
+
*.sqlite3
|
19
|
+
rdoc/*
|
20
|
+
spec/tmp/
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -21,12 +21,16 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
+
Register with AppDirect (free): https://www.appdirect.com/developers/register
|
25
|
+
|
26
|
+
Create an application and and copy your consumer key and consumer secret.
|
27
|
+
|
24
28
|
Add appdirect_integration gem to Gemfile
|
25
29
|
```ruby
|
26
30
|
gem 'appdirect_integration'
|
27
31
|
```
|
28
32
|
|
29
|
-
Add
|
33
|
+
Add Generate your Order scaffold
|
30
34
|
```ruby
|
31
35
|
rails g scaffold Order
|
32
36
|
```
|
@@ -40,9 +44,11 @@ Generate configuration
|
|
40
44
|
```ruby
|
41
45
|
rails g appdirect_integration:install
|
42
46
|
```
|
43
|
-
which will generate `config/appdirect.rb` file
|
47
|
+
which will generate `config/initializers/appdirect.rb` file.
|
48
|
+
|
49
|
+
Edit initializer config/initializers/appdirect.rb and specify your consumer key, consumer secret, and Order model there.
|
44
50
|
|
45
|
-
gem will automatically create (new) and save your Order ActiveRecord/Mongoid object
|
51
|
+
gem will automatically create (new) and save your Order ActiveRecord/Mongoid object at runtime.
|
46
52
|
|
47
53
|
the list of supported fields:
|
48
54
|
* `company_uuid`
|
@@ -28,7 +28,7 @@ module AppdirectIntegration
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def cancel
|
31
|
-
respond_to_event('cancel')
|
31
|
+
respond_to_event('cancel', 'CANCELLED')
|
32
32
|
end
|
33
33
|
|
34
34
|
def notify
|
@@ -70,7 +70,7 @@ module AppdirectIntegration
|
|
70
70
|
parsed_result
|
71
71
|
end
|
72
72
|
|
73
|
-
def respond_to_event(name)
|
73
|
+
def respond_to_event(name, new_status)
|
74
74
|
puts "Received #{name} event from AppDirect, requesting info..."
|
75
75
|
|
76
76
|
parsed_result = read_event_data()
|
@@ -80,6 +80,10 @@ module AppdirectIntegration
|
|
80
80
|
order = AppdirectIntegration.configuration.order_class.find(id)
|
81
81
|
order = update_order_object(parsed_result, order)
|
82
82
|
|
83
|
+
if new_status.present? && order.respond_to?('status=')
|
84
|
+
order.status = new_status
|
85
|
+
end
|
86
|
+
|
83
87
|
if order.save
|
84
88
|
render json: success_response("Event #{name} processed successfuly", id)
|
85
89
|
else
|
@@ -93,12 +97,12 @@ module AppdirectIntegration
|
|
93
97
|
if parsed_result["payload"].present?
|
94
98
|
order_data = parsed_result["payload"]["order"]
|
95
99
|
|
96
|
-
if
|
100
|
+
if order_data.present? && order_data["items"].present? && order_data["items"].length > 0
|
97
101
|
if order.respond_to?('order_items') && order.order_items.respond_to?('build')
|
98
102
|
order_data["items"].each do |item|
|
99
103
|
order_item = order.order_items.build()
|
100
|
-
order_item.quantity =
|
101
|
-
order_item.unit =
|
104
|
+
order_item.quantity = item["quantity"] if order_item.respond_to?('quantity=')
|
105
|
+
order_item.unit = item["unit"] if order_item.respond_to?('unit=')
|
102
106
|
end
|
103
107
|
end
|
104
108
|
end
|
@@ -115,11 +119,11 @@ module AppdirectIntegration
|
|
115
119
|
if parsed_result["payload"].present?
|
116
120
|
order_data = parsed_result["payload"]["order"]
|
117
121
|
|
118
|
-
if
|
122
|
+
if order_data.present? && order_data["items"].present? && order_data["items"].length > 0
|
119
123
|
if order.respond_to?('order_items') && order.order_items.respond_to?('build')
|
120
124
|
order_data["items"].each do |item|
|
121
|
-
order_item = order.order_items.find_or_create_by(unit:
|
122
|
-
order_item.quantity =
|
125
|
+
order_item = order.order_items.find_or_create_by(unit: item["unit"])
|
126
|
+
order_item.quantity = item["quantity"] if order_item.respond_to?('quantity=')
|
123
127
|
end
|
124
128
|
end
|
125
129
|
end
|
@@ -6,10 +6,13 @@ Some setup you must do manually if you haven't yet:
|
|
6
6
|
|
7
7
|
2. Create an application and and copy your consumer key and consumer secret.
|
8
8
|
|
9
|
-
3. Generate
|
9
|
+
3. Generate your Order scaffold
|
10
10
|
|
11
|
-
rails g
|
11
|
+
rails g scaffold Order
|
12
|
+
4. Setup Order model to work with AppDirect and generate migrations
|
12
13
|
|
13
|
-
|
14
|
+
rails g appdirect_integration Order
|
15
|
+
|
16
|
+
5. Edit initializer config/initializers/appdirect.rb and specify your consumer key, consumer secret, and Order model there.
|
14
17
|
|
15
18
|
===============================================================================
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appdirect_integration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Golubev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|