Skip to content

Commit 3203232

Browse files
committed
Merge pull request #3 from outboundio/upgrading-to-1.0.0
moving to 1.0.0, combining user info and attributes in calls
2 parents 5fcfdf5 + d2e1f8c commit 3203232

File tree

2 files changed

+25
-107
lines changed

2 files changed

+25
-107
lines changed

README.md

Lines changed: 2 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,4 @@
11
# Outbound Ruby Library
22

3-
## Install
4-
### Simple
5-
gem install outbound
6-
7-
### Bundler
8-
gem 'outbound', '~> 0.1.0', :require => 'outbound'
9-
10-
## Setup
11-
require 'outbound'
12-
require 'logger'
13-
14-
Outbound.init("Your API KEY", Logger::ERROR)
15-
16-
## Identify User
17-
18-
require 'outbound'
19-
user_info = {
20-
:first_name => "FirstName",
21-
:last_name => "LastName",
22-
:email => "[email protected]",
23-
:phone_number => "5551234567",
24-
:apns_tokens => ["ios device token"],
25-
:gcm_tokens => ["android device token"]
26-
}
27-
user_attributes = {
28-
:some_other_attribute => "Something"
29-
}
30-
Outbound.identify("USER ID", user_info, user_attributes)
31-
32-
## Track Event
33-
34-
require 'outbound'
35-
event_properties = {
36-
:some_event_property => "Something"
37-
}
38-
Outbound.track("USER ID", "EVENT NAME", event_properties)
39-
40-
## Register a device token
41-
You can register device tokens for push notification by sending them in the `identify` or individually using the `register` call.
42-
43-
require 'outbound'
44-
45-
# To register a token for Apple Push Notification Service (iOS)
46-
Outbound.register Outbound.APNS, "USER_ID", "DEVICE_TOKEN_HERE"
47-
48-
# To register a token for Google Cloud Messaging (Android)
49-
Outbound.register Outbound.GCM, "USER_ID", "DEVICE_TOKEN_HERE"
50-
51-
## Disable a device token
52-
You can also disable a previously registered device tokens.
53-
54-
require 'outbound'
55-
56-
# To disable a token for Apple Push Notification Service (iOS)
57-
Outbound.disable Outbound.APNS, "USER_ID", "DEVICE_TOKEN_HERE"
58-
59-
# To disable a token for Google Cloud Messaging (Android)
60-
Outbound.disable Outbound.GCM, "USER_ID", "DEVICE_TOKEN_HERE"
61-
62-
## Specifics
63-
### User ID
64-
- A user ID must ALWAYS be a string or a number. Anything else will trigger an error and the call will not be sent to Outbound. User IDs are always stored as strings. Keep this in mind if you have different types. A user with ID of 1 (the number) will be considered the same as user with ID of "1" (the string).
65-
- A user ID should be static. It should be the same value you use to identify the user in your own system.
66-
- Some times you don't have a user id yet for a user but you still want to identify them and trigger events for them. You can do this by generating a new ID (call this the anonymous ID) and identify the user as you normally would. Then, once the user becomes a real, identifiable user and you have a real ID for them, make another identify call, this time pass in the anonymous ID as the previous ID.
67-
68-
user_info = {
69-
:previous_id => anonymous_id,
70-
}
71-
Outbound.identify("USER ID", user_info)
72-
73-
### Groups
74-
You can create a set of attributes and have them be inherited by a group of users. This can all be done with the `identify` call.
75-
76-
user_info = {
77-
:group_id => 'group identifier',
78-
:group_attributes => {
79-
... attributes shared by the group ...
80-
}
81-
}
82-
Outbound.identify("USER ID", user_info)
83-
84-
- Group IDs are treated just like user IDs. They should only be strings or numbers.
85-
- Users in a group will inherit group attributes but user attributes take precedences. So if there is an attribute `state` set on the group and it is set to "California" and there is also a `state` attribute set on the user but set to "New York", the value for that user is "New York". If the user didn't have that attribute, the value of `state` for that user would be the group value which is "California".
86-
- You only need to pass in the group attributes when they are initially set or when they are updated but you do need to set the group id for each user you want to be in the group.
87-
88-
### Event Name
89-
- An event name in a track can only be a string. Any other type of value will trigger an error and the call will not be sent to Outbound.
90-
- Event names can be anything you want them to be (as long as they are strings) and contain any character you want.
91-
92-
### Device Tokens
93-
- If you send a device token through an `identify` call, that is equivalent to sending a `register` call. Regardless of the state of that token it will become active again and we will attempt to send notifications to it. It is recommended that if you use the `register` and `disable` calls that you DO NOT send any tokens in `identify` calls. This way you can more easily control the state of your tokens.
94-
95-
### Results
96-
- Both the `identify` and `track` methods return a `Outbound::Result` instance. It has `error` and `received_call` attributes that are accesible. `received_call` is a boolean that indicates if the http request was even made. `error` will be either `nil` or a string error message. There is also a `success?` method that returns true if the call went through to Outbound and did not have any errors. There are also `?` method available for each different error type.
3+
Learn more about the Outbound Ruby Library by going
4+
to [docs.outbound.io](http://docs.outbound.io/v2/docs/ruby).

lib/outbound.rb

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require 'uri'
55

66
module Outbound
7-
VERSION = '0.4.0'
7+
VERSION = '1.0.0'
88
BASE_URL = 'https://api.outbound.io/v2'
99

1010
APNS = "apns"
@@ -34,23 +34,22 @@ def Outbound.init api_key, log_level=Logger::ERROR
3434
@ob = Outbound::Client.new api_key, @logger
3535
end
3636

37-
def Outbound.identify user_id, info={}, attributes={}
37+
def Outbound.identify user_id, info={}
3838
if @ob == nil
3939
res = Result.new Outbound::ERROR_INIT, false
4040
@logger.error res.error
4141
return res
4242
end
43-
44-
return @ob.identify user_id, info, attributes
43+
return @ob.identify user_id, info
4544
end
4645

47-
def Outbound.track user_id, event, properties={}, user_info={}, user_attributes={}
46+
def Outbound.track user_id, event, properties={}, user_info={}, timestamp
4847
if @ob == nil
4948
res = Result.new Outbound::ERROR_INIT, false
5049
@logger.error res.error
5150
return res
5251
end
53-
return @ob.track user_id, event, properties, user_info, user_attributes
52+
return @ob.track user_id, event, properties, user_info, timestamp
5453
end
5554

5655
def Outbound.disable platform, user_id, token
@@ -119,7 +118,7 @@ def initialize api_key, logger
119118
@logger = logger
120119
end
121120

122-
def identify user_id, info={}, attributes={}
121+
def identify user_id, info={}
123122
unless user_id.is_a? String or user_id.is_a? Numeric
124123
res = Result.new Outbound::ERROR_USER_ID, false
125124
@logger.error res.error
@@ -128,7 +127,7 @@ def identify user_id, info={}, attributes={}
128127

129128
user_data = {:user_id => user_id}
130129
begin
131-
user = user(info, attributes)
130+
user = user(info)
132131
user_data = user_data.merge user
133132
rescue
134133
@logger.error "Could not use user info (#{info}) and/or user attributes #{attributes} given to identify call."
@@ -137,7 +136,7 @@ def identify user_id, info={}, attributes={}
137136
return post(@api_key, '/identify', user_data)
138137
end
139138

140-
def track user_id, event, properties={}, user_info={}, user_attributes={}
139+
def track user_id, event, properties={}, user_info={}, timestamp
141140
unless user_id.is_a? String or user_id.is_a? Numeric
142141
res = Result.new Outbound::ERROR_USER_ID, false
143142
@logger.error res.error
@@ -153,7 +152,7 @@ def track user_id, event, properties={}, user_info={}, user_attributes={}
153152
data = {:user_id => user_id, :event => event}
154153

155154
begin
156-
user = user(user_info, user_attributes)
155+
user = user(user_info)
157156
if user.length > 0
158157
data[:user] = user
159158
end
@@ -169,6 +168,16 @@ def track user_id, event, properties={}, user_info={}, user_attributes={}
169168
@logger.error "Could not use event properties (#{properties}) given to track call."
170169
end
171170

171+
puts timestamp
172+
173+
unless timestamp == {}
174+
data[:timestamp] = timestamp
175+
else
176+
data[:timestamp] = Time.now.to_i
177+
end
178+
179+
puts data[:timestamp]
180+
172181
return post(@api_key, '/track', data)
173182
end
174183

@@ -244,8 +253,8 @@ def post api_key, path, data
244253
return err, true
245254
end
246255

247-
def user info={}, attributes={}
248-
unless info.is_a? Hash and attributes.is_a? Hash
256+
def user info={}
257+
unless info.is_a? Hash
249258
raise
250259
end
251260

@@ -259,9 +268,10 @@ def user info={}, attributes={}
259268
:group_id => info[:group_id],
260269
:group_attributes => info[:group_attributes],
261270
:previous_id => info[:previous_id],
262-
:attributes => attributes,
271+
:attributes => info[:attributes],
263272
}
264273
return user.delete_if { |k, v| v.nil? || v.empty? }
265274
end
275+
266276
end
267277
end

0 commit comments

Comments
 (0)