comptroller 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rbenv-gemsets
19
+ .ruby-version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in duxtape_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 hubert
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Comptroller
2
+
3
+ Client gem for the optimis duxtape service
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'comptroller'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install comptroller
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'comptroller/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "comptroller"
8
+ spec.version = Comptroller::VERSION
9
+ spec.authors = ["hubert"]
10
+ spec.email = ["hubert77@gmail.com"]
11
+ spec.description = %q{Client gem for accessing the duxtape api}
12
+ spec.summary = %q{Client gem for accessing the duxtape api}
13
+ spec.homepage = "https://github.com/hubert/comptroller"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'her', '>= 0.6'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency 'rspec', '>= 2.0'
26
+ spec.add_development_dependency 'mimic', '>= 0.4.3'
27
+ end
@@ -0,0 +1,11 @@
1
+ module Comptroller
2
+ class ClaimError
3
+ include Her::Model
4
+ use_api BILLING_API
5
+ collection_path '/duxware_errors'
6
+
7
+ def eql?(other)
8
+ id.eql? other.id
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Comptroller
2
+ class Configuration
3
+ PORT = 11999
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ module Comptroller
2
+ class Practice
3
+ include Her::Model
4
+ use_api BILLING_API
5
+ collection_path 'practices'
6
+ include_root_in_json true
7
+
8
+ attributes :export_url, :token, :external_id
9
+ validates :export_url, :token, :external_id, :presence => true
10
+
11
+ def eql?(other)
12
+ export_url == other.export_url &&
13
+ external_id == other.external_id &&
14
+ token == other.token
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Comptroller
2
+ class Railtie < Rails::Railtie
3
+ initializer 'comptroller_railtie.initialization' do
4
+ if Rails.env.test? || Rails.env.integration?
5
+ require 'spec/fake_server'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Comptroller
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require "comptroller/version"
2
+ require 'comptroller/configuration'
3
+ require 'initializers/her'
4
+ require 'comptroller/railtie' if defined? Rails
5
+
6
+ module Comptroller
7
+ autoload :Practice, 'comptroller/practice'
8
+ autoload :ClaimError, 'comptroller/claim_error'
9
+ end
@@ -0,0 +1,22 @@
1
+ require 'her'
2
+
3
+ her_url = 'http://127.0.0.1:3001'
4
+
5
+ if defined? Rails
6
+ her_url = case Rails.env
7
+ when 'production'
8
+ when 'rc', 'megatron'
9
+ 'https://dux-canary-rc.optimispt.com'
10
+ when 'test','integration'
11
+ "http://127.0.0.1:#{Comptroller::Configuration::PORT}"
12
+ else
13
+ 'http://127.0.0.1:3001'
14
+ end
15
+ end
16
+
17
+ BILLING_API = Her::API.new
18
+ BILLING_API.setup url: her_url do |c|
19
+ c.use Faraday::Request::UrlEncoded
20
+ c.use Her::Middleware::DefaultParseJSON
21
+ c.use Faraday::Adapter::NetHttp
22
+ end
@@ -0,0 +1,90 @@
1
+ require 'mimic'
2
+ require 'socket'
3
+
4
+ class DataManager
5
+ class << self
6
+ def memo
7
+ {
8
+ 1 => {
9
+ id: 1,
10
+ export_url: "https://optimis.duxware.com",
11
+ external_id: 3,
12
+ token: "12345",
13
+ migrated_at: nil,
14
+ billing: true,
15
+ created_at: "2013-07-16T01:16:45Z",
16
+ updated_at: "2013-07-16T01:16:45Z"
17
+ }
18
+ }
19
+ end
20
+
21
+ def practices
22
+ @practices || memo.dup
23
+ end
24
+
25
+ def reset
26
+ @practices = memo.dup
27
+ end
28
+ end
29
+ end
30
+
31
+ Mimic.mimic(:port => Comptroller::Configuration::PORT) do
32
+ if defined?(Rails)
33
+ p "[NOTICE] Starting fake billing service on port #{Comptroller::Configuration::PORT}"
34
+ end
35
+
36
+ get '/practices' do
37
+ [ 200, {}, DataManager.practices.values.to_json ]
38
+ end
39
+
40
+ get '/practices/:id' do
41
+ [ 200, {}, DataManager.practices[params[:id].to_i].to_json ]
42
+ end
43
+
44
+ post '/practices' do
45
+ practice_params = params[:practice]
46
+ new_id = DataManager.practices.keys.max + 1 # fake auto incrementing private keys
47
+ new_practice = {
48
+ billing: false,
49
+ created_at: "2013-07-16T01:16:45Z",
50
+ export_url: practice_params[:export_url],
51
+ external_id: practice_params[:external_id].to_i,
52
+ id: new_id,
53
+ migrated_at: nil,
54
+ token: practice_params[:token],
55
+ updated_at: "2013-07-16T01:16:45Z"
56
+ }
57
+
58
+ DataManager.practices[new_id] = new_practice
59
+ [ 200, {}, new_practice.to_json ]
60
+ end
61
+
62
+ put '/practices/:id' do
63
+ practice = DataManager.practices[params[:id].to_i]
64
+ practice.merge!(params[:practice])
65
+ [ 200, {}, practice.to_json ]
66
+ end
67
+
68
+ delete '/practices/:id' do
69
+ deleted_practice = DataManager.practices.extract!(params[:id].to_i)[params[:id].to_i]
70
+ [ 200, {}, deleted_practice.to_json ]
71
+ end
72
+
73
+ get '/duxware_errors' do
74
+ [200, {}, [{
75
+ error_message: 'Send to optimis.duxware.com failed with ERROR: Did not find this ICD code in DB: 729.90',
76
+ external_id: 3,
77
+ id: 1,
78
+ message_body: '<?xml version="1.0" encoding="UTF-8"?><incomingHeader></incomingHeader>',
79
+ record_id: 43334,
80
+ resent_at: nil,
81
+ created_at: "2013-06-13T16:17:02Z",
82
+ updated_at: "2013-06-13T16:17:02Z"
83
+ }].to_json
84
+ ]
85
+ end
86
+
87
+ get '/resets' do
88
+ DataManager.reset
89
+ end
90
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ module Comptroller
4
+ describe ClaimError do
5
+ it 'retrieves claim errors' do
6
+ expect(ClaimError.all.first).to eql(ClaimError.new(:id => 1))
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ module Comptroller
4
+ describe Practice do
5
+ context 'crud api' do
6
+ it 'retrieves all pratices' do
7
+ expect(Practice.all.first).to eql(Practice.new(:export_url => 'https://optimis.duxware.com', :token => '12345', :external_id => 3))
8
+ end
9
+
10
+ it 'creates new practices' do
11
+ practice = Practice.create(:external_id => 5, :export_url => 'http://hello.world', :token => '12345')
12
+ expect(practice).to eql(Practice.new(:external_id => 5, :export_url => 'http://hello.world', :token => '12345'))
13
+ end
14
+
15
+ it 'retrieves practice by id' do
16
+ practice = Practice.find(1)
17
+ expect(practice).to eql(Practice.new(:external_id => 3, :export_url => 'https://optimis.duxware.com', :token => '12345'))
18
+ end
19
+
20
+ it 'updates practices' do
21
+ expect(Practice.save_existing(1, :export_url => 'https://optimis.webpt.com')).to be_true
22
+ expect(Practice.find(1).export_url).to eql('https://optimis.webpt.com')
23
+ end
24
+
25
+ it 'deletes practices' do
26
+ Practice.destroy_existing(1)
27
+ practice_ids = Practice.all.map(&:id)
28
+ expect(practice_ids.include?(1)).to be_false
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ require 'support/reset_helper'
2
+ require 'comptroller'
3
+ require 'spec/fake_server'
4
+
5
+ her_url = ENV['API_URL'] || "http://127.0.0.1:#{Comptroller::Configuration::PORT}"
6
+
7
+
8
+ BILLING_API = Her::API.new
9
+ BILLING_API.setup url: her_url do |c|
10
+ c.use Faraday::Request::UrlEncoded
11
+ c.use Her::Middleware::DefaultParseJSON
12
+ c.use Faraday::Adapter::NetHttp
13
+ end
14
+
15
+ Rspec.configure do |config|
16
+ config.after do
17
+ Comptroller::ResetHelper.reset
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ module Comptroller
2
+ module ResetHelper
3
+ def self.reset
4
+ Net::HTTP.get(URI("http://127.0.0.1:#{Comptroller::Configuration::PORT}/resets"))
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: comptroller
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - hubert
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: her
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0.6'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '2.0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '2.0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: mimic
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 0.4.3
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.4.3
94
+ description: Client gem for accessing the duxtape api
95
+ email:
96
+ - hubert77@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - comptroller.gemspec
107
+ - lib/comptroller.rb
108
+ - lib/comptroller/claim_error.rb
109
+ - lib/comptroller/configuration.rb
110
+ - lib/comptroller/practice.rb
111
+ - lib/comptroller/railtie.rb
112
+ - lib/comptroller/version.rb
113
+ - lib/initializers/her.rb
114
+ - lib/spec/fake_server.rb
115
+ - spec/claim_error_spec.rb
116
+ - spec/practice_spec.rb
117
+ - spec/spec_helper.rb
118
+ - spec/support/reset_helper.rb
119
+ homepage: https://github.com/hubert/comptroller
120
+ licenses:
121
+ - MIT
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 1.8.23
141
+ signing_key:
142
+ specification_version: 3
143
+ summary: Client gem for accessing the duxtape api
144
+ test_files:
145
+ - spec/claim_error_spec.rb
146
+ - spec/practice_spec.rb
147
+ - spec/spec_helper.rb
148
+ - spec/support/reset_helper.rb