mdlive_shared 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dea3879cdf74ecac205363a7200ed7d2008a4ffe
4
+ data.tar.gz: 95de409c2796e696b1061c9e991a133fc70b5074
5
+ SHA512:
6
+ metadata.gz: e8120d71d7677d66181c978fa79d6b90943e1d628a50994539e59ecdcedffe61c72dd7272b58e35b343550a111f2d0542ad8773c26b283952959ccd65c2a84d9
7
+ data.tar.gz: 0c955eb01574774ec9549a355c45b80aa2356357950645b7f5c94b40609eeae96f705a6bc3f2444b1dedaec9db32fe2d379702e0c6c27032ae93717a05a110ad
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /*/*.swo
4
+ /*/*.swp
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0@mdlive_shared
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mdlive_shared.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # MdliveShared
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mdlive_shared`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mdlive_shared'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mdlive_shared
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mdlive_shared.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mdlive_shared"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require "json"
2
+ require "active_support"
3
+ require "bunny"
4
+ require "mdlive_shared/bunny/system_timer"
5
+ require "mdlive_shared/event_notifier"
6
+ require "mdlive_shared/static_assets"
@@ -0,0 +1,11 @@
1
+ if RUBY_VERSION < "1.9"
2
+ begin
3
+ require "bunny/system_timer"
4
+ class Bunny::SystemTimer
5
+ class Error < Exception
6
+ end
7
+ end
8
+ rescue LoadError
9
+
10
+ end
11
+ end
@@ -0,0 +1,61 @@
1
+ module MdliveShared
2
+ class EventNotifier
3
+
4
+ EVENT_NAMES = {
5
+ "patient:logged_in" => 1,
6
+ "patient:created" => 1,
7
+ "consultation:scheduled" => 1,
8
+ "consultation:completed" => 1,
9
+ "eligible_member:imported" => 1,
10
+ "signup_url:created" => 1,
11
+ "provider:waiting_room_changed" => 1,
12
+ "provider:avail_changed" => 1,
13
+ "provider:consult_list_changed" => 1,
14
+ "provider:profile_changed" => 1,
15
+ "message:created" => 1
16
+ }.freeze
17
+
18
+ ATTRIBUTES_FOR_EVENTS = {
19
+ "patient:created" => [ :id ],
20
+ "patient:logged_in" => [ :id ],
21
+ "consultation:scheduled" => [ :id ],
22
+ "consultation:completed" => [ :id ],
23
+ "eligible_member:imported" => [ :id ],
24
+ "signup_url:created" => [ :id ],
25
+ "provider:waiting_room_changed" => [:cocq_id],
26
+ "provider:avail_changed" => [:provider_id],
27
+ "provider:consult_list_changed" => [:provider_id],
28
+ "provider:profile_changed" => [:provider_id],
29
+ "message:created" => [:msg_id]
30
+ }.freeze
31
+
32
+ def self.event(event, attrs, opts={})
33
+ event_names.fetch(event)
34
+ attrs = JSON.parse(attrs.to_json)
35
+ attrs = attributes_for_events.fetch(event).inject({}) do |hsh, attr|
36
+ hsh[attr] = attrs.fetch(attr.to_s)
37
+ hsh
38
+ end
39
+ with_exchange(event) do |exchange|
40
+ exchange.publish(attrs.to_json, opts)
41
+ end
42
+ end
43
+
44
+ def self.with_exchange(event)
45
+ conn = Bunny.new(AMQ::Settings.parse_amqp_url(ENV.fetch("RABBIT_MQ_URL")),
46
+ :read_timeout => 25,
47
+ :connection_timeout => 25)
48
+ conn.start
49
+ yield(conn.create_channel.fanout(event, :durable => true))
50
+ conn.close
51
+ end
52
+
53
+ def self.event_names
54
+ EVENT_NAMES
55
+ end
56
+
57
+ def self.attributes_for_events
58
+ ATTRIBUTES_FOR_EVENTS
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,15 @@
1
+ class MdliveShared::StaticAssets
2
+ class << self
3
+ def get_url(filename)
4
+ "#{cdn_url}/#{container}/static_asset/#{filename}"
5
+ end
6
+
7
+ def cdn_url
8
+ "https://mdlive.azureedge.net"
9
+ end
10
+
11
+ def container
12
+ "affiliations-prod"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module MdliveShared
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,119 @@
1
+ class BunnyMock
2
+
3
+ def start
4
+ :connected
5
+ end
6
+
7
+ def qos
8
+ :qos_ok
9
+ end
10
+
11
+ def stop
12
+ nil
13
+ end
14
+
15
+ def queue(*attrs)
16
+ BunnyMock::Queue.new(*attrs)
17
+ end
18
+
19
+ def exchange(*attrs)
20
+ BunnyMock::Exchange.new(*attrs)
21
+ end
22
+
23
+ class Consumer
24
+ attr_accessor :message_count
25
+ def initialize(c)
26
+ self.message_count = c
27
+ end
28
+ end
29
+
30
+ class Queue
31
+ attr_accessor :name, :attrs, :messages, :delivery_count
32
+ def initialize(name, attrs = {})
33
+ self.name = name
34
+ self.attrs = attrs.dup
35
+ self.messages = []
36
+ self.delivery_count = 0
37
+ end
38
+
39
+ def bind(exchange)
40
+ exchange.queues << self
41
+ end
42
+
43
+ # Note that this doesn't block waiting for messages like the real world.
44
+ def subscribe(*args, &block)
45
+ while message = messages.shift
46
+ self.delivery_count += 1
47
+ yield({:payload => message})
48
+ end
49
+ end
50
+
51
+ def default_consumer
52
+ BunnyMock::Consumer.new(self.delivery_count)
53
+ end
54
+
55
+ # NOTE: This is NOT a method that is supported on real Bunny queues.
56
+ # This is a custom method to get us a deep copy of
57
+ # all the messages currently in the queue. This is provided
58
+ # to aid in testing a system where it is not practical for the
59
+ # test to subscribe to the queue and read the messages, but we
60
+ # need to verify that certain messages have been published.
61
+ def snapshot_messages
62
+ Marshal.load(Marshal.dump(messages))
63
+ end
64
+
65
+ def method_missing(method, *args)
66
+ method_name = method.to_s
67
+ is_predicate = false
68
+ if method_name =~ /^(.*)\?$/
69
+ key = $1.to_sym
70
+ is_predicate = true
71
+ else
72
+ key = method.to_sym
73
+ end
74
+
75
+ if attrs.has_key? key
76
+ value = attrs[key]
77
+ is_predicate ? !!value : value
78
+ else
79
+ super
80
+ end
81
+ end
82
+ end
83
+
84
+ class Exchange
85
+ attr_accessor :name, :attrs, :queues
86
+ def initialize(name, attrs = {})
87
+ self.name = name
88
+ self.attrs = attrs.dup
89
+ self.queues = []
90
+ end
91
+
92
+ def publish(msg, msg_attrs = {})
93
+ queues.each { |q| q.messages << msg }
94
+ end
95
+
96
+ def bound_to?(queue_name)
97
+ queues.any?{|q| q.name == queue_name}
98
+ end
99
+
100
+ def method_missing(method, *args)
101
+ method_name = method.to_s
102
+ is_predicate = false
103
+ if method_name =~ /^(.*)\?$/
104
+ key = $1.to_sym
105
+ is_predicate = true
106
+ else
107
+ key = method.to_sym
108
+ end
109
+
110
+ if attrs.has_key? key
111
+ value = attrs[key]
112
+ is_predicate ? !!value : value
113
+ else
114
+ super
115
+ end
116
+ end
117
+ end
118
+
119
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path("../lib/mdlive_shared/version", __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'mdlive_shared'
5
+ s.summary = "Shared interactions between MDLIVE applications"
6
+ s.description = "Shared interactions between MDLIVE applications"
7
+ s.authors = ["Nakort Valles"]
8
+ s.platform = Gem::Platform::RUBY
9
+ s.version = MdliveShared::VERSION
10
+ s.add_development_dependency "bundler", ">= 1.0.0"
11
+ s.add_development_dependency "pry-rails"
12
+ s.add_development_dependency "pry-byebug"
13
+ s.add_development_dependency "rspec", "~> 3.2"
14
+ s.add_runtime_dependency "bunny", ">= 1.7.1"
15
+ s.add_runtime_dependency "json", ">= 1.8.1"
16
+ s.add_runtime_dependency "activesupport", ">= 2.3.6"
17
+ s.files = `git ls-files`.split("\n")
18
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
19
+ s.require_path = 'lib'
20
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe MdliveShared::EventNotifier do
4
+
5
+ describe "#event" do
6
+ let(:bunny_mock) { BunnyMock.new }
7
+ let(:notifier_class) { MdliveShared::EventNotifier }
8
+
9
+ context "exisiting event" do
10
+ before do
11
+ allow(notifier_class).to receive(:with_exchange).and_yield(exchange)
12
+ end
13
+
14
+ MdliveShared::EventNotifier.event_names.each do |event, _|
15
+ let!(:event) { "#{event}" }
16
+
17
+ context "#{event}" do
18
+ before do
19
+ queue.bind(exchange)
20
+ notifier_class.event(event, attributes)
21
+ end
22
+
23
+ let(:queue) { bunny_mock.queue("test") }
24
+ let(:exchange) { bunny_mock.exchange(event) }
25
+ let(:attributes) {
26
+ attrs = notifier_class.attributes_for_events[event]
27
+ attrs.inject({}) do |hsh, attr|
28
+ hsh[attr]= SecureRandom.hex
29
+ hsh
30
+ end
31
+ }
32
+
33
+ it "publishes to queue" do
34
+ expect(queue.messages.size).to eq(1)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe MdliveShared::StaticAssets do
4
+
5
+ it "should return the url from the cdn" do
6
+ expect(MdliveShared::StaticAssets.get_url("signup_url_email_android_white.png")).to eq("https://mdlive.azureedge.net/affiliations-prod/static_asset/signup_url_email_android_white.png")
7
+
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe MdliveShared do
4
+ it 'has a version number' do
5
+ expect(MdliveShared::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'mdlive_shared'
3
+ require 'support/bunny_mock'
4
+ require 'pp'
5
+ require 'securerandom'
6
+ require "pry"
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mdlive_shared
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Nakort Valles
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bunny
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.7.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.7.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.8.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 2.3.6
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 2.3.6
111
+ description: Shared interactions between MDLIVE applications
112
+ email:
113
+ executables:
114
+ - console
115
+ - setup
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".ruby-version"
122
+ - ".travis.yml"
123
+ - Gemfile
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/mdlive_shared.rb
129
+ - lib/mdlive_shared/.event_notifier.rb.swp
130
+ - lib/mdlive_shared/bunny/system_timer.rb
131
+ - lib/mdlive_shared/event_notifier.rb
132
+ - lib/mdlive_shared/static_assets.rb
133
+ - lib/mdlive_shared/version.rb
134
+ - lib/support/bunny_mock.rb
135
+ - mdlive_shared.gemspec
136
+ - spec/lib/.event_notifier_spec.rb.swp
137
+ - spec/lib/event_notifier_spec.rb
138
+ - spec/lib/static_assets_spec.rb
139
+ - spec/mdlive_shared_spec.rb
140
+ - spec/spec_helper.rb
141
+ homepage:
142
+ licenses: []
143
+ metadata: {}
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.5.1
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: Shared interactions between MDLIVE applications
164
+ test_files: []