jirafe 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rbenv-version +1 -1
- data/Gemfile +5 -0
- data/README.md +22 -0
- data/jirafe.gemspec +1 -1
- data/lib/jirafe.rb +12 -1
- data/lib/jirafe/callback/event.rb +0 -2
- data/lib/jirafe/callback/jirafe_callback.rb +3 -3
- data/lib/jirafe/resource/jirafe_resource.rb +5 -5
- data/lib/jirafe/version.rb +3 -0
- data/spec/jirafe/callback/event_spec.rb +1 -1
- data/spec/jirafe/resource/sites/dashboard_spec.rb +16 -3
- data/spec/jirafe/resource/sites/period_data_spec.rb +2 -2
- data/spec/jirafe/resource/sites/segments_carts_spec.rb +4 -4
- data/spec/jirafe/resource/sites/segments_sales_spec.rb +10 -4
- metadata +2 -1
data/.rbenv-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.9.3-
|
1
|
+
1.9.3-p194
|
data/Gemfile
CHANGED
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
|
data/jirafe.gemspec
CHANGED
data/lib/jirafe.rb
CHANGED
@@ -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
|
16
|
+
autoload :VERSION, "jirafe/version.rb"
|
6
17
|
autoload :Configuration, "jirafe/configuration.rb"
|
7
18
|
autoload :Error, "jirafe/error.rb"
|
8
19
|
module Resource
|
@@ -11,13 +11,13 @@ module Jirafe
|
|
11
11
|
Jirafe.config.logger
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def callback_url
|
15
15
|
"/cmb"
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def notify(site_id)
|
19
19
|
raise Jirafe::Error::MissingSiteId if site_id.nil?
|
20
|
-
response = post(
|
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
|
17
|
-
|
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.
|
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.
|
180
|
+
(attrs || []).inject({}) do |hash, attr|
|
181
181
|
hash[attr] = self.send(attr)
|
182
182
|
hash
|
183
183
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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.
|
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
|