athena_health 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: 3dc8c8a778d52620ecf30dc9905b0ad73051f8c1
4
+ data.tar.gz: b4b1ad49e12dae99a0d2a7b06a7caa5c6d4c5607
5
+ SHA512:
6
+ metadata.gz: a0f2c6a0b6469ec41348df80a893898a9c3fb6b192dc5d85afc6655c52e819c0856094d5a7a4032c5e7870d45b742fe2b642c3b783e0ee56a375501af98472cc
7
+ data.tar.gz: 05ff909c2ed582080d89b4f5e8ef6c1ee47fd88b5e95c234017a6da02f281a4dd43a2e35b03fc12904223c0e1db8f6aa5655de9f9f3797dac71f6f3a93896e22
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
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 athena_health.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Mateusz Urbański
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,6 @@
1
+ [![Build Status](https://travis-ci.org/MatUrbanski/athena_health.svg?branch=master)](https://travis-ci.org/MatUrbanski/athena_health)
2
+ [![Dependency Status](https://gemnasium.com/MatUrbanski/athena_health.svg)](https://gemnasium.com/MatUrbanski/athena_health)
3
+
4
+ # AthenaHealth
5
+
6
+ Ruby wrapper for Athenahealth API.
@@ -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
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'athena_health/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'athena_health'
8
+ spec.version = AthenaHealth::VERSION
9
+ spec.authors = ["Mateusz Urbański"]
10
+ spec.email = ['mateuszurbanski@yahoo.pl']
11
+
12
+ spec.summary = 'Ruby wrapper for Athenahealth API.'
13
+ spec.description = 'Ruby wrapper for Athenahealth API. See https://developer.athenahealth.com/io-docs for more details.'
14
+ spec.homepage = 'https://github.com/MatUrbanski/athena_health'
15
+ spec.license = 'MIT'
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'typhoeus'
22
+ spec.add_dependency 'virtus'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.11'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.2'
27
+ spec.add_development_dependency 'vcr', '~> 3.0'
28
+ end
@@ -0,0 +1,12 @@
1
+ require 'typhoeus'
2
+ require 'virtus'
3
+
4
+ require 'athena_health/version'
5
+ require 'athena_health/connection'
6
+ require 'athena_health/error'
7
+ require 'athena_health/client'
8
+ require 'athena_health/practice'
9
+ require 'athena_health/practice_collection'
10
+
11
+ module AthenaHealth
12
+ end
@@ -0,0 +1,17 @@
1
+ module AthenaHealth
2
+ class Client
3
+ def initialize(version:, key:, secret:)
4
+ @api = AthenaHealth::Connection.new(version: version, key: key, secret: secret)
5
+ end
6
+
7
+ def all_practices(params: {})
8
+ response = @api.call(endpoint: '1/practiceinfo', method: :get, params: params)
9
+ PracticeCollection.new(response)
10
+ end
11
+
12
+ def find_practice(practice_id:, params: {})
13
+ response = @api.call(endpoint: "#{practice_id}/practiceinfo", method: :get, params: params)
14
+ PracticeCollection.new(response).practiceinfo.first
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,44 @@
1
+ require 'json'
2
+
3
+ module AthenaHealth
4
+ class Connection
5
+ BASE_URL = 'https://api.athenahealth.com'.freeze
6
+ AUTH_PATH = { 'v1' => 'oauth', 'preview1' => 'oauthpreview', 'openpreview1' => 'oauthopenpreview' }
7
+
8
+ def initialize(version:, key:, secret:)
9
+ @version = version
10
+ @key = key
11
+ @secret = secret
12
+ end
13
+
14
+ def authenticate
15
+ response = Typhoeus.post(
16
+ "#{BASE_URL}/#{AUTH_PATH[@version]}/token",
17
+ userpwd: "#{@key}:#{@secret}",
18
+ body: { grant_type: 'client_credentials' }
19
+ ).response_body
20
+
21
+ @token = JSON.parse(response)['access_token']
22
+ end
23
+
24
+ def call(endpoint:, method:, params: {}, second_call: false)
25
+ authenticate if @token.nil?
26
+
27
+ request = Typhoeus::Request.new(
28
+ "#{BASE_URL}/#{@version}/#{endpoint}",
29
+ method: method,
30
+ headers: { "Authorization" => "Bearer #{@token}"},
31
+ params: params
32
+ ).run
33
+
34
+ if request.response_code == 401 && !second_call
35
+ authenticate
36
+ call(endpoint: endpoint, method: method, second_call: true)
37
+ end
38
+
39
+ AthenaHealth::Error.new(code: request.response_code).render if request.response_code != 200
40
+
41
+ JSON.parse(request.response_body)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ module AthenaHealth
2
+ class Error
3
+ def initialize(code:)
4
+ @code = code
5
+ end
6
+
7
+ def render
8
+ fail errors[@code]
9
+ end
10
+
11
+ private
12
+
13
+ def errors
14
+ {
15
+ 400 => BadRequestError,
16
+ 401 => UnauthorizedError,
17
+ 402 => IncorrectPermissionsError,
18
+ 403 => ForbiddenError,
19
+ 404 => NotFoundError,
20
+ 409 => ConflictError,
21
+ 500 => InternalServerError,
22
+ 503 => ServiceUnavailableError,
23
+ }
24
+ end
25
+ end
26
+
27
+ class BadRequestError < StandardError; end
28
+ class UnauthorizedError < StandardError; end
29
+ class IncorrectPermissionsError < StandardError; end
30
+ class ForbiddenError < StandardError; end
31
+ class NotFoundError < StandardError; end
32
+ class ConflictError < StandardError; end
33
+ class InternalServerError < StandardError; end
34
+ class ServiceUnavailableError < StandardError; end
35
+ end
@@ -0,0 +1,14 @@
1
+ module AthenaHealth
2
+ class Practice
3
+ include Virtus.model
4
+
5
+ attribute :hascommunicator, Boolean
6
+ attribute :iscoordinatorsender, Boolean
7
+ attribute :iscoordinatorreceiver, Boolean
8
+ attribute :hasclinicals, Boolean
9
+ attribute :name, String
10
+ attribute :hascollector, Boolean
11
+ attribute :publicnames, Array
12
+ attribute :practiceid, Integer
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ module AthenaHealth
2
+ class PracticeCollection
3
+ include Virtus.model
4
+
5
+ attribute :totalcount, Integer
6
+ attribute :practiceinfo, Array[Practice]
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module AthenaHealth
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: athena_health
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mateusz Urbański
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-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: virtus
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: Ruby wrapper for Athenahealth API. See https://developer.athenahealth.com/io-docs
98
+ for more details.
99
+ email:
100
+ - mateuszurbanski@yahoo.pl
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - athena_health.gemspec
113
+ - lib/athena_health.rb
114
+ - lib/athena_health/client.rb
115
+ - lib/athena_health/connection.rb
116
+ - lib/athena_health/error.rb
117
+ - lib/athena_health/practice.rb
118
+ - lib/athena_health/practice_collection.rb
119
+ - lib/athena_health/version.rb
120
+ homepage: https://github.com/MatUrbanski/athena_health
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.8
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Ruby wrapper for Athenahealth API.
144
+ test_files: []
145
+ has_rdoc: