appboy 0.0.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rspec +1 -0
  4. data/README.md +111 -21
  5. data/appboy.gemspec +18 -10
  6. data/lib/appboy.rb +5 -3
  7. data/lib/appboy/api.rb +18 -30
  8. data/lib/appboy/deprecated.rb +19 -0
  9. data/lib/appboy/endpoints/email_status.rb +13 -0
  10. data/lib/appboy/endpoints/schedule_messages.rb +15 -0
  11. data/lib/appboy/endpoints/send_messages.rb +15 -0
  12. data/lib/appboy/endpoints/track_users.rb +29 -0
  13. data/lib/appboy/http.rb +24 -0
  14. data/lib/appboy/rest.rb +7 -0
  15. data/lib/appboy/rest/base.rb +15 -0
  16. data/lib/appboy/rest/email_status.rb +21 -0
  17. data/lib/appboy/rest/export_users.rb +27 -0
  18. data/lib/appboy/rest/list_segments.rb +11 -0
  19. data/lib/appboy/rest/schedule_messages.rb +25 -0
  20. data/lib/appboy/rest/send_messages.rb +23 -0
  21. data/lib/appboy/rest/track_users.rb +14 -0
  22. data/lib/appboy/version.rb +1 -1
  23. data/spec/appboy/api_spec.rb +4 -0
  24. data/spec/appboy/endpoints/track_users_spec.rb +72 -0
  25. data/spec/appboy/rest/email_status_spec.rb +19 -0
  26. data/spec/appboy/rest/export_users_spec.rb +20 -0
  27. data/spec/appboy/rest/schedule_messages_spec.rb +34 -0
  28. data/spec/appboy/rest/send_messages_spec.rb +36 -0
  29. data/spec/appboy/rest/track_users_spec.rb +24 -0
  30. data/spec/factories.rb +32 -0
  31. data/spec/fixtures/responses/email_status/existing_email/responds_with_created.yml +54 -0
  32. data/spec/fixtures/responses/email_status/existing_email/responds_with_success_message.yml +54 -0
  33. data/spec/fixtures/responses/email_status/unknown_email/responds_with_bad_request.yml +52 -0
  34. data/spec/fixtures/responses/email_status/unknown_email/responds_with_error_message.yml +52 -0
  35. data/spec/fixtures/responses/export_users/by_ids/with_success/responds_with_created.yml +56 -0
  36. data/spec/fixtures/responses/export_users/by_segment/with_success/responds_with_created.yml +54 -0
  37. data/spec/fixtures/responses/list_segments/with_success/responds_with_a_list_of_segments.yml +58 -0
  38. data/spec/fixtures/responses/list_segments/with_success/responds_with_success.yml +58 -0
  39. data/spec/fixtures/responses/schedule_messages/unauthorized/responds_with_unauthorize.yml +53 -0
  40. data/spec/fixtures/responses/schedule_messages/with_success/responds_with_created.yml +55 -0
  41. data/spec/fixtures/responses/schedule_messages/with_success/responds_with_success_message.yml +55 -0
  42. data/spec/fixtures/responses/send_messages/unauthorized/responds_with_unauthorized.yml +52 -0
  43. data/spec/fixtures/responses/send_messages/with_success/responds_with_created.yml +54 -0
  44. data/spec/fixtures/responses/send_messages/with_success/responds_with_success_message.yml +54 -0
  45. data/spec/fixtures/responses/track_users/unauthorized/responds_with_unauthorized.yml +54 -0
  46. data/spec/fixtures/responses/track_users/with_success/responds_with_created.yml +56 -0
  47. data/spec/fixtures/responses/track_users/with_success/responds_with_success_message.yml +56 -0
  48. data/spec/integrations/email_status_spec.rb +36 -0
  49. data/spec/integrations/export_users_spec.rb +27 -0
  50. data/spec/integrations/list_segments_spec.rb +21 -0
  51. data/spec/integrations/schedule_messages_spec.rb +31 -0
  52. data/spec/integrations/send_messages_spec.rb +30 -0
  53. data/spec/integrations/track_users_spec.rb +35 -0
  54. data/spec/spec_helper.rb +10 -1
  55. data/spec/support/factory_girl.rb +10 -0
  56. data/spec/support/integrations.rb +19 -0
  57. data/spec/support/vcr.rb +17 -0
  58. metadata +212 -18
  59. data/spec/api_spec.rb +0 -60
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9b08323e1d2602a33183a99f18a06a7bb59ad1e
4
- data.tar.gz: 984094644be733e86940bb0e4b6d2c0dcf397d36
3
+ metadata.gz: 9222a09ffa3f7d75b06a1366c1845b02c42ccef8
4
+ data.tar.gz: 45ada71360cdd58a539e7d4763e6a9cd2b4cf1f7
5
5
  SHA512:
6
- metadata.gz: 4f39f353d4618c26b0b340ea7580d535042f40baf1b03e74c578d80066db094b70e65f283e1a408a54b6946087a436417788da032265e2e4168131fcce10fc8c
7
- data.tar.gz: ec645bebf908780c2d633bdb18b7e211b72d304024ccf5afcb02e519921db65b49373bd3626489e4dd8573779a6ae2fcc2427fa29502800d901535907c1cbc8b
6
+ metadata.gz: 7811017c20de7850940245f6e8d6b921fd454d4fe8c007d7628c6622c4f0b86a2297151562c73beebbc6f8adb64c56417446a21396aca68611aa4b1e0fea0c64
7
+ data.tar.gz: db42fb17c83fa3fa23a14fb23d86bd1a7517c1e1e746c8732dc376511cba5c9e6f9e95f88ba08c11ed24c0186803f6832701fdf515b964d5a9421b80d450bb8a
data/.gitignore CHANGED
@@ -3,6 +3,8 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .ruby-version
7
+ .env
6
8
  Gemfile.lock
7
9
  InstalledFiles
8
10
  _yardoc
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 using HTTParty
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('<secret>', '<app-group-id>')
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.track [{external_id: 123,
31
- first_name: 'John',
32
- last_name: 'Smith',
33
- gender: 'male',
34
- email: 'jsmith@example.com'}]
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
- events = [
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
- message = {android_push: {alert: 'Hello Android'},
51
- apple_push: {alert: "Hello iOS"}}
107
+ api.send_messages(messages: messages, external_user_ids: [123, 456])
108
+ ```
52
109
 
53
- user_ids = [123, 456]
110
+ ##### Option B, Using Segment ID
54
111
 
55
- api.send_message(message, user_ids)
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
- message = {android_push: {alert: 'Hello Android'},
62
- apple_push: {alert: "Hello iOS"}}
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
- api.schedule_message(send_at, message, segment_id)
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
@@ -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 = "appboy"
7
+ spec.name = 'appboy'
8
8
  spec.version = Appboy::VERSION
9
- spec.authors = ["Josh Nussbaum"]
10
- spec.email = ["josh@godynamo.com"]
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 = "http://appboy.com"
14
- spec.license = "MIT"
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 = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'httparty'
22
- spec.add_development_dependency "bundler", "~> 1.3"
23
- spec.add_development_dependency "rake"
24
- spec.add_development_dependency "rspec"
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
@@ -1,6 +1,8 @@
1
- require "appboy/version"
2
- require 'httparty'
1
+ require 'json'
2
+ require 'virtus'
3
+ require 'appboy/version'
3
4
 
4
5
  module Appboy
5
- autoload :API, "appboy/api"
6
+ autoload :API, 'appboy/api'
7
+ autoload :REST, 'appboy/rest'
6
8
  end
@@ -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 HTTParty
4
-
5
- base_uri 'https://api.appboy.com'
9
+ include Appboy::Deprecated
6
10
 
7
- def initialize(secret, app_group_id)
8
- @secret, @app_group_id = secret, app_group_id
9
- end
11
+ include Appboy::Endpoints::TrackUsers
12
+ include Appboy::Endpoints::SendMessages
13
+ include Appboy::Endpoints::ScheduleMessages
14
+ include Appboy::Endpoints::EmailStatus
10
15
 
11
- def track(attributes, events=[], purchases=[])
12
- post '/users/track', company_secret: @secret,
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 send_message(message, user_ids, segment_id = nil)
20
- post '/messages/send', company_secret: @secret,
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
- def schedule_message(date, message, segment_id, local_timezone=false)
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
- private
36
- def post(url, payload)
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,13 @@
1
+ module Appboy
2
+ module Endpoints
3
+ module EmailStatus
4
+ def email_status(**payload)
5
+ email_status_service.new(app_group_id, payload).perform
6
+ end
7
+
8
+ def email_status_service
9
+ Appboy::REST::EmailStatus
10
+ end
11
+ end
12
+ end
13
+ 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
@@ -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
@@ -0,0 +1,7 @@
1
+ require 'appboy/rest/base'
2
+ require 'appboy/rest/track_users'
3
+ require 'appboy/rest/send_messages'
4
+ require 'appboy/rest/schedule_messages'
5
+ require 'appboy/rest/email_status'
6
+ require 'appboy/rest/export_users'
7
+ require 'appboy/rest/list_segments'
@@ -0,0 +1,15 @@
1
+ require 'appboy/http'
2
+
3
+ module Appboy
4
+ module REST
5
+ class Base
6
+ attr_writer :http
7
+
8
+ private
9
+
10
+ def http
11
+ @http ||= Appboy::HTTP.new
12
+ end
13
+ end
14
+ end
15
+ end