m_and_m 0.0.5 → 0.0.6

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: 33449224abc2ad6dc3066445f6d5bf41936d5cb1
4
- data.tar.gz: c61c0f4f29f487b0da890f194adf387948c9b42e
3
+ metadata.gz: b3c9985bbdbe5ada5160ec014ad84d0e89b5373a
4
+ data.tar.gz: c4bbcfe308d991b2559f8158f64a9b964e965394
5
5
  SHA512:
6
- metadata.gz: 0533d96b03ff4ec8c520571c0f520a36ca7183dcad5253d4091eaee78acf3c08adc7fcd6d4657a45329c092b8648c2d2a39c65f5233fc668bb633c49f99743b6
7
- data.tar.gz: 0e3b88112939c18bbb680567d98fbb4aafdc954004cecf7d32c13228589ccc9829cfefae5c4a0c57c27d281006b318e99a361ec43ae210f42d5229e72996edb2
6
+ metadata.gz: 9b763e10366a437628efe96a6b7d8b7b60ae3025ae6b5b1a2d0d8e1dc8c6c54343ca4c16496793b7e48e7b0b289e952db09dd4fa5614b86602c89f7d9d95f285
7
+ data.tar.gz: 48ad4d1ec4c7db4175f3b7553de3c7493e9c8aa3c7508d96273093a7278cbd67e7ddc6ea8923aad128eb3c11d5aab3d0f94dec7fda2c024a613009087cbc12a5
data/lib/m_and_m/cli.rb CHANGED
@@ -10,14 +10,28 @@ class MAndM::Cli
10
10
  @preferences = MAndM::Preferences.new '.m_and_m'
11
11
  end
12
12
 
13
- def execute
14
- url = preferences.ask :url, 'What is the server url'
15
- token = preferences.ask :token, 'What is the authentication token'
16
- MAndM::Server.new(url, preferences).messages.each do |message|
13
+ def execute *args
14
+ command = args.shift
15
+ command = :list unless command
16
+ send command, *args
17
+ end
18
+
19
+ def list
20
+ server.messages.each do |message|
17
21
  puts "#{c :yellow, time(message["at"])} #{c :magenta, message["from"]} said #{c :green, message["message"]}"
18
22
  end
19
23
  end
20
24
 
25
+ def say who, message_id
26
+ server.say uuid_for(who), message_id
27
+ end
28
+
29
+ private
30
+
31
+ def server
32
+ MAndM::Server.new url, preferences
33
+ end
34
+
21
35
  def time at
22
36
  Time.at(at).strftime("%d/%b %H:%M:%S")
23
37
  end
@@ -25,4 +39,12 @@ class MAndM::Cli
25
39
  def c colour, text
26
40
  text.to_s.foreground colour
27
41
  end
42
+
43
+ def uuid_for name
44
+ preferences.ask "#{name}_uuid".to_sym, "What is the uuid for #{name}"
45
+ end
46
+
47
+ def url
48
+ preferences.ask :url, 'What is the server url'
49
+ end
28
50
  end
@@ -13,7 +13,7 @@ class MAndM::Preferences
13
13
  def ask key, prompt
14
14
  unless hash[key]
15
15
  print "#{prompt} ? "
16
- self[key] = gets.chomp
16
+ self[key] = $stdin.gets.chomp
17
17
  end
18
18
  self[key]
19
19
  end
@@ -3,12 +3,32 @@ require 'httparty'
3
3
  MAndM::Server = Struct.new :base_url, :preferences
4
4
 
5
5
  class MAndM::Server
6
+ def messages
7
+ HTTParty.get message_url
8
+ end
9
+
10
+ def say to_uuid, message_id
11
+ HTTParty.post base_url,
12
+ body: message_body(to_uuid, message_id),
13
+ headers: headers
14
+ end
15
+
16
+ private
17
+
18
+ def message_body to_uuid, message_id
19
+ {uuid: token, to_uuid: to_uuid, message_id: message_id}
20
+ end
21
+
22
+ def headers
23
+ {'ContentType' => 'application/json'}
24
+ end
25
+
6
26
  def last_message_id
7
27
  preferences[:last_message_id]
8
28
  end
9
29
 
10
30
  def token
11
- preferences[:token]
31
+ preferences.ask :token, 'What is the authentication token'
12
32
  end
13
33
 
14
34
  def authenticated_base_url
@@ -18,8 +38,4 @@ class MAndM::Server
18
38
  def message_url
19
39
  last_message_id ? "#{authenticated_base_url}&id=#{last_message_id}" : authenticated_base_url
20
40
  end
21
-
22
- def messages
23
- HTTParty.get message_url
24
- end
25
41
  end
@@ -1,3 +1,3 @@
1
1
  module MAndM
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: m_and_m
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lionel Randall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-30 00:00:00.000000000 Z
11
+ date: 2013-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty