pillboxr 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +2 -0
- data/lib/pillboxr.rb +2 -2
- data/lib/pillboxr/attributes.rb +1 -1
- data/lib/pillboxr/config.rb +36 -0
- data/lib/pillboxr/constants.rb +1 -7
- data/lib/pillboxr/params.rb +3 -3
- data/lib/pillboxr/request.rb +5 -5
- data/lib/pillboxr/result.rb +6 -6
- data/lib/pillboxr/version.rb +1 -1
- data/pillboxr.gemspec +0 -1
- data/test/pillboxr/params_test.rb +2 -2
- data/test/pillboxr/pillboxr_test.rb +14 -0
- metadata +8 -6
- data/.rvmrc +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfea71f63f4e797781867df304d09cf34eebaf84
|
4
|
+
data.tar.gz: 63f2c31b307acec4c62b585557853ae55a46f266
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a69d0095894eaa8d5c748338c6282891b5e91a81bf7c7344c959b7f979c49582c6aae100d3f9336bfa47585204db249e6eb766176105ae43c33094069e49c96b
|
7
|
+
data.tar.gz: b7a786475a570292a02b87647953ee86952d218880f36095c0cafe7144965464bab3c32ab9e968e5376b4e9dc0d69234645744ed0ac9886d7a0ad0376c99f2fb
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pillboxr
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.2
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Pillboxr
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/pillboxr)
|
4
|
+
|
3
5
|
Pillboxr is a Ruby wrapper for the National Library of Medicine Pillbox API Service located at [http://pillbox.nlm.nih.gov](http://pillbox.nlm.nih.gov).
|
4
6
|
|
5
7
|
The pillbox API provides information from the FDA about various prescription medications.
|
data/lib/pillboxr.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
+
require_relative 'pillboxr/config'
|
3
4
|
require_relative 'pillboxr/extensions'
|
4
5
|
require_relative 'pillboxr/result'
|
5
6
|
require_relative 'pillboxr/pill'
|
@@ -7,7 +8,6 @@ require_relative 'pillboxr/params'
|
|
7
8
|
require_relative 'pillboxr/request'
|
8
9
|
|
9
10
|
module Pillboxr
|
10
|
-
|
11
11
|
# Assign an api_key to this session. Delegates to Request#api_key=
|
12
12
|
# @param [String, Pathname, File, Object] the key itself, or a way to load the key, or an object that responds to the 'key' method.
|
13
13
|
def api_key=(arg)
|
@@ -67,4 +67,4 @@ module Pillboxr
|
|
67
67
|
klass.extend(Pillboxr::Extensions) unless klass.methods.include?(:to_constant)
|
68
68
|
klass.to_constant.new(value)
|
69
69
|
end
|
70
|
-
end
|
70
|
+
end
|
data/lib/pillboxr/attributes.rb
CHANGED
@@ -253,7 +253,7 @@ module Pillboxr
|
|
253
253
|
class Lowerlimit
|
254
254
|
attr_accessor :lower_limit
|
255
255
|
|
256
|
-
def initialize(limit =
|
256
|
+
def initialize(limit = Pillboxr.config.default_lower_limit)
|
257
257
|
@lower_limit = case limit
|
258
258
|
when NilClass; raise LowerLimitError
|
259
259
|
when Integer; limit
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module Pillboxr
|
5
|
+
class Config
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
attr_accessor :records_per_page,
|
9
|
+
:default_lower_limit,
|
10
|
+
:no_records_error_message,
|
11
|
+
:no_records_response,
|
12
|
+
:api_key_error_message
|
13
|
+
|
14
|
+
attr_reader :base_uri
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
@records_per_page = 201
|
18
|
+
@default_lower_limit = 1
|
19
|
+
@base_uri = 'pillbox.nlm.nih.gov'
|
20
|
+
@no_records_error_message = "The document \"No records found\" does not have a valid root"
|
21
|
+
@no_records_response = "No records found"
|
22
|
+
@api_key_error_message = "The document \"Key does not match, you may not access this service\" does not have a valid root"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
# Global config object
|
26
|
+
def config
|
27
|
+
Config.instance
|
28
|
+
end
|
29
|
+
|
30
|
+
def config=(hash)
|
31
|
+
Config.send(:new, hash)
|
32
|
+
end
|
33
|
+
|
34
|
+
module_function :config
|
35
|
+
end
|
36
|
+
|
data/lib/pillboxr/constants.rb
CHANGED
@@ -1,11 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
module Pillboxr
|
3
|
-
RECORDS_PER_PAGE = 201
|
4
|
-
DEFAULT_LOWER_LIMIT = 1
|
5
|
-
BASE_URI = 'pillbox.nlm.nih.gov'
|
6
|
-
NO_RECORDS_ERROR_MESSAGE = "The document \"No records found\" does not have a valid root"
|
7
|
-
API_KEY_ERROR_MESSAGE = "The document \"Key does not match, you may not access this service\" does not have a valid root"
|
8
|
-
|
9
3
|
module Attributes
|
10
4
|
SHAPES = {
|
11
5
|
:bullet=> :C48335,
|
@@ -58,4 +52,4 @@ module Pillboxr
|
|
58
52
|
|
59
53
|
SCHEDULE_CODES = DEA_CODES.invert
|
60
54
|
end
|
61
|
-
end
|
55
|
+
end
|
data/lib/pillboxr/params.rb
CHANGED
@@ -15,7 +15,7 @@ module Pillboxr
|
|
15
15
|
# @param [Hash] options for which page to fetch
|
16
16
|
def get(options = {}, &block)
|
17
17
|
if options[:page]
|
18
|
-
self << Pillboxr::Attributes::Lowerlimit.new(options.fetch(:page) *
|
18
|
+
self << Pillboxr::Attributes::Lowerlimit.new(options.fetch(:page) * Pillboxr.config.records_per_page)
|
19
19
|
end
|
20
20
|
@module_name.send(:complete, self, &block)
|
21
21
|
end
|
@@ -25,7 +25,7 @@ module Pillboxr
|
|
25
25
|
limit = self.select { |param| param.respond_to?(:lower_limit) }.first.lower_limit
|
26
26
|
return limit
|
27
27
|
else
|
28
|
-
return
|
28
|
+
return Pillboxr.config.default_lower_limit
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -38,4 +38,4 @@ module Pillboxr
|
|
38
38
|
@module_name.send(:method_missing, method_name, *args)
|
39
39
|
end
|
40
40
|
end
|
41
|
-
end
|
41
|
+
end
|
data/lib/pillboxr/request.rb
CHANGED
@@ -6,18 +6,18 @@ module Pillboxr
|
|
6
6
|
class Request
|
7
7
|
include HTTParty
|
8
8
|
format :xml
|
9
|
-
base_uri
|
9
|
+
base_uri Pillboxr.config.base_uri
|
10
10
|
parser(Class.new(HTTParty::Parser) do
|
11
11
|
def parse
|
12
12
|
begin
|
13
13
|
body.gsub!(/^<disclaimer>.+<\/disclaimer>/, "")
|
14
|
-
body.gsub!(
|
14
|
+
body.gsub!(/\&/, '&')
|
15
15
|
super
|
16
16
|
rescue MultiXml::ParseError => e
|
17
|
-
if e.message ==
|
17
|
+
if e.message == Pillboxr.config.no_records_error_message or body == Pillboxr.config.no_records_response
|
18
18
|
result = {'Pills' => {'pill' => [], 'record_count' => 0 }}
|
19
19
|
return result
|
20
|
-
elsif e.message ==
|
20
|
+
elsif e.message == Pillboxr.config.api_key_error_message
|
21
21
|
raise "Invalid api_key. Check format and try again."
|
22
22
|
else
|
23
23
|
raise
|
@@ -83,4 +83,4 @@ module Pillboxr
|
|
83
83
|
"/PHP/pillboxAPIService.php?key=#{self.class.api_key}"
|
84
84
|
end
|
85
85
|
end
|
86
|
-
end
|
86
|
+
end
|
data/lib/pillboxr/result.rb
CHANGED
@@ -7,7 +7,7 @@ module Pillboxr
|
|
7
7
|
attr_accessor :record_count, :pages
|
8
8
|
|
9
9
|
def initialize(api_response, &block)
|
10
|
-
initial_page_number = Integer(api_response.query.params.limit /
|
10
|
+
initial_page_number = Integer(api_response.query.params.limit / Pillboxr.config.records_per_page )
|
11
11
|
@record_count = Integer(api_response.body['Pills']['record_count'])
|
12
12
|
|
13
13
|
puts "#{@record_count} records available. #{api_response.body['Pills']['pill'].size} records retrieved."
|
@@ -23,7 +23,7 @@ module Pillboxr
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.subsequent(api_response)
|
26
|
-
return parse_pills(api_response,
|
26
|
+
return parse_pills(api_response, Pillboxr.config.records_per_page)
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.parse_pills(api_response, record_count)
|
@@ -62,19 +62,19 @@ module Pillboxr
|
|
62
62
|
|
63
63
|
def initialize_pages_array(api_response, initial_page_number)
|
64
64
|
unless record_count == 0
|
65
|
-
record_count.divmod(
|
65
|
+
record_count.divmod(Pillboxr.config.records_per_page).tap do |ary|
|
66
66
|
if ary[1] == 0
|
67
67
|
return Pages.new(ary[0]) do |i|
|
68
68
|
page_params = api_response.query.params.dup
|
69
69
|
page_params.delete_if { |param| param.respond_to?(:lower_limit)}
|
70
|
-
page_params << Attributes::Lowerlimit.new(i *
|
70
|
+
page_params << Attributes::Lowerlimit.new(i * Pillboxr.config.records_per_page)
|
71
71
|
Page.new(i == initial_page_number, i == initial_page_number, i, [], page_params)
|
72
72
|
end
|
73
73
|
else
|
74
74
|
return Pages.new(ary[0] + 1) do |i|
|
75
75
|
page_params = api_response.query.params.dup
|
76
76
|
page_params.delete_if { |param| param.respond_to?(:lower_limit)}
|
77
|
-
page_params << Attributes::Lowerlimit.new(i *
|
77
|
+
page_params << Attributes::Lowerlimit.new(i * Pillboxr.config.records_per_page)
|
78
78
|
Page.new(i == initial_page_number, i == initial_page_number, i, [], page_params)
|
79
79
|
end
|
80
80
|
end
|
@@ -83,4 +83,4 @@ module Pillboxr
|
|
83
83
|
return Pages.new(1) { |i| Page.new(true, true, i, [], api_response.query.params.dup)}
|
84
84
|
end
|
85
85
|
end
|
86
|
-
end
|
86
|
+
end
|
data/lib/pillboxr/version.rb
CHANGED
data/pillboxr.gemspec
CHANGED
@@ -18,7 +18,6 @@ The pillbox API provides information from the FDA about various prescription med
|
|
18
18
|
*Note:* This library is designed for use with Ruby 1.9.3 and above, and will not work with earlier versions of Ruby.
|
19
19
|
END
|
20
20
|
|
21
|
-
s.required_rubygems_version = "~> 1.8.6"
|
22
21
|
s.rubyforge_project = "pillboxr"
|
23
22
|
|
24
23
|
s.add_dependency 'httparty', '~> 0.8.3'
|
@@ -18,7 +18,7 @@ class TestParams < MiniTest::Unit::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_limit_method
|
21
|
-
assert_equal(Pillboxr
|
21
|
+
assert_equal(Pillboxr.config.default_lower_limit, @params.limit)
|
22
22
|
@params << Pillboxr::Attributes::Lowerlimit.new(300)
|
23
23
|
assert_equal(300, @params.limit)
|
24
24
|
end
|
@@ -45,4 +45,4 @@ class TestParams < MiniTest::Unit::TestCase
|
|
45
45
|
refute_empty r
|
46
46
|
assert_instance_of(Pillboxr::Attributes::Color, r.first)
|
47
47
|
end
|
48
|
-
end
|
48
|
+
end
|
@@ -195,4 +195,18 @@ class TestPillboxr < MiniTest::Unit::TestCase
|
|
195
195
|
assert_equal(3, @result.pages.current.number)
|
196
196
|
end
|
197
197
|
end
|
198
|
+
|
199
|
+
def test_empty_record_set_response_caught
|
200
|
+
VCR.use_cassette(:empty_record_set) do
|
201
|
+
no_records_response = Pillboxr.config.no_records_response
|
202
|
+
Pillboxr.config.no_records_response = "foo"
|
203
|
+
no_records_error_message = Pillboxr.config.no_records_error_message
|
204
|
+
Pillboxr.config.no_records_error_message = "bar"
|
205
|
+
assert_raises(MultiXml::ParseError) do
|
206
|
+
@result = Pillboxr.with(:color => [:blue,:green], :size => 100)
|
207
|
+
end
|
208
|
+
Pillboxr.config.no_records_error_message = no_records_error_message
|
209
|
+
Pillboxr.config.no_records_response = no_records_response
|
210
|
+
end
|
211
|
+
end
|
198
212
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pillboxr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Gautreaux
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-
|
14
|
+
date: 2014-10-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: httparty
|
@@ -109,13 +109,15 @@ executables: []
|
|
109
109
|
extensions: []
|
110
110
|
extra_rdoc_files: []
|
111
111
|
files:
|
112
|
-
- ".
|
112
|
+
- ".ruby-gemset"
|
113
|
+
- ".ruby-version"
|
113
114
|
- Gemfile
|
114
115
|
- Gemfile.lock
|
115
116
|
- README.md
|
116
117
|
- Rakefile
|
117
118
|
- lib/pillboxr.rb
|
118
119
|
- lib/pillboxr/attributes.rb
|
120
|
+
- lib/pillboxr/config.rb
|
119
121
|
- lib/pillboxr/constants.rb
|
120
122
|
- lib/pillboxr/extensions.rb
|
121
123
|
- lib/pillboxr/pages.rb
|
@@ -147,12 +149,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
149
|
version: '0'
|
148
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
151
|
requirements:
|
150
|
-
- - "
|
152
|
+
- - ">="
|
151
153
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
154
|
+
version: '0'
|
153
155
|
requirements: []
|
154
156
|
rubyforge_project: pillboxr
|
155
|
-
rubygems_version: 2.
|
157
|
+
rubygems_version: 2.4.1
|
156
158
|
signing_key:
|
157
159
|
specification_version: 4
|
158
160
|
summary: Access the NLM Pillbox API using Ruby.
|
data/.rvmrc
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
-
# development environment upon cd'ing into the directory
|
5
|
-
|
6
|
-
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
-
# Only full ruby name is supported here, for short names use:
|
8
|
-
# echo "rvm use 2.0.0" > .rvmrc
|
9
|
-
environment_id="ruby-2.0.0-p0@pillboxr"
|
10
|
-
|
11
|
-
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
-
# rvmrc_rvm_version="1.18.18 (latest)" # 1.10.1 seams as a safe start
|
13
|
-
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
-
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
-
# return 1
|
16
|
-
# }
|
17
|
-
|
18
|
-
# First we attempt to load the desired environment directly from the environment
|
19
|
-
# file. This is very fast and efficient compared to running through the entire
|
20
|
-
# CLI and selector. If you want feedback on which environment was used then
|
21
|
-
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
-
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
-
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
-
then
|
25
|
-
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
-
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
-
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
-
if [[ $- == *i* ]] # check for interactive shells
|
29
|
-
then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
|
30
|
-
else echo "Using: $GEM_HOME" # don't use colors in non-interactive shells
|
31
|
-
fi
|
32
|
-
else
|
33
|
-
# If the environment file has not yet been created, use the RVM CLI to select.
|
34
|
-
rvm --create use "$environment_id" || {
|
35
|
-
echo "Failed to create RVM environment '${environment_id}'."
|
36
|
-
return 1
|
37
|
-
}
|
38
|
-
fi
|
39
|
-
|
40
|
-
# If you use bundler, this might be useful to you:
|
41
|
-
# if [[ -s Gemfile ]] && {
|
42
|
-
# ! builtin command -v bundle >/dev/null ||
|
43
|
-
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
44
|
-
# }
|
45
|
-
# then
|
46
|
-
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
47
|
-
# gem install bundler
|
48
|
-
# fi
|
49
|
-
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
50
|
-
# then
|
51
|
-
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
52
|
-
# fi
|