spree_dash 1.0.4 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/spree/admin/analytics_controller.rb +55 -0
- data/app/controllers/spree/admin/overview_controller.rb +7 -6
- data/app/helpers/spree/admin/overview_helper.rb +13 -0
- data/app/helpers/spree/analytics_helper.rb +172 -5
- data/app/models/spree/dash_configuration.rb +2 -0
- data/app/overrides/analytics_header.rb +2 -1
- data/app/views/spree/admin/analytics/sign_up.html.erb +45 -0
- data/app/views/spree/admin/overview/index.html.erb +27 -35
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +3 -1
- data/lib/spree/dash.rb +2 -10
- data/lib/spree/dash/jirafe.rb +74 -0
- metadata +21 -6
@@ -0,0 +1,55 @@
|
|
1
|
+
module Spree
|
2
|
+
class Admin::AnalyticsController < Admin::BaseController
|
3
|
+
before_filter :redirect_if_registered
|
4
|
+
|
5
|
+
def sign_up
|
6
|
+
@store = {
|
7
|
+
:first_name => '',
|
8
|
+
:last_name => '',
|
9
|
+
:email => current_user.email,
|
10
|
+
:currency => 'USD',
|
11
|
+
:time_zone => Time.zone,
|
12
|
+
:name => Spree::Config.site_name,
|
13
|
+
:url => format_url(Spree::Config.site_url)
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def register
|
18
|
+
@store = params[:store]
|
19
|
+
@store[:url] = format_url(@store[:url])
|
20
|
+
|
21
|
+
unless @store.has_key? :terms_of_service
|
22
|
+
flash[:error] = t(:agree_to_terms_of_service)
|
23
|
+
return render :sign_up
|
24
|
+
end
|
25
|
+
|
26
|
+
unless @store.has_key? :privacy_policy
|
27
|
+
flash[:error] = t(:agree_to_privacy_policy)
|
28
|
+
return render :sign_up
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
@store = Spree::Dash::Jirafe.register(@store)
|
33
|
+
Spree::Dash::Config.app_id = @store[:app_id]
|
34
|
+
Spree::Dash::Config.app_token = @store[:app_token]
|
35
|
+
Spree::Dash::Config.site_id = @store[:site_id]
|
36
|
+
Spree::Dash::Config.token = @store[:site_token]
|
37
|
+
redirect_to admin_path, :notice => t(:successfully_signed_up_for_analytics)
|
38
|
+
rescue Spree::Dash::JirafeException => e
|
39
|
+
flash[:error] = e.message
|
40
|
+
render :sign_up
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def redirect_if_registered
|
47
|
+
redirect_to admin_path, :notice => t(:already_signed_up_for_analytics) if Spree::Dash::Config.configured?
|
48
|
+
end
|
49
|
+
|
50
|
+
def format_url(url)
|
51
|
+
url =~ /^http/ ? url : "http://#{url}"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
module Spree
|
2
2
|
class Admin::OverviewController < Admin::BaseController
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
JIRAFE_LOCALES = { :english => 'en_US',
|
5
|
+
:french => 'fr_FR',
|
6
|
+
:german => 'de_DE',
|
7
|
+
:japanese => 'ja_JA' }
|
6
8
|
|
7
|
-
def
|
8
|
-
|
9
|
-
Spree::Dash::Config
|
9
|
+
def index
|
10
|
+
if JIRAFE_LOCALES.values.include? params[:locale]
|
11
|
+
Spree::Dash::Config.locale = params[:locale]
|
10
12
|
end
|
11
|
-
redirect_to admin_path
|
12
13
|
end
|
13
14
|
|
14
15
|
end
|
@@ -2,7 +2,7 @@ module Spree
|
|
2
2
|
module AnalyticsHelper
|
3
3
|
|
4
4
|
def spree_analytics
|
5
|
-
render :partial => 'analytics/header'
|
5
|
+
render :partial => 'spree/analytics/header'
|
6
6
|
end
|
7
7
|
|
8
8
|
def analytics_tags
|
@@ -19,7 +19,7 @@ module Spree
|
|
19
19
|
{ :product => { :name => @product.name,
|
20
20
|
:price => @product.price,
|
21
21
|
:sku => @product.sku,
|
22
|
-
:categories => @product.taxons.map
|
22
|
+
:categories => @product.taxons.map(&:permalink)
|
23
23
|
}
|
24
24
|
}
|
25
25
|
end
|
@@ -31,7 +31,7 @@ module Spree
|
|
31
31
|
|
32
32
|
def keywords_analytics_tags
|
33
33
|
return {} unless params[:keywords]
|
34
|
-
{ :search => { :keyword => params[:keywords] } }
|
34
|
+
{ :search => { :keyword => u(params[:keywords]) } }
|
35
35
|
end
|
36
36
|
|
37
37
|
def cart_analytics_tags
|
@@ -56,14 +56,181 @@ module Spree
|
|
56
56
|
def products_for_order
|
57
57
|
@order.line_items.map do |line_item|
|
58
58
|
variant = line_item.variant
|
59
|
-
{
|
59
|
+
{
|
60
|
+
:name => variant.name,
|
60
61
|
:qty => line_item.quantity,
|
61
62
|
:price => variant.price,
|
62
63
|
:sku => variant.sku,
|
63
|
-
:categories => variant.product.taxons.map
|
64
|
+
:categories => variant.product.taxons.map(&:permalink)
|
64
65
|
}
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
69
|
+
CURRENCIES = [
|
70
|
+
["Australian Dollar", "AUD"],
|
71
|
+
["New Zealand Dollar", "NZD"],
|
72
|
+
["US Dollar", "USD"],
|
73
|
+
["Euro", "EUR"],
|
74
|
+
["British Pound", "GBP"],
|
75
|
+
["Japanese Yen", "JPY"],
|
76
|
+
["Afghanistan Afghani", "AFA"],
|
77
|
+
["Albanian Lek", "ALL"],
|
78
|
+
["Algerian Dinar", "DZD"],
|
79
|
+
["Andorran Franc", "ADF"],
|
80
|
+
["Andorran Peseta", "ADP"],
|
81
|
+
["Angolan New Kwanza", "AON"],
|
82
|
+
["Argentine Peso", "ARS"],
|
83
|
+
["Aruban Florin", "AWG"],
|
84
|
+
["Austrian Schilling", "ATS"],
|
85
|
+
["Bahamanian Dollar", "BSD"],
|
86
|
+
["Bahraini Dinar", "BHD"],
|
87
|
+
["Bangladeshi Taka", "BDT"],
|
88
|
+
["Barbados Dollar", "BBD"],
|
89
|
+
["Belgian Franc", "BEF"],
|
90
|
+
["Belize Dollar", "BZD"],
|
91
|
+
["Bermudian Dollar", "BMD"],
|
92
|
+
["Bhutan Ngultrum", "BTN"],
|
93
|
+
["Bolivian Boliviano", "BOB"],
|
94
|
+
["Botswana Pula", "BWP"],
|
95
|
+
["Brazilian Real", "BRL"],
|
96
|
+
["Brunei Dollar", "BND"],
|
97
|
+
["Bulgarian Lev", "BGL"],
|
98
|
+
["Burundi Franc", "BIF"],
|
99
|
+
["CFA Franc BCEAO", "XOF"],
|
100
|
+
["CFA Franc BEAC", "XAF"],
|
101
|
+
["Cambodian Riel", "KHR"],
|
102
|
+
["Canadian Dollar", "CAD"],
|
103
|
+
["Cape Verde Escudo", "CVE"],
|
104
|
+
["Cayman Islands Dollar", "KYD"],
|
105
|
+
["Central Pacific Franc", "CFP"],
|
106
|
+
["Chilean Peso", "CLP"],
|
107
|
+
["Chinese Yuan Renminbi", "CNY"],
|
108
|
+
["Colombian Peso", "COP"],
|
109
|
+
["Comoros Franc", "KMF"],
|
110
|
+
["Costa Rican Colon", "CRC"],
|
111
|
+
["Croatian Kuna", "HRK"],
|
112
|
+
["Cuban Peso", "CUP"],
|
113
|
+
["Cyprus Pound", "CYP"],
|
114
|
+
["Czech Koruna", "CSK"],
|
115
|
+
["Danish Krone", "DKK"],
|
116
|
+
["Djibouti Franc", "DJF"],
|
117
|
+
["Dominican R. Peso", "DOP"],
|
118
|
+
["Dutch Guilder", "NLG"],
|
119
|
+
["ECU", "XEU"],
|
120
|
+
["East Caribbean Dollar", "XCD"],
|
121
|
+
["Ecuador Sucre", "ECS"],
|
122
|
+
["Egyptian Pound", "EGP"],
|
123
|
+
["El Salvador Colon", "SVC"],
|
124
|
+
["Estonian Kroon", "EEK"],
|
125
|
+
["Ethiopian Birr", "ETB"],
|
126
|
+
["Falkland Islands Pound", "FKP"],
|
127
|
+
["Fiji Dollar", "FJD"],
|
128
|
+
["Finnish Markka", "FIM"],
|
129
|
+
["French Franc", "FRF"],
|
130
|
+
["Gambian Dalasi", "GMD"],
|
131
|
+
["German Mark", "DEM"],
|
132
|
+
["Ghanaian Cedi", "GHC"],
|
133
|
+
["Gibraltar Pound", "GIP"],
|
134
|
+
["Greek Drachma", "GRD"],
|
135
|
+
["Guatemalan Quetzal", "GTQ"],
|
136
|
+
["Guinea Franc", "GNF"],
|
137
|
+
["Guyanese Dollar", "GYD"],
|
138
|
+
["Haitian Gourde", "HTG"],
|
139
|
+
["Honduran Lempira", "HNL"],
|
140
|
+
["Hong Kong Dollar", "HKD"],
|
141
|
+
["Hungarian Forint", "HUF"],
|
142
|
+
["Iceland Krona", "ISK"],
|
143
|
+
["Indian Rupee", "INR"],
|
144
|
+
["Indonesian Rupiah", "IDR"],
|
145
|
+
["Iranian Rial", "IRR"],
|
146
|
+
["Iraqi Dinar", "IQD"],
|
147
|
+
["Irish Punt", "IEP"],
|
148
|
+
["Israeli New Shekel", "ILS"],
|
149
|
+
["Italian Lira", "ITL"],
|
150
|
+
["Jamaican Dollar", "JMD"],
|
151
|
+
["Jordanian Dinar", "JOD"],
|
152
|
+
["Kazakhstan Tenge", "KZT"],
|
153
|
+
["Kenyan Shilling", "KES"],
|
154
|
+
["Kuwaiti Dinar", "KWD"],
|
155
|
+
["Lao Kip", "LAK"],
|
156
|
+
["Latvian Lats", "LVL"],
|
157
|
+
["Lebanese Pound", "LBP"],
|
158
|
+
["Lesotho Loti", "LSL"],
|
159
|
+
["Liberian Dollar", "LRD"],
|
160
|
+
["Libyan Dinar", "LYD"],
|
161
|
+
["Lithuanian Litas", "LTL"],
|
162
|
+
["Luxembourg Franc", "LUF"],
|
163
|
+
["Macau Pataca", "MOP"],
|
164
|
+
["Malagasy Franc", "MGF"],
|
165
|
+
["Malawi Kwacha", "MWK"],
|
166
|
+
["Malaysian Ringgit", "MYR"],
|
167
|
+
["Maldive Rufiyaa", "MVR"],
|
168
|
+
["Maltese Lira", "MTL"],
|
169
|
+
["Mauritanian Ouguiya", "MRO"],
|
170
|
+
["Mauritius Rupee", "MUR"],
|
171
|
+
["Mexican Peso", "MXP"],
|
172
|
+
["Mongolian Tugrik", "MNT"],
|
173
|
+
["Moroccan Dirham", "MAD"],
|
174
|
+
["Mozambique Metical", "MZM"],
|
175
|
+
["Myanmar Kyat", "MMK"],
|
176
|
+
["NL Antillian Guilder", "ANG"],
|
177
|
+
["Namibia Dollar", "NAD"],
|
178
|
+
["Nepalese Rupee", "NPR"],
|
179
|
+
["Nicaraguan Cordoba Oro", "NIO"],
|
180
|
+
["Nigerian Naira", "NGN"],
|
181
|
+
["North Korean Won", "KPW"],
|
182
|
+
["Norwegian Kroner", "NOK"],
|
183
|
+
["Omani Rial", "OMR"],
|
184
|
+
["Pakistan Rupee", "PKR"],
|
185
|
+
["Panamanian Balboa", "PAB"],
|
186
|
+
["Papua New Guinea Kina", "PGK"],
|
187
|
+
["Paraguay Guarani", "PYG"],
|
188
|
+
["Peruvian Nuevo Sol", "PEN"],
|
189
|
+
["Philippine Peso", "PHP"],
|
190
|
+
["Polish Zloty", "PLZ"],
|
191
|
+
["Portuguese Escudo", "PTE"],
|
192
|
+
["Qatari Rial", "QAR"],
|
193
|
+
["Romanian Leu", "ROL"],
|
194
|
+
["Russian Rouble", "RUB"],
|
195
|
+
["Samoan Tala", "WST"],
|
196
|
+
["Sao Tome/Principe Dobra", "STD"],
|
197
|
+
["Saudi Riyal", "SAR"],
|
198
|
+
["Seychelles Rupee", "SCR"],
|
199
|
+
["Sierra Leone Leone", "SLL"],
|
200
|
+
["Singapore Dollar", "SGD"],
|
201
|
+
["Slovak Koruna", "SKK"],
|
202
|
+
["Slovenian Tolar", "SIT"],
|
203
|
+
["Solomon Islands Dollar", "SBD"],
|
204
|
+
["Somali Shilling", "SOS"],
|
205
|
+
["South African Rand", "ZAR"],
|
206
|
+
["South-Korean Won", "KRW"],
|
207
|
+
["Spanish Peseta", "ESP"],
|
208
|
+
["Sri Lanka Rupee", "LKR"],
|
209
|
+
["St. Helena Pound", "SHP"],
|
210
|
+
["Sudanese Dinar", "SDD"],
|
211
|
+
["Sudanese Pound", "SDP"],
|
212
|
+
["Suriname Guilder", "SRG"],
|
213
|
+
["Swaziland Lilangeni", "SZL"],
|
214
|
+
["Swedish Krona", "SEK"],
|
215
|
+
["Swiss Franc", "CHF"],
|
216
|
+
["Syrian Pound", "SYP"],
|
217
|
+
["Taiwan Dollar", "TWD"],
|
218
|
+
["Tanzanian Shilling", "TZS"],
|
219
|
+
["Thai Baht", "THB"],
|
220
|
+
["Tonga Pa'anga", "TOP"],
|
221
|
+
["Trinidad/Tobago Dollar", "TTD"],
|
222
|
+
["Tunisian Dinar", "TND"],
|
223
|
+
["Turkish Lira", "TRL"],
|
224
|
+
["Uganda Shilling", "UGS"],
|
225
|
+
["Ukraine Hryvnia", "UAH"],
|
226
|
+
["Uruguayan Peso", "UYP"],
|
227
|
+
["Utd. Arab Emir. Dirham", "AED"],
|
228
|
+
["Vanuatu Vatu", "VUV"],
|
229
|
+
["Venezuelan Bolivar", "VEB"],
|
230
|
+
["Vietnamese Dong", "VND"],
|
231
|
+
["Yugoslav Dinar", "YUN"],
|
232
|
+
["Zambian Kwacha", "ZMK"],
|
233
|
+
["ZWD","Zimbabwe Dollar"]
|
234
|
+
]
|
68
235
|
end
|
69
236
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module Spree
|
2
2
|
class DashConfiguration < Preferences::Configuration
|
3
3
|
preference :app_id, :string
|
4
|
+
preference :app_token, :string
|
4
5
|
preference :site_id, :string
|
5
6
|
preference :token, :string
|
7
|
+
preference :locale, :string, :default => 'en_US'
|
6
8
|
|
7
9
|
def configured?
|
8
10
|
preferred_app_id.present? and preferred_site_id.present? and preferred_token.present?
|
@@ -1,4 +1,5 @@
|
|
1
1
|
Deface::Override.new(:virtual_path => "spree/layouts/spree_application",
|
2
2
|
:name => "add_analytics_header",
|
3
3
|
:insert_bottom => "[data-hook='inside_head']",
|
4
|
-
:partial => "spree/analytics/header"
|
4
|
+
:partial => "spree/analytics/header",
|
5
|
+
:original => '6f23c8af6e863d0499835c00b3f2763cb98e1d75')
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<%= form_tag admin_analytics_register_path do %>
|
2
|
+
<fieldset id="analytics_signup" data-hook>
|
3
|
+
<legend><%= t(:analytics_sign_up) %></legend>
|
4
|
+
<p>
|
5
|
+
<%= check_box_tag 'store[terms_of_service]', @store[:terms_of_service], @store.has_key?(:terms_of_service), :size => 50 %>
|
6
|
+
<%= label_tag t(:agree_to_terms_of_service) %> (<a href="http://jirafe.com/terms" target="_new"><%= t(:review) %></a>)
|
7
|
+
</p>
|
8
|
+
<p>
|
9
|
+
<%= check_box_tag 'store[privacy_policy]', @store[:privacy_policy], @store.has_key?(:privacy_policy), :size => 50 %>
|
10
|
+
<%= label_tag t(:agree_to_privacy_policy) %> (<a href="http://jirafe.com/privacy" target="_new"><%= t(:review) %></a>)
|
11
|
+
</p>
|
12
|
+
<p>
|
13
|
+
<%= label_tag :first_name %><br>
|
14
|
+
<%= text_field_tag 'store[first_name]', @store[:first_name], :size => 50 %>
|
15
|
+
</p>
|
16
|
+
<p>
|
17
|
+
<%= label_tag :last_name %><br>
|
18
|
+
<%= text_field_tag 'store[last_name]', @store[:last_name], :size => 50 %>
|
19
|
+
</p>
|
20
|
+
<p>
|
21
|
+
<%= label_tag :email %><br>
|
22
|
+
<%= email_field_tag 'store[email]', @store[:email], :size => 50 %>
|
23
|
+
</p>
|
24
|
+
<p>
|
25
|
+
<%= label_tag :store_name %><br>
|
26
|
+
<%= text_field_tag 'store[name]', @store[:name], :size => 50 %>
|
27
|
+
</p>
|
28
|
+
<p>
|
29
|
+
<%= label_tag :store_url %><br>
|
30
|
+
<%= url_field_tag 'store[url]', @store[:url], :size => 50 %>
|
31
|
+
</p>
|
32
|
+
<p>
|
33
|
+
<%= label_tag :currency %><br>
|
34
|
+
<%= select_tag 'store[currency]', options_for_select(Spree::AnalyticsHelper::CURRENCIES, @store[:currency]) %>
|
35
|
+
</p>
|
36
|
+
<p>
|
37
|
+
<%= label_tag :time_zone %><br>
|
38
|
+
<%= select_tag 'store[time_zone]', time_zone_options_for_select(@store[:time_zone]) %>
|
39
|
+
</p>
|
40
|
+
</fieldset>
|
41
|
+
<p class="form-buttons" data-hook="buttons">
|
42
|
+
<%= button t(:activate) %>
|
43
|
+
<%= t(:or) %> <%= link_to t(:cancel), admin_path %>
|
44
|
+
</p>
|
45
|
+
<% end %>
|
@@ -1,43 +1,35 @@
|
|
1
1
|
<% content_for :head do %>
|
2
|
-
|
3
|
-
|
2
|
+
<%= stylesheet_link_tag 'https://api.jirafe.com/dashboard/css/spree_ui.css', :media => 'all' %>
|
3
|
+
<%= javascript_include_tag 'https://jirafe.com/dashboard/js/spree_namespaced_ui.js' %>
|
4
4
|
<% end %>
|
5
5
|
|
6
|
-
<% if
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
version: 'spree-v0.1.0'
|
20
|
-
});
|
21
|
-
})(jQuery);
|
6
|
+
<% if Spree::Dash::Config.configured? %>
|
7
|
+
<h1><%= t(:overview) %></h1>
|
8
|
+
<div id="jirafe"></div>
|
9
|
+
<%= javascript_tag :defer => 'defer' do %>
|
10
|
+
jirafe.jQuery('#jirafe').jirafe({
|
11
|
+
api_url: 'https://api.jirafe.com/v1',
|
12
|
+
api_token: '<%= Spree::Dash::Config.token %>',
|
13
|
+
app_id: '<%= Spree::Dash::Config.app_id %>',
|
14
|
+
version: 'spree-v0.1.0',
|
15
|
+
locale: '<%= Spree::Dash::Config.locale %>' });
|
16
|
+
setTimeout(function() {
|
17
|
+
if ($('mod-jirafe') == undefined) {
|
18
|
+
$('messages').insert ("<ul class=\"messages\"><li class=\"error-msg\">We're unable to connect with the Jirafe service for the moment. Please wait a few minutes and refresh this page later.</li></ul>");
|
22
19
|
}
|
23
|
-
|
24
|
-
if ($('mod-jirafe') == undefined){
|
25
|
-
$('messages').insert ("<ul class=\"messages\"><li class=\"error-msg\">We're unable to connect with the Jirafe service for the moment. Please wait a few minutes and refresh this page later.</li></ul>");
|
26
|
-
}
|
27
|
-
}, 10000);
|
28
|
-
</script>
|
29
|
-
<% else %>
|
30
|
-
<div class="analytics_splash">
|
31
|
-
<%= image_tag 'analytics_dashboard_preview.png', :alt => 'Spree Analytics' %>
|
32
|
-
</div>
|
20
|
+
}, 10000);
|
33
21
|
<% end %>
|
34
|
-
<
|
22
|
+
<div id="jirafe_locales">
|
23
|
+
<%= raw jirafe_locale_links.join(' | ') %>
|
24
|
+
</div>
|
25
|
+
<% else %>
|
26
|
+
<div class="analytics_splash">
|
27
|
+
<%= image_tag 'analytics_dashboard_preview.png', :alt => 'Spree Analytics' %>
|
28
|
+
</div>
|
29
|
+
<br/>
|
35
30
|
<div class="preview-buttons">
|
36
|
-
<%= link_to
|
31
|
+
<%= link_to content_tag(:span, t(:activate)), admin_analytics_sign_up_path, :class => 'button green' %>
|
37
32
|
<%= t(:or) %>
|
38
|
-
<%= link_to t(:learn_more), "http://spreecommerce.com/blog/2012/01/31/introducing-spree-analytics/", :class =>
|
33
|
+
<%= link_to content_tag(:span, t(:learn_more)), "http://spreecommerce.com/blog/2012/01/31/introducing-spree-analytics/", :class => 'button', :target => '_blank' %>
|
39
34
|
</div>
|
40
|
-
|
41
|
-
<% end %>
|
42
|
-
|
43
|
-
|
35
|
+
<% end %>
|
data/config/locales/en.yml
CHANGED
@@ -1 +1,6 @@
|
|
1
1
|
en:
|
2
|
+
activate: Activate
|
3
|
+
agree_to_terms_of_service: Agree to Terms of Service
|
4
|
+
agree_to_privacy_policy: Agree to Privacy Policy
|
5
|
+
already_signed_up_for_analytics: You have already signed up for Spree Analytics
|
6
|
+
successfully_signed_up_for_analytics: Successfully signed up for Spree Analytics
|
data/config/routes.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
Spree::Core::Engine.routes.prepend do
|
2
2
|
match '/admin' => 'admin/overview#index', :as => :admin
|
3
|
-
|
3
|
+
|
4
|
+
get '/admin/analytics/sign_up' => 'admin/analytics#sign_up', :as => :admin_analytics_sign_up
|
5
|
+
post '/admin/analytics/register' => 'admin/analytics#register', :as => :admin_analytics_register
|
4
6
|
end
|
data/lib/spree/dash.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spree_core'
|
2
|
+
require 'httparty'
|
2
3
|
|
3
4
|
module Spree
|
4
5
|
module Dash
|
@@ -7,14 +8,5 @@ module Spree
|
|
7
8
|
end
|
8
9
|
|
9
10
|
require 'spree/dash/engine'
|
11
|
+
require 'spree/dash/jirafe'
|
10
12
|
|
11
|
-
# add helper to all the base controllers
|
12
|
-
# Spree::BaseController includes Spree::Core::ControllerHelpers
|
13
|
-
require 'spree/core/controller_helpers'
|
14
|
-
class << Spree::Core::ControllerHelpers
|
15
|
-
def included_with_analytics(receiver)
|
16
|
-
included_without_analytics(receiver)
|
17
|
-
receiver.send :helper, 'spree/analytics'
|
18
|
-
end
|
19
|
-
alias_method_chain :included, :analytics
|
20
|
-
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Spree
|
2
|
+
module Dash
|
3
|
+
class JirafeException < Exception; end
|
4
|
+
|
5
|
+
class Jirafe
|
6
|
+
include HTTParty
|
7
|
+
base_uri 'https://api.jirafe.com/v1'
|
8
|
+
format :json
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def register(store)
|
12
|
+
validate_required_keys! store
|
13
|
+
store[:time_zone] = ActiveSupport::TimeZone::MAPPING[store[:time_zone]] # jirafe expects 'America/New_York'
|
14
|
+
|
15
|
+
store = register_application(store)
|
16
|
+
store = synchronize_resources(store)
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate_required_keys!(store)
|
20
|
+
[:first_name, :url, :email, :currency, :time_zone, :name].each do |key|
|
21
|
+
unless store[key].present?
|
22
|
+
raise JirafeException, "#{key.to_s.titleize} is required"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def register_application(store)
|
28
|
+
return if store[:app_id].present? && store[:app_token].present?
|
29
|
+
|
30
|
+
options = {
|
31
|
+
:body => {
|
32
|
+
:name => store[:name],
|
33
|
+
:url => store[:url]
|
34
|
+
}
|
35
|
+
}
|
36
|
+
response = post '/applications', options
|
37
|
+
raise JirafeException, 'unable to create jirafe application' unless response.code == 200 &&
|
38
|
+
response['app_id'].present? &&
|
39
|
+
response['token'].present?
|
40
|
+
store[:app_id] = response['app_id']
|
41
|
+
store[:app_token] = response['token']
|
42
|
+
store
|
43
|
+
end
|
44
|
+
|
45
|
+
def synchronize_resources(store)
|
46
|
+
return unless store.has_key?(:app_id) and store.has_key?(:app_token)
|
47
|
+
|
48
|
+
options = {
|
49
|
+
:headers => { 'Content-type' => 'application/json' },
|
50
|
+
:query => { :token => store[:app_token] },
|
51
|
+
:body => {
|
52
|
+
:sites => [{ :description => store[:name],
|
53
|
+
:url => store[:url],
|
54
|
+
:currency => store[:currency],
|
55
|
+
:timezone => store[:time_zone],
|
56
|
+
:external_id => 1,
|
57
|
+
:site_id => store[:site_id] }],
|
58
|
+
:users => [{ :email => store[:email],
|
59
|
+
:first_name => store[:first_name],
|
60
|
+
:last_name => store[:last_name] }]
|
61
|
+
}.to_json
|
62
|
+
}
|
63
|
+
response = post "/applications/#{store[:app_id]}/resources", options
|
64
|
+
raise JirafeException, 'unable to synchronize store' unless response.code == 200 &&
|
65
|
+
response['sites'].present? &&
|
66
|
+
response['users'].present?
|
67
|
+
store[:site_id] = response["sites"].first["site_id"]
|
68
|
+
store[:site_token] = response["users"].first["token"]
|
69
|
+
store
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_dash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,19 +9,30 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: spree_core
|
16
|
-
requirement: &
|
16
|
+
requirement: &70357991597740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - =
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.0.
|
21
|
+
version: 1.0.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70357991597740
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: httparty
|
27
|
+
requirement: &70357991597280 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.8.1
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70357991597280
|
25
36
|
description: Required dependency for Spree
|
26
37
|
email: brian@spreecommerce.com
|
27
38
|
executables: []
|
@@ -31,16 +42,20 @@ files:
|
|
31
42
|
- LICENSE
|
32
43
|
- README.md
|
33
44
|
- app/assets/images/analytics_dashboard_preview.png
|
45
|
+
- app/controllers/spree/admin/analytics_controller.rb
|
34
46
|
- app/controllers/spree/admin/overview_controller.rb
|
47
|
+
- app/helpers/spree/admin/overview_helper.rb
|
35
48
|
- app/helpers/spree/analytics_helper.rb
|
36
49
|
- app/models/spree/dash_configuration.rb
|
37
50
|
- app/overrides/analytics_header.rb
|
51
|
+
- app/views/spree/admin/analytics/sign_up.html.erb
|
38
52
|
- app/views/spree/admin/overview/_form.html.erb
|
39
53
|
- app/views/spree/admin/overview/index.html.erb
|
40
54
|
- app/views/spree/analytics/_header.html.erb
|
41
55
|
- config/locales/en.yml
|
42
56
|
- config/routes.rb
|
43
57
|
- lib/spree/dash/engine.rb
|
58
|
+
- lib/spree/dash/jirafe.rb
|
44
59
|
- lib/spree/dash.rb
|
45
60
|
- lib/spree_dash.rb
|
46
61
|
homepage: http://spreecommerce.com
|
@@ -63,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
78
|
version: '0'
|
64
79
|
segments:
|
65
80
|
- 0
|
66
|
-
hash:
|
81
|
+
hash: -1742301049403710925
|
67
82
|
requirements:
|
68
83
|
- none
|
69
84
|
rubyforge_project:
|