orwell-mole 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +27 -0
- data/lib/orwell/mole/client.rb +33 -0
- data/lib/orwell/mole/config.rb +52 -0
- data/lib/orwell/mole/errors/missing_api_token_error.rb +7 -0
- data/lib/orwell/mole/event.rb +21 -0
- data/lib/orwell/mole/transport/basic_http.rb +47 -0
- data/lib/orwell/mole/transporter.rb +37 -0
- data/lib/orwell/mole/version.rb +3 -0
- data/lib/orwell/mole.rb +33 -0
- metadata +168 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 25f0049bf2485cbd493191b024fe25d40892e338
|
4
|
+
data.tar.gz: 6fd44b51ea7258f51a13f9150d29d9b649803398
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 861cd019f9b8b09688b82a55b873ae1aed232f9e77a4357d7977ad430ffdf6610a27446d818870a98617ea8ce98691df73501b2e23212e854ba096e37f5a3c31
|
7
|
+
data.tar.gz: 2ed88dd3a601855dfcf2a646dac56a132bb5e876e60f0f4da5797374701709d80815a90a5aab20000592913ab83abbc7692acdf70d074dc3eefc0bbb589adf47
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Sean
|
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.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Mole
|
2
|
+
|
3
|
+
Easily send events to Orwell from within your Ruby application.
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/orwell-mole.png)](https://rubygems.org/gems/orwell-mole)[![Build Status](https://travis-ci.org/doomspork/mole.svg?branch=master)](https://travis-ci.org/doomspork/mole) [![Code Climate](https://codeclimate.com/github/doomspork/mole/badges/gpa.svg)](https://codeclimate.com/github/doomspork/mole) [![Coverage Status](https://coveralls.io/repos/doomspork/mole/badge.png)](https://coveralls.io/r/doomspork/mole) [![Dependency Status](https://gemnasium.com/doomspork/mole.svg)](https://gemnasium.com/doomspork/mole)
|
6
|
+
|
7
|
+
### Gemfile
|
8
|
+
|
9
|
+
+ `gem 'orwell-mole', require: 'orwell/mole'`
|
10
|
+
|
11
|
+
### Configuration
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
Mole.config do |c|
|
15
|
+
c.api_token = 'your orwell api token'
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
### Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
@channel = Mole.channel(:accounts)
|
23
|
+
@channel.record(:new_account, params[:email], params)
|
24
|
+
|
25
|
+
@channel = Mole.track(@user.email, :accounts)
|
26
|
+
@channel.record(:password_change)
|
27
|
+
```
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Mole
|
2
|
+
class Client
|
3
|
+
|
4
|
+
attr_reader :channel, :identifier, :transporter
|
5
|
+
|
6
|
+
def initialize(channel, transporter)
|
7
|
+
@channel = channel
|
8
|
+
@transporter = transporter
|
9
|
+
end
|
10
|
+
|
11
|
+
def identify(id)
|
12
|
+
@identifier = id
|
13
|
+
end
|
14
|
+
|
15
|
+
def record(event, *args)
|
16
|
+
identifier, details = expand_args(args)
|
17
|
+
event = Event.new(channel, event, identifier, details)
|
18
|
+
@transporter.perform(event)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def expand_args(args)
|
24
|
+
id, details = args
|
25
|
+
if id.is_a?(Hash)
|
26
|
+
details = id
|
27
|
+
id = nil
|
28
|
+
end
|
29
|
+
id = @identifier unless id
|
30
|
+
[id, details]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'orwell/mole/errors/missing_api_token_error'
|
2
|
+
|
3
|
+
module Mole
|
4
|
+
class Config
|
5
|
+
DEFAULT_HOST = 'api.orwell.io'
|
6
|
+
DEFAULT_POST = 80
|
7
|
+
DEFAULT_API_VERSION = '0.1.0'
|
8
|
+
|
9
|
+
attr_accessor :api_token
|
10
|
+
attr_writer :api_version, :host, :logger, :method, :port
|
11
|
+
|
12
|
+
def api_token
|
13
|
+
raise MissingApiTokenError unless @api_token
|
14
|
+
@api_token
|
15
|
+
end
|
16
|
+
|
17
|
+
def api_version
|
18
|
+
@api_version || DEFAULT_API_VERSION
|
19
|
+
end
|
20
|
+
|
21
|
+
def host
|
22
|
+
@host || DEFAULT_HOST
|
23
|
+
end
|
24
|
+
|
25
|
+
def log
|
26
|
+
@logger || default_logger
|
27
|
+
end
|
28
|
+
|
29
|
+
def method
|
30
|
+
@method || :basic_http
|
31
|
+
end
|
32
|
+
|
33
|
+
def port
|
34
|
+
@port || DEFAULT_POST
|
35
|
+
end
|
36
|
+
|
37
|
+
def reset!
|
38
|
+
@api_token, @api_version, @host, @logger, @method, @port = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def default_logger
|
44
|
+
unless @default_logger
|
45
|
+
require 'logger'
|
46
|
+
@default_logger = Logger.new(STDOUT)
|
47
|
+
end
|
48
|
+
@default_logger
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Mole
|
2
|
+
class Event
|
3
|
+
attr_accessor :channel, :event, :identifier, :details
|
4
|
+
|
5
|
+
def initialize(channel, event, identifier, details = {})
|
6
|
+
@channel = channel
|
7
|
+
@event = event
|
8
|
+
@identifier = identifier
|
9
|
+
@details = details
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_h
|
13
|
+
{
|
14
|
+
channel: channel,
|
15
|
+
event: event,
|
16
|
+
identifier: identifier,
|
17
|
+
details: details
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module Mole
|
5
|
+
module Transport
|
6
|
+
class BasicHttp
|
7
|
+
attr_reader :host, :port, :token, :version
|
8
|
+
|
9
|
+
def initialize(opts = {})
|
10
|
+
@host = opts[:host]
|
11
|
+
@port = opts[:port]
|
12
|
+
@token = opts[:api_token]
|
13
|
+
@version = opts[:api_version]
|
14
|
+
end
|
15
|
+
|
16
|
+
def perform(event)
|
17
|
+
json = event_json(event)
|
18
|
+
response = post(json)
|
19
|
+
success(response)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def success(resp)
|
25
|
+
resp.is_a? Net::HTTPSuccess
|
26
|
+
end
|
27
|
+
|
28
|
+
def post(params)
|
29
|
+
Net::HTTP.start(host, port) do |http|
|
30
|
+
http.post('/events', params, headers)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def event_json(event)
|
35
|
+
JSON.generate(event.to_h)
|
36
|
+
end
|
37
|
+
|
38
|
+
def headers
|
39
|
+
{
|
40
|
+
'accept' => "application/vnd.orwell.api.json; version=#{version}",
|
41
|
+
'orwell_token' => token
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'orwell/mole/transport/basic_http'
|
2
|
+
|
3
|
+
module Mole
|
4
|
+
class Transporter
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def_delegators :transport, :perform
|
8
|
+
|
9
|
+
attr_reader :transport
|
10
|
+
|
11
|
+
def initialize(transport)
|
12
|
+
@transport = lookup(transport)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def lookup(transport)
|
18
|
+
case transport
|
19
|
+
when :basic_http
|
20
|
+
Transport::BasicHttp.new(config_hash)
|
21
|
+
when :sidekiq
|
22
|
+
raise NotImplementedError
|
23
|
+
else nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def config_hash
|
28
|
+
{
|
29
|
+
api_token: Mole.config.api_token,
|
30
|
+
api_version: Mole.config.api_version,
|
31
|
+
host: Mole.config.host,
|
32
|
+
port: Mole.config.port
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/orwell/mole.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'orwell/mole/version'
|
2
|
+
require 'orwell/mole/config'
|
3
|
+
require 'orwell/mole/event'
|
4
|
+
require 'orwell/mole/transporter'
|
5
|
+
require 'orwell/mole/client'
|
6
|
+
|
7
|
+
module Mole
|
8
|
+
def self.config
|
9
|
+
@config ||= Config.new
|
10
|
+
yield @config if block_given?
|
11
|
+
@config
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.channel(name)
|
15
|
+
new_client(name)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.track(identifier, name)
|
19
|
+
client = new_client(name)
|
20
|
+
client.identify(identifier)
|
21
|
+
client
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def self.new_client(channel)
|
27
|
+
Client.new(channel, self.transporter)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.transporter
|
31
|
+
@transporter ||= Transporter.new(config.method)
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: orwell-mole
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Callan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-29 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coveralls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rr
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-its
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.9'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.9'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.18'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.18'
|
125
|
+
description: Mole allows developers to send events from within their code directly
|
126
|
+
to Orwell.
|
127
|
+
email:
|
128
|
+
- seancallan@gmail.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- README.md
|
134
|
+
- LICENSE
|
135
|
+
- lib/orwell/mole/client.rb
|
136
|
+
- lib/orwell/mole/config.rb
|
137
|
+
- lib/orwell/mole/errors/missing_api_token_error.rb
|
138
|
+
- lib/orwell/mole/event.rb
|
139
|
+
- lib/orwell/mole/transport/basic_http.rb
|
140
|
+
- lib/orwell/mole/transporter.rb
|
141
|
+
- lib/orwell/mole/version.rb
|
142
|
+
- lib/orwell/mole.rb
|
143
|
+
homepage: http://www.orwell.io
|
144
|
+
licenses:
|
145
|
+
- MIT
|
146
|
+
metadata: {}
|
147
|
+
post_install_message:
|
148
|
+
rdoc_options: []
|
149
|
+
require_paths:
|
150
|
+
- lib
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - '>='
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - '>='
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
requirements: []
|
162
|
+
rubyforge_project:
|
163
|
+
rubygems_version: 2.0.14
|
164
|
+
signing_key:
|
165
|
+
specification_version: 4
|
166
|
+
summary: A client library for Orwell
|
167
|
+
test_files: []
|
168
|
+
has_rdoc:
|