appboy 0.0.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/README.md +111 -21
- data/appboy.gemspec +18 -10
- data/lib/appboy.rb +5 -3
- data/lib/appboy/api.rb +18 -30
- data/lib/appboy/deprecated.rb +19 -0
- data/lib/appboy/endpoints/email_status.rb +13 -0
- data/lib/appboy/endpoints/schedule_messages.rb +15 -0
- data/lib/appboy/endpoints/send_messages.rb +15 -0
- data/lib/appboy/endpoints/track_users.rb +29 -0
- data/lib/appboy/http.rb +24 -0
- data/lib/appboy/rest.rb +7 -0
- data/lib/appboy/rest/base.rb +15 -0
- data/lib/appboy/rest/email_status.rb +21 -0
- data/lib/appboy/rest/export_users.rb +27 -0
- data/lib/appboy/rest/list_segments.rb +11 -0
- data/lib/appboy/rest/schedule_messages.rb +25 -0
- data/lib/appboy/rest/send_messages.rb +23 -0
- data/lib/appboy/rest/track_users.rb +14 -0
- data/lib/appboy/version.rb +1 -1
- data/spec/appboy/api_spec.rb +4 -0
- data/spec/appboy/endpoints/track_users_spec.rb +72 -0
- data/spec/appboy/rest/email_status_spec.rb +19 -0
- data/spec/appboy/rest/export_users_spec.rb +20 -0
- data/spec/appboy/rest/schedule_messages_spec.rb +34 -0
- data/spec/appboy/rest/send_messages_spec.rb +36 -0
- data/spec/appboy/rest/track_users_spec.rb +24 -0
- data/spec/factories.rb +32 -0
- data/spec/fixtures/responses/email_status/existing_email/responds_with_created.yml +54 -0
- data/spec/fixtures/responses/email_status/existing_email/responds_with_success_message.yml +54 -0
- data/spec/fixtures/responses/email_status/unknown_email/responds_with_bad_request.yml +52 -0
- data/spec/fixtures/responses/email_status/unknown_email/responds_with_error_message.yml +52 -0
- data/spec/fixtures/responses/export_users/by_ids/with_success/responds_with_created.yml +56 -0
- data/spec/fixtures/responses/export_users/by_segment/with_success/responds_with_created.yml +54 -0
- data/spec/fixtures/responses/list_segments/with_success/responds_with_a_list_of_segments.yml +58 -0
- data/spec/fixtures/responses/list_segments/with_success/responds_with_success.yml +58 -0
- data/spec/fixtures/responses/schedule_messages/unauthorized/responds_with_unauthorize.yml +53 -0
- data/spec/fixtures/responses/schedule_messages/with_success/responds_with_created.yml +55 -0
- data/spec/fixtures/responses/schedule_messages/with_success/responds_with_success_message.yml +55 -0
- data/spec/fixtures/responses/send_messages/unauthorized/responds_with_unauthorized.yml +52 -0
- data/spec/fixtures/responses/send_messages/with_success/responds_with_created.yml +54 -0
- data/spec/fixtures/responses/send_messages/with_success/responds_with_success_message.yml +54 -0
- data/spec/fixtures/responses/track_users/unauthorized/responds_with_unauthorized.yml +54 -0
- data/spec/fixtures/responses/track_users/with_success/responds_with_created.yml +56 -0
- data/spec/fixtures/responses/track_users/with_success/responds_with_success_message.yml +56 -0
- data/spec/integrations/email_status_spec.rb +36 -0
- data/spec/integrations/export_users_spec.rb +27 -0
- data/spec/integrations/list_segments_spec.rb +21 -0
- data/spec/integrations/schedule_messages_spec.rb +31 -0
- data/spec/integrations/send_messages_spec.rb +30 -0
- data/spec/integrations/track_users_spec.rb +35 -0
- data/spec/spec_helper.rb +10 -1
- data/spec/support/factory_girl.rb +10 -0
- data/spec/support/integrations.rb +19 -0
- data/spec/support/vcr.rb +17 -0
- metadata +212 -18
- data/spec/api_spec.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9222a09ffa3f7d75b06a1366c1845b02c42ccef8
|
4
|
+
data.tar.gz: 45ada71360cdd58a539e7d4763e6a9cd2b4cf1f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7811017c20de7850940245f6e8d6b921fd454d4fe8c007d7628c6622c4f0b86a2297151562c73beebbc6f8adb64c56417446a21396aca68611aa4b1e0fea0c64
|
7
|
+
data.tar.gz: db42fb17c83fa3fa23a14fb23d86bd1a7517c1e1e746c8732dc376511cba5c9e6f9e95f88ba08c11ed24c0186803f6832701fdf515b964d5a9421b80d450bb8a
|
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Appboy
|
2
2
|
|
3
|
-
A wrapper for the Appboy REST API
|
3
|
+
A wrapper for the Appboy REST API.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -21,51 +21,141 @@ Or install it yourself as:
|
|
21
21
|
### Initializing API
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
api = Appboy::API.new('<
|
24
|
+
api = Appboy::API.new('<app-group-id>')
|
25
25
|
```
|
26
26
|
|
27
|
-
### Track User
|
27
|
+
### Track User Attributes
|
28
|
+
|
29
|
+
See: [User Attributes Object Specification](https://documentation.appboy.com/REST_APIs/User_Data#user-attribute-object)
|
28
30
|
|
29
31
|
```ruby
|
30
|
-
api.
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
api.track_users(attributes: [{
|
33
|
+
external_id: 123,
|
34
|
+
first_name: 'John',
|
35
|
+
last_name: 'Smith',
|
36
|
+
gender: 'male',
|
37
|
+
email: 'jsmith@example.com'
|
38
|
+
}])
|
39
|
+
```
|
40
|
+
|
41
|
+
##### Track Attributes for Single User
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
api.track_attribute(external_id: 123, first_name: 'John', ...)
|
35
45
|
```
|
36
46
|
|
37
47
|
### Track Event
|
38
48
|
|
49
|
+
See: [Event Object Specification](https://documentation.appboy.com/REST_APIs/User_Data#event-object)
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
api.track_users(events: [{
|
53
|
+
external_id: 123,
|
54
|
+
name: 'add-to-cart',
|
55
|
+
time: Time.now
|
56
|
+
}]
|
57
|
+
```
|
58
|
+
|
59
|
+
##### Track Events for Single User
|
60
|
+
|
39
61
|
```ruby
|
40
|
-
|
41
|
-
{external_id: 123, name: 'add-to-cart', time: Time.now}
|
42
|
-
]
|
43
|
-
api.track [], events
|
62
|
+
api.track_event(external_id: 123, name: 'Event', ...)
|
44
63
|
```
|
45
64
|
|
46
65
|
### Track Purchase
|
66
|
+
|
67
|
+
See: [Purchase Object Specfication](https://documentation.appboy.com/REST_APIs/User_Data#purchase-object)
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
api.track_users(purchases: [{
|
71
|
+
external_id: 123,
|
72
|
+
product_id: 456,
|
73
|
+
currency: 'CAD',
|
74
|
+
price: 1.99,
|
75
|
+
time: Time.now
|
76
|
+
}]
|
77
|
+
```
|
78
|
+
|
79
|
+
##### Track Purchases for Single User
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
api.track_purchase(external_id: 123, product_id: 456, ...)
|
83
|
+
```
|
84
|
+
|
85
|
+
### Track Everything for Everyone All at Once
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
api.track_users(purchases: purchases, events: events, attributes: attributes)
|
89
|
+
```
|
90
|
+
|
47
91
|
### Send Message
|
48
92
|
|
93
|
+
See: [Platform Push Object Specifications](https://documentation.appboy.com/REST_APIs/Messaging#platform-push-object)
|
94
|
+
|
95
|
+
##### Messages Payload
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
messages = {
|
99
|
+
android_push: { alert: 'Hello Android' },
|
100
|
+
apple_push: { alert: "Hello iOS" }
|
101
|
+
}
|
102
|
+
```
|
103
|
+
|
104
|
+
##### Option A, Using External User IDs
|
105
|
+
|
49
106
|
```ruby
|
50
|
-
|
51
|
-
|
107
|
+
api.send_messages(messages: messages, external_user_ids: [123, 456])
|
108
|
+
```
|
52
109
|
|
53
|
-
|
110
|
+
##### Option B, Using Segment ID
|
54
111
|
|
55
|
-
|
112
|
+
```ruby
|
113
|
+
api.send_messages(messages: messages, segment_id: '<segment-id>')
|
56
114
|
```
|
57
115
|
|
116
|
+
|
58
117
|
### Schedule Message
|
59
118
|
|
119
|
+
See: [Platform Push Object Specifications](https://documentation.appboy.com/REST_APIs/Messaging#platform-push-object)
|
120
|
+
|
60
121
|
```ruby
|
61
|
-
|
62
|
-
|
63
|
-
segment_id = '<segment id>'
|
64
|
-
send_at = Time.new(2014, 3, 12)
|
122
|
+
api.schedule_messages(send_at: 1.hour.since, messages: messages, segment_id: '<segment-id>')
|
123
|
+
```
|
65
124
|
|
66
|
-
|
125
|
+
### Changing Email Subscription
|
126
|
+
|
127
|
+
See: [Changing Email Subscription Status](https://documentation.appboy.com/REST_APIs/Email_Sync#post)
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
api.email_status(email: 'john@example.com', status: :opted_in)
|
67
131
|
```
|
68
132
|
|
133
|
+
### List Segments
|
134
|
+
|
135
|
+
See: [Segment Export](https://documentation.appboy.com/REST_APIs/Export)
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
api.list_segments
|
139
|
+
```
|
140
|
+
|
141
|
+
### Export Users
|
142
|
+
|
143
|
+
See: [User Export](https://documentation.appboy.com/REST_APIs/Export#user-export)
|
144
|
+
|
145
|
+
#### By IDs
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
api.export_users(external_ids: [1])
|
149
|
+
```
|
150
|
+
|
151
|
+
#### By Segment
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
api.export_users(segment_id: segment_id, callback_endpoint: 'https://example.com')
|
155
|
+
```
|
156
|
+
|
157
|
+
|
158
|
+
|
69
159
|
## Contributing
|
70
160
|
|
71
161
|
1. Fork it
|
data/appboy.gemspec
CHANGED
@@ -4,22 +4,30 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'appboy/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'appboy'
|
8
8
|
spec.version = Appboy::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email =
|
9
|
+
spec.authors = ['Josh Nussbaum', 'Hugo Bastien']
|
10
|
+
spec.email = %w(josh@godynamo.com hugo@godynamo.com)
|
11
11
|
spec.description = %q{Appboy wrapper}
|
12
12
|
spec.summary = %q{A wrapper for the Appboy REST API, track users/events/purchases, send & schedule messages}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = 'http://appboy.com'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency '
|
22
|
-
spec.
|
23
|
-
spec.
|
24
|
-
spec.add_development_dependency
|
21
|
+
spec.add_dependency 'virtus'
|
22
|
+
spec.add_dependency 'faraday'
|
23
|
+
spec.add_dependency 'faraday_middleware'
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
spec.add_development_dependency 'dotenv'
|
28
|
+
spec.add_development_dependency 'vcr'
|
29
|
+
spec.add_development_dependency 'webmock'
|
30
|
+
spec.add_development_dependency 'pry'
|
31
|
+
spec.add_development_dependency 'activesupport'
|
32
|
+
spec.add_development_dependency 'factory_girl'
|
25
33
|
end
|
data/lib/appboy.rb
CHANGED
data/lib/appboy/api.rb
CHANGED
@@ -1,42 +1,30 @@
|
|
1
|
+
require 'appboy/deprecated'
|
2
|
+
require 'appboy/endpoints/track_users'
|
3
|
+
require 'appboy/endpoints/send_messages'
|
4
|
+
require 'appboy/endpoints/schedule_messages'
|
5
|
+
require 'appboy/endpoints/email_status'
|
6
|
+
|
1
7
|
module Appboy
|
2
8
|
class API
|
3
|
-
include
|
4
|
-
|
5
|
-
base_uri 'https://api.appboy.com'
|
9
|
+
include Appboy::Deprecated
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
11
|
+
include Appboy::Endpoints::TrackUsers
|
12
|
+
include Appboy::Endpoints::SendMessages
|
13
|
+
include Appboy::Endpoints::ScheduleMessages
|
14
|
+
include Appboy::Endpoints::EmailStatus
|
10
15
|
|
11
|
-
def
|
12
|
-
|
13
|
-
app_group_id: @app_group_id,
|
14
|
-
attributes: attributes,
|
15
|
-
events: events,
|
16
|
-
purchases: purchases
|
16
|
+
def export_users(**payload)
|
17
|
+
Appboy::REST::ExportUsers.new.perform(app_group_id, payload)
|
17
18
|
end
|
18
19
|
|
19
|
-
def
|
20
|
-
|
21
|
-
app_group_id: @app_group_id,
|
22
|
-
messages: message,
|
23
|
-
external_user_ids: user_ids,
|
24
|
-
segment_ids: [segment_id].compact
|
20
|
+
def list_segments
|
21
|
+
Appboy::REST::ListSegments.new.perform(app_group_id)
|
25
22
|
end
|
26
23
|
|
27
|
-
|
28
|
-
post '/messages/schedule', company_secret: @secret,
|
29
|
-
segment_ids: [segment_id],
|
30
|
-
send_at: date,
|
31
|
-
deliver_in_local_timezone: local_timezone,
|
32
|
-
messages: message
|
33
|
-
end
|
24
|
+
attr_reader :app_group_id
|
34
25
|
|
35
|
-
|
36
|
-
|
37
|
-
response = self.class.post(url, query: payload)
|
38
|
-
puts response.inspect
|
39
|
-
response['message'] == 'success'
|
26
|
+
def initialize(app_group_id)
|
27
|
+
@app_group_id = app_group_id
|
40
28
|
end
|
41
29
|
end
|
42
30
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Appboy
|
2
|
+
module Deprecated
|
3
|
+
def track(attribute, events = [], purchases = [])
|
4
|
+
warn('[Appboy] `track` is deprecated. Please use `track_users` instead.')
|
5
|
+
track_users(attribute: attribute, events: events, purchases: purchases)
|
6
|
+
end
|
7
|
+
|
8
|
+
def send_message(message, user_ids, segment_ids = nil)
|
9
|
+
warn('[Appboy] `send_message` is deprecated. Please use `send_messages` instead.')
|
10
|
+
send_messages(messages: message, user_ids: user_ids, segment_ids: segment_ids)
|
11
|
+
end
|
12
|
+
|
13
|
+
def schedule_message(date, message, segment_id, local_timezone = false)
|
14
|
+
warn('[Appboy] `schedule_message` is deprecated. Please use `schedule_messages` instead.')
|
15
|
+
schedule_messages(send_at: date, messages: message,
|
16
|
+
segment_id: segment_id, local_timezone: local_timezone)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Appboy
|
2
|
+
module Endpoints
|
3
|
+
module ScheduleMessages
|
4
|
+
def schedule_messages(**payload)
|
5
|
+
schedule_messages_service.new(app_group_id, payload).perform
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def schedule_messages_service
|
11
|
+
Appboy::REST::ScheduleMessages
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Appboy
|
2
|
+
module Endpoints
|
3
|
+
module SendMessages
|
4
|
+
def send_messages(**payload)
|
5
|
+
send_messages_service.new(app_group_id, payload).perform
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def send_messages_service
|
11
|
+
Appboy::REST::SendMessages
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Appboy
|
2
|
+
module Endpoints
|
3
|
+
module TrackUsers
|
4
|
+
attr_writer :track_users_service
|
5
|
+
|
6
|
+
def track_users(**payload)
|
7
|
+
track_users_service.perform(app_group_id, payload)
|
8
|
+
end
|
9
|
+
|
10
|
+
def track_purchase(payload)
|
11
|
+
track_users(purchases: [payload])
|
12
|
+
end
|
13
|
+
|
14
|
+
def track_event(payload)
|
15
|
+
track_users(events: [payload])
|
16
|
+
end
|
17
|
+
|
18
|
+
def track_attribute(payload)
|
19
|
+
track_users(attributes: [payload])
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def track_users_service
|
25
|
+
@track_users_service ||= Appboy::REST::TrackUsers.new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/appboy/http.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module Appboy
|
5
|
+
class HTTP
|
6
|
+
def post(path, payload)
|
7
|
+
connection.post path do |request|
|
8
|
+
request.body = payload
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(path, query)
|
13
|
+
connection.get path, query
|
14
|
+
end
|
15
|
+
|
16
|
+
def connection
|
17
|
+
@connection ||= Faraday.new(url: 'https://api.appboy.com') do |connection|
|
18
|
+
connection.request :json
|
19
|
+
|
20
|
+
connection.adapter Faraday.default_adapter
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/appboy/rest.rb
ADDED