hyperfocal 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc9860648d47875518439d878fee9c6413df7666
4
- data.tar.gz: d5d4479d9d5a7ea19bfec3553d12de7596658427
3
+ metadata.gz: 6c47d9b331310563355dcb8b4bb2c1b7aa2e9534
4
+ data.tar.gz: e576d76d0078155f23cdb3b803df78a4f8dba3ab
5
5
  SHA512:
6
- metadata.gz: 3b6addbcd704ae91679a7bd1a126ff10bfaa08dd1a05b6c8c7bb33b0a9ca4a8c20ae4beaf8937d70e3abf7b9ba79eb7eb2a50ceab8578443025364bf62ee2d43
7
- data.tar.gz: 73638686a4a29194b4aa4611b7999c083c74e5385c2e51749671478b3b6c1a0b137367f7dcb29bc902a8a56ba30dcd2cefac8dffb4fb03fa640a40fa0b7b7f8b
6
+ metadata.gz: 61f9f5ad2fee2b3cccd81f3a9f9e0919b4a3825e4d5ce4a8b930544a8bd3f558bbe1823190ede5a9337178173dfcfbea1f668bda99042207fe6d17eab413ce41
7
+ data.tar.gz: 5af1ccb7e298781fce47c09349f7eb6783f9b991b23cceacb294417ff4523086bddd7cba6d0bac7eb86fb91c1cd3c405c3534ef10df9d1640c0749744f795897
data/README.md CHANGED
@@ -1,39 +1,52 @@
1
1
  # Hyperfocal
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hyperfocal`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ ## Installation
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Visit [hyperfocal.io](http://hyperfocal.io) to set up an account, and find installation instructions
6
6
 
7
- ## Installation
7
+ ## Usage
8
8
 
9
- Add this line to your application's Gemfile:
9
+ After making sure you have an account on Hyperfocal, you can use the following
10
+ in your application.
10
11
 
11
- ```ruby
12
- gem 'hyperfocal'
13
- ```
12
+ ### Event Tracking
14
13
 
15
- And then execute:
14
+ To track an event, simply use this line in your application
15
+ `Hyperfocal.event('event_name', other_attributes_as_hash)`
16
16
 
17
- $ bundle
17
+ Optional (but helpful) attributes to include
18
18
 
19
- Or install it yourself as:
19
+ ```
20
+ user_id: Used to filter events by user/unique user
21
+ ```
20
22
 
21
- $ gem install hyperfocal
23
+ This will send an event to Hyperfocal
22
24
 
23
- ## Usage
24
25
 
25
- TODO: Write usage instructions here
26
+ ### Metric Tracking
27
+
28
+ Hyperfocal allows you to report metrics to the system. You can view them,
29
+ as averages, mins, or maxs.
30
+
31
+ To track a metric, use the following code in your application
32
+ `Hyperfocal.metric('metric_name', 'metric_value', other_attributes_as_hash)`
26
33
 
27
- ## Development
34
+ The supported metric values are strings, and integers. If you report the metrics
35
+ as integers, you can use the average, min, and max reporting type in Hyperfocal
28
36
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
37
 
31
- 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).
38
+ ### User Tracking
32
39
 
33
- ## Contributing
40
+ If you'd like to see more detailed information about your users in Hyperfocal,
41
+ you can report the User information to Hyperfocal.
34
42
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hyperfocal.
43
+ To report a user to Hyperfocal, simply use the following
44
+ `Hyperfocal.user(attributes_as_hash)`.
36
45
 
46
+ The only required field for a user, is whatever unique identifier is used by
47
+ your application. This is required to be unique for all your users,
48
+ as if you report two differnet users with the same ID. We will overwrite the
49
+ previous information, as the reported information is taken as gospel.
37
50
 
38
51
  ## License
39
52
 
data/bin/hyperfocal ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require "hyperfocal/commands"
3
+ Hyperfocal::Commands.start(ARGV)
@@ -0,0 +1,68 @@
1
+ require 'hyperfocal'
2
+ require 'net/http'
3
+ require 'thor'
4
+ require 'json'
5
+
6
+ module Hyperfocal
7
+ class Commands < Thor
8
+ desc :setup, 'Set up Hyperfocal'
9
+ def setup(token=nil)
10
+ return say('A token is required. Please visit http://hyperfocal.io to get a setup token', :red) if token.nil?
11
+ return say('Invalid app token, please make sure you have it correct', :red) unless valid_token?(token)
12
+
13
+ if File.exists?(initializer_path)
14
+ say('Initializer already exists', :red)
15
+ say('You can view your app at http://hyperfocal.io or remove config/initializers/hyperfocal.rb and set it up as a new app', :red)
16
+ else
17
+ write_initializer(token)
18
+ activate_app(token)
19
+ say('Congratulations, your app is ready to send events to Hyperfocal', :green)
20
+ end
21
+ end
22
+
23
+ desc :uninstall, 'Uninstall Hyperfocal'
24
+ def uninstall
25
+ if File.exists?(initializer_path)
26
+ File.delete(initializer_path)
27
+ say('The Hyperfocal initializer has been removed.')
28
+ say('Removing the gem from your Gemfile, and code from your app will complete the installation')
29
+ say("We're sad to see you go, if there's anything we can do, drop us a line at support@hyperfocal.io")
30
+ else
31
+ say('Hyperfocal does not have a configuration file, there is nothing to uninstall', :red)
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def initializer_path
38
+ File.expand_path(relative_initializer_path)
39
+ end
40
+
41
+ def relative_initializer_path
42
+ 'config/initializers/hyperfocal.rb'
43
+ end
44
+
45
+ def write_initializer(token)
46
+ FileUtils.mkdir_p(File.dirname(initializer_path))
47
+
48
+ File.open(initializer_path, 'w') do |f|
49
+ f.puts <<-CONF
50
+ Hyperfocal.configure do |config|
51
+ config.app_id = #{token}
52
+ end
53
+ CONF
54
+ end
55
+ end
56
+
57
+ def activate_app(token)
58
+ uri = URI('http://api.hyperfocal.io/activate')
59
+ req = Net::HTTP.post_form(uri, { token: token })
60
+ end
61
+
62
+ def valid_token?(token)
63
+ req = Net::HTTP.get("api.hyperfocal.io", "/validate?token=#{token}")
64
+ return JSON.parse(req.to_s)['valid']
65
+ end
66
+ end
67
+ end
68
+
@@ -0,0 +1,2 @@
1
+ module Hyperfocal
2
+ class
@@ -0,0 +1,17 @@
1
+ module Hyperfocal
2
+ module Transmitter
3
+ module_function
4
+
5
+ def send(type, params)
6
+ url = URI(url_for(type))
7
+ Net::HTTP.post_form(url, params)
8
+ end
9
+
10
+ def url_for(type)
11
+ raise 'Unknown Tracking Type' unless %w[ event metric user ].include?(type)
12
+
13
+ host = Hyperfocal.host
14
+ return "#{host}/#{type}"
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Hyperfocal
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/hyperfocal.rb CHANGED
@@ -1,5 +1,59 @@
1
+ require "yaml"
1
2
  require "hyperfocal/version"
3
+ require "hyperfocal/transmitter"
2
4
 
3
5
  module Hyperfocal
4
- # Your code goes here...
6
+ class << self
7
+ attr_accessor :configuration
8
+
9
+ def configure
10
+ self.configuration ||= Configuration.new
11
+ yield(configuration)
12
+ configuration.host = 'https://api.hyperfocal.io'
13
+ end
14
+
15
+ def host
16
+ raise 'App ID Not Set' if configuration.app_id.nil?
17
+
18
+ configuration.host + '/track/' + configuration.app_id
19
+ end
20
+
21
+ def event(event, attrs = {})
22
+ send_request do
23
+ event_params = { event: attrs.merge(title: event) }
24
+ Transmitter.send('event', event_params)
25
+ end
26
+ end
27
+
28
+ def metric(metric, value, attrs = {})
29
+ send_request do
30
+ metric_params = { metric: attrs.merge(title: metric, value: value) }
31
+ Transmitter.send('metric', metric_params)
32
+ end
33
+ end
34
+
35
+ def user(attrs)
36
+ send_request do
37
+ user_params = { user: attrs }
38
+ Transmitter.send('user', user_params)
39
+ end
40
+ end
41
+
42
+ def send_request(&block)
43
+ thr = Thread.new do
44
+ yield
45
+ end
46
+ thr.join
47
+ thr.exit
48
+ end
49
+ end
50
+
51
+ class Configuration
52
+ attr_accessor :app_id
53
+ attr_reader :host
54
+
55
+ def initialize
56
+ @host = 'https://api.hyperfocal.io'
57
+ end
58
+ end
5
59
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperfocal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Aaron Miler
7
+ - Pineworks Inc.
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-18 00:00:00.000000000 Z
11
+ date: 2017-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -54,22 +68,18 @@ dependencies:
54
68
  version: '3.0'
55
69
  description:
56
70
  email:
57
- - aaron@pineworks.io
58
- executables: []
71
+ - support@pineworks.io
72
+ executables:
73
+ - hyperfocal
59
74
  extensions: []
60
75
  extra_rdoc_files: []
61
76
  files:
62
- - ".gitignore"
63
- - ".rspec"
64
- - ".travis.yml"
65
- - Gemfile
66
- - LICENSE.txt
67
77
  - README.md
68
- - Rakefile
69
- - bin/console
70
- - bin/setup
71
- - hyperfocal.gemspec
78
+ - bin/hyperfocal
72
79
  - lib/hyperfocal.rb
80
+ - lib/hyperfocal/commands.rb
81
+ - lib/hyperfocal/record.rb
82
+ - lib/hyperfocal/transmitter.rb
73
83
  - lib/hyperfocal/version.rb
74
84
  homepage: http://hyperfocal.io
75
85
  licenses:
@@ -95,5 +105,5 @@ rubyforge_project:
95
105
  rubygems_version: 2.5.1
96
106
  signing_key:
97
107
  specification_version: 4
98
- summary: A Ruby gem for reporting to hyperfocal.io
108
+ summary: An event reporting app for Ruby
99
109
  test_files: []
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.1
5
- before_install: gem install bundler -v 1.13.1
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in hyperfocal.gemspec
4
- gemspec
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 Aaron Miler
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/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "hyperfocal"
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 DELETED
@@ -1,8 +0,0 @@
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
data/hyperfocal.gemspec DELETED
@@ -1,36 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'hyperfocal/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "hyperfocal"
8
- spec.version = Hyperfocal::VERSION
9
- spec.authors = ["Aaron Miler"]
10
- spec.email = ["aaron@pineworks.io"]
11
-
12
- spec.summary = %q{A Ruby gem for reporting to hyperfocal.io}
13
- spec.homepage = "http://hyperfocal.io"
14
- spec.license = "MIT"
15
-
16
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- if spec.respond_to?(:metadata)
19
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
- else
21
- raise "RubyGems 2.0 or newer is required to protect against " \
22
- "public gem pushes."
23
- end
24
-
25
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
- f.match(%r{^(test|spec|features)/})
27
- end
28
-
29
- spec.bindir = "exe"
30
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
32
-
33
- spec.add_development_dependency "bundler", "~> 1.13"
34
- spec.add_development_dependency "rake", "~> 10.0"
35
- spec.add_development_dependency "rspec", "~> 3.0"
36
- end