jirafe 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,12 +14,14 @@ end
14
14
 
15
15
  module Jirafe
16
16
  autoload :VERSION, "jirafe/version.rb"
17
+ autoload :LOCALES, "jirafe/locales.rb"
17
18
  autoload :Configuration, "jirafe/configuration.rb"
18
19
  autoload :Error, "jirafe/error.rb"
19
20
  autoload :ResponseParser, "jirafe/response_parser.rb"
20
21
  autoload :Model, "jirafe/model.rb"
21
22
  autoload :Asset, "jirafe/asset.rb"
22
23
  autoload :Tracker, "jirafe/tracker.rb"
24
+ autoload :Dashboard, "jirafe/dashboard.rb"
23
25
  module Resource
24
26
  autoload :JirafeResource, "jirafe/resource/jirafe_resource.rb"
25
27
  autoload :Version, "jirafe/resource/version.rb"
@@ -2,7 +2,7 @@ module Jirafe
2
2
  class Asset
3
3
  class << self
4
4
  def js_url_for(component, platform)
5
- [base_url, component, "js", "#{platform}_namespaced_ui.js"].join("/")
5
+ [base_url, component, "js", "#{platform}_ui.js"].join("/")
6
6
  end
7
7
 
8
8
  def css_url_for(component, platform)
@@ -0,0 +1,50 @@
1
+ module Jirafe
2
+ class Dashboard
3
+ class << self
4
+
5
+ def js_url(platform)
6
+ Jirafe::Asset.js_url_for(:dashboard, platform)
7
+ end
8
+
9
+ def css_url(platform)
10
+ Jirafe::Asset.css_url_for(:dashboard, platform)
11
+ end
12
+
13
+ def js_tag(api_token, app_id, version, locale, options = {})
14
+ target_id = options[:target_id] || "jirafe"
15
+ error_id = options[:error_id] || "messages"
16
+ error_html = options[:error_html] || default_error_html
17
+ timeout = options[:timeout] || 10000
18
+
19
+ <<-HTML
20
+ <script type='text/javascript' defer='defer'>
21
+ jirafe.jQuery('##{target_id}').jirafe({
22
+ api_url: '#{Jirafe.config.url}',
23
+ api_token: '#{api_token}',
24
+ app_id: '#{app_id}',
25
+ version: '#{version}',
26
+ locale: '#{locale}' });
27
+ setTimeout(function() {
28
+ if ($('mod-jirafe') == undefined) {
29
+ $('#{error_id}').insert ("#{error_html}");
30
+ }
31
+ }, #{timeout});
32
+ </script>
33
+ HTML
34
+ end
35
+
36
+ def default_error_html
37
+ <<-HTML
38
+ <ul class="messages">
39
+ <li class="error-msg">
40
+ We're unable to connect with the Jirafe service for the moment.
41
+ Please wait a few minutes and refresh this page later.
42
+ </li>
43
+ </ul>
44
+ HTML
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+
@@ -0,0 +1,8 @@
1
+ module Jirafe
2
+ LOCALES = {
3
+ :english => 'en_US',
4
+ :french => 'fr_FR',
5
+ :german => 'de_DE',
6
+ :japanese => 'ja_JA'
7
+ }
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Jirafe
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -6,7 +6,7 @@ describe Jirafe::Asset do
6
6
 
7
7
  context "given a component and platform" do
8
8
  let(:component) { "dashboard" }
9
- let(:platform) { "spree" }
9
+ let(:platform) { "spree_namespaced" }
10
10
 
11
11
  it { should == "https://test.jirafe.com/dashboard/js/spree_namespaced_ui.js" }
12
12
  end
@@ -0,0 +1,50 @@
1
+ require "spec_helper"
2
+
3
+ describe Jirafe::Dashboard do
4
+ describe ".js_url" do
5
+ subject { Jirafe::Dashboard.js_url(platform) }
6
+ let(:platform) { "spree_namespaced"}
7
+
8
+ it { should == "https://test.jirafe.com/dashboard/js/spree_namespaced_ui.js" }
9
+ end
10
+
11
+ describe ".css_url" do
12
+ subject { Jirafe::Dashboard.css_url(platform) }
13
+ let(:platform) { "spree"}
14
+
15
+ it { should == "https://test.jirafe.com/dashboard/css/spree_ui.css" }
16
+ end
17
+
18
+ describe ".js_tag" do
19
+ subject { Jirafe::Dashboard.js_tag(api_token, app_id, version, locale, options) }
20
+
21
+ context "given a valid API token, APP ID, platform version and locale" do
22
+ let(:api_token) { "MY_APP_TOKEN" }
23
+ let(:app_id) { 123 }
24
+ let(:version) { "myplatform-v1.0.1" }
25
+ let(:locale) { Jirafe::LOCALES[:english] }
26
+ let(:options) { { :error_html => "myerror" } }
27
+
28
+ let(:expected_html) do
29
+ <<-HTML
30
+ <script type='text/javascript' defer='defer'>
31
+ jirafe.jQuery('#jirafe').jirafe({
32
+ api_url: 'http://api.jirafe.dev/v1',
33
+ api_token: 'MY_APP_TOKEN',
34
+ app_id: '123',
35
+ version: 'myplatform-v1.0.1',
36
+ locale: 'en_US' });
37
+ setTimeout(function() {
38
+ if ($('mod-jirafe') == undefined) {
39
+ $('messages').insert ("myerror");
40
+ }
41
+ }, 10000);
42
+ </script>
43
+ HTML
44
+ end
45
+
46
+ it { should == expected_html }
47
+ end
48
+ end
49
+ end
50
+
@@ -11,12 +11,12 @@ describe Jirafe::Tracker do
11
11
  subject { Jirafe::Tracker.js_tag(json_data, {:id => 'myid'}) }
12
12
 
13
13
  context "given some JSON data" do
14
- let(:json_data) { { "foo" => "bar" }.to_json }
14
+ let(:json_data) { {}.to_json }
15
15
 
16
16
  let(:expected_html) do
17
17
  <<-HTML
18
18
  <script type='text/javascript' id='myid'>
19
- var jirafe = {"baseUrl":"#{Jirafe.config.data_path}","foo":"bar"};
19
+ var jirafe = {"baseUrl":"#{Jirafe.config.data_path}"};
20
20
  (function(){
21
21
  var d=document,g=d.createElement('script'),s=d.getElementsByTagName('script')[0];
22
22
  g.type='text/javascript',g.defer=g.async=true;g.src=d.location.protocol+'//#{Jirafe.config.tracking_path}/jirafe.js';
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jirafe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
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-09-17 00:00:00.000000000 Z
12
+ date: 2012-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -225,7 +225,9 @@ files:
225
225
  - lib/jirafe/callback/events/refund.rb
226
226
  - lib/jirafe/callback/jirafe_callback.rb
227
227
  - lib/jirafe/configuration.rb
228
+ - lib/jirafe/dashboard.rb
228
229
  - lib/jirafe/error.rb
230
+ - lib/jirafe/locales.rb
229
231
  - lib/jirafe/model.rb
230
232
  - lib/jirafe/resource/application.rb
231
233
  - lib/jirafe/resource/jirafe_resource.rb
@@ -267,6 +269,7 @@ files:
267
269
  - spec/jirafe/callback/event_spec.rb
268
270
  - spec/jirafe/callback/events/data_helper_spec.rb
269
271
  - spec/jirafe/configuration_spec.rb
272
+ - spec/jirafe/dashboard_spec.rb
270
273
  - spec/jirafe/jirafe_spec.rb
271
274
  - spec/jirafe/resource/application_spec.rb
272
275
  - spec/jirafe/resource/jirafe_resource_spec.rb
@@ -335,6 +338,7 @@ test_files:
335
338
  - spec/jirafe/callback/event_spec.rb
336
339
  - spec/jirafe/callback/events/data_helper_spec.rb
337
340
  - spec/jirafe/configuration_spec.rb
341
+ - spec/jirafe/dashboard_spec.rb
338
342
  - spec/jirafe/jirafe_spec.rb
339
343
  - spec/jirafe/resource/application_spec.rb
340
344
  - spec/jirafe/resource/jirafe_resource_spec.rb