shopqi-app-webhook 0.1.4 → 0.1.5
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.
- data/README.md +1 -1
- data/app/models/shop.rb +1 -1
- data/lib/generators/shopqi_app_webhook/shopqi_app_webhook_generator.rb +2 -2
- data/lib/generators/shopqi_app_webhook/templates/README +1 -1
- data/lib/generators/shopqi_app_webhook/templates/app/controllers/webhook_controller.rb +9 -9
- data/lib/generators/shopqi_app_webhook/templates/app/jobs/webhook_job.rb +9 -0
- data/lib/generators/shopqi_app_webhook/templates/app/models/order.rb +1 -1
- data/lib/generators/shopqi_app_webhook/templates/db/migrate/create_delayed_jobs.rb +22 -0
- data/lib/generators/shopqi_app_webhook/templates/script/delayed_job +5 -0
- data/lib/shopqi-app-webhook.rb +1 -0
- data/lib/shopqi_app_webhook/engine.rb +0 -6
- data/lib/shopqi_app_webhook/rails/routes.rb +0 -1
- data/lib/shopqi_app_webhook/version.rb +1 -1
- data/lib/tasks/shopqi-app-webhook_tasks.rake +0 -3
- metadata +10 -24
- data/lib/generators/shopqi_app_webhook/templates/app/jobs/webhook_worker.rb +0 -12
data/README.md
CHANGED
data/app/models/shop.rb
CHANGED
@@ -7,6 +7,7 @@ class ShopQiAppWebhookGenerator < Rails::Generators::Base
|
|
7
7
|
|
8
8
|
def copy_files
|
9
9
|
directory 'app'
|
10
|
+
directory 'script'
|
10
11
|
end
|
11
12
|
|
12
13
|
def add_routes
|
@@ -16,11 +17,10 @@ class ShopQiAppWebhookGenerator < Rails::Generators::Base
|
|
16
17
|
def update_files
|
17
18
|
prepend_to_file "app/models/shop.rb", "require \"\#{ShopQiAppWebhook::Engine.models_dir}/shop\"\n"
|
18
19
|
insert_into_file "app/models/shop.rb", "\s\shas_many :orders\n", after: /class Shop( < ActiveRecord::Base){0,1}\n/
|
19
|
-
insert_into_file "config/app_secret_config.yml", "\s\s\s\shost: 'lvh.me:3000'\n", after: /defaults:(.|\n|\s)+?domain:\n/
|
20
|
-
insert_into_file "config/app_secret_config.yml", "\s\s\s\shost: 'example.shopqiapp.com'\n", after: /production:(.|\n|\s)+?domain:\n/
|
21
20
|
end
|
22
21
|
|
23
22
|
def install_migration
|
23
|
+
migration_template 'db/migrate/create_delayed_jobs.rb', 'db/migrate/create_delayed_jobs.rb'
|
24
24
|
migration_template 'db/migrate/create_orders.rb', 'db/migrate/create_orders.rb'
|
25
25
|
end
|
26
26
|
|
@@ -1,16 +1,16 @@
|
|
1
1
|
class WebhookController < ShopQiAppWebhook::WebhookController
|
2
2
|
|
3
3
|
def orders_fulfilled
|
4
|
-
|
4
|
+
order = JSON(request.body.read)['order']
|
5
5
|
shop.orders.where(order_id: order_id).first_or_create!({
|
6
|
-
name:
|
7
|
-
financial_status_name:
|
8
|
-
financial_status:
|
9
|
-
fulfillment_status:
|
10
|
-
fulfillment_status_name:
|
11
|
-
order_id:
|
12
|
-
total_price:
|
13
|
-
created_at:
|
6
|
+
name: order['name'],
|
7
|
+
financial_status_name: order['financial_status_name'],
|
8
|
+
financial_status: order['financial_status'],
|
9
|
+
fulfillment_status: order['fulfillment_status'],
|
10
|
+
fulfillment_status_name: order['fulfillment_status_name'],
|
11
|
+
order_id: order['id'],
|
12
|
+
total_price: order['total_price'],
|
13
|
+
created_at: order['created_at']
|
14
14
|
})
|
15
15
|
render nothing: true
|
16
16
|
end
|
@@ -3,6 +3,6 @@ class Order < ActiveRecord::Base
|
|
3
3
|
attr_accessible :name, :financial_status, :financial_status_name, :fulfillment_status, :fulfillment_status_name, :order_id, :total_price, :created_at
|
4
4
|
|
5
5
|
def admin_url
|
6
|
-
"#{
|
6
|
+
"#{shop.admin_url}/orders/#{order_id}"
|
7
7
|
end
|
8
8
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CreateDelayedJobs < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :delayed_jobs, :force => true do |table|
|
4
|
+
table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
|
5
|
+
table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
|
6
|
+
table.text :handler # YAML-encoded string of the object that will do work
|
7
|
+
table.text :last_error # reason for last failure (See Note below)
|
8
|
+
table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
|
9
|
+
table.datetime :locked_at # Set when a client is working on this object
|
10
|
+
table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
|
11
|
+
table.string :locked_by # Who is working on this object (if locked)
|
12
|
+
table.string :queue # The name of the queue this job is in
|
13
|
+
table.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.down
|
20
|
+
drop_table :delayed_jobs
|
21
|
+
end
|
22
|
+
end
|
data/lib/shopqi-app-webhook.rb
CHANGED
@@ -17,11 +17,5 @@ module ShopQiAppWebhook
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
initializer "shopqi_app_webhook.resque" do
|
21
|
-
require 'resque/server'
|
22
|
-
current_app_name = ::Rails.application.class.to_s.split("::").first
|
23
|
-
Resque.redis.namespace = "resque:#{current_app_name}"
|
24
|
-
end
|
25
|
-
|
26
20
|
end
|
27
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopqi-app-webhook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -44,13 +44,13 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 0.2.5
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: delayed_job_active_record
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 0.3.2
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.3.2
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: sqlite3
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,22 +91,6 @@ dependencies:
|
|
91
91
|
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: 2.10.1
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: resque_spec
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ! '>='
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '0'
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
110
94
|
- !ruby/object:Gem::Dependency
|
111
95
|
name: factory_girl_rails
|
112
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,12 +136,14 @@ files:
|
|
152
136
|
- app/models/shop.rb
|
153
137
|
- app/assets/javascripts/shopqi_app_webhook/application.js
|
154
138
|
- app/assets/stylesheets/shopqi_app_webhook/application.css
|
139
|
+
- lib/generators/shopqi_app_webhook/templates/db/migrate/create_delayed_jobs.rb
|
155
140
|
- lib/generators/shopqi_app_webhook/templates/db/migrate/create_orders.rb
|
156
|
-
- lib/generators/shopqi_app_webhook/templates/app/jobs/
|
141
|
+
- lib/generators/shopqi_app_webhook/templates/app/jobs/webhook_job.rb
|
157
142
|
- lib/generators/shopqi_app_webhook/templates/app/controllers/webhook_controller.rb
|
158
143
|
- lib/generators/shopqi_app_webhook/templates/app/controllers/home_controller.rb
|
159
144
|
- lib/generators/shopqi_app_webhook/templates/app/models/order.rb
|
160
145
|
- lib/generators/shopqi_app_webhook/templates/app/views/home/index.html.haml
|
146
|
+
- lib/generators/shopqi_app_webhook/templates/script/delayed_job
|
161
147
|
- lib/generators/shopqi_app_webhook/templates/README
|
162
148
|
- lib/generators/shopqi_app_webhook/shopqi_app_webhook_generator.rb
|
163
149
|
- lib/generators/shopqi_app_webhook/USAGE
|
@@ -183,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
183
169
|
version: '0'
|
184
170
|
segments:
|
185
171
|
- 0
|
186
|
-
hash:
|
172
|
+
hash: 715442061
|
187
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
174
|
none: false
|
189
175
|
requirements:
|
@@ -192,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
178
|
version: '0'
|
193
179
|
segments:
|
194
180
|
- 0
|
195
|
-
hash:
|
181
|
+
hash: 715442061
|
196
182
|
requirements: []
|
197
183
|
rubyforge_project:
|
198
184
|
rubygems_version: 1.8.24
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module WebhookWorker
|
3
|
-
|
4
|
-
@queue = "webhook_worker"
|
5
|
-
|
6
|
-
def self.perform(shop_id)
|
7
|
-
shop = Shop.find(shop_id)
|
8
|
-
Shopkit.setup url: shop.shopqi_domain, access_token: shop.access_token
|
9
|
-
Shopkit.create_webhook event: 'orders/fulfilled', callback_url: "http://#{SecretSetting.domain.host}/webhook"
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|