ids-converter-client 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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.1)
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
@@ -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.
@@ -0,0 +1,19 @@
1
+ = ids-converter-client
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to ids-converter-client
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
+
@@ -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/ids-converter-client/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 = "ids-converter-client"
17
+ gem.homepage = "http://github.com/masciugo/ids-converter-client"
18
+ gem.license = "MIT"
19
+ gem.summary = %Q{ids-converter-client service client}
20
+ gem.description = %Q{A library to access the ids-converter-client service}
21
+ gem.email = "masciugo@gmail.com"
22
+ gem.authors = ["masciugo"]
23
+ gem.version = IdsConverterClient::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 = "ids-converter-client #{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 'ids-converter-client/version.rb'
5
+ require 'ids-converter-client/exceptions.rb'
6
+ require 'ids-converter-client/config.rb'
7
+ require 'ids-converter-client/remote_converter.rb'
8
+
@@ -0,0 +1,22 @@
1
+ module IdsConverterClient
2
+
3
+ class << self
4
+ attr_accessor :configuration
5
+ end
6
+
7
+ class Config
8
+ attr_accessor :host, :hydra, :token, :port
9
+
10
+ def initialize
11
+ self.port = 80
12
+ self.hydra = Typhoeus::Hydra.new
13
+ end
14
+
15
+ end
16
+
17
+ def self.configure
18
+ self.configuration ||= Config.new
19
+ yield(configuration) if block_given?
20
+ end
21
+
22
+ end
@@ -0,0 +1,4 @@
1
+ module IdsConverterClient
2
+ class WrongIdException < RuntimeError; end
3
+ class UnauthorizedConversionException < RuntimeError; end
4
+ end
@@ -0,0 +1,58 @@
1
+ class IdsConverterClient::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 IdsConverterClient::WrongIdException
26
+ when 401
27
+ raise IdsConverterClient::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
+ IdsConverterClient.configuration.hydra.queue(request)
42
+ IdsConverterClient.configuration.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://#{IdsConverterClient.configuration.host}:#{IdsConverterClient.configuration.port}"
51
+ end
52
+
53
+ def self.uri_token_part
54
+ postfix = "token=#{IdsConverterClient.configuration.token}"
55
+ postfix.insert(0, '?') unless postfix.start_with? '?'
56
+ end
57
+
58
+ end
@@ -0,0 +1,3 @@
1
+ module IdsConverterClient
2
+ VERSION = "0.3.0"
3
+ end
@@ -0,0 +1,76 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "IdsConverterClient version" do
4
+ subject { IdsConverterClient::VERSION }
5
+ it {should be_a_kind_of(String)}
6
+ it {should match(/\d+\.\d+\.\d+/)}
7
+ end
8
+
9
+ describe "IdsConverterClient configuration attributes for service on linux2" do
10
+ before(:each) do
11
+ IdsConverterClient.configure do |config|
12
+ config.host = 'localhost'
13
+ config.token = 'zU4vFmORUQ9DBJPlJlt'
14
+ end
15
+ end
16
+ subject {IdsConverterClient.configuration}
17
+ its(:hydra){ should be_a_kind_of(Typhoeus::Hydra)}
18
+ its(:host){ should == 'localhost'}
19
+ its(:token){ should == 'zU4vFmORUQ9DBJPlJlt'}
20
+ its(:port){ should == 80}
21
+ context "when set port to 3001" do
22
+ before(:each) do
23
+ IdsConverterClient.configuration.port = 3001
24
+ end
25
+ its(:port){ should == 3001}
26
+ end
27
+ end
28
+
29
+ # following test are based on ids_converter web service running locally on port 3001 with two test user
30
+ describe IdsConverterClient::RemoteConverter do
31
+ subject(:converter) { IdsConverterClient::RemoteConverter }
32
+ before(:each) do
33
+ IdsConverterClient.configure do |config|
34
+ config.host = 'localhost'
35
+ config.token = 'zU4vFmORUQ9DBJPlJlt'
36
+ config.port = 3001
37
+ end
38
+ end
39
+
40
+ describe ".connected?" do
41
+ it "returns true" do
42
+ converter.connected?.should be_true
43
+ end
44
+ end
45
+
46
+ describe ".code" do
47
+ context "when providing a correct public id" do
48
+ it "returns coding" do
49
+ converter.code('AN000127').should == 'XX999341'
50
+ end
51
+ end
52
+ context "when providing a wrong public id" do
53
+ specify { expect {converter.code('AN000127xs')}.to raise_error IdsConverterClient::WrongIdException }
54
+ specify { expect {converter.code('')}.to raise_error IdsConverterClient::WrongIdException }
55
+ end
56
+ context "when providing a new public id but user has no intert privileges" do
57
+ # for this to work AN000000 should be missing in the conversion id DB (ids_pair table)
58
+ before(:each) do
59
+ IdsConverterClient.configuration.token = 'dFdwK5Hhk5d3ocIebea' #test user without insert public id privilege
60
+ end
61
+ specify { expect {converter.code('AN000000')}.to raise_error IdsConverterClient::UnauthorizedConversionException }
62
+ end
63
+ end
64
+
65
+ describe ".decode" do
66
+ context "when providing a correct clinic id" do
67
+ it "returns decoding" do
68
+ converter.decode('XX999341').should == 'AN000127'
69
+ end
70
+ end
71
+ context "when providing a wrong clinic id" do
72
+ specify { expect {converter.decode('XX999341xxx')}.to raise_error IdsConverterClient::WrongIdException }
73
+ specify { expect {converter.decode('')}.to raise_error IdsConverterClient::WrongIdException }
74
+ end
75
+ end
76
+ 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 'ids-converter-client'
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ids-converter-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - masciugo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: typhoeus
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
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'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
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: rdoc
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '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: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: bundler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
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'
94
+ - !ruby/object:Gem::Dependency
95
+ name: jeweler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: debugger
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: A library to access the ids-converter-client service
127
+ email: masciugo@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files:
131
+ - LICENSE.txt
132
+ - README.rdoc
133
+ files:
134
+ - Gemfile
135
+ - Gemfile.lock
136
+ - LICENSE.txt
137
+ - README.rdoc
138
+ - Rakefile
139
+ - VERSION
140
+ - lib/ids-converter-client.rb
141
+ - lib/ids-converter-client/config.rb
142
+ - lib/ids-converter-client/exceptions.rb
143
+ - lib/ids-converter-client/remote_converter.rb
144
+ - lib/ids-converter-client/version.rb
145
+ - spec/ids-converter-client_spec.rb
146
+ - spec/spec_helper.rb
147
+ homepage: http://github.com/masciugo/ids-converter-client
148
+ licenses:
149
+ - MIT
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ segments:
161
+ - 0
162
+ hash: -3212252422715226401
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ none: false
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 1.8.23
172
+ signing_key:
173
+ specification_version: 3
174
+ summary: ids-converter-client service client
175
+ test_files: []