sensor 0.0.2 → 0.0.3

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmFkNzYxYzdkZTFkMTI4ZTNkYWFlMTQ5NjViOGY1YjIzYjllZjIzYw==
4
+ NDBiYmRkOWNkYzAzZTkwZGI3MzAyZjNiYjQxMDQ4YWE1ZjU1ZDA1Zg==
5
5
  data.tar.gz: !binary |-
6
- OTNjOWFkZTFkMDM0YjUwMjJjNWRkZGU4YTU5ZWVmZGMxOGM5M2Y3Mg==
6
+ NWY0NGQyOGQ3NTVhYzk1YWU2MjJiYTJhNDNjZWQwZTZlNWE3NzhiYQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MjQ2NWZiYTFlMmI1MzM0MjE3ZjZlNWQwMDA1NTgyYzNlNTdkZjgxMWQxYzlj
10
- OTBmMzhkOTM4OTRiNjM4YTY2NjU2ZjU5NTk1MmMwNmVkMjI1ZDM4NjRmYzI2
11
- MGFjZjMwOTBlODJiMGVjMDU5NWIzYWYwM2RiOGM3NzI5OGM5ZDI=
9
+ MDhjMTJhMzkwM2QwOTZmNTVjZTFhMjA3ZjMxODBhYTY5MWI3ZDI1ODY5NDMx
10
+ ODFhOGViMDhjOWE2YjMwYTVhZjVjYjk3ZjdiZjhkZjdjMzI3Nzg3ODZkY2I4
11
+ MjM0ZDg1MDk1YjZjNjE4NjhhMzVmODkyY2IxZjJiMGVmZTZiZmE=
12
12
  data.tar.gz: !binary |-
13
- Y2ZkNjgyNWU0MmZjM2Q2NDEzMWE3NmM1MGFkNDczZGNmOGJiMzBjMzM4OTYx
14
- Yjg3YTI5NGEyMWUyYjk0MGQ0ZDhhZmNjMDBkYzg0OWI5NzgzY2JkNTU2NWIw
15
- Mzc3ODUxMzk4NTJlODNlYjAzYmQ0N2Q0ZDg2YzgzY2MwN2ViYTk=
13
+ MDhjMTlhZTg2NWRhOGQ2ODZiNTkxZDFhZmQ5ZTk1NWYxNWZjNDZiNDM4Zjhl
14
+ NWYwYzJlNTIxZmIxMTZlZTUyMjVmMzhlZWYyZTQwY2I3MDliMmUzNDI2YzJl
15
+ NzFjZTQ5OWQyMjk1ZDExYWVkODk2MDY4MGNhNWFmOWJkNTUyYWY=
data/.env.example CHANGED
@@ -6,6 +6,7 @@ export TWITTER_CONSUMER_KEY=""
6
6
  export TWITTER_CONSUMER_SECRET=""
7
7
  export TWITTER_ACCESS_TOKEN=""
8
8
  export TWITTER_ACCESS_TOKEN_SECRET=""
9
+ export TWITTER_ACCOUNT=""
9
10
 
10
11
  export FACEBOOK_API_KEY=""
11
12
  export FACEBOOK_SECRET_KEY=""
@@ -31,18 +31,22 @@ module Sensor
31
31
  end
32
32
 
33
33
  def tweet_count
34
- search = client.search("from:launchacademy_",
34
+ search = client.search("from:#{account}",
35
35
  search_options
36
36
  )
37
37
  search.entries.count
38
38
  end
39
39
 
40
40
  def mention_count
41
- search = client.search("to:launchacademy_",
41
+ search = client.search("@#{account} -from:#{account}",
42
42
  search_options)
43
43
  search.entries.count
44
44
  end
45
45
 
46
+ def account
47
+ ENV['TWITTER_ACCOUNT']
48
+ end
49
+
46
50
  def client
47
51
  if !@client
48
52
  @client = Twitter::REST::Client.new do |config|
@@ -0,0 +1,30 @@
1
+ module Sensor
2
+ class Configuration
3
+ attr_accessor :actuators
4
+
5
+ def initialize(&block)
6
+ yield(self) if block_given?
7
+
8
+ assign_defaults!
9
+ end
10
+
11
+ def append_actuator(actuator_class)
12
+ @actuators ||= []
13
+ unless @actuators.include?(actuator_class)
14
+ @actuators << actuator_class
15
+ end
16
+ end
17
+
18
+ protected
19
+ def assign_defaults!
20
+ Sensor.require("analytics_retrieval")
21
+ Sensor.require("facebook_retrieval")
22
+ Sensor.require("twitter_retrieval")
23
+ self.actuators = [
24
+ Sensor::Actuator::AnalyticsRetrieval,
25
+ Sensor::Actuator::FacebookRetrieval,
26
+ Sensor::Actuator::TwitterRetrieval
27
+ ]
28
+ end
29
+ end
30
+ end
@@ -17,11 +17,7 @@ module Sensor
17
17
  end
18
18
 
19
19
  def acquire
20
- [
21
- Sensor::Actuator::AnalyticsRetrieval,
22
- Sensor::Actuator::TwitterRetrieval,
23
- Sensor::Actuator::FacebookRetrieval
24
- ].each do |actuator|
20
+ actuator_classes.each do |actuator|
25
21
  @data.merge!(actuator.new(@time_range).acquire)
26
22
  end
27
23
 
@@ -31,5 +27,10 @@ module Sensor
31
27
  def distribute
32
28
  Sensor::OutputDistribution::FlowDock.new(self).distribute
33
29
  end
30
+
31
+ protected
32
+ def actuator_classes
33
+ Sensor.configuration.actuators
34
+ end
34
35
  end
35
36
  end
@@ -1,3 +1,3 @@
1
1
  module Sensor
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/sensor.rb CHANGED
@@ -1,9 +1,23 @@
1
+ require 'sensor/configuration'
2
+
1
3
  module Sensor
2
- def self.require(path)
3
- begin
4
- super("sensor/actuator/#{path}")
5
- rescue LoadError
6
- super("sensor/output_distribution/#{path}")
4
+ class << self
5
+ attr_accessor :configuration
6
+
7
+ def configure(&block)
8
+ @configuration = Sensor::Configuration.new(&block)
9
+ end
10
+
11
+ def configuration
12
+ @configuration ||= Sensor::Configuration.new
13
+ end
14
+
15
+ def require(path)
16
+ begin
17
+ super("sensor/actuator/#{path}")
18
+ rescue LoadError
19
+ super("sensor/output_distribution/#{path}")
20
+ end
7
21
  end
8
22
  end
9
23
  end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sensor::Configuration do
4
+ let(:config) { Sensor::Configuration.new }
5
+ let(:actuator) { Sensor::Actuator::TwitterRetrieval }
6
+ it 'appends actuators' do
7
+ config.append_actuator(actuator)
8
+ expect(config.actuators).to include(actuator)
9
+ end
10
+
11
+ it 'appends actuators only once' do
12
+ config.actuators = []
13
+ 2.times { config.append_actuator(actuator) }
14
+ expect(config.actuators).to include(actuator)
15
+ expect(config.actuators.size).to eql(1)
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ Sensor.require("twitter_retrieval")
4
+ Sensor.require("facebook_retrieval")
5
+ Sensor.require("flow_dock")
6
+
7
+ describe Sensor do
8
+ before do
9
+ @old_config = Sensor.configuration
10
+ end
11
+
12
+ after do
13
+ Sensor.configuration = @old_config
14
+ end
15
+
16
+ it 'allows me to set desired actuators' do
17
+ Sensor.configure do |config|
18
+ config.actuators = [
19
+ Sensor::Actuator::TwitterRetrieval,
20
+ Sensor::Actuator::FacebookRetrieval
21
+ ]
22
+ end
23
+ end
24
+
25
+ it 'defaults to the whole collection' do
26
+ Sensor.configure do |config|
27
+ end
28
+
29
+ expect(Sensor.configuration.actuators.size).to_not eql(0)
30
+ end
31
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Pickett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-27 00:00:00.000000000 Z
11
+ date: 2013-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chronic
@@ -213,6 +213,7 @@ files:
213
213
  - lib/sensor/actuator/analytics_retrieval.rb
214
214
  - lib/sensor/actuator/facebook_retrieval.rb
215
215
  - lib/sensor/actuator/twitter_retrieval.rb
216
+ - lib/sensor/configuration.rb
216
217
  - lib/sensor/output_distribution/flow_dock.rb
217
218
  - lib/sensor/payload.rb
218
219
  - lib/sensor/rake_task.rb
@@ -223,7 +224,9 @@ files:
223
224
  - spec/sensor/actuator/analytics_retrieval_spec.rb
224
225
  - spec/sensor/actuator/facebook_retrieval_spec.rb
225
226
  - spec/sensor/actuator/twitter_retrieval_spec.rb
227
+ - spec/sensor/configuration_spec.rb
226
228
  - spec/sensor/time_range_spec.rb
229
+ - spec/sensor_spec.rb
227
230
  - spec/spec_helper.rb
228
231
  homepage: ''
229
232
  licenses:
@@ -254,5 +257,7 @@ test_files:
254
257
  - spec/sensor/actuator/analytics_retrieval_spec.rb
255
258
  - spec/sensor/actuator/facebook_retrieval_spec.rb
256
259
  - spec/sensor/actuator/twitter_retrieval_spec.rb
260
+ - spec/sensor/configuration_spec.rb
257
261
  - spec/sensor/time_range_spec.rb
262
+ - spec/sensor_spec.rb
258
263
  - spec/spec_helper.rb