forwardlytics 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 33b629b94546b4d59f6c2c9c06a4b185313e424f
4
+ data.tar.gz: 6b8e1abdb7023b0e39ad150f2dc90c2dc00ba45e
5
+ SHA512:
6
+ metadata.gz: 88a1a72f85edc82013574cb4edfafc9fd9708ad05d4db2861f5d1368e27fb0d8e8d200fe3dee70a2e43762bf9fbfcd7aeed105bb8ac6339dbc231bc07ee2964d
7
+ data.tar.gz: 97f8ea860f5be91931dfdfdd842a36bf6c31676a9a5fe283e8cc12122be80a83ca5f90d8ca6273ef28dd269456a4dbd75f23da305cb697dcb3d471aaf2c69def
@@ -0,0 +1,37 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+ /Gemfile.lock
13
+
14
+ ## Specific to RubyMotion:
15
+ .dat*
16
+ .repl_history
17
+ build/
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalization:
26
+ /.bundle/
27
+ /vendor/bundle
28
+ /lib/bundler/man/
29
+
30
+ # for a library or gem, you might want to ignore these files since the code is
31
+ # intended to run in multiple environments; otherwise, check them in:
32
+ # Gemfile.lock
33
+ # .ruby-version
34
+ # .ruby-gemset
35
+
36
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
37
+ .rvmrc
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ - 2.2
5
+ - 2.1
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in forwardlytics.gemspec
4
+ gemspec
5
+
6
+ gem 'pry'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jean-Philippe Boily
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,97 @@
1
+ # Forwardlytics: the Ruby client
2
+
3
+ <p align="center">
4
+ <img src="https://s3.amazonaws.com/forwardlytics-assets/logo-color.svg">
5
+ </p>
6
+
7
+ Sends stuff to [Forwardlytics](https://github.com/jipiboily/forwardlytics).
8
+
9
+ Where are we at? What needs to be done and what's in the pipeline? See [Forawrdlytics on waffle.io][forwardlytics-ruby-on-waffle]
10
+
11
+ [![Build Status](https://travis-ci.org/jipiboily/forwardlytics-ruby.svg?branch=master)](https://travis-ci.org/jipiboily/forwardlytics-ruby)
12
+ [![Stories in Progress](https://badge.waffle.io/jipiboily/forwardlytics-ruby.svg?label=In%20Progress&title=In%20Progress)](http://waffle.io/jipiboily/forwardlytics-ruby)
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'forwardlytics'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ ## How to use it?
27
+
28
+
29
+ ### Setup
30
+
31
+ You need to set both `FORWARDLYTICS_API_KEY` and `FORWARDLYTICS_URL` environment variables.
32
+
33
+ `FORWARDLYTICS_API_KEY` is the API key you configured on [Forwardlytics](https://github.com/jipiboily/forwardlytics).
34
+
35
+ `FORWARDLYTICS_URL` is the URL to reach your instance of [Forwardlytics](https://github.com/jipiboily/forwardlytics).
36
+
37
+ Example:
38
+
39
+ ```
40
+ FORWARDLYTICS_API_KEY=123ma
41
+ FORWARDLYTICS_URL=http://localhost:3000
42
+ ```
43
+
44
+ ### Exception handler
45
+
46
+ Forwardlytics will do its work in threads, so if any exception is raised, it will be silent. We don't want that, so we made an exception handler. Here is how you could configure it in your project:
47
+
48
+ ```ruby
49
+ Forwardlytics.exception_handler = -> (ex) {
50
+ puts "Exception in Forwardlytics caught by exception_handler: #{ex}"
51
+ Bugsnag.notify(ex)
52
+ }
53
+ ```
54
+
55
+ ### Dispatch events and identifications
56
+
57
+ For user identification:
58
+
59
+ ```ruby
60
+ Forwardlytics.identify(
61
+ user_id: 42,
62
+ traits: {
63
+ email: 'john@example.com',
64
+ created_at: 1462183499,
65
+ some: 'thing?'
66
+ }
67
+ )
68
+ ```
69
+
70
+ For event tracking:
71
+
72
+ ```ruby
73
+ Forwardlytics.track(
74
+ event: 'Updated Alert',
75
+ user_id: 42,
76
+ properties: {
77
+ some_id: 123,
78
+ some_other_prop: "",
79
+ })
80
+ ```
81
+
82
+ ## Development
83
+
84
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
85
+
86
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
87
+
88
+ ## Contributing
89
+
90
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jipiboily/forwardlytics. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
91
+
92
+
93
+ ## License
94
+
95
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
96
+
97
+ [forwardlytics-ruby-on-waffle]: https://waffle.io/jipiboily/forwardlytics-ruby
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ # Set default Rake task to spec
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task default: :spec
8
+ rescue LoadError => ex
9
+ # That's ok, it just means we don't have RSpec loaded
10
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "forwardlytics"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'forwardlytics/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "forwardlytics"
8
+ spec.version = Forwardlytics::VERSION
9
+ spec.authors = ["JP Boily"]
10
+ spec.email = ["j@jipi.ca"]
11
+
12
+ spec.summary = %q{This is a client for Forwardlytics.}
13
+ spec.description = %q{This is a client for Forwardlytics (https://github.com/jipiboily/forwardlytics). Takes event in and forwards them to various providers, mostly analytics providers.}
14
+ spec.homepage = "https://github.com/jipiboily/forwardlytics"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", ">= 3.4.0"
24
+ spec.add_development_dependency "webmock", ">= 2.0.0"
25
+ spec.add_development_dependency "timecop", ">= 0.8.0"
26
+ end
@@ -0,0 +1,49 @@
1
+ require 'forwardlytics/version'
2
+ require 'forwardlytics/identify'
3
+ require 'forwardlytics/track'
4
+ require 'json'
5
+
6
+ FORWARDLYTICS_API_KEY = ENV.fetch('FORWARDLYTICS_API_KEY')
7
+ FORWARDLYTICS_URL = ENV.fetch('FORWARDLYTICS_URL')
8
+
9
+ module Forwardlytics
10
+ class NetException < StandardError
11
+ end
12
+
13
+ def self.post(uri, params)
14
+ begin
15
+ # Forces the user_id to be a string, which is the expected format by Forwardlytics (the server part)
16
+ params[:userID] = params[:userID].to_s unless params[:userID].nil?
17
+
18
+ full_url = URI("#{FORWARDLYTICS_URL}#{uri}")
19
+ http = Net::HTTP.new(full_url.host, full_url.port)
20
+ if full_url.port == 443
21
+ http.use_ssl = true
22
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
23
+ end
24
+ req = Net::HTTP::Post.new(full_url, initheader = {'Content-Type' =>'application/json'})
25
+ req['Forwardlytics-Api-Key'] = FORWARDLYTICS_API_KEY
26
+ req.body = params.to_json
27
+ res = http.request(req)
28
+
29
+ case res
30
+ when Net::HTTPSuccess, Net::HTTPRedirection
31
+ # OK
32
+ else
33
+ raise NetException, "Potential problem posting to Forwardlytics (#{full_url}) - #{res.inspect} - #{res.code} - #{res.body}"
34
+ end
35
+ rescue Exception => ex
36
+ exception_handler(ex)
37
+ end
38
+ end
39
+
40
+ def self.exception_handler=(handler)
41
+ @exception_handler = handler
42
+ end
43
+
44
+ def self.exception_handler(ex)
45
+ if @exception_handler
46
+ @exception_handler.call(ex)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,11 @@
1
+ module Forwardlytics
2
+ def self.identify(user_id:, traits: {})
3
+ params = {
4
+ userID: user_id,
5
+ userTraits: traits,
6
+ timestamp: Time.now().to_i
7
+ }
8
+
9
+ t = Thread.new { post('/identify', params) }
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Forwardlytics
2
+ def self.track(event:, user_id:, properties: {})
3
+ params = {
4
+ name: event,
5
+ userID: user_id,
6
+ properties: properties,
7
+ timestamp: Time.now().to_i
8
+ }
9
+
10
+ t = Thread.new { post('/track', params) }
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Forwardlytics
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: forwardlytics
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - JP Boily
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.4.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.4.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: timecop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.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.8.0
69
+ description: This is a client for Forwardlytics (https://github.com/jipiboily/forwardlytics).
70
+ Takes event in and forwards them to various providers, mostly analytics providers.
71
+ email:
72
+ - j@jipi.ca
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - forwardlytics.gemspec
87
+ - lib/forwardlytics.rb
88
+ - lib/forwardlytics/identify.rb
89
+ - lib/forwardlytics/track.rb
90
+ - lib/forwardlytics/version.rb
91
+ homepage: https://github.com/jipiboily/forwardlytics
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.6.8
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: This is a client for Forwardlytics.
115
+ test_files: []
116
+ has_rdoc: