scamp 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -232,6 +232,7 @@ First class support, commits and pull requests, thanks guys!
232
232
 
233
233
  * [Caius Durling](http://caius.name/)
234
234
  * Sudara Williams of [Ramen Music](http://ramenmusic.com)
235
+ * [Dom Hodgson](http://www.thehodge.co.uk/) (for the name)
235
236
 
236
237
  ## License
237
238
 
@@ -2,7 +2,7 @@ class Scamp
2
2
  module Connection
3
3
  private
4
4
 
5
- def connect(api_key, room_list)
5
+ def connect(api_key, room_list, &blk)
6
6
  EventMachine.run do
7
7
 
8
8
  # Check for rooms to join, and join them
@@ -15,6 +15,11 @@ class Scamp
15
15
  populate_room_list do
16
16
  logger.debug "Adding #{room_list.join ', '} to list of rooms to join"
17
17
  @rooms_to_join = room_list.map{|c| room_id(c) }
18
+
19
+ # Call a post connection block
20
+ if block_given?
21
+ yield
22
+ end
18
23
  end
19
24
 
20
25
  # populate bot data separately, in case we are ignoring ourselves
data/lib/scamp/users.rb CHANGED
@@ -3,23 +3,31 @@ class Scamp
3
3
  # Return the user_id if we haven't got the real name and
4
4
  # kick off a user data fetch
5
5
  def username_for(user_id)
6
- return user_cache[user_id]["name"] if user_cache[user_id]
7
- fetch_data_for(user_id)
8
- return user_id.to_s
6
+ if cached_user?(user_id)
7
+ user_cache[user_id]["name"]
8
+ else
9
+ fetch_data_for(user_id)
10
+ user_id.to_s
11
+ end
9
12
  end
10
-
13
+
11
14
  def is_me?(user_id)
12
15
  if user_cache['me']
13
- return user_cache['me']['id'] == user_id
16
+ user_cache['me']['id'] == user_id
14
17
  else
15
18
  fetch_data_for('me')
16
- return false
19
+ false
17
20
  end
18
21
  end
19
-
20
- private
21
-
22
+
23
+ def cached_user? user_id
24
+ user_cache[user_id] != nil
25
+ end
26
+
27
+ private
28
+
22
29
  def fetch_data_for(user_id)
30
+ return unless user_id
23
31
  url = "https://#{subdomain}.campfirenow.com/users/#{user_id}.json"
24
32
  http = EventMachine::HttpRequest.new(url).get(:head => {'authorization' => [api_key, 'X'], "Content-Type" => "application/json"})
25
33
  http.callback do
data/lib/scamp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Scamp
2
- VERSION = "0.2.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/scamp.rb CHANGED
@@ -46,9 +46,9 @@ class Scamp
46
46
  instance_eval &block
47
47
  end
48
48
 
49
- def connect!(room_list)
49
+ def connect!(room_list, &blk)
50
50
  logger.info "Starting up"
51
- connect(api_key, room_list)
51
+ connect(api_key, room_list, &blk)
52
52
  end
53
53
 
54
54
  def command_list
@@ -550,6 +550,7 @@ describe Scamp do
550
550
  context "room operations" do
551
551
  before do
552
552
  @room_list_url = "https://#{@valid_params[:subdomain]}.campfirenow.com/rooms.json"
553
+ @me_list_url = "https://#{@valid_params[:subdomain]}.campfirenow.com/users/me.json"
553
554
  @room_url = "https://#{@valid_params[:subdomain]}.campfirenow.com/room/123.json"
554
555
  @stream_url = "https://streaming.campfirenow.com/room/123/live.json"
555
556
  end
@@ -566,7 +567,37 @@ describe Scamp do
566
567
  }
567
568
  logger_output.should =~ /DEBUG.*Fetched room list/
568
569
  end
569
-
570
+
571
+ it "should invoke the post connection callback" do
572
+ mock_logger
573
+ bot = a Scamp
574
+
575
+ invoked_cb = false
576
+
577
+ EM.run_block {
578
+ stub_request(:get, @room_list_url).
579
+ with(:headers => {
580
+ 'Authorization'=>[@valid_params[:api_key], 'X'],
581
+ 'Content-Type' => 'application/json'
582
+ }).
583
+ to_return(:status => 200, :body => Yajl::Encoder.encode(:rooms => @valid_room_cache_data.values), :headers => {})
584
+
585
+ stub_request(:get, @room_list_url).
586
+ with(:headers => {
587
+ 'Authorization'=>[@valid_params[:api_key], 'X']
588
+ }).
589
+ to_return(:status => 200, :body => Yajl::Encoder.encode(:rooms => @valid_room_cache_data.values), :headers => {})
590
+
591
+ # Disable fetch_data_for, not important to this test.
592
+ Scamp.any_instance.expects(:fetch_data_for).returns(nil)
593
+
594
+ bot.send(:connect!, [@valid_room_cache_data.keys.first]) do
595
+ invoked_cb = true
596
+ end
597
+ }
598
+ invoked_cb.should be_true
599
+ end
600
+
570
601
  it "should handle HTTP errors fetching the room list" do
571
602
  mock_logger
572
603
  bot = a Scamp
@@ -705,7 +736,7 @@ describe Scamp do
705
736
  def mock_logger
706
737
  @logger_string = StringIO.new
707
738
  @fake_logger = Logger.new(@logger_string)
708
- Scamp.any_instance.expects(:logger).returns(@fake_logger)
739
+ Scamp.any_instance.expects(:logger).at_least(1).returns(@fake_logger)
709
740
  end
710
741
 
711
742
  # Bleurgh
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scamp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-21 00:00:00.000000000Z
12
+ date: 2011-12-09 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
16
- requirement: &70213556054000 !ruby/object:Gem::Requirement
16
+ requirement: &70092491483860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0.beta.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70213556054000
24
+ version_requirements: *70092491483860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yajl-ruby
27
- requirement: &70213556053500 !ruby/object:Gem::Requirement
27
+ requirement: &70092491483340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.8.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70213556053500
35
+ version_requirements: *70092491483340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: em-http-request
38
- requirement: &70213556053020 !ruby/object:Gem::Requirement
38
+ requirement: &70092491482760 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0.beta.4
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70213556053020
46
+ version_requirements: *70092491482760
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70213556052560 !ruby/object:Gem::Requirement
49
+ requirement: &70092491482300 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.9.2
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70213556052560
57
+ version_requirements: *70092491482300
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &70213556052060 !ruby/object:Gem::Requirement
60
+ requirement: &70092491481840 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 2.6.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70213556052060
68
+ version_requirements: *70092491481840
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
- requirement: &70213556051600 !ruby/object:Gem::Requirement
71
+ requirement: &70092491481380 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.10.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70213556051600
79
+ version_requirements: *70092491481380
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: webmock
82
- requirement: &70213556051020 !ruby/object:Gem::Requirement
82
+ requirement: &70092491480920 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: 1.7.6
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70213556051020
90
+ version_requirements: *70092491480920
91
91
  description: Eventmachine based Campfire bot framework
92
92
  email:
93
93
  - will@willj.net