appdirect_integration 0.0.1 → 1.0.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
2
  SHA1:
3
- metadata.gz: f3ba59cdf99d841fddeddae374b7aac811ef2e38
4
- data.tar.gz: 3fc5c50a2c718b585009f8696603c7be0930fcda
3
+ metadata.gz: f01e227540090b6cfbb952f07fe04e04a69662cb
4
+ data.tar.gz: d45eddf596ce7365da9d2684d19665165c66262b
5
5
  SHA512:
6
- metadata.gz: 1da5398bc72302e7e6d5962c653b09fae877359f3c83fb3ddbb78755f65351a65a8d7fa04fe727b3a9295cc8906a85387a98bd5af5ae3b3bac1def9f498643f9
7
- data.tar.gz: 0b158d5ffae19d4556f7e68ac6cd3029d64dd8f267ed98cd1b4dfacf18593594b8a3568194e445ef85f9201a43260511446cdef07a4199cbf9ce1c1d6df55182
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/*.log
10
+ log/
11
11
  spec/dummy/db/*.sqlite3
12
12
  spec/dummy/db/*.sqlite3-journal
13
- spec/dummy/log/*.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
@@ -3,4 +3,10 @@
3
3
  * Initial release
4
4
  * Main supported fields;
5
5
  * Generators;
6
- * Integration logic.
6
+ * Integration logic.
7
+
8
+ ## 1.0.0
9
+
10
+ * Release stable version
11
+ * implemented all methods
12
+ * fixed sub-items bug
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 Genrate your Order scaffold
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 which you need to check to setup (may be change your model name).
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 !order_data["items"].nil? && order_data["items"].length > 0
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 = order_item["quantity"] if order_item.respond_to?('quantity=')
101
- order_item.unit = order_item["unit"] if order_item.respond_to?('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 !order_data["items"].nil? && order_data["items"].length > 0
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: order_item["unit"])
122
- order_item.quantity = order_item["quantity"] if order_item.respond_to?('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
@@ -1,3 +1,3 @@
1
1
  module AppdirectIntegration
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  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 appdirect.rb initializer by running:
9
+ 3. Generate your Order scaffold
10
10
 
11
- rails g appdirect_integration:install
11
+ rails g scaffold Order
12
+ 4. Setup Order model to work with AppDirect and generate migrations
12
13
 
13
- 4. Edit initializer config/initializers/appdirect.rb and specify your consumer key and consumer secret there.
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.1
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-05 00:00:00.000000000 Z
11
+ date: 2015-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails