orwell-mole 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c28540d10a1580c8b9aa5875ebe7e78cca83146f
4
- data.tar.gz: a181ec77d9aa664f7bb99939b4c03d5a2309c0f3
3
+ metadata.gz: 1c3507531d3dea7b5252d3cac1c66fcc5eabf0e4
4
+ data.tar.gz: 26e95b013ae6d17ca9299c2ee2671394d12d75ff
5
5
  SHA512:
6
- metadata.gz: 6953a976f1052330d109be320ed431c96fcfa5fae36197e66c4d82162d117ef2caec5322bb97b69b691035c30cf3db0d07b13f4f4b7ad405ad2b98b488f5c09a
7
- data.tar.gz: c68b70b61af652fa7b65e5e540369f13e4dfbbd8137afae0b435e75df80a284de73ec52eca6981a6d06a90922b1722223bd39aa6eef0d0d0a890b02c77cbdc8f
6
+ metadata.gz: 0374d17469ac8cee408278ee8b5a17ff0b854bf0352ec9a26a0b9d28ff4274f78e00a846fbcc756fbe7719c0fab0bba27ab6071d8a8c25f366d1128f4dd0819c
7
+ data.tar.gz: 9562b552d6a12d887401498e09ed64dabf91715e072b442bfc49938a7f44f97280281b65c8f466cb05f82db0ce5276b9d594d5c0edf4e8c52d4eb41675198647
data/README.md CHANGED
@@ -29,16 +29,15 @@ Currently there is only one required configuration option: `api_token`.
29
29
  ```ruby
30
30
  Mole.config do |c|
31
31
  c.api_token = 'your orwell api token'
32
- c.logger = Log4r::Logger[Rails.env]
32
+ c.method = :sidekiq
33
33
  end
34
34
  ```
35
35
 
36
36
  ### Options
37
37
  + `api_token` - The application's API token provided by Orwell.
38
- + `logger` - Override the logger Mole will use, the default uses `Logger` to stdout.
39
38
  + `method` - Set the transport used by Mole to transmit events, valid options:
40
39
  - `:basic_http` - No frills HTTP requests via `net/http`, the default.
41
- - `:sucker_punch` - Uses [SuckerPunch](https://github.com/brandonhilkert/sucker_punch) to asynchroniously transmit events.
40
+ - `:sucker_punch` - Uses [SuckerPunch](https://github.com/brandonhilkert/sucker_punch) to asynchroniously transmit events.
42
41
  - `:sidekiq` - Similar to `:sucker_punch` but the underlying library is [Sidekiq](https://github.com/mperham/sidekiq).
43
42
 
44
43
  _Note_: To use either `:sucker_punch` or `:sidekiq` you'll need to require them first:
@@ -46,38 +45,19 @@ _Note_: To use either `:sucker_punch` or `:sidekiq` you'll need to require them
46
45
  ```ruby
47
46
  # Sidekiq
48
47
  require 'orwell/mole/transport/sidekiq'
49
-
48
+
50
49
  # SuckerPunch
51
50
  require 'orwell/mole/transport/sucker_punch'
52
51
  ```
53
52
 
54
53
  ## Usage
55
54
 
56
- To create a channel for a specific user's actions, add the following line to the beginnging of your code:
57
-
58
- ```ruby
59
- @channel = Mole.track(@user.email, :accounts)
60
- ```
61
-
62
- Now to record an event on this channel we use:
63
-
64
- ```ruby
65
- @channel.record(:new_tweet, tweet: '...', timestamp: '...')
66
- ```
67
-
68
- Alternatively it may be necessary for a channel to remain open where individual events will be tagged with differing identifiers, to create one of these channels we use:
55
+ To record an event all we need to do is:
69
56
 
70
57
  ```ruby
71
- @channel = Mole.channel(:accounts)
58
+ Mole.record(:new_tweet, tweet: '...', timestamp: '...')
72
59
  ```
73
60
 
74
- When we record events on one of these channels it's required that an identifier is provided as second parameter followed by any additional details:
75
-
76
- ```ruby
77
- @channel.record(:new_account, params[:email], params)
78
- ```
79
-
80
-
81
61
  ## Contributing
82
62
 
83
63
  Feedback and fixes are always welcome. Please make use of [Issues](https://github.com/doomspork/autocomplete-me/issues) and [Pull Requests](https://github.com/doomspork/autocomplete-me/pulls), all code should have test coverage.
@@ -5,29 +5,24 @@ require 'orwell/mole/transporter'
5
5
  require 'orwell/mole/client'
6
6
 
7
7
  module Mole
8
+ extend SingleForwardable
9
+
8
10
  def self.config
9
11
  @config ||= Config.new
10
12
  yield @config if block_given?
11
13
  @config
12
14
  end
13
15
 
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
16
+ def_delegators :config, :logger
17
+ def_delegators :client, :record
23
18
 
24
19
  private
25
20
 
26
- def self.new_client(channel)
27
- Client.new(channel, self.transporter)
21
+ def self.client
22
+ @client ||= Client.new(new_transporter)
28
23
  end
29
24
 
30
- def self.transporter
31
- @transporter ||= Transporter.new(config.method)
25
+ def self.new_transporter
26
+ Transporter.new(config.method)
32
27
  end
33
28
  end
@@ -1,33 +1,15 @@
1
1
  module Mole
2
2
  class Client
3
3
 
4
- attr_reader :channel, :identifier, :transporter
4
+ attr_reader :transporter
5
5
 
6
- def initialize(channel, transporter)
7
- @channel = channel
6
+ def initialize(transporter)
8
7
  @transporter = transporter
9
8
  end
10
9
 
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)
10
+ def record(event, details = {})
11
+ event = Event.new(event, details)
18
12
  @transporter.perform(event)
19
13
  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
14
  end
33
15
  end
@@ -4,10 +4,10 @@ module Mole
4
4
  class Config
5
5
  DEFAULT_HOST = 'api.orwell.io'
6
6
  DEFAULT_POST = 80
7
- DEFAULT_API_VERSION = '0.1.0'
7
+ DEFAULT_API_VERSION = '0.4'
8
8
 
9
9
  attr_accessor :api_token
10
- attr_writer :api_version, :host, :logger, :method, :port
10
+ attr_writer :api_version, :host, :method, :port
11
11
 
12
12
  def api_token
13
13
  raise MissingApiTokenError unless @api_token
@@ -15,38 +15,23 @@ module Mole
15
15
  end
16
16
 
17
17
  def api_version
18
- @api_version || DEFAULT_API_VERSION
18
+ @api_version ||= DEFAULT_API_VERSION
19
19
  end
20
20
 
21
21
  def host
22
- @host || DEFAULT_HOST
23
- end
24
-
25
- def log
26
- @logger || default_logger
22
+ @host ||= DEFAULT_HOST
27
23
  end
28
24
 
29
25
  def method
30
- @method || :basic_http
26
+ @method ||= :basic_http
31
27
  end
32
28
 
33
29
  def port
34
- @port || DEFAULT_POST
30
+ @port ||= DEFAULT_POST
35
31
  end
36
32
 
37
33
  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
34
+ @api_token, @api_version, @host, @method, @port = nil
49
35
  end
50
-
51
36
  end
52
37
  end
@@ -1,20 +1,18 @@
1
1
  module Mole
2
2
  class Event
3
- attr_accessor :channel, :event, :identifier, :details
3
+ attr_accessor :event, :details, :timestamp
4
4
 
5
- def initialize(channel, event, identifier, details = {})
6
- @channel = channel
5
+ def initialize(event, details = {})
7
6
  @event = event
8
- @identifier = identifier
9
7
  @details = details
8
+ @timestamp = Time.now.utc.to_i
10
9
  end
11
10
 
12
11
  def to_h
13
12
  {
14
- channel: channel,
15
- event: event,
16
- identifier: identifier,
17
- details: details
13
+ event: event,
14
+ details: details,
15
+ timestamp: timestamp
18
16
  }
19
17
  end
20
18
  end
@@ -4,6 +4,8 @@ require 'net/http'
4
4
  module Mole
5
5
  module Transport
6
6
  class BasicHttp
7
+ CONTENT_TYPE = 'application/vnd.orwell.api.json'
8
+
7
9
  attr_reader :host, :port, :token, :version
8
10
 
9
11
  def initialize(opts = {})
@@ -37,11 +39,11 @@ module Mole
37
39
 
38
40
  def headers
39
41
  {
40
- 'accept' => "application/vnd.orwell.api.json; version=#{version}",
41
- 'orwell_token' => token
42
+ 'Accept' => "#{CONTENT_TYPE}; version=#{version}",
43
+ 'Content-Type' => CONTENT_TYPE,
44
+ 'Orwell-Token' => token
42
45
  }
43
46
  end
44
-
45
47
  end
46
48
  end
47
49
  end
@@ -1,3 +1,3 @@
1
1
  module Mole
2
- VERSION = '0.3.0'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,153 +1,153 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orwell-mole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Callan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2014-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: coveralls
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.7'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.7'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rr
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.1'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: '3.1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.1'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec-its
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
89
  version: '1.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: sidekiq
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ~>
102
102
  - !ruby/object:Gem::Version
103
103
  version: '3.2'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: '3.2'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ~>
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0.9'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ~>
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.9'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: sucker_punch
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ~>
130
130
  - !ruby/object:Gem::Version
131
131
  version: '1.2'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ~>
137
137
  - !ruby/object:Gem::Version
138
138
  version: '1.2'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: webmock
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - ~>
144
144
  - !ruby/object:Gem::Version
145
145
  version: '1.18'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - "~>"
150
+ - - ~>
151
151
  - !ruby/object:Gem::Version
152
152
  version: '1.18'
153
153
  description: Mole allows developers to send events from within their code directly
@@ -158,9 +158,8 @@ executables: []
158
158
  extensions: []
159
159
  extra_rdoc_files: []
160
160
  files:
161
- - LICENSE
162
161
  - README.md
163
- - lib/orwell/mole.rb
162
+ - LICENSE
164
163
  - lib/orwell/mole/client.rb
165
164
  - lib/orwell/mole/config.rb
166
165
  - lib/orwell/mole/errors/missing_api_token_error.rb
@@ -170,6 +169,7 @@ files:
170
169
  - lib/orwell/mole/transport/sucker_punch.rb
171
170
  - lib/orwell/mole/transporter.rb
172
171
  - lib/orwell/mole/version.rb
172
+ - lib/orwell/mole.rb
173
173
  homepage: http://www.orwell.io
174
174
  licenses:
175
175
  - MIT
@@ -180,17 +180,17 @@ require_paths:
180
180
  - lib
181
181
  required_ruby_version: !ruby/object:Gem::Requirement
182
182
  requirements:
183
- - - ">="
183
+ - - '>='
184
184
  - !ruby/object:Gem::Version
185
185
  version: '0'
186
186
  required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  requirements:
188
- - - ">="
188
+ - - '>='
189
189
  - !ruby/object:Gem::Version
190
190
  version: '0'
191
191
  requirements: []
192
192
  rubyforge_project:
193
- rubygems_version: 2.2.2
193
+ rubygems_version: 2.0.14
194
194
  signing_key:
195
195
  specification_version: 4
196
196
  summary: A client library for Orwell