localytics-ruby 0.0.3 → 0.0.4
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.
- checksums.yaml +8 -8
- data/lib/localytics.rb +2 -1
- data/lib/localytics/app.rb +39 -0
- data/test/localytics_test.rb +17 -0
- data/test/test_helper.rb +75 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDI0MmVjNmMxZjVmNzBlNTI4MTUxMGQ4MzQyNDk3OWM5OGJjMzhjOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDA0YmUzNDFhM2VmYzRlNDkxMTYyZWIwYmViNzdhNTYxZDVkZTBkMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzYwYzU3YTIxN2IxYjUxMjVlY2RlZGMwNjI1MGM0NDlmODZlMjY5MGIxNTZj
|
10
|
+
ZWRlYTA0NzNiMGI2ZGJjYThhZTM3YmVmMjJlZmUyYjJlMTAzMWVmZmUwNTlh
|
11
|
+
ZTUyYmIxZDEwNTBjMWQyMGQzZjJhYWY1MDFkYjA3OTNjODhjMzA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzNmMTlkMTljZDNmN2FjNDZmNTVkN2Q1ZWM4MzJiYTc5YzJmZjg5ZTk0OWRj
|
14
|
+
ODVlNDcwOGQxMjBiNzgwYWIxMTljYzgwNzViNGQzZTY5YjkwYjJiODM2Y2U4
|
15
|
+
ZTEyYzI1NjE0MjU5MWE4ZDM5MWUzMzQwYzQ2ZjA1NjgzMDBjNzc=
|
data/lib/localytics.rb
CHANGED
@@ -3,6 +3,7 @@ require 'json'
|
|
3
3
|
require 'base64'
|
4
4
|
require_relative 'localytics/profile'
|
5
5
|
require_relative 'localytics/push'
|
6
|
+
require_relative 'localytics/app'
|
6
7
|
|
7
8
|
module Localytics
|
8
9
|
class Error < StandardError
|
@@ -77,4 +78,4 @@ module Localytics
|
|
77
78
|
raise Error.new(exception.to_s, body['errors'])
|
78
79
|
end
|
79
80
|
|
80
|
-
end
|
81
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Localytics
|
2
|
+
class App
|
3
|
+
|
4
|
+
class << self
|
5
|
+
attr_accessor :app_id
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.show_app(app_id=nil, api_key=nil, api_secret=nil)
|
9
|
+
Localytics.request api_base, :get, url(app_id), api_key, api_secret
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.app_attributes(app_id=nil, api_key=nil, api_secret=nil)
|
13
|
+
Localytics.request api_base, :get, url(app_id, true), api_key, api_secret
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.show_apps(app_id=nil, api_key=nil, api_secret=nil)
|
17
|
+
Localytics.request api_base, :get, '', api_key, api_secret
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def self.api_base
|
22
|
+
"https://api.localytics.com/v1/apps"
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.url(app_id=nil, attributes=nil)
|
26
|
+
unless app_id ||= self.app_id
|
27
|
+
raise Error.new('No APP id provided')
|
28
|
+
end
|
29
|
+
|
30
|
+
url = "/#{app_id}"
|
31
|
+
|
32
|
+
if attributes
|
33
|
+
url = url + "/attributes"
|
34
|
+
end
|
35
|
+
|
36
|
+
return url
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/test/localytics_test.rb
CHANGED
@@ -71,3 +71,20 @@ test 'send push' do |mock|
|
|
71
71
|
Localytics::Push.push_to_customers [{alert: 'message', target: 1}], 'app_id'
|
72
72
|
end
|
73
73
|
|
74
|
+
test 'show apps' do |mock|
|
75
|
+
mock.expects(:get).once.with('https://api.localytics.com/v1/apps', {}).returns(test_response(test_show_apps, 200))
|
76
|
+
apps = Localytics::App.show_apps
|
77
|
+
assert_equal 'App Name', apps[:_embedded][:apps][0][:name]
|
78
|
+
end
|
79
|
+
|
80
|
+
test 'show app' do |mock|
|
81
|
+
mock.expects(:get).once.with('https://api.localytics.com/v1/apps/umdois', {}).returns(test_response(test_show_app, 200))
|
82
|
+
app = Localytics::App.show_app('umdois')
|
83
|
+
assert_equal 'App Name', app[:name]
|
84
|
+
end
|
85
|
+
|
86
|
+
test 'show app attributes' do |mock|
|
87
|
+
mock.expects(:get).once.with('https://api.localytics.com/v1/apps/umdois/attributes', {}).returns(test_response(test_apps_attributes, 200))
|
88
|
+
events = Localytics::App.app_attributes('umdois')
|
89
|
+
assert_equal 'Clicked Link', events[:events][0][:event_name]
|
90
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -83,6 +83,33 @@ def test_profiles(params={})
|
|
83
83
|
}.merge(params)
|
84
84
|
end
|
85
85
|
|
86
|
+
def test_show_apps(params={})
|
87
|
+
{
|
88
|
+
"_embedded": {
|
89
|
+
"apps": [
|
90
|
+
{
|
91
|
+
"name": "App Name",
|
92
|
+
"app_id": "umdois",
|
93
|
+
"created_at": "2012-04-10T04:07:13Z",
|
94
|
+
"_links": {
|
95
|
+
"self": { "href": "/v1/apps/umdois" },
|
96
|
+
"apps": { "href": "/v1/apps" },
|
97
|
+
"query": {
|
98
|
+
"templated": true,
|
99
|
+
"href": "/v1/apps/umdois/query{?app_id,metrics,dimensions,conditions,limit,order,days,comment,translate}"
|
100
|
+
},
|
101
|
+
"root": { "href": "/v1" }
|
102
|
+
}
|
103
|
+
}
|
104
|
+
]
|
105
|
+
},
|
106
|
+
"_links": {
|
107
|
+
"self": { "href": "/v1/apps" },
|
108
|
+
"root": { "href": "/v1" }
|
109
|
+
}
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
86
113
|
def profile_params
|
87
114
|
{
|
88
115
|
attributes: {
|
@@ -93,6 +120,53 @@ def profile_params
|
|
93
120
|
}
|
94
121
|
end
|
95
122
|
|
123
|
+
|
124
|
+
def test_apps_attributes()
|
125
|
+
{
|
126
|
+
"events": [
|
127
|
+
{
|
128
|
+
"event_name": "Clicked Link",
|
129
|
+
"attributes": [ "link_text", "link_target", "link_placement" ],
|
130
|
+
"high_cardinality_attributes": [ "link_text" ]
|
131
|
+
},
|
132
|
+
{
|
133
|
+
"event_name": "Added to Cart",
|
134
|
+
"attributes": [ "item_name", "item_id" ],
|
135
|
+
"high_cardinality_attributes": [ "item_name", "item_id" ]
|
136
|
+
}
|
137
|
+
],
|
138
|
+
"_links": {
|
139
|
+
"app": { "href": "/v1/apps/umdois" },
|
140
|
+
"root": { "href": "/v1" }
|
141
|
+
}
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_show_app()
|
146
|
+
app_info = test_show_apps.delete(:_embedded)[:apps][0]
|
147
|
+
|
148
|
+
more_info = {
|
149
|
+
"stats": {
|
150
|
+
"sessions": 52291,
|
151
|
+
"closes": 46357,
|
152
|
+
"users": 7008,
|
153
|
+
"events": 865290,
|
154
|
+
"data_points": 963938,
|
155
|
+
"platforms": ["HTML5"],
|
156
|
+
"client_libraries": ["html5_2.6", "html5_2.5", "html5_2.4"],
|
157
|
+
"begin_date": "2013-08-10",
|
158
|
+
"end_date": "2013-09-10"
|
159
|
+
},
|
160
|
+
"icon_url": "https://example.com/app-icon.png",
|
161
|
+
"custom_dimensions": {
|
162
|
+
"custom_0_dimension": "Blood Type",
|
163
|
+
"custom_1_dimension": "Moon Phase"
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
167
|
+
app_info.merge(more_info)
|
168
|
+
end
|
169
|
+
|
96
170
|
def bad_request
|
97
171
|
json = {
|
98
172
|
'errors' => [{
|
@@ -100,4 +174,4 @@ def bad_request
|
|
100
174
|
}]
|
101
175
|
}
|
102
176
|
RestClient::Exception.new(test_response(json, 404), 400)
|
103
|
-
end
|
177
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: localytics-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobuy development team
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-10-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -62,6 +62,7 @@ extra_rdoc_files: []
|
|
62
62
|
files:
|
63
63
|
- lib/localytics-ruby.rb
|
64
64
|
- lib/localytics.rb
|
65
|
+
- lib/localytics/app.rb
|
65
66
|
- lib/localytics/profile.rb
|
66
67
|
- lib/localytics/push.rb
|
67
68
|
- test/localytics_test.rb
|