ctgb-ids-converter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NGYxZmEwYzBkZjIxZDg0YmRhNWI2NmI1NDI2ZGZiYTU3NTMwYmIwZQ==
5
+ data.tar.gz: !binary |-
6
+ NzJhMGVjYzM2OTk1M2I0MjRiZjI4NjI1NWZiMzA1YTA0ZmQ1ZTdjZg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NTI3OThmNjFjMDYzZWI3OTQxYzU0ZTdlMmQ0ZTI3M2U1ZGUyODRjNTlhZWE1
10
+ NDQzMTRiZGRmODRjNzQ2OTdjNzBlZTFhMGIyZDVlNTkyOGQ4MWE5MDFmZjdi
11
+ NTYwNDRmYTBmZmQxYzNiMWZjZTQxY2NjMzE3ZTg0ZDBlNDRiYzM=
12
+ data.tar.gz: !binary |-
13
+ OTQ3N2NmZDUxMTE5ZmU3NzNiZGZiNGM0ZWNjNDNiMmNjMDdjZjM4MzA5OWE3
14
+ YmU1MmNlZjZhYWZhZDc2YmM3Y2FhMzQwMjY4NGM5OTFlNzU1YjFhZmQ3ZWEw
15
+ Y2IzZDRmNzdlMGYwMzk1Y2M1Njk4NmI1NDY5ZTY4NjJmMGFmNzQ=
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ gem "typhoeus"
5
+ gem "json"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "rspec"
11
+ gem "rdoc"
12
+ gem "bundler"
13
+ gem "jeweler"
14
+ # gem "rcov"
15
+ gem "debugger"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,80 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ builder (3.2.2)
6
+ columnize (0.3.6)
7
+ debugger (1.5.0)
8
+ columnize (>= 0.3.1)
9
+ debugger-linecache (~> 1.2.0)
10
+ debugger-ruby_core_source (~> 1.2.0)
11
+ debugger-linecache (1.2.0)
12
+ debugger-ruby_core_source (1.2.0)
13
+ diff-lcs (1.2.4)
14
+ ethon (0.6.1)
15
+ ffi (>= 1.3.0)
16
+ mime-types (~> 1.18)
17
+ faraday (0.8.8)
18
+ multipart-post (~> 1.2.0)
19
+ ffi (1.9.0)
20
+ git (1.2.6)
21
+ github_api (0.10.1)
22
+ addressable
23
+ faraday (~> 0.8.1)
24
+ hashie (>= 1.2)
25
+ multi_json (~> 1.4)
26
+ nokogiri (~> 1.5.2)
27
+ oauth2
28
+ hashie (2.0.5)
29
+ highline (1.6.19)
30
+ httpauth (0.2.0)
31
+ jeweler (1.8.7)
32
+ builder
33
+ bundler (~> 1.0)
34
+ git (>= 1.2.5)
35
+ github_api (= 0.10.1)
36
+ highline (>= 1.6.15)
37
+ nokogiri (= 1.5.10)
38
+ rake
39
+ rdoc
40
+ json (1.8.0)
41
+ jwt (0.1.8)
42
+ multi_json (>= 1.5)
43
+ mime-types (1.25)
44
+ multi_json (1.8.0)
45
+ multi_xml (0.5.5)
46
+ multipart-post (1.2.0)
47
+ nokogiri (1.5.10)
48
+ oauth2 (0.9.2)
49
+ faraday (~> 0.8)
50
+ httpauth (~> 0.2)
51
+ jwt (~> 0.1.4)
52
+ multi_json (~> 1.0)
53
+ multi_xml (~> 0.5)
54
+ rack (~> 1.2)
55
+ rack (1.5.2)
56
+ rake (10.1.0)
57
+ rdoc (3.12.2)
58
+ json (~> 1.4)
59
+ rspec (2.14.1)
60
+ rspec-core (~> 2.14.0)
61
+ rspec-expectations (~> 2.14.0)
62
+ rspec-mocks (~> 2.14.0)
63
+ rspec-core (2.14.5)
64
+ rspec-expectations (2.14.2)
65
+ diff-lcs (>= 1.1.3, < 2.0)
66
+ rspec-mocks (2.14.3)
67
+ typhoeus (0.6.5)
68
+ ethon (~> 0.6.1)
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ bundler
75
+ debugger
76
+ jeweler
77
+ json
78
+ rdoc
79
+ rspec
80
+ typhoeus
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 masciugo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = ctgb-ids-converter
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to ctgb-ids-converter
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 masciugo. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+ require 'jeweler'
12
+ require './lib/ctgb-ids-converter/version.rb'
13
+
14
+ Jeweler::Tasks.new do |gem|
15
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
16
+ gem.name = "ctgb-ids-converter"
17
+ gem.homepage = "http://github.com/masciugo/ctgb-ids-converter"
18
+ gem.license = "MIT"
19
+ gem.summary = %Q{ctgb-ids-converter service client}
20
+ gem.description = %Q{A library to access the ctgb-ids-converter service}
21
+ gem.email = "masciugo@gmail.com"
22
+ gem.authors = ["masciugo"]
23
+ gem.version = CtgbIdsConverter::VERSION
24
+ gem.files = FileList['lib/**/*.rb', '[A-Z]*','spec/**/*'].to_a
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.rspec_opts = "--format documentation --color --debug"
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ # RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ # spec.pattern = 'spec/**/*_spec.rb'
38
+ # spec.rcov = true
39
+ # end
40
+
41
+ task :default => :spec
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "ctgb-ids-converter #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,8 @@
1
+ require 'typhoeus'
2
+ require 'json'
3
+
4
+ require 'ctgb-ids-converter/version.rb'
5
+ require 'ctgb-ids-converter/exceptions.rb'
6
+ require 'ctgb-ids-converter/config.rb'
7
+ require 'ctgb-ids-converter/remote_converter.rb'
8
+
@@ -0,0 +1,6 @@
1
+ class CtgbIdsConverter::Config
2
+ class << self
3
+ attr_accessor :host, :hydra, :token, :port
4
+ end
5
+ @port = 80
6
+ end
@@ -0,0 +1,4 @@
1
+ module CtgbIdsConverter
2
+ class WrongIdException < RuntimeError; end
3
+ class UnauthorizedConversionException < RuntimeError; end
4
+ end
@@ -0,0 +1,58 @@
1
+ class CtgbIdsConverter::RemoteConverter
2
+
3
+ def self.connected?
4
+ run_request('/api/check_connection') do |response|
5
+ response.code == 200
6
+ end
7
+ end
8
+
9
+ def self.code(code)
10
+ convert(code,:sp2r)
11
+ end
12
+
13
+ def self.decode(code)
14
+ convert(code,:sr2p)
15
+ end
16
+
17
+ private
18
+
19
+ def self.convert(code,direction)
20
+ run_request("/api/projects/convert/1/#{direction}/#{code}", :method => :put ) do |response|
21
+ case response.code
22
+ when 200
23
+ return JSON.parse(response.response_body)['conv_id']
24
+ when 400
25
+ raise CtgbIdsConverter::WrongIdException
26
+ when 401
27
+ raise CtgbIdsConverter::UnauthorizedConversionException
28
+ else
29
+ raise "Conversion service returned code #{response.code}"
30
+ end
31
+ end
32
+ end
33
+
34
+ def self.run_request(resource_path, opts = {}, &block)
35
+ request = Typhoeus::Request.new(get_uri(resource_path), opts)
36
+ request.on_complete do |response|
37
+ # puts response.request.base_url
38
+ # puts response.response_body.class
39
+ return yield(response)
40
+ end
41
+ CtgbIdsConverter::Config.hydra.queue(request)
42
+ CtgbIdsConverter::Config.hydra.run
43
+ end
44
+
45
+ def self.get_uri(resource_path)
46
+ uri_host_part + resource_path + uri_token_part
47
+ end
48
+
49
+ def self.uri_host_part
50
+ "http://#{CtgbIdsConverter::Config.host}:#{CtgbIdsConverter::Config.port}"
51
+ end
52
+
53
+ def self.uri_token_part
54
+ postfix = "token=#{CtgbIdsConverter::Config.token}"
55
+ postfix.insert(0, '?') unless postfix.start_with? '?'
56
+ end
57
+
58
+ end
@@ -0,0 +1,3 @@
1
+ module CtgbIdsConverter
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,74 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "CtgbIdsConverter version" do
4
+ subject { CtgbIdsConverter::VERSION }
5
+ it {should be_a_kind_of(String)}
6
+ it {should match(/\d+\.\d+\.\d+/)}
7
+ end
8
+
9
+ describe "CtgbIdsConverter configuration attributes for service on linux2" do
10
+ before(:each) do
11
+ CtgbIdsConverter::Config.hydra = Typhoeus::Hydra.new
12
+ CtgbIdsConverter::Config.host = 'localhost'
13
+ CtgbIdsConverter::Config.token = 'zU4vFmORUQ9DBJPlJlt'
14
+ end
15
+ subject {CtgbIdsConverter::Config}
16
+ its(:hydra){ should be_a_kind_of(Typhoeus::Hydra)}
17
+ its(:host){ should == 'localhost'}
18
+ its(:token){ should == 'zU4vFmORUQ9DBJPlJlt'}
19
+ its(:port){ should == 80}
20
+ context "when set port to 3001" do
21
+ before(:each) do
22
+ CtgbIdsConverter::Config.port = 3001
23
+ end
24
+ its(:port){ should == 3001}
25
+ end
26
+ end
27
+
28
+ # following test are based on ids_converter web service running locally on port 3001 with two test user
29
+ describe CtgbIdsConverter::RemoteConverter do
30
+ subject(:converter) { CtgbIdsConverter::RemoteConverter }
31
+ before(:each) do
32
+ CtgbIdsConverter::Config.hydra = Typhoeus::Hydra.new
33
+ CtgbIdsConverter::Config.host = 'localhost'
34
+ CtgbIdsConverter::Config.token = 'zU4vFmORUQ9DBJPlJlt' #test user with insert public id privilege
35
+ CtgbIdsConverter::Config.port = 3001
36
+ end
37
+
38
+ describe ".connected?" do
39
+ it "returns true" do
40
+ converter.connected?.should be_true
41
+ end
42
+ end
43
+
44
+ describe ".code" do
45
+ context "when providing a correct public id" do
46
+ it "returns coding" do
47
+ converter.code('AN000127').should == 'XX999341'
48
+ end
49
+ end
50
+ context "when providing a wrong public id" do
51
+ specify { expect {converter.code('AN000127xs')}.to raise_error CtgbIdsConverter::WrongIdException }
52
+ specify { expect {converter.code('')}.to raise_error CtgbIdsConverter::WrongIdException }
53
+ end
54
+ context "when providing a new public id but user has no intert privileges" do
55
+ # for this to work AN000000 should be missing in the conversion id DB (ids_pair table)
56
+ before(:each) do
57
+ CtgbIdsConverter::Config.token = 'dFdwK5Hhk5d3ocIebea' #test user without insert public id privilege
58
+ end
59
+ specify { expect {converter.code('AN000000')}.to raise_error CtgbIdsConverter::UnauthorizedConversionException }
60
+ end
61
+ end
62
+
63
+ describe ".decode" do
64
+ context "when providing a correct clinic id" do
65
+ it "returns decoding" do
66
+ converter.decode('XX999341').should == 'AN000127'
67
+ end
68
+ end
69
+ context "when providing a wrong clinic id" do
70
+ specify { expect {converter.decode('XX999341xxx')}.to raise_error CtgbIdsConverter::WrongIdException }
71
+ specify { expect {converter.decode('')}.to raise_error CtgbIdsConverter::WrongIdException }
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,10 @@
1
+ require 'rspec'
2
+
3
+ # Requires supporting files with custom matchers and macros, etc,
4
+ # in ./support/ and its subdirectories.
5
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
6
+
7
+ RSpec.configure do |config|
8
+ end
9
+
10
+ require 'ctgb-ids-converter'
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ctgb-ids-converter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - masciugo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: rspec
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: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jeweler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: debugger
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A library to access the ctgb-ids-converter service
112
+ email: masciugo@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files:
116
+ - LICENSE.txt
117
+ - README.rdoc
118
+ files:
119
+ - Gemfile
120
+ - Gemfile.lock
121
+ - LICENSE.txt
122
+ - README.rdoc
123
+ - Rakefile
124
+ - VERSION
125
+ - lib/ctgb-ids-converter.rb
126
+ - lib/ctgb-ids-converter/config.rb
127
+ - lib/ctgb-ids-converter/exceptions.rb
128
+ - lib/ctgb-ids-converter/remote_converter.rb
129
+ - lib/ctgb-ids-converter/version.rb
130
+ - spec/ctgb-ids-converter_spec.rb
131
+ - spec/spec_helper.rb
132
+ homepage: http://github.com/masciugo/ctgb-ids-converter
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.0.3
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: ctgb-ids-converter service client
156
+ test_files: []