jirafe 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- 1.9.3-p125
1
+ 1.9.3-p194
data/Gemfile CHANGED
@@ -1,6 +1,11 @@
1
1
  source :rubygems
2
2
  gemspec
3
3
 
4
+ group :test do
5
+ gem "rake"
6
+ gem "json_pure", :require => false
7
+ end
8
+
4
9
  group :debug do
5
10
  gem "ffi", "1.1.0"
6
11
  gem "ruby-debug19"
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Jirafe Analytics Ruby Client
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/jirafe/jirafe-ruby-client.png)](http://travis-ci.org/jirafe/jirafe-ruby-client)
4
+
3
5
  This is the official [Jirafe](http://jirafe.com/) rubygem.
4
6
  It fully wraps Jirafe's [API](http://api.jirafe.com).
5
7
 
@@ -54,6 +56,26 @@ To get all sites associated with this application:
54
56
  application.sites
55
57
  ```
56
58
 
59
+ To send order data events:
60
+
61
+ ```ruby
62
+ site = application.sites.first
63
+ Jirafe::Callback::Event.notify(site.identifier)
64
+
65
+ # Jirafe will send a GET request to your site's store_api_url with a confirmToken parameter
66
+ token = params['confirmToken']
67
+
68
+ event = Jirafe::Callback::Events::Order.new(:version => 1,
69
+ :action => :create,
70
+ :identifier => 1,
71
+ :grand_total => 100.00,
72
+ :sub_total => 80.00,
73
+ :tax_amount => 20.00,
74
+ :discount_amount => 0.00,
75
+ :status => :pending)
76
+ Jirafe::Callback::Event.send(site.identifier, token, [event])
77
+ ```
78
+
57
79
  ## Development
58
80
 
59
81
  Specs
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "jirafe"
3
+ require "jirafe/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "jirafe"
@@ -1,8 +1,19 @@
1
1
  require "httparty"
2
2
  require "logger"
3
+ unless Object.const_defined?(:JSON)
4
+ begin
5
+ require 'json_pure'
6
+ rescue LoadError
7
+ begin
8
+ require 'json-ruby'
9
+ rescue LoadError
10
+ require 'json'
11
+ end
12
+ end
13
+ end
3
14
 
4
15
  module Jirafe
5
- VERSION = "0.1.0"
16
+ autoload :VERSION, "jirafe/version.rb"
6
17
  autoload :Configuration, "jirafe/configuration.rb"
7
18
  autoload :Error, "jirafe/error.rb"
8
19
  module Resource
@@ -1,5 +1,3 @@
1
- require "json"
2
-
3
1
  module Jirafe
4
2
  module Callback
5
3
  class Event < JirafeCallback
@@ -11,13 +11,13 @@ module Jirafe
11
11
  Jirafe.config.logger
12
12
  end
13
13
 
14
- def establish_callback_url
14
+ def callback_url
15
15
  "/cmb"
16
16
  end
17
17
 
18
- def establish(site_id)
18
+ def notify(site_id)
19
19
  raise Jirafe::Error::MissingSiteId if site_id.nil?
20
- response = post(establish_callback_url, {:body => {"siteId" => site_id }})
20
+ response = post(callback_url, {:body => {"siteId" => site_id }})
21
21
  check_response_for_exception(response)
22
22
  true
23
23
  end
@@ -13,8 +13,8 @@ module Jirafe
13
13
  end
14
14
 
15
15
  def attributes(attrs = {})
16
- attrs.each do |attr|
17
- attr_name, options = attr
16
+ return @attributes if @attributes && attrs === {}
17
+ attrs.each_pair do |attr_name, options|
18
18
  attr_accessor attr_name
19
19
  if options.include?(:identifier)
20
20
  define_method attr_name do
@@ -136,7 +136,7 @@ module Jirafe
136
136
  end
137
137
 
138
138
  def attributes
139
- self.class.attributes.keys.inject({}) do |hash, attr|
139
+ self.class.attributes.inject({}) do |hash, attr|
140
140
  hash[attr] = self.send(attr)
141
141
  hash
142
142
  end
@@ -174,10 +174,10 @@ module Jirafe
174
174
  end
175
175
 
176
176
  def attributes_for_change(key)
177
- attrs = self.class.attributes.select do |attribute|
177
+ attrs = self.class.attributes.keys.select do |attribute|
178
178
  self.class.attributes[attribute].include?(key)
179
179
  end
180
- attrs.keys.inject({}) do |hash, attr|
180
+ (attrs || []).inject({}) do |hash, attr|
181
181
  hash[attr] = self.send(attr)
182
182
  hash
183
183
  end
@@ -0,0 +1,3 @@
1
+ module Jirafe
2
+ VERSION = "0.2.0"
3
+ end
@@ -31,7 +31,7 @@ describe Jirafe::Callback::Event do
31
31
 
32
32
  use_app_token(app)
33
33
  @site.create
34
- Jirafe::Callback::Event.establish(@site.identifier)
34
+ Jirafe::Callback::Event.notify(@site.identifier)
35
35
  while @query_capture.empty?
36
36
  sleep 0.1
37
37
  end
@@ -12,9 +12,22 @@ describe Jirafe::Resource::Sites::Dashboard do
12
12
 
13
13
  context "after making a request" do
14
14
  describe "#observe" do
15
- subject { request.observe }
16
-
17
- its(:keys) { should == ["sales", "visits", "carts", "customers", "referrer", "keyword", "origin", "product", "category", "abandoned_product", "abandoned_category", "metrics"] }
15
+ subject { request.observe.keys.sort }
16
+
17
+ it { should == [
18
+ "abandoned_category",
19
+ "abandoned_product",
20
+ "carts",
21
+ "category",
22
+ "customers",
23
+ "keyword",
24
+ "metrics",
25
+ "origin",
26
+ "product",
27
+ "referrer",
28
+ "sales",
29
+ "visits"]
30
+ }
18
31
  end
19
32
 
20
33
  describe "#tracked_customers" do
@@ -12,9 +12,9 @@ describe Jirafe::Resource::Sites::PeriodData do
12
12
 
13
13
  context "after making a request" do
14
14
  describe "#observe" do
15
- subject { request.observe }
15
+ subject { request.observe.keys.sort }
16
16
 
17
- its(:keys) { should == ["sales", "visits", "carts"] }
17
+ it { should == ["carts", "sales", "visits"] }
18
18
  end
19
19
  end
20
20
  end
@@ -13,15 +13,15 @@ describe Jirafe::Resource::Sites::SegmentsCarts do
13
13
 
14
14
  context "after making a request" do
15
15
  describe "#observe" do
16
- subject { request.observe }
16
+ subject { request.observe.keys.sort }
17
17
 
18
- its(:keys) { should == ["product", "category"] }
18
+ it { should == ["category", "product"] }
19
19
  end
20
20
 
21
21
  describe "#highlights" do
22
- subject { request.highlights }
22
+ subject { request.highlights.keys.sort }
23
23
 
24
- its(:keys) { should == ["increase", "decrease"] }
24
+ it { should == ["decrease", "increase"] }
25
25
  end
26
26
  end
27
27
  end
@@ -13,15 +13,21 @@ describe Jirafe::Resource::Sites::SegmentsSales do
13
13
 
14
14
  context "after making a request" do
15
15
  describe "#observe" do
16
- subject { request.observe }
16
+ subject { request.observe.keys.sort }
17
17
 
18
- its(:keys) { should == ["origin", "search_query", "referrer_name", "product", "category"] }
18
+ it { should == [
19
+ "category",
20
+ "origin",
21
+ "product",
22
+ "referrer_name",
23
+ "search_query"]
24
+ }
19
25
  end
20
26
 
21
27
  describe "#highlights" do
22
- subject { request.highlights }
28
+ subject { request.highlights.keys.sort }
23
29
 
24
- its(:keys) { should == ["increase", "decrease"] }
30
+ it { should == ["decrease", "increase"] }
25
31
  end
26
32
  end
27
33
  end
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.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -254,6 +254,7 @@ files:
254
254
  - lib/jirafe/resource/time_series.rb
255
255
  - lib/jirafe/resource/user.rb
256
256
  - lib/jirafe/resource/version.rb
257
+ - lib/jirafe/version.rb
257
258
  - spec/jirafe/callback/event_spec.rb
258
259
  - spec/jirafe/configuration_spec.rb
259
260
  - spec/jirafe/jirafe_spec.rb