minitel 0.1.1 β†’ 0.2.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: 61598e19639554992b7c083cac60ad2d778bdfda
4
- data.tar.gz: 4acd579629f98f79f24533de0dbe40461c51dbe6
3
+ metadata.gz: fd03aab2f252c52edc3cfffe5d961c5c11969186
4
+ data.tar.gz: 5628686bc64d830a1624f63a798f90f9374b6349
5
5
  SHA512:
6
- metadata.gz: 3d474d99a5d486cfbd0c4395bdd6f6c4ed0fd83abbe3d769c89adfe6acda17dd84c43c69211395084833be3e2c18a6bfd4cd0648635be3aad6aa5d5121dd6171
7
- data.tar.gz: 82219867b18537333452e8011340fa6a5ba7e59809160c20ca1227b2300fcad938202864489febec9f3814836d72d57d743ed3238aa3749da2a26538f0acd659
6
+ metadata.gz: 22c953d027651ba60ae09c5ec203131885fdc1aaf9fa95b4bcf1959244f7b4111f988d75e4945a211d241050b65800da82b6cca3dbdaa40918e39e0a8d8113e3
7
+ data.tar.gz: 50e829ace42d49d3d2225900c23d7a13e21adbfc74bf8b546f9a92d96b79bfb8adf4040740706cfd85b7d87f773bc4fd3faf3058a56d9eacf050a52367e4a04e
checksums.yaml.gz.sig CHANGED
Binary file
data/Readme.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # 𝕄𝕀ℕ𝕀𝕋𝔼𝕃
2
2
  A 𝕋𝔼𝕃𝔼𝕏 client
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/minitel.svg)](http://badge.fury.io/rb/minitel)
4
5
  [![Build Status](https://travis-ci.org/heroku/minitel.svg?branch=master)](https://travis-ci.org/heroku/minitel)
5
6
 
data/changelog.txt CHANGED
@@ -1,3 +1,8 @@
1
+ 0.2.0 2014-10-10
2
+ ================
3
+
4
+ Add Client#notify_user for sending notifications to a single user
5
+
1
6
  0.1.1 2014-10-08
2
7
  ================
3
8
 
@@ -17,17 +17,22 @@ module Minitel
17
17
  end
18
18
 
19
19
  def notify_app(args)
20
- keywords = [:app_uuid, :body, :title]
21
- app_uuid, body, title = args[:app_uuid], args[:body], args[:title]
20
+ StrictArgs.enforce(args, [:app_uuid, :body, :title], :app_uuid)
21
+ post_message('app', args[:app_uuid], args[:title], args[:body])
22
+ end
23
+
24
+ def notify_user(args)
25
+ StrictArgs.enforce(args, [:user_uuid, :body, :title], :user_uuid)
26
+ post_message('user', args[:user_uuid], args[:title], args[:body])
27
+ end
22
28
 
23
- ensure_strict_args(args.keys, keywords)
24
- ensure_no_nils(args, keywords)
25
- ensure_is_uuid(app_uuid)
29
+ private
26
30
 
31
+ def post_message(type, id, title, body)
27
32
  message = {
28
33
  title: title,
29
34
  body: body,
30
- target: {type: 'app', id: app_uuid}
35
+ target: {type: type, id: id}
31
36
  }
32
37
 
33
38
  response = connection.post(
@@ -37,28 +42,5 @@ module Minitel
37
42
 
38
43
  MultiJson.load(response.body)
39
44
  end
40
-
41
- private
42
-
43
- # A Ruby 2.1 required keyword argument sorta backport
44
- def ensure_strict_args(keys, accept_keys)
45
- if keys.sort != accept_keys.sort
46
- delta = accept_keys - keys
47
- raise ArgumentError, "missing or extra keywords: #{delta.join(', ')}"
48
- end
49
- end
50
-
51
- def ensure_no_nils(args, keys)
52
- keys.each do |key|
53
- raise ArgumentError, "keyword #{key} is nil" unless args[key]
54
- end
55
- end
56
-
57
- def ensure_is_uuid(uuid)
58
- unless uuid =~ /\A[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}\z/i
59
- raise ArgumentError, "not formated like a uuid"
60
- end
61
- end
62
-
63
45
  end
64
46
  end
@@ -0,0 +1,30 @@
1
+ module Minitel
2
+ module StrictArgs
3
+ extend self
4
+ def enforce(args, keywords, uuid_field)
5
+ ensure_strict_args(args.keys, keywords)
6
+ ensure_no_nils(args, keywords)
7
+ ensure_is_uuid(args[uuid_field])
8
+ end
9
+
10
+ # A Ruby 2.1 required keyword argument sorta backport
11
+ def ensure_strict_args(keys, accept_keys)
12
+ if keys.sort != accept_keys.sort
13
+ delta = accept_keys - keys
14
+ raise ArgumentError, "missing or extra keywords: #{delta.join(', ')}"
15
+ end
16
+ end
17
+
18
+ def ensure_no_nils(args, keys)
19
+ keys.each do |key|
20
+ raise ArgumentError, "keyword #{key} is nil" unless args[key]
21
+ end
22
+ end
23
+
24
+ def ensure_is_uuid(uuid)
25
+ unless uuid =~ /\A[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}\z/i
26
+ raise ArgumentError, "'#{uuid.inspect}' not formated like a uuid"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Minitel
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/minitel.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'minitel/version'
2
2
  require 'minitel/client'
3
+ require 'minitel/strict_args'
3
4
 
@@ -28,41 +28,6 @@ describe Minitel::Client, '#initialize' do
28
28
  end
29
29
 
30
30
  describe Minitel::Client, '#notify_app' do
31
- describe 'arguments' do
32
- let(:defaults) { {title: 'a title', body: 'a body', app_uuid: SecureRandom.uuid} }
33
- let(:client) { Minitel::Client.new('https://u:p@h.com') }
34
-
35
- before do
36
- Excon.stub({}, body: MultiJson.dump({}), status: 201)
37
- end
38
-
39
- it 'works when all 3 are present' do
40
- expect { client.notify_app(defaults) }.to_not raise_error
41
- end
42
-
43
- [:title, :body, :app_uuid].each do |key|
44
- it "fails when #{key} is missing from the arg hash" do
45
- defaults.delete(key)
46
- expect { client.notify_app(defaults) }.to raise_error(ArgumentError)
47
- end
48
-
49
- it "fails when #{key} is nil" do
50
- defaults[key] = nil
51
- expect { client.notify_app(defaults) }.to raise_error(ArgumentError)
52
- end
53
- end
54
-
55
- it 'fails if app_uuid is not a uuid' do
56
- defaults[:app_uuid] = "not a uuid"
57
- expect { client.notify_app(defaults) }.to raise_error(ArgumentError)
58
- end
59
-
60
- it 'fails if there is an extra key' do
61
- defaults.merge!( {foo: 3} )
62
- expect { client.notify_app(defaults) }.to raise_error(ArgumentError)
63
- end
64
- end
65
-
66
31
  describe 'action' do
67
32
  let(:defaults) { {title: 'a title', body: 'a body', app_uuid: SecureRandom.uuid} }
68
33
  let(:client) { Minitel::Client.new('https://u:p@h.com') }
@@ -92,3 +57,33 @@ describe Minitel::Client, '#notify_app' do
92
57
  end
93
58
  end
94
59
  end
60
+
61
+
62
+ describe Minitel::Client, '#notify_user' do
63
+ let(:defaults) { {title: 'a title', body: 'a body', user_uuid: SecureRandom.uuid} }
64
+ let(:client) { Minitel::Client.new('https://u:p@h.com') }
65
+
66
+ before do
67
+ request = {path: '/producer/messages', method: :post}
68
+ response = {status: 201, body: MultiJson.dump({'success' => true})}
69
+ body = MultiJson.dump({
70
+ title: 'a title',
71
+ body: 'a body',
72
+ target: {type: 'user', id: defaults[:user_uuid]}
73
+ })
74
+
75
+ Excon.stub(request.merge(body: body), response)
76
+ end
77
+
78
+ it 'posts a proper json body to the producer messages endpoint' do
79
+ expect{ client.notify_user(defaults) }.to_not raise_error
80
+
81
+ unstubbed_body = defaults.merge({title: 'bad title'})
82
+ expect{ client.notify_user(unstubbed_body) }.to raise_error(Excon::Errors::StubNotFound)
83
+ end
84
+
85
+ it 'returns a parsed json response' do
86
+ result = client.notify_user(defaults)
87
+ expect(result['success']).to eq(true)
88
+ end
89
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Minitel::StrictArgs, '.enforce' do
4
+ describe 'arguments' do
5
+ before do
6
+ @hash = {one: 1, two: 2, uuid: SecureRandom.uuid}
7
+ @keys = @hash.keys
8
+ end
9
+
10
+ it 'works when all listed args are present' do
11
+ expect { Minitel::StrictArgs.enforce(@hash, @keys, :uuid) }.to_not raise_error
12
+ end
13
+
14
+ it "fails when a key is missing from the arg hash" do
15
+ @hash.delete(:one)
16
+ expect { Minitel::StrictArgs.enforce(@hash, @keys, :uuid) }.to raise_error(ArgumentError)
17
+ end
18
+
19
+ it "fails when a key is nil" do
20
+ @hash[:one] = nil
21
+ expect { Minitel::StrictArgs.enforce(@hash, @keys, :uuid) }.to raise_error(ArgumentError)
22
+ end
23
+
24
+ it 'fails if the uuid column uuid is not a uuid' do
25
+ @hash[:uuid] = "not a uuid"
26
+ expect { Minitel::StrictArgs.enforce(@hash, @keys, :uuid) }.to raise_error(ArgumentError)
27
+ end
28
+
29
+ it 'fails if there is an extra key' do
30
+ @hash.merge!( {foo: 3} )
31
+ expect { Minitel::StrictArgs.enforce(@hash, @keys, :uuid) }.to raise_error(ArgumentError)
32
+ end
33
+ end
34
+ end
35
+
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Leinweber
@@ -28,7 +28,7 @@ cert_chain:
28
28
  5bkhRfJHSD/uX/cHbjmopLRbPlHrGbZTDIP4VEC5l0QLPiZ1nhKQnf3+U0+FSy2o
29
29
  CCngcLCR6q+mLf+A4L54VxmyrtFpcBfmkU72QYyf3vJ9QipL3XbvJvbpPkWSn1DX
30
30
  -----END CERTIFICATE-----
31
- date: 2014-10-08 00:00:00.000000000 Z
31
+ date: 2014-10-10 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: excon
@@ -95,9 +95,11 @@ files:
95
95
  - changelog.txt
96
96
  - lib/minitel.rb
97
97
  - lib/minitel/client.rb
98
+ - lib/minitel/strict_args.rb
98
99
  - lib/minitel/version.rb
99
100
  - minitel.gemspec
100
101
  - spec/minitel/client_spec.rb
102
+ - spec/minitel/strict_args_spec.rb
101
103
  - spec/spec_helper.rb
102
104
  homepage: https://github.com/heroku/minitel
103
105
  licenses:
@@ -125,5 +127,6 @@ specification_version: 4
125
127
  summary: "\U0001D54B\U0001D53C\U0001D543\U0001D53C\U0001D54F client: see https://github.com/heroku/telex"
126
128
  test_files:
127
129
  - spec/minitel/client_spec.rb
130
+ - spec/minitel/strict_args_spec.rb
128
131
  - spec/spec_helper.rb
129
132
  has_rdoc:
metadata.gz.sig CHANGED
Binary file