growthpush 0.0.0 → 0.1.0
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.
- data/lib/growth_push.rb +239 -0
- data/lib/growthpush/client.rb +85 -0
- data/lib/growthpush/event.rb +88 -0
- data/lib/growthpush/growth_push_exception.rb +21 -0
- data/lib/growthpush/http_client.rb +52 -0
- data/lib/growthpush/http_response.rb +32 -0
- data/lib/growthpush/tag.rb +86 -0
- data/lib/growthpush/version.rb +3 -0
- data/spec/growthpush_spec.rb +290 -0
- data/spec/spec_helper.rb +1 -0
- metadata +109 -14
- data/bin/growthpush +0 -1
- data/lib/growthpush.rb +0 -3
data/lib/growth_push.rb
ADDED
@@ -0,0 +1,239 @@
|
|
1
|
+
require 'growthpush/version'
|
2
|
+
require 'growthpush/client'
|
3
|
+
require 'growthpush/event'
|
4
|
+
require 'growthpush/tag'
|
5
|
+
require 'growthpush/growth_push_exception'
|
6
|
+
require 'growthpush/http_client'
|
7
|
+
require 'growthpush/http_response'
|
8
|
+
|
9
|
+
#
|
10
|
+
# GrowthPush Class (GrowthPush クラス)
|
11
|
+
#
|
12
|
+
# @version 0.1.0
|
13
|
+
# @!attribute [r] application_id
|
14
|
+
# @return [String] application id (アプリID)
|
15
|
+
# @!attribute [r] secret
|
16
|
+
# @return [String] secret key (アプリのシークレットキー)
|
17
|
+
# @!attribute [r] environment
|
18
|
+
# @return [String] environment (環境設定)
|
19
|
+
#
|
20
|
+
class GrowthPush
|
21
|
+
OS_IOS = 'ios';
|
22
|
+
OS_ANDROID = 'android';
|
23
|
+
|
24
|
+
ENVIRONMENT_PRODUCTION = 'production';
|
25
|
+
ENVIRONMENT_DEVELOPMENT = 'development';
|
26
|
+
|
27
|
+
attr_reader :application_id
|
28
|
+
attr_reader :secret
|
29
|
+
attr_reader :environment
|
30
|
+
|
31
|
+
#
|
32
|
+
# initializer (イニシャライザ)
|
33
|
+
# @param [Integer] application_id application id (アプリID)
|
34
|
+
# @param [String] secret secret key (アプリのシークレットキー)
|
35
|
+
# @param [String] environment environment (環境設定)
|
36
|
+
#
|
37
|
+
def initialize(application_id, secret, environment= GrowthPush::ENVIRONMENT_PRODUCTION)
|
38
|
+
@application_id = application_id
|
39
|
+
@secret = secret
|
40
|
+
@environment = environment
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# create client (クライアントを作成する)
|
45
|
+
# @param [String] token device token (デバイス・トークン)
|
46
|
+
# @param [String] os os name (OS名)
|
47
|
+
# @return [Client] client object (クライアント)
|
48
|
+
#
|
49
|
+
def create_client(token, os)
|
50
|
+
client = Client.new(token, os)
|
51
|
+
@client = client
|
52
|
+
return client.save(self)
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# create event (イベントを作成する)
|
57
|
+
# @overload create_event(name)
|
58
|
+
# @param [String] name event name (イベント名)
|
59
|
+
# @raise [GrowthPushException] exception (例外)
|
60
|
+
# @return [Event] event (イベント)
|
61
|
+
# @overload create_event(map)
|
62
|
+
# @param [Hash] map event hash (イベントのハッシュ)
|
63
|
+
# @raise [GrowthPushException] exception (例外)
|
64
|
+
# @return [Event] event (イベント)
|
65
|
+
# @overload create_event(name, value)
|
66
|
+
# @param [String] name event name (イベント名)
|
67
|
+
# @param [String] value optional info of event (イベントの追加情報)
|
68
|
+
# @raise [GrowthPushException] exception (例外)
|
69
|
+
# @return [Event] event (イベント)
|
70
|
+
# @overload create_event(token, name)
|
71
|
+
# @param [String] token device token (デバイス・トークン)
|
72
|
+
# @param [String] name event name (イベント名)
|
73
|
+
# @raise [GrowthPushException] exception (例外)
|
74
|
+
# @return [Event] event (イベント)
|
75
|
+
# @overload create_event(client, name)
|
76
|
+
# @param [Client] client Client object (クライアント)
|
77
|
+
# @param [String] name event name (イベント名)
|
78
|
+
# @raise [GrowthPushException] exception (例外)
|
79
|
+
# @return [Event] event (イベント)
|
80
|
+
# @overload create_event(token, name, value)
|
81
|
+
# @param [String] token device token (デバイス・トークン)
|
82
|
+
# @param [String] name event name (イベント名)
|
83
|
+
# @param [String] value optional info of event (イベントの追加情報)
|
84
|
+
# @raise [GrowthPushException]exception (例外)
|
85
|
+
# @return [Event] event (イベント)
|
86
|
+
# @overload create_event(client, name, value)
|
87
|
+
# @param [Client] client Client object (クライアント)
|
88
|
+
# @param [String] name event name (イベント名)
|
89
|
+
# @param [String] value optional info of event (イベントの追加情報)
|
90
|
+
# @raise [GrowthPushException] exception (例外)
|
91
|
+
# @return [Event] event (イベント)
|
92
|
+
#
|
93
|
+
def create_event(*args)
|
94
|
+
case args.length
|
95
|
+
when 1
|
96
|
+
if args[0].kind_of? Hash
|
97
|
+
create_event_1(args[0])
|
98
|
+
else
|
99
|
+
create_event_2(args[0])
|
100
|
+
end
|
101
|
+
when 2
|
102
|
+
if args[0].kind_of? String
|
103
|
+
if !@client.nil?
|
104
|
+
create_event_2(args[0],args[1])
|
105
|
+
else
|
106
|
+
create_event_3(args[0],args[1])
|
107
|
+
end
|
108
|
+
elsif args[0].kind_of? Client
|
109
|
+
create_event_3(args[0],args[1])
|
110
|
+
else
|
111
|
+
raise ArgumentError
|
112
|
+
end
|
113
|
+
when 3
|
114
|
+
create_event_3(args[0],args[1],args[2])
|
115
|
+
else
|
116
|
+
raise ArgumentError
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def create_event_3(client, name, value=nil)
|
121
|
+
|
122
|
+
if !client.instance_of? Client
|
123
|
+
client = Client.new(client)
|
124
|
+
end
|
125
|
+
|
126
|
+
@client = client
|
127
|
+
|
128
|
+
return create_event_2(name, value)
|
129
|
+
end
|
130
|
+
private :create_event_3
|
131
|
+
|
132
|
+
def create_event_2(name, value = nil)
|
133
|
+
event = Event.new(@client, name, value)
|
134
|
+
return event.save(self)
|
135
|
+
end
|
136
|
+
private :create_event_2
|
137
|
+
|
138
|
+
def create_event_1(map={})
|
139
|
+
if @client.nil?
|
140
|
+
raise GrowthPushException.new('Client not found')
|
141
|
+
end
|
142
|
+
|
143
|
+
return create_event_2(map.keys[0].to_s, map.values[0])
|
144
|
+
end
|
145
|
+
private :create_event_1
|
146
|
+
|
147
|
+
#
|
148
|
+
# create tag (タグを作成する)
|
149
|
+
# @overload create_tag(name)
|
150
|
+
# @param [String] name tag name (タグ名)
|
151
|
+
# @raise [GrowthPushException] exception (例外)
|
152
|
+
# @return [Tag] tag (タグ)
|
153
|
+
# @overload create_tag(map)
|
154
|
+
# @param [Hash] map tag hash (タグのハッシュ)
|
155
|
+
# @raise [GrowthPushException] exception (例外)
|
156
|
+
# @return [Tag] tag (タグ)
|
157
|
+
# @overload create_tag(name, value)
|
158
|
+
# @param [String] name tag name (タグ名)
|
159
|
+
# @param [String] value tag value (タグの値)
|
160
|
+
# @raise [GrowthPushException] exception (例外)
|
161
|
+
# @return [Tag] tag (タグ)
|
162
|
+
# @overload create_tag(token, name)
|
163
|
+
# @param [String] token device token (デバイス・トークン)
|
164
|
+
# @param [String] name tag name (タグ名)
|
165
|
+
# @raise [GrowthPushException] exception (例外)
|
166
|
+
# @return [Tag] tag (タグ)
|
167
|
+
# @overload create_tag(client, name)
|
168
|
+
# @param [Client] client Client object (クライアント)
|
169
|
+
# @param [String] name tag name (タグ名)
|
170
|
+
# @raise [GrowthPushException] exception (例外)
|
171
|
+
# @return [Tag] tag (タグ)
|
172
|
+
# @overload create_tag(token, name, value)
|
173
|
+
# @param [String] token device token (デバイス・トークン)
|
174
|
+
# @param [String] name tag name (タグ名)
|
175
|
+
# @param [String] value tag value (タグの値)
|
176
|
+
# @raise [GrowthPushException] exception (例外)
|
177
|
+
# @return [Tag] tag (タグ)
|
178
|
+
# @overload create_tag(client, name, value)
|
179
|
+
# @param [Client] client Client object (クライアント)
|
180
|
+
# @param [String] name tag name (タグ名)
|
181
|
+
# @param [String] value value (タグの値)
|
182
|
+
# @raise [GrowthPushException] exception (例外)
|
183
|
+
# @return [Tag] tag (タグ)
|
184
|
+
#
|
185
|
+
def create_tag(*args)
|
186
|
+
case args.length
|
187
|
+
when 1
|
188
|
+
if args[0].kind_of? Hash
|
189
|
+
create_tag_1(args[0])
|
190
|
+
else
|
191
|
+
create_tag_2(args[0])
|
192
|
+
end
|
193
|
+
when 2
|
194
|
+
if args[0].kind_of? String
|
195
|
+
if !@client.nil?
|
196
|
+
create_tag_2(args[0],args[1])
|
197
|
+
else
|
198
|
+
create_tag_3(args[0],args[1])
|
199
|
+
end
|
200
|
+
elsif args[0].kind_of? Client
|
201
|
+
create_tag_3(args[0],args[1])
|
202
|
+
else
|
203
|
+
raise ArgumentError
|
204
|
+
end
|
205
|
+
when 3
|
206
|
+
create_tag_3(args[0],args[1],args[2])
|
207
|
+
else
|
208
|
+
raise ArgumentError
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def create_tag_3(client, name, value=nil)
|
213
|
+
|
214
|
+
if !client.instance_of? Client
|
215
|
+
client = Client.new(client)
|
216
|
+
end
|
217
|
+
|
218
|
+
@client = client
|
219
|
+
|
220
|
+
return create_tag_2(name, value)
|
221
|
+
end
|
222
|
+
private :create_tag_3
|
223
|
+
|
224
|
+
def create_tag_2(name, value=nil)
|
225
|
+
tag = Tag.new(@client, name, value)
|
226
|
+
return tag.save(self)
|
227
|
+
end
|
228
|
+
private :create_tag_2
|
229
|
+
|
230
|
+
def create_tag_1(map={})
|
231
|
+
if @client.nil?
|
232
|
+
raise GrowthPushException.new('Client not found')
|
233
|
+
end
|
234
|
+
|
235
|
+
return create_tag_2(map.keys[0].to_s, map.values[0])
|
236
|
+
end
|
237
|
+
private :create_tag_1
|
238
|
+
|
239
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#
|
2
|
+
# Client Class (クライント クラス)
|
3
|
+
#
|
4
|
+
# @!attribute [r] id
|
5
|
+
# @return [String] client id (クライアントID)
|
6
|
+
# @!attribute [r] application_id
|
7
|
+
# @return [String] application id (アプリID)
|
8
|
+
# @!attribute [r] code
|
9
|
+
# @return [String] authentication key (認証キー)
|
10
|
+
# @!attribute [r] token
|
11
|
+
# @return [String] device token (デバイス・トークン)
|
12
|
+
# @!attribute [r] os
|
13
|
+
# @return [String] os name (OS名)
|
14
|
+
# @!attribute [r] environment
|
15
|
+
# @return [String] environment (環境設定)
|
16
|
+
# @!attribute [r] status
|
17
|
+
# @return [String] status (状態)
|
18
|
+
# @!attribute [r] created
|
19
|
+
# @return [String] created datetime (作成日時)
|
20
|
+
#
|
21
|
+
class Client
|
22
|
+
|
23
|
+
attr_reader :id
|
24
|
+
attr_reader :application_id
|
25
|
+
attr_reader :code
|
26
|
+
attr_reader :token
|
27
|
+
attr_reader :os
|
28
|
+
attr_reader :environment
|
29
|
+
attr_reader :status
|
30
|
+
attr_reader :created
|
31
|
+
|
32
|
+
#
|
33
|
+
# initializer (イニシャライザ)
|
34
|
+
# @param [String] token device token (デバイス・トークン)
|
35
|
+
# @param [String] os os name (OS名)
|
36
|
+
#
|
37
|
+
def initialize(token, os=nil)
|
38
|
+
@token = token
|
39
|
+
@os = os
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# save client (クライアントを登録する)
|
44
|
+
# @param [GrowthPush] growth_push GrowthPush object (GrowthPushオブジェクト)
|
45
|
+
# @raise [GrowthPushException] exception (例外)
|
46
|
+
# @return [Client] client (クライアント)
|
47
|
+
#
|
48
|
+
def save(growth_push)
|
49
|
+
|
50
|
+
begin
|
51
|
+
http_response = HttpClient.instance.post('clients',
|
52
|
+
{
|
53
|
+
'applicationId' => growth_push.application_id,
|
54
|
+
'secret' => growth_push.secret,
|
55
|
+
'token' => self.token,
|
56
|
+
'os' => self.os,
|
57
|
+
'environment' => growth_push.environment
|
58
|
+
}
|
59
|
+
)
|
60
|
+
rescue GrowthPushException => ex
|
61
|
+
raise GrowthPushException.new('Failed to save client: ' << ex.message, ex.code)
|
62
|
+
end
|
63
|
+
|
64
|
+
self.attributes = http_response.body
|
65
|
+
|
66
|
+
return self
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# set attributes (属性をセットする)
|
71
|
+
# @param [Hash] attributes attributes (属性)
|
72
|
+
#
|
73
|
+
def attributes=(attributes)
|
74
|
+
@id = attributes['id']
|
75
|
+
@application_id = attributes['applicationId']
|
76
|
+
@code = attributes['code']
|
77
|
+
@token = attributes['token']
|
78
|
+
@os = attributes['os']
|
79
|
+
@environment = attributes['environment']
|
80
|
+
@status = attributes['status']
|
81
|
+
@created = attributes['created']
|
82
|
+
end
|
83
|
+
private :attributes=
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
#
|
2
|
+
# Event Class (イベント クラス)
|
3
|
+
#
|
4
|
+
# @!attribute [r] name
|
5
|
+
# @return [String] event name (イベント名)
|
6
|
+
# @!attribute [r] goal_id
|
7
|
+
# @return [String] goal id (ゴールID)
|
8
|
+
# @!attribute [r] timestamp
|
9
|
+
# @return [String] time stamp (タイム・スタンプ)
|
10
|
+
# @!attribute [r] client_id
|
11
|
+
# @return [String] client id (クライアントID)
|
12
|
+
# @!attribute [r] value
|
13
|
+
# @return [String] optional info of event (イベントの追加情報)
|
14
|
+
#
|
15
|
+
class Event
|
16
|
+
|
17
|
+
attr_reader :name
|
18
|
+
attr_reader :goal_id
|
19
|
+
attr_reader :timestamp
|
20
|
+
attr_reader :client_id
|
21
|
+
attr_reader :value
|
22
|
+
|
23
|
+
#
|
24
|
+
# initializer (イニシャライザ)
|
25
|
+
# @param [Client] client Client object (クライアント)
|
26
|
+
# @param [String] name event name (イベント名)
|
27
|
+
# @param [String] value optional info of event (イベントの追加情報)
|
28
|
+
#
|
29
|
+
def initialize(client, name, value=nil)
|
30
|
+
@client = client
|
31
|
+
@name = name
|
32
|
+
@value = value
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# save event (イベントを登録する)
|
37
|
+
# @param [GrowthPush] growth_push GrowthPush object (GrowthPushオブジェクト)
|
38
|
+
# @raise [GrowthPushException] exception (例外)
|
39
|
+
# @return [Event] event (イベント)
|
40
|
+
#
|
41
|
+
def save(growth_push)
|
42
|
+
begin
|
43
|
+
if @client.id && @client.code
|
44
|
+
http_response = HttpClient.instance.post('events',
|
45
|
+
{
|
46
|
+
'clientId' => @client.id,
|
47
|
+
'code' => @client.code,
|
48
|
+
'name' => self.name,
|
49
|
+
'value' => self.value
|
50
|
+
}
|
51
|
+
)
|
52
|
+
elsif @client.token
|
53
|
+
http_response = HttpClient.instance.post('events',
|
54
|
+
{
|
55
|
+
'applicationId' => growth_push.application_id,
|
56
|
+
'secret' => growth_push.secret,
|
57
|
+
'token' => @client.token,
|
58
|
+
'name' => self.name,
|
59
|
+
'value' => self.value,
|
60
|
+
}
|
61
|
+
)
|
62
|
+
else
|
63
|
+
raise GrowthPushException.new('Invalid client')
|
64
|
+
end
|
65
|
+
|
66
|
+
rescue GrowthPushException => ex
|
67
|
+
raise GrowthPushException.new('Failed to save event: ' << ex.message, ex.code)
|
68
|
+
end
|
69
|
+
|
70
|
+
body = http_response.body
|
71
|
+
self.attributes = body
|
72
|
+
|
73
|
+
return self
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# set attributes (属性をセットする)
|
78
|
+
# @param [Hash] attributes attributes (属性)
|
79
|
+
#
|
80
|
+
def attributes=(attributes)
|
81
|
+
@goal_id = attributes['goalId'];
|
82
|
+
@timestamp = attributes['timestamp'];
|
83
|
+
@client_id = attributes['clientId'];
|
84
|
+
@value = attributes['value'];
|
85
|
+
end
|
86
|
+
private :attributes=
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#
|
2
|
+
# GrowthPush Exception Class (GrowthPush 例外クラス)
|
3
|
+
#
|
4
|
+
# @!attribute [r] code
|
5
|
+
# @return [String] error code (エラー・コード)
|
6
|
+
#
|
7
|
+
class GrowthPushException < Exception
|
8
|
+
|
9
|
+
attr_reader :code
|
10
|
+
|
11
|
+
#
|
12
|
+
# initializer (イニシャライザ)
|
13
|
+
# @param [String] message error message (エラー・メッセージ)
|
14
|
+
# @param [Integer] code error code (エラー・コード)
|
15
|
+
#
|
16
|
+
def initialize(message, code=nil)
|
17
|
+
super(message)
|
18
|
+
@code = code
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday_middleware'
|
4
|
+
|
5
|
+
#
|
6
|
+
# HTTP Client Class (HTTPクライアント クラス)
|
7
|
+
#
|
8
|
+
class HttpClient
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
ENDPOINT = 'https://api.growthpush.com/'
|
12
|
+
|
13
|
+
#
|
14
|
+
# initializer (イニシャライザ)
|
15
|
+
#
|
16
|
+
def initialize
|
17
|
+
@conn = Faraday.new(:url => ENDPOINT) do |faraday|
|
18
|
+
faraday.request :url_encoded # form-encode POST params
|
19
|
+
faraday.response :logger # log requests to STDOUT
|
20
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
21
|
+
faraday.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# post (POSTする)
|
27
|
+
# @param [String] api api identifier (API識別子)
|
28
|
+
# @param [Hash] params http request parameters (HTTPリクエスト パラメータ)
|
29
|
+
# @param [Integer] version api version (APIバージョン)
|
30
|
+
# @raise [GrowthPushException] exception (例外)
|
31
|
+
# @return [HttpResponse] http response (HTTPレスポンス)
|
32
|
+
#
|
33
|
+
def post(api,params,version = 1)
|
34
|
+
url = "/#{version}/#{api}"
|
35
|
+
|
36
|
+
response = @conn.post do |req|
|
37
|
+
req.url url
|
38
|
+
req.headers['Content-Type'] = 'application/json'
|
39
|
+
req.params = params
|
40
|
+
end
|
41
|
+
|
42
|
+
http_response = HttpResponse.new(response)
|
43
|
+
|
44
|
+
if !http_response.ok?
|
45
|
+
body = http_response.body
|
46
|
+
raise GrowthPushException.new(body['message'], response.status)
|
47
|
+
end
|
48
|
+
|
49
|
+
http_response
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# HTTP Response Class (HTTPレスポンス クラス)
|
3
|
+
#
|
4
|
+
# @!attribute [r] header
|
5
|
+
# @return [Hash] http response headers (HTTPレスポンス・ヘッダ)
|
6
|
+
# @!attribute [r] body
|
7
|
+
# @return [Hash] http response body (HTTPレスポンス・ボディ)
|
8
|
+
#
|
9
|
+
class HttpResponse
|
10
|
+
|
11
|
+
attr_reader :header
|
12
|
+
attr_reader :body
|
13
|
+
|
14
|
+
#
|
15
|
+
# initializer (イニシャライザ)
|
16
|
+
# @param [Faraday::Response] response http response (HTTPレスポンス)
|
17
|
+
#
|
18
|
+
def initialize(response)
|
19
|
+
@response = response
|
20
|
+
@header = response.headers
|
21
|
+
@body = response.body
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# return result of http request (HTTPリクエストの成否を返す)
|
26
|
+
# @return [TrueClass,FalseClass] result (成否)
|
27
|
+
#
|
28
|
+
def ok?
|
29
|
+
@response.success?
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
#
|
2
|
+
# Tag Class (タグクラス)
|
3
|
+
#
|
4
|
+
# @!attribute [r] name
|
5
|
+
# @return [String] tag name (タグ名)
|
6
|
+
# @!attribute [r] id
|
7
|
+
# @return [String] tag id (タグID)
|
8
|
+
# @!attribute [r] client_id
|
9
|
+
# @return [String] client id (クライアントID)
|
10
|
+
# @!attribute [r] value
|
11
|
+
# @return [String] tag value (タグの値)
|
12
|
+
#
|
13
|
+
class Tag
|
14
|
+
|
15
|
+
attr_reader :name
|
16
|
+
attr_reader :id
|
17
|
+
attr_reader :client_id
|
18
|
+
attr_reader :value
|
19
|
+
|
20
|
+
alias_method :tag_id, :id
|
21
|
+
|
22
|
+
#
|
23
|
+
# initializer (イニシャライザ)
|
24
|
+
# @param [Client] client client object (クライント)
|
25
|
+
# @param [String] name tag name (タグ名)
|
26
|
+
# @param [String] value value (タグの値)
|
27
|
+
#
|
28
|
+
def initialize(client,name,value=nil)
|
29
|
+
@client = client
|
30
|
+
@name = name
|
31
|
+
@value = value
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# save tag (タグを登録する)
|
36
|
+
# @param [GrowthPush] growth_push GrowthPush object (GrowthPushオブジェクト)
|
37
|
+
# @raise [GrowthPushException] exception (例外)
|
38
|
+
# @return [Tag] tag (タグ)
|
39
|
+
#
|
40
|
+
def save(growth_push)
|
41
|
+
begin
|
42
|
+
if @client.id && @client.code
|
43
|
+
http_response = HttpClient.instance.post('tags',
|
44
|
+
{
|
45
|
+
'clientId' => @client.id,
|
46
|
+
'code' => @client.code,
|
47
|
+
'name' => self.name,
|
48
|
+
'value' => self.value
|
49
|
+
}
|
50
|
+
)
|
51
|
+
elsif @client.token
|
52
|
+
http_response = HttpClient.instance.post('tags',
|
53
|
+
{
|
54
|
+
'applicationId' => growth_push.application_id,
|
55
|
+
'secret' => growth_push.secret,
|
56
|
+
'token' => @client.token,
|
57
|
+
'name' => self.name,
|
58
|
+
'value' => self.value,
|
59
|
+
}
|
60
|
+
)
|
61
|
+
else
|
62
|
+
raise GrowthPushException.new('Invalid client')
|
63
|
+
end
|
64
|
+
|
65
|
+
rescue GrowthPushException => ex
|
66
|
+
raise GrowthPushException.new('Failed to save tag: ' << ex.message, ex.code)
|
67
|
+
end
|
68
|
+
|
69
|
+
body = http_response.body
|
70
|
+
self.attributes = body
|
71
|
+
|
72
|
+
return self
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# set attributes (属性をセットする)
|
77
|
+
# @param [Hash] attributes attributes (属性)
|
78
|
+
#
|
79
|
+
def attributes=(attributes)
|
80
|
+
@id = attributes['tagId'];
|
81
|
+
@client_id = attributes['clientId'];
|
82
|
+
@value = attributes['value'];
|
83
|
+
end
|
84
|
+
private :attributes=
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,290 @@
|
|
1
|
+
require 'digest/sha2'
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'growth_push'
|
4
|
+
|
5
|
+
APPLICATION_ID = 128
|
6
|
+
SECRET = 'FUAOPniE3pGTczjU7kUkzbY2j2K1SU5S'
|
7
|
+
TOKEN = '2ffaa8b5eb147c0ebc3ecb0824315d683be40a8bb7aca6aa6fced34c008092ae'
|
8
|
+
CLIENT_ID = 763605
|
9
|
+
|
10
|
+
describe "Growthpush" do
|
11
|
+
|
12
|
+
growth_push = nil
|
13
|
+
growth_push2 = nil
|
14
|
+
client = nil
|
15
|
+
token = nil
|
16
|
+
event = nil
|
17
|
+
tag = nil
|
18
|
+
|
19
|
+
before(:all) do
|
20
|
+
growth_push = GrowthPush.new(APPLICATION_ID, SECRET)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "initialize" do
|
24
|
+
it 'test' do
|
25
|
+
growth_push.application_id.should == APPLICATION_ID
|
26
|
+
growth_push.secret.should == SECRET
|
27
|
+
growth_push.environment.should == GrowthPush::ENVIRONMENT_PRODUCTION
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'create_client' do
|
32
|
+
before(:all) do
|
33
|
+
token = Digest::SHA256.hexdigest(Random.rand.to_s)
|
34
|
+
client = growth_push.create_client(token, GrowthPush::OS_IOS)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'test' do
|
38
|
+
(client.id > 0).should be_true
|
39
|
+
client.token.should == token
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'create client with duplicate token' do
|
44
|
+
before(:all) do
|
45
|
+
client = growth_push.create_client(TOKEN, GrowthPush::OS_IOS)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'test' do
|
49
|
+
client.id.should == CLIENT_ID
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'create client with bad token' do
|
54
|
+
|
55
|
+
it 'test' do
|
56
|
+
proc{ growth_push.create_client('bad_token', GrowthPush::OS_IOS) }.should raise_error
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'create client with bad os' do
|
62
|
+
it 'test' do
|
63
|
+
proc{ growth_push.create_client(TOKEN, 'bad_os') }.should raise_error
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'create event (using token)' do
|
68
|
+
before(:all) do
|
69
|
+
event = growth_push.create_event(TOKEN,'Launch', '')
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'test' do
|
73
|
+
(event.goal_id > 0).should be_true
|
74
|
+
(event.timestamp > 0).should be_true
|
75
|
+
(event.client_id > 0).should be_true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe 'create event (with client)' do
|
80
|
+
before(:all) do
|
81
|
+
client = growth_push.create_client(TOKEN, GrowthPush::OS_IOS)
|
82
|
+
event = growth_push.create_event(client,'Launch', '')
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'test' do
|
86
|
+
(event.goal_id > 0).should be_true
|
87
|
+
(event.timestamp > 0).should be_true
|
88
|
+
(event.client_id > 0).should be_true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe 'create event (with client) using name & value' do
|
93
|
+
before(:all) do
|
94
|
+
growth_push.create_client(TOKEN, GrowthPush::OS_IOS)
|
95
|
+
event = growth_push.create_event('Launch', '')
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'test' do
|
99
|
+
(event.goal_id > 0).should be_true
|
100
|
+
(event.timestamp > 0).should be_true
|
101
|
+
(event.client_id > 0).should be_true
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe 'create event (with client) using hash (name => value)' do
|
106
|
+
before(:all) do
|
107
|
+
growth_push.create_client(TOKEN, GrowthPush::OS_IOS)
|
108
|
+
event = growth_push.create_event('Launch' => '')
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'test' do
|
112
|
+
(event.goal_id > 0).should be_true
|
113
|
+
(event.timestamp > 0).should be_true
|
114
|
+
(event.client_id > 0).should be_true
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'create event without client using name & value' do
|
119
|
+
before(:all) do
|
120
|
+
growth_push2 = GrowthPush.new(APPLICATION_ID, SECRET)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'test' do
|
124
|
+
proc{ growth_push2.create_event('Launch', '') }.should raise_error
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe 'create event without client using hash (name => value)' do
|
129
|
+
before(:all) do
|
130
|
+
growth_push2 = GrowthPush.new(APPLICATION_ID, SECRET)
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'test' do
|
134
|
+
proc{ growth_push2.create_event('Launch' => '') }.should raise_error
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe 'create event with empty name (using token)' do
|
139
|
+
before(:all) do
|
140
|
+
growth_push2 = GrowthPush.new(APPLICATION_ID, SECRET)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'test' do
|
144
|
+
proc{ growth_push2.create_event(TOKEN, '') }.should raise_error
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe 'create event with empty name (with client)' do
|
149
|
+
before(:all) do
|
150
|
+
client = growth_push.create_client(TOKEN, GrowthPush::OS_IOS)
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'test' do
|
154
|
+
proc{ growth_push.create_event(client, '') }.should raise_error
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe 'create event with long name (using token)' do
|
159
|
+
before(:all) do
|
160
|
+
growth_push2 = GrowthPush.new(APPLICATION_ID, SECRET)
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'test' do
|
164
|
+
proc{ growth_push2.create_event(TOKEN, 'long' * 100) }.should raise_error
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe 'create event with long name (with client)' do
|
169
|
+
before(:all) do
|
170
|
+
client = growth_push.create_client(TOKEN, GrowthPush::OS_IOS)
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'test' do
|
174
|
+
proc{ growth_push.create_event(client, 'long' * 100) }.should raise_error
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe 'create tag (using token)' do
|
179
|
+
before(:all) do
|
180
|
+
tag = growth_push.create_tag(TOKEN, 'Gender', 'male')
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'test' do
|
184
|
+
(tag.tag_id > 0).should be_true
|
185
|
+
(tag.client_id > 0).should be_true
|
186
|
+
tag.value.should == 'male'
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe 'create tag (with client)' do
|
191
|
+
before(:all) do
|
192
|
+
client = growth_push.create_client(TOKEN, GrowthPush::OS_IOS)
|
193
|
+
tag = growth_push.create_tag(client, 'Gender', 'male')
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'test' do
|
197
|
+
(tag.tag_id > 0).should be_true
|
198
|
+
(tag.client_id > 0).should be_true
|
199
|
+
tag.value.should == 'male'
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
describe 'create tag (with client) using name & value' do
|
204
|
+
before(:all) do
|
205
|
+
growth_push.create_client(TOKEN, GrowthPush::OS_IOS)
|
206
|
+
tag = growth_push.create_tag('Gender', 'male')
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'test' do
|
210
|
+
(tag.tag_id > 0).should be_true
|
211
|
+
(tag.client_id > 0).should be_true
|
212
|
+
tag.value.should == 'male'
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe 'create tag (with client) using hash (name => value)' do
|
217
|
+
before(:all) do
|
218
|
+
growth_push.create_client(TOKEN, GrowthPush::OS_IOS)
|
219
|
+
tag = growth_push.create_tag('Gender' => 'male')
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'test' do
|
223
|
+
(tag.tag_id > 0).should be_true
|
224
|
+
(tag.client_id > 0).should be_true
|
225
|
+
tag.value.should == 'male'
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe 'create tag without client using name & value' do
|
230
|
+
before(:all) do
|
231
|
+
growth_push2 = GrowthPush.new(APPLICATION_ID, SECRET)
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'test' do
|
235
|
+
proc{ growth_push2.create_tag('Gender', 'male') }.should raise_error
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
describe 'create tag without client using hash (name => value)' do
|
240
|
+
before(:all) do
|
241
|
+
growth_push2 = GrowthPush.new(APPLICATION_ID, SECRET)
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'test' do
|
245
|
+
proc{ growth_push2.create_tag('Gender' => 'male') }.should raise_error
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
describe 'create tag with empty name (using token)' do
|
250
|
+
before(:all) do
|
251
|
+
growth_push2 = GrowthPush.new(APPLICATION_ID, SECRET)
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'test' do
|
255
|
+
proc{ growth_push2.create_tag(TOKEN, '') }.should raise_error
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
describe 'create tag with empty name (with client)' do
|
260
|
+
before(:all) do
|
261
|
+
client = growth_push.create_client(TOKEN, GrowthPush::OS_IOS)
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'test' do
|
265
|
+
proc{ growth_push.create_tag(client, '') }.should raise_error
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe 'create tag with long name (using token)' do
|
270
|
+
before(:all) do
|
271
|
+
growth_push2 = GrowthPush.new(APPLICATION_ID, SECRET)
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'test' do
|
275
|
+
proc{ growth_push2.create_tag(TOKEN, 'long' * 100) }.should raise_error
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
describe 'create tag with long name (with client)' do
|
280
|
+
before(:all) do
|
281
|
+
client = growth_push.create_client(TOKEN, GrowthPush::OS_IOS)
|
282
|
+
end
|
283
|
+
|
284
|
+
it 'test' do
|
285
|
+
proc{ growth_push.create_tag(client, 'long' * 100) }.should raise_error
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
290
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rubygems'
|
metadata
CHANGED
@@ -1,27 +1,118 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: growthpush
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- katty0324
|
9
|
+
- asip
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
date: 2013-09-03 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.3'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.3'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: rake
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: faraday
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: faraday_middleware
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
type: :runtime
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
description: GrowthPush SDK for Ruby
|
96
|
+
email:
|
97
|
+
- kataoka@sirok.co.jp
|
98
|
+
- ys.ashida@gmail.com
|
99
|
+
executables: []
|
18
100
|
extensions: []
|
19
101
|
extra_rdoc_files: []
|
20
102
|
files:
|
21
|
-
-
|
22
|
-
- lib/growthpush.rb
|
23
|
-
|
24
|
-
|
103
|
+
- lib/growth_push.rb
|
104
|
+
- lib/growthpush/client.rb
|
105
|
+
- lib/growthpush/event.rb
|
106
|
+
- lib/growthpush/growth_push_exception.rb
|
107
|
+
- lib/growthpush/http_client.rb
|
108
|
+
- lib/growthpush/http_response.rb
|
109
|
+
- lib/growthpush/tag.rb
|
110
|
+
- lib/growthpush/version.rb
|
111
|
+
- spec/growthpush_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
homepage: https://github.com/SIROK/growthpush-ruby
|
114
|
+
licenses:
|
115
|
+
- Apache License
|
25
116
|
post_install_message:
|
26
117
|
rdoc_options: []
|
27
118
|
require_paths:
|
@@ -39,9 +130,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
130
|
- !ruby/object:Gem::Version
|
40
131
|
version: '0'
|
41
132
|
requirements: []
|
42
|
-
rubyforge_project:
|
133
|
+
rubyforge_project:
|
43
134
|
rubygems_version: 1.8.23
|
44
135
|
signing_key:
|
45
136
|
specification_version: 3
|
46
|
-
summary: GrowthPush
|
47
|
-
|
137
|
+
summary: GrowthPush is push notification and analysis platform for smart devices.
|
138
|
+
GrowthPush SDK for Ruby provides registration function of client devices and events.
|
139
|
+
test_files:
|
140
|
+
- spec/growthpush_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
has_rdoc: yard
|
data/bin/growthpush
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
data/lib/growthpush.rb
DELETED