cumulus_ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5af02cb62dc660797bdf396064f6a52acc368a5d
4
+ data.tar.gz: 1fbf4d0689353a996d4cc1b32f6321678761dc50
5
+ SHA512:
6
+ metadata.gz: 7ec0090158c3e9c0517108bbe77aac7aad934dad267c5eeae122fe63f314178d4eb9a0a47908dfc2681019cd68b0b1a0213d5e8dd34fb1c81f46828a8404990f
7
+ data.tar.gz: 27a4f397ee02138d24d45ccf331e8675ccdd9a10f78d44d2710bfd8557f46cc1d01a89f3bd14e44c1fc11c8289a85d7e77a840fe95e88ffed2cd6b73807f0bb6
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cumulus_ruby.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Amed Rodriguez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,80 @@
1
+ # Cumulus Ruby Gem
2
+
3
+ A Ruby wrapper for the Cumulus API.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ $ gem install cumulus_ruby
9
+ ```
10
+
11
+ ## API Usage Examples
12
+
13
+ You will need to get an access token. Once you have it, initialize the client
14
+ to make authenticated further calls.
15
+
16
+ ```ruby
17
+ # initializing the client
18
+ client = Cumulus::Client.new(token: 'access-token')
19
+ ```
20
+
21
+ ### Patients
22
+
23
+ Create a patient.
24
+
25
+ ```ruby
26
+ attributes = { first_name: 'John', middle_name: 'Doe', curp: 'JDOE' }
27
+ patient = Cumulus::Patient.new(client, attributes)
28
+ patient.create
29
+ # or
30
+ patient = Patient.new(client)
31
+ patient.create(attributes)
32
+ ```
33
+
34
+ Update a patient.
35
+
36
+ ```ruby
37
+ patient.update(first_name: 'Mike')
38
+ ```
39
+
40
+ Fetch a patient.
41
+
42
+ ```ruby
43
+ patient.fetch(other_patient.curp)
44
+ ```
45
+
46
+ Search patient info.
47
+
48
+ ```ruby
49
+ patient.search(other_patient.curp, { query: 'foo' })
50
+ ```
51
+
52
+ ### P*mex
53
+
54
+ ```ruby
55
+ pmx = Cumulus::Pmx.new(client)
56
+ ```
57
+
58
+ Look for companies
59
+
60
+ ```ruby
61
+ pmx.companies({ 'numeroEmpleado' => '123' })
62
+ ```
63
+
64
+ Look for entitlement
65
+
66
+ ```ruby
67
+ pmx.entitled({ 'numeroEmpresa' => '123',
68
+ 'numeroEmpleado' => '123', 'codigoDerechoHabiente' => '0' })
69
+ ```
70
+
71
+ Look for a patient
72
+
73
+ ```ruby
74
+ pmx.patient({ 'numeroEmpresa' => '123',
75
+ 'numeroEmpleado' => '123', 'codigoDerechoHabiente' => '0' })
76
+ ```
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cumulus_ruby"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cumulus/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cumulus_ruby"
8
+ spec.version = Cumulus::VERSION
9
+ spec.authors = ["Amed Rodriguez"]
10
+ spec.email = ["amed.rdz@gmail.com"]
11
+
12
+ spec.summary = %q{Cumulus API Ruby Wrapper}
13
+ spec.homepage = "https://github.com/amedrz/cumulus_ruby"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.10"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec"
32
+ spec.add_development_dependency "webmock"
33
+ spec.add_development_dependency "vcr"
34
+ spec.add_development_dependency "pry"
35
+
36
+ spec.add_dependency "faraday"
37
+ spec.add_dependency "faraday_middleware"
38
+ spec.add_dependency "json"
39
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'cumulus/version'
2
+ require_relative 'cumulus/client'
3
+ require_relative 'cumulus/patient'
4
+ require_relative 'cumulus/pmx'
5
+ require_relative 'cumulus/utils/parameters_handler'
6
+
7
+ module Cumulus
8
+ end
@@ -0,0 +1,61 @@
1
+ require 'faraday'
2
+ require 'logger'
3
+ require 'faraday_middleware'
4
+
5
+ module Cumulus
6
+ class Client
7
+ attr_accessor :request
8
+
9
+ API_URL = 'https://api-cumulus.com'
10
+
11
+ def initialize(options={})
12
+ @token = options[:token]
13
+ end
14
+
15
+ def request(type, path, params={})
16
+ block = Proc.new do |request|
17
+ request.url path
18
+ request.headers['Authorization'] = "Token #{token}"
19
+ request.headers['Content-Type'] = 'application/json'
20
+ end
21
+
22
+ send("#{type}_request", path, params, &block)
23
+ end
24
+
25
+ private
26
+ def put_request(path, params={}, &block)
27
+ connection.put do |request|
28
+ yield(request)
29
+ request.body = params.to_json
30
+ end
31
+ .body
32
+ end
33
+
34
+ def post_request(path, params={}, &block)
35
+ connection.post do |request|
36
+ yield(request)
37
+ request.body = params.to_json
38
+ end
39
+ .body
40
+ end
41
+
42
+ def get_request(path, params={}, &block)
43
+ connection.get do |request|
44
+ yield(request)
45
+ params.each { |key, val| request.params[key] = val }
46
+ end
47
+ .body
48
+ end
49
+
50
+ def token
51
+ @token
52
+ end
53
+
54
+ def connection
55
+ @connection ||= Faraday.new(url: Cumulus::Client::API_URL) do |b|
56
+ b.adapter Faraday.default_adapter
57
+ b.use FaradayMiddleware::ParseJson
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,55 @@
1
+ module Cumulus
2
+ class Patient
3
+ PARAMETERS = {
4
+ 'id' => 'id',
5
+ 'first_name' => 'nombre',
6
+ 'middle_name' => 'apellido',
7
+ 'last_name' => 'apellidoSegundo',
8
+ 'telephone' => 'telefono',
9
+ 'telephone2' => 'telefonoAlt',
10
+ 'email' => 'correo',
11
+ 'born_at' => 'fechaNacimiento',
12
+ 'gender' => 'sexo',
13
+ 'curp' => 'curp',
14
+ 'street' => 'calle',
15
+ 'city' => 'ciudad',
16
+ 'state' => 'estado',
17
+ 'country' => 'pais',
18
+ 'zipcode' => 'codigoPostal'
19
+ }
20
+
21
+ PARAMETERS.keys.each { |k| attr_accessor k }
22
+
23
+ def initialize(client, parameters={})
24
+ @client = client
25
+ parameters_handler.set(parameters)
26
+ end
27
+
28
+ def create(parameters={})
29
+ parameters_handler.set(parameters)
30
+ client.request(:post, '/pacientes', parameters_handler.for_request)
31
+ end
32
+
33
+ def update(parameters={})
34
+ parameters_handler.set(parameters)
35
+ client.request(:put, "/pacientes/#{curp}", parameters_handler.for_request)
36
+ end
37
+
38
+ def fetch(curp)
39
+ client.request(:get, "/pacientes/#{curp}")
40
+ end
41
+
42
+ def search(curp, query)
43
+ client.request(:post, "/pacientes/#{curp}/busqueda", { query: query })
44
+ end
45
+
46
+ private
47
+ def client
48
+ @client
49
+ end
50
+
51
+ def parameters_handler
52
+ @parameters ||= Cumulus::Utils::ParametersHandler.new(PARAMETERS, self)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,24 @@
1
+ module Cumulus
2
+ class Pmx
3
+ def initialize(client)
4
+ @client = client
5
+ end
6
+
7
+ def companies(params)
8
+ client.request(:post, '/pemex/empresa', params)
9
+ end
10
+
11
+ def entitled(params)
12
+ client.request(:post, '/pemex/derecho_habiente', params)
13
+ end
14
+
15
+ def patient(params)
16
+ client.request(:post, '/pemex/paciente', params)
17
+ end
18
+
19
+ private
20
+ def client
21
+ @client
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ module Cumulus
2
+ module Utils
3
+ class ParametersHandler
4
+ attr_reader :parameters, :object
5
+
6
+ def initialize(parameters, object)
7
+ @parameters = parameters
8
+ @object = object
9
+ end
10
+
11
+ def for_request
12
+ parameters.each_with_object({}) { |j, k| k[j[1]] = object.send(j[0]) }
13
+ .reject { |k, v| v.nil? }
14
+ end
15
+
16
+ def set(attributes)
17
+ cleanup(attributes).each { |k, v| object.send("#{k}=", v) }
18
+ end
19
+
20
+ def cleanup(attributes)
21
+ Hash[attributes.map { |k, v| [k.to_s, v] }]
22
+ .select { |k, v| parameters.key?(k) }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Cumulus
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cumulus_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Amed Rodriguez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-31 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: webmock
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: vcr
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: pry
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: faraday
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: faraday_middleware
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: json
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email:
141
+ - amed.rdz@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".travis.yml"
148
+ - CODE_OF_CONDUCT.md
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - bin/console
154
+ - bin/setup
155
+ - cumulus_ruby.gemspec
156
+ - lib/cumulus.rb
157
+ - lib/cumulus/client.rb
158
+ - lib/cumulus/patient.rb
159
+ - lib/cumulus/pmx.rb
160
+ - lib/cumulus/utils/parameters_handler.rb
161
+ - lib/cumulus/version.rb
162
+ homepage: https://github.com/amedrz/cumulus_ruby
163
+ licenses:
164
+ - MIT
165
+ metadata:
166
+ allowed_push_host: https://rubygems.org
167
+ post_install_message:
168
+ rdoc_options: []
169
+ require_paths:
170
+ - lib
171
+ required_ruby_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ requirements: []
182
+ rubyforge_project:
183
+ rubygems_version: 2.4.5
184
+ signing_key:
185
+ specification_version: 4
186
+ summary: Cumulus API Ruby Wrapper
187
+ test_files: []