-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exploding va_rx gem into vets-api -- with minor refactor #88
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
37b25db
exploding va_rx gem into vets-api -- initial commit with minor refact…
saneshark 33cfb01
fixing rubocop errors
saneshark 2a862e6
fixing time zone issue
saneshark 9764d4c
make sure the dependency for rx/client is specified in controller
saneshark c4a6d6b
Merge branch 'master' into explode_varx_gem_into_lib
saneshark 73e4e68
addressing comments around spaceship operator usage
saneshark 0bc5408
Merge branch 'explode_varx_gem_into_lib' of https://github.com/depart…
saneshark 3dcd8a4
adding comment about timeouts being in seconds
saneshark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
require 'common/models/base' | ||
# Prescription model | ||
# Reference: https://github.com/department-of-veterans-affairs/prescriptions-team/blob/master/API/sample_mvh_api_calls | ||
class Prescription < Common::Base | ||
attribute :prescription_id, Integer | ||
attribute :refill_status, String | ||
attribute :refill_submit_date, Common::UTCTime | ||
attribute :refill_date, Common::UTCTime | ||
attribute :refill_remaining, Integer | ||
attribute :facility_name, String | ||
attribute :ordered_date, Common::UTCTime | ||
attribute :quantity, Integer | ||
attribute :expiration_date, Common::UTCTime | ||
attribute :prescription_number, String | ||
attribute :prescription_name, String | ||
attribute :dispensed_date, Common::UTCTime | ||
attribute :station_number, String | ||
attribute :is_refillable, Boolean | ||
attribute :is_trackable, Boolean | ||
|
||
alias refillable? is_refillable | ||
alias trackable? is_trackable | ||
|
||
def <=>(other) | ||
return -1 if prescription_id < other.prescription_id | ||
return 1 if prescription_id > other.prescription_id | ||
0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
require 'common/models/base' | ||
# Tracking Model | ||
class Tracking < Common::Base | ||
attribute :prescription_id, Integer | ||
attribute :prescription_name, String | ||
attribute :prescription_number, String | ||
attribute :facility_name, String | ||
attribute :rx_info_phone_number, String | ||
attribute :ndc_number, String | ||
attribute :shipped_date, Common::UTCTime | ||
attribute :delivery_service, String | ||
attribute :tracking_number, String | ||
|
||
def <=>(other) | ||
return -1 if shipped_date < other.shipped_date | ||
return 1 if shipped_date > other.shipped_date | ||
0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
module Common | ||
module Client | ||
# Configuration class used to setup the environment used by client | ||
class Configuration | ||
OPEN_TIMEOUT = 15 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment with units. Seconds? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, i can do that -- ping me when you're done reviewing. |
||
READ_TIMEOUT = 15 | ||
|
||
attr_reader :app_token, :open_timeout, :read_timeout | ||
|
||
def initialize(host:, app_token:, open_timeout: OPEN_TIMEOUT, read_timeout: READ_TIMEOUT, enforce_ssl: true) | ||
@app_token = app_token | ||
@host = URI.parse(host) | ||
@open_timeout = open_timeout | ||
@read_timeout = read_timeout | ||
assert_ssl if enforce_ssl | ||
end | ||
|
||
def base_path | ||
raise NotImplementedError, 'you must provide a base_path.' | ||
end | ||
|
||
private | ||
|
||
def assert_ssl | ||
raise ArgumentError, 'host must use ssl' unless @host.is_a?(URI::HTTPS) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
require 'faraday/error' | ||
|
||
# FIXME: this needs to be adapted to use va-api-common style errors | ||
module Common | ||
module Client | ||
# The error class defines the various error types that the client can encounter | ||
module Errors | ||
class Error < StandardError; end | ||
|
||
class NotAuthenticated < Error; end | ||
class Client < Error; end | ||
class Serialization < Error; end | ||
class RequestTimeout < ::Faraday::Error::TimeoutError; end | ||
class ConnectionFailed < ::Faraday::Error::ConnectionFailed; end | ||
|
||
# This error class is for handling the various error types identified in error_codes.rb | ||
class ClientResponse < Error | ||
def initialize(status_code, parsed_json) | ||
@status_code = status_code | ||
@parsed_json = parsed_json | ||
end | ||
|
||
def error | ||
return @cause unless @cause.nil? | ||
self | ||
end | ||
|
||
def major | ||
@status_code | ||
end | ||
|
||
def minor | ||
@parsed_json['errorCode'] | ||
end | ||
|
||
def message | ||
@parsed_json['message'] | ||
end | ||
|
||
def developer_message | ||
@parsed_json['developerMessage'] | ||
end | ||
|
||
def as_json | ||
return debug_hash if defined?(Rails) && (Rails.env.development? || Rails.env.test?) | ||
base_json | ||
end | ||
|
||
delegate :to_json, to: :as_json | ||
|
||
def to_s | ||
to_json | ||
end | ||
|
||
private | ||
|
||
def base_json | ||
{ major: major, minor: minor, message: message } | ||
end | ||
|
||
def cause_to_hash | ||
@cause.nil? ? {} : { message: @cause.message, backtrace: @cause.backtrace } | ||
end | ||
|
||
def debug_hash | ||
base_json.merge(developer_message: developer_message, error: backtrace, cause: cause_to_hash) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
require 'common/models/base' | ||
require 'common/models/attribute_types/utc_time' | ||
module Common | ||
module Client | ||
# A generic session model - see how RX implements it | ||
class Session < Common::Base | ||
EXPIRATION_THRESHOLD_SECONDS = 20 | ||
|
||
attribute :user_id, Integer | ||
attribute :expires_at, Common::UTCTime | ||
attribute :token, String | ||
|
||
def expired? | ||
return true if expires_at.nil? | ||
expires_at.to_i <= Time.now.utc.to_i + EXPIRATION_THRESHOLD_SECONDS | ||
end | ||
|
||
def valid? | ||
user_id.is_a?(Fixnum) | ||
end | ||
|
||
def original_json | ||
nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
module Common | ||
# This is a custom type class for ensuring Time is always coerced as UTC | ||
class UTCTime < Virtus::Attribute | ||
def coerce(value) | ||
return nil if value.to_s.empty? | ||
return Time.parse(value).utc if value.is_a?(String) | ||
value.utc | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
require 'active_model' | ||
require 'common/models/attribute_types/utc_time' | ||
|
||
module Common | ||
# This is a base serialization class | ||
class Base | ||
include Comparable | ||
include ActiveModel::Serialization | ||
extend ActiveModel::Naming | ||
include Virtus.model(nullify_blank: true) | ||
|
||
attr_reader :attributes | ||
attr_accessor :metadata, :errors | ||
alias to_h attributes | ||
alias to_hash attributes | ||
|
||
def initialize(attributes = {}) | ||
@attributes = attributes[:data] || attributes | ||
@metadata = attributes[:metadata] || {} | ||
@errors = attributes[:errors] || {} | ||
@attributes.each do |key, value| | ||
setter = "#{key.to_s.underscore}=".to_sym | ||
send(setter, value) if respond_to?(setter) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be shortened to
prescription_id <=> other.prescription_id
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe... (it should) let me test that out really quick -- will make similar change for tracking if its the case.