smartlist_push_api 0.1.13

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9b47169a3ba69b2c338c2335ce397cd492f13525
4
+ data.tar.gz: 6b5595ebf954eac27764859406190fd3b0228185
5
+ SHA512:
6
+ metadata.gz: 4403e960567adde50c633cc8bde86356521f0bd1126adf3401ba04da4a6e428b1b1efca7d46dda58beed9bf7b43c05f04754a0555470933b2499d5de8e7cfbab
7
+ data.tar.gz: 8946649e944635b593eff11e99e90df050e7e3318c7cd6e8e6737873429ede66f5b15cf3a65cda1ad60dc2fad07e9f631d6104b9670faae9f4cc8fe0fc82ccb5
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at bajalovic@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in smartlist_push_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ivan Bajalovic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # Smartlist Push API
2
+
3
+ THe Smartlist Push API allows you to send your user activity to Smartlist to drive analytics and automated messaging through the Smartlist application. The data that you send to Smartlist is used to set up filters that enable the creation of segments and targeting for automated messaging to users.
4
+
5
+ ## Installation
6
+
7
+ To get started, add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'smartlist_push_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```
22
+ $ gem install smartlist_push_api
23
+ ```
24
+
25
+ ## Enabling Push API
26
+
27
+ First, you will need an account at [Smartlist](http://smartlisthq.com). After you create an account, you can enable the Push API from your [profile settings](http://smartlisthq.com/app/profile/push-api) where you can get an access token.
28
+
29
+ Create initializer `smartlist_push_api.rb` and put
30
+
31
+ ```ruby
32
+ SmartlistPushApi.access_token = 'your-access-token'
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ #### User Account
38
+
39
+ Once a user registers within your app, you can send that information to Smartlist via the following:
40
+
41
+ ```ruby
42
+ SmartlistPushApi::User.create({
43
+ email: 'user@example.com', # required
44
+ ref_id: 'ref_user_102', # required
45
+ first_name: 'John', # optional
46
+ last_name: 'Doe', # optional
47
+ display_name: 'John Doe', # optional
48
+ company_name: 'ABC Corp', # optional
49
+ ref_created_at: '2016-07-26 20:28:37', # required
50
+ ref_updated_at: '2016-07-27 18:08:37' # required
51
+ })
52
+ ```
53
+
54
+ The field `ref_id` is required and should be unique for each user from your app. You will use that field to create or update a user’s information.
55
+
56
+ When a user changes their data, you can sync information with Smartlist with the following method:
57
+
58
+ ```ruby
59
+ SmartlistPushApi::User.update('ref_user_102', {first_name: 'Joana'})
60
+ ```
61
+
62
+ The first attribute is a `ref_id` and the second attribute is the object that has any of the previously mentioned user attributes, as well as the attribute `unsubscribed`. Setting `unsubscribed` to false will prevent this user from receiving emails. If user leaves your app, you should remove them from Smartlist with the following:
63
+
64
+ ```ruby
65
+ SmartlistPushApi::User.destroy('ref_user_102')
66
+ ```
67
+ The above method will remove user who has `ref_id` set to `ref_user_102` from Smartlist.
68
+
69
+
70
+ #### Login Activity
71
+
72
+ Every time user logs in in your app, you can update Smartlist (as a way to track user activity):
73
+
74
+ ```ruby
75
+ SmartlistPushApi::User.signed_in('ref_user_102', Time.current)
76
+ ```
77
+ This method receive two attributes: user's `ref_id` and a `datetime` object.
78
+
79
+
80
+ #### Subscription Activity
81
+
82
+ If your app has subscription plans, you can send that to Smartlist to filter users by subscription type.. In addition, we recognize four different subscription event types: **signed_up**, **canceled**, **upgraded** and **downgraded**.
83
+
84
+ - **signed_up** should be sent when user start using a plan for the first time (after first registering with your app);
85
+ - **canceled** should be sent when user cancels a plan;
86
+ - **upgraded** when user upgrades to a higher plan;
87
+ - **downgrade** when user downgrades to a lower plan.
88
+
89
+ ```ruby
90
+ # ref_id, plan name, datetime object when subscription started
91
+ SmartlistPushApi::User.started_subscription('ref_user_102', 'Freemium', 1.week.ago)
92
+ # ref_id, from plan name, to plan name, datetime object when subscription was upgraded
93
+ SmartlistPushApi::User.upgraded_subscription('ref_user_102', 'Freemium', 'Pro', 1.week.ago)
94
+ # ref_id, from plan name, to plan name, datetime object when subscription was downgraded
95
+ SmartlistPushApi::User.downgraded_subscription('ref_user_102', 'Pro', 'Freemium', 2.days.ago)
96
+ # ref_id, plan name that was canceled, datetime object when subscription was cancelled
97
+ SmartlistPushApi::User.canceled_subscription('ref_user_102', 'Pro', 2.days.ago)
98
+ ```
99
+
100
+ ## License
101
+
102
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "smartlist_push_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ module SmartlistPushApi
2
+ module Http
3
+ class HttpClient
4
+
5
+ def initialize()
6
+ @default_headers = {
7
+ 'x-access-token' => SmartlistPushApi.access_token,
8
+ 'Accept' => 'application/json'
9
+ }
10
+ end
11
+
12
+ def post_request(url, data)
13
+ HTTParty.post("#{SmartlistPushApi.base_uri}#{url}", {body: data, headers: @default_headers})
14
+ end
15
+
16
+ def patch_request(url, data)
17
+ HTTParty.patch("#{SmartlistPushApi.base_uri}#{url}", {body: data, headers: @default_headers})
18
+ end
19
+
20
+ def get_request(url)
21
+ HTTParty.get("#{SmartlistPushApi.base_uri}#{url}", {headers: @default_headers})
22
+ end
23
+
24
+ def delete_request(url)
25
+ HTTParty.delete("#{SmartlistPushApi.base_uri}#{url}", {headers: @default_headers})
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,70 @@
1
+ module SmartlistPushApi
2
+ class User
3
+
4
+ def self.create(data)
5
+ SmartlistPushApi.make_post_request('/users/', data)
6
+ end
7
+
8
+ def self.update(user_id, data)
9
+ SmartlistPushApi.make_patch_request("/users/#{user_id}/", data)
10
+ end
11
+
12
+ def self.destroy(user_id)
13
+ SmartlistPushApi.make_delete_request("/users/#{user_id}/")
14
+ end
15
+
16
+ def self.started_subscription(user_id, plan_name, started_at)
17
+ raise InvalidDataException if plan_name.blank?
18
+ raise InvalidDataException if started_at.blank?
19
+
20
+ SmartlistPushApi.make_post_request("/users/#{user_id}/subscription/", {
21
+ type: :signed_up,
22
+ plan_name: plan_name,
23
+ event_at: started_at.utc.strftime('%Y-%m-%d %H:%M:%S')
24
+ })
25
+ end
26
+
27
+ def self.canceled_subscription(user_id, plan_name, canceled_at)
28
+ raise InvalidDataException if plan_name.blank?
29
+ raise InvalidDataException if canceled_at.blank?
30
+
31
+ SmartlistPushApi.make_post_request("/users/#{user_id}/subscription/", {
32
+ type: :canceled,
33
+ plan_name: plan_name,
34
+ event_at: canceled_at.utc.strftime('%Y-%m-%d %H:%M:%S')
35
+ })
36
+ end
37
+
38
+ def self.upgraded_subscription(user_id, from_plan, to_plan, conversion_at)
39
+ raise InvalidDataException if from_plan.blank?
40
+ raise InvalidDataException if to_plan.blank?
41
+ raise InvalidDataException if conversion_at.blank?
42
+
43
+ SmartlistPushApi.make_post_request("/users/#{user_id}/subscription/", {
44
+ type: :upgraded,
45
+ plan_name: to_plan,
46
+ from_plan: from_plan,
47
+ event_at: conversion_at.utc.strftime('%Y-%m-%d %H:%M:%S')
48
+ })
49
+ end
50
+
51
+ def self.downgraded_subscription(user_id, from_plan, to_plan, conversion_at)
52
+ raise InvalidDataException if from_plan.blank?
53
+ raise InvalidDataException if to_plan.blank?
54
+ raise InvalidDataException if conversion_at.blank?
55
+
56
+ SmartlistPushApi.make_post_request("/users/#{user_id}/subscription/", {
57
+ type: :downgraded,
58
+ plan_name: to_plan,
59
+ from_plan: from_plan,
60
+ event_at: conversion_at.utc.strftime('%Y-%m-%d %H:%M:%S')
61
+ })
62
+ end
63
+
64
+ def self.signed_in(user_id, date)
65
+ raise InvalidDataException if date.blank?
66
+
67
+ SmartlistPushApi.make_post_request("/users/#{user_id}/login/", {date: date.utc.strftime('%Y-%m-%d %H:%M:%S')})
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ module SmartlistPushApi
2
+ VERSION = "0.1.13"
3
+ end
@@ -0,0 +1,58 @@
1
+ require 'smartlist_push_api/version'
2
+ require 'smartlist_push_api/http/http_client'
3
+ require 'smartlist_push_api/user'
4
+
5
+ module SmartlistPushApi
6
+ class InvalidDataException < StandardError;
7
+ end
8
+
9
+ @base_uri = 'http://smartlisthq.com/push'
10
+ @access_token = ''
11
+
12
+ class << self
13
+ attr_accessor :base_uri, :access_token
14
+ end
15
+
16
+ def self.make_post_request(url, data)
17
+ SmartlistPushApi.make_request(:POST, url, data)
18
+ end
19
+
20
+ def self.make_patch_request(url, data)
21
+ SmartlistPushApi.make_request(:PATCH, url, data)
22
+ end
23
+
24
+ def self.make_get_request(url)
25
+ SmartlistPushApi.make_request(:GET, url)
26
+ end
27
+
28
+ def self.make_delete_request(url)
29
+ SmartlistPushApi.make_request(:GET, url)
30
+ end
31
+
32
+ def self.make_request(request_method, url, data = nil)
33
+
34
+ http_client = Http::HttpClient.new
35
+ if request_method == :POST
36
+ raise InvalidDataException if data.nil?
37
+
38
+ response = http_client.post_request(url, data)
39
+ return response.code == 200
40
+ elsif request_method == :PATCH
41
+ raise InvalidDataException if data.nil?
42
+
43
+ response = http_client.patch_request(url, data)
44
+ return response.code == 200
45
+ elsif request_method == :GET
46
+ response = http_client.get_request(url)
47
+ return response.code == 200
48
+ elsif request_method == :DELETE
49
+ response = http_client.delete_request(url)
50
+ return response.code == 204
51
+ end
52
+
53
+ return false
54
+ rescue => e
55
+ return false
56
+ end
57
+
58
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smartlist_push_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "smartlist_push_api"
8
+ spec.version = SmartlistPushApi::VERSION
9
+ spec.authors = ["Ivan Bajalovic"]
10
+ spec.email = ["bajalovic@gmail.com"]
11
+
12
+ spec.summary = %q{Smartlist Push API}
13
+ spec.description = %q{Log events from your app to Smartlist so you can create customer segments and campaigns.}
14
+ spec.homepage = "http://smartlisthq.com"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "minitest", "~> 5.0"
33
+ spec.add_development_dependency "httparty"
34
+ spec.add_development_dependency "railties"
35
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smartlist_push_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.13
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Bajalovic
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: railties
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Log events from your app to Smartlist so you can create customer segments
84
+ and campaigns.
85
+ email:
86
+ - bajalovic@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/smartlist_push_api.rb
101
+ - lib/smartlist_push_api/http/http_client.rb
102
+ - lib/smartlist_push_api/user.rb
103
+ - lib/smartlist_push_api/version.rb
104
+ - smartlist_push_api.gemspec
105
+ homepage: http://smartlisthq.com
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.6.4
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Smartlist Push API
129
+ test_files: []