delayable_km 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## v0.0.1: 2012/01/24
4
+
5
+ * Wrote initial methods and documentation for instantiating a
6
+ KISSmetrics API client and recording events, aliasing identifiers, and
7
+ setting properties
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in delayable_km.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Nicholas Firth-McCoy
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # delayable_km
2
+
3
+ `delayable_km` is a minimal implementation of the [KISSmetrics](http://www.kissmetrics.com/) API that can be used with `delayed_job`.
4
+
5
+ The [official KISSmetrics gem](https://github.com/kissmetrics/km) is written is incompatible with `delayed_job`. They instead use a [cron based](http://support.kissmetrics.com/apis/cron) method to asynchronously send data to KISSmetrics.
6
+
7
+ I'd prefer to use `delayed_job`, hence the gem.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'delayable_km'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install delayable_km
22
+
23
+ ## Usage
24
+
25
+ This gem is used in a similar way to the [official gem](https://github.com/kissmetrics/km), but it requires that you instantiate an API client:
26
+
27
+ # Official km gem approach:
28
+ KM.initialize(your_api_key)
29
+ KM.identify(current_user.email)
30
+ KM.record('some event')
31
+
32
+ # delayable_km approach:
33
+ @km ||= KM.initialize(your_api_key)
34
+ @km.identify(current_user.email)
35
+ @km.record(event, optional_properties)
36
+
37
+ As a result, it can be used with `delayed_job`:
38
+
39
+ # Will be added to your queue of jobs for delayed_job to run
40
+ @km.delay.record(event, optional_properties)
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+
4
+ # Define a task to make sure the gem's files are world readable.
5
+ task :set_permissions do
6
+ system("find . -type f -exec chmod 644 {} \\;")
7
+ system("find . -type d -exec chmod 755 {} \\;")
8
+ end
9
+
10
+ # Add :set_permissions as a dependency for the :build, :install, and :release
11
+ # tasks that bundler provides, so that the correct permissions are always set.
12
+ task :build => :set_permissions
13
+ task :install => :set_permissions
14
+ task :release => :set_permissions
15
+
16
+ begin
17
+ require 'rspec/core/rake_task'
18
+ RSpec::Core::RakeTask.new('spec')
19
+
20
+ require 'yard'
21
+ YARD::Rake::YardocTask.new(:yard)
22
+ rescue LoadError
23
+ abort "You need to install the gem's development dependencies. Run `bundle install`."
24
+ end
25
+
26
+ task :default => :spec
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/delayable_km/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Nicholas Firth-McCoy"]
6
+ gem.email = ["nicholas@2suggestions.com.au"]
7
+ gem.summary = %q{A minimal wrapper for the KISSmetrics API that can be used with delayed_job}
8
+ gem.homepage = "https://github.com/nfm/delayable_km"
9
+
10
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
11
+ gem.files = `git ls-files`.split("\n")
12
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
+ gem.name = "delayable_km"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = DelayableKm::VERSION
16
+
17
+ gem.required_rubygems_version = '>= 1.3.6'
18
+ gem.add_runtime_dependency 'httparty'
19
+
20
+ gem.add_development_dependency 'rspec'
21
+ gem.add_development_dependency 'webmock'
22
+ gem.add_development_dependency 'simplecov'
23
+ gem.add_development_dependency 'yard'
24
+ end
@@ -0,0 +1,12 @@
1
+ require "delayable_km/version"
2
+
3
+ # delayable_km: A minimal wrapper for the KISSmetrics API that can be used with delayed_job
4
+ #
5
+ # @see https://github.com/kissmetrics/km The official KISSmetrics Ruby gem: km
6
+ # @see http://support.kissmetrics.com/apis/specifications The official KISSmetrics API specification
7
+ # @see http://support.kissmetrics.com/apis/api-tips Tips for using the KISSmetrics API
8
+ # @see http://support.kissmetrics.com/apis/common-methods Commonly used API calls
9
+ # @see http://support.kissmetrics.com/apis/ruby-specific#basic-rails-integration Tips for integrating the KISSmetrics Ruby and Javascript APIs with Rails
10
+ module DelayableKm
11
+ require 'delayable_km/km'
12
+ end
@@ -0,0 +1,61 @@
1
+ # The main delayable_km class, containing methods for initializing a KISSmetrics API client and making API calls
2
+ class KM
3
+ # The default KISSmetrics API endpoint that all requests are sent to
4
+ DEFAULT_API_ENDPOINT = 'http://trk.kissmetrics.com'
5
+
6
+ # Create a KISSmetrics API client.
7
+ #
8
+ # @param [String] :api_key Your site's KISSmetrics API key
9
+ def initialize(api_key, options = {})
10
+ @api_key = api_key
11
+ @api_endpoint = DEFAULT_API_ENDPOINT
12
+ end
13
+
14
+ # Set the identity of a person using your site
15
+ # @see http://support.kissmetrics.com/apis/common-methods#identify
16
+ #
17
+ # @param [String] :id A unique identifier for a person (email address, user id, or login are common choices)
18
+ def identify(id)
19
+ @id = id
20
+ end
21
+
22
+ # Record a KISSmetrics event
23
+ # @see http://support.kissmetrics.com/apis/common-methods#record
24
+ #
25
+ # @param [String] event
26
+ # @param [Hash] params
27
+ # @option options [String] :_p (@id) The identity of the person you are setting properties on. You can also set this by calling #identify.
28
+ def record(event, params = {})
29
+ defaults = { :_n => event, :_p => @id }
30
+ params = defaults.merge(params)
31
+ request('e', params)
32
+ end
33
+
34
+ # Associate one KISSmetrics identity with another
35
+ # @see http://support.kissmetrics.com/apis/common-methods#alias
36
+ # @note The order of arguments to this method doesn't actually matter. You can call it with the existing identifier first or second.
37
+ #
38
+ # @param [String] name An existing identifier for a user
39
+ # @param [String] alias_to A new identifier to associate with the user
40
+ def alias(name, alias_to)
41
+ params = { :_n => alias_to, :_p => name }
42
+ request('a', params)
43
+ end
44
+
45
+ # Set properties on a person without recording a named event
46
+ # @see http://support.kissmetrics.com/apis/common-methods#set
47
+ #
48
+ # @param [Hash] params An arbitrary hash of properties to associate with a person
49
+ # @option options [String] :_p (@id) The identity of the person you are setting properties on. You can also set this by calling #identify.
50
+ def set(params)
51
+ defaults = { :_p => @id }
52
+ params = defaults.merge(params)
53
+ request('s', params)
54
+ end
55
+
56
+ private
57
+ def request(path, params)
58
+ params = { :_t => Time.now.utc.to_i.to_s, :_d => 1, :_k => @api_key }.merge(params)
59
+ HTTParty.get("#{@api_endpoint}/#{path}", :query => params)
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ module DelayableKm
2
+ # The version of delayable_km that you're using. delayable_km is versioned using semantic versioning.
3
+ # @see http://semver.org/
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe KM do
4
+ describe '.record' do
5
+ pending
6
+ end
7
+
8
+ describe '.alias' do
9
+ pending
10
+ end
11
+
12
+ describe '.set' do
13
+ pending
14
+ end
15
+ end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1,7 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'rspec'
5
+ require 'webmock/rspec'
6
+
7
+ require 'delayable_km'
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: delayable_km
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nicholas Firth-McCoy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &23060740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *23060740
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &23060240 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *23060240
36
+ - !ruby/object:Gem::Dependency
37
+ name: webmock
38
+ requirement: &23059700 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *23059700
47
+ - !ruby/object:Gem::Dependency
48
+ name: simplecov
49
+ requirement: &23059160 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *23059160
58
+ - !ruby/object:Gem::Dependency
59
+ name: yard
60
+ requirement: &23058500 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *23058500
69
+ description:
70
+ email:
71
+ - nicholas@2suggestions.com.au
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - CHANGELOG.md
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - delayable_km.gemspec
83
+ - lib/delayable_km.rb
84
+ - lib/delayable_km/km.rb
85
+ - lib/delayable_km/version.rb
86
+ - spec/delayable_km/km_spec.rb
87
+ - spec/delayable_km_spec.rb
88
+ - spec/spec_helper.rb
89
+ homepage: https://github.com/nfm/delayable_km
90
+ licenses: []
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: 1.3.6
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.15
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: A minimal wrapper for the KISSmetrics API that can be used with delayed_job
113
+ test_files: []
114
+ has_rdoc: