pillboxr 0.8.1 → 0.8.2
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.
- data/lib/pillboxr/request.rb +6 -6
- data/lib/pillboxr/result.rb +6 -0
- data/lib/pillboxr/version.rb +1 -1
- data/test/pillboxr/pillboxr_test.rb +4 -0
- data/test/pillboxr/request_test.rb +34 -1
- metadata +1 -1
data/lib/pillboxr/request.rb
CHANGED
@@ -60,12 +60,6 @@ module Pillboxr
|
|
60
60
|
end
|
61
61
|
when File
|
62
62
|
return YAML.load_file(@api_key)
|
63
|
-
when Object
|
64
|
-
begin
|
65
|
-
return @api_key.key
|
66
|
-
rescue NoMethodError => e
|
67
|
-
raise e, "The object passed as an argument to api_key= must respond to the 'key' method."
|
68
|
-
end
|
69
63
|
when nil
|
70
64
|
begin
|
71
65
|
return YAML.load_file(File.expand_path("api_key.yml"))
|
@@ -74,6 +68,12 @@ module Pillboxr
|
|
74
68
|
rescue TypeError => e
|
75
69
|
raise e, "The api_key.yml in this directory does not contain an appropriate key."
|
76
70
|
end
|
71
|
+
when Object
|
72
|
+
begin
|
73
|
+
return @api_key.key
|
74
|
+
rescue NoMethodError => e
|
75
|
+
raise e, "The object passed as an argument to api_key= must respond to the 'key' method."
|
76
|
+
end
|
77
77
|
else
|
78
78
|
raise ArgumentError, "api_key must be one of 'String', 'Pathname', 'File', or an object that responds to the 'key' method."
|
79
79
|
end
|
data/lib/pillboxr/result.rb
CHANGED
@@ -52,6 +52,12 @@ module Pillboxr
|
|
52
52
|
|
53
53
|
alias_method :to_s, :inspect
|
54
54
|
|
55
|
+
# Shortcut method for listing all the pills on the current page of results
|
56
|
+
# @return [Array] An array of pill objects
|
57
|
+
def pills
|
58
|
+
self.pages.current.pills
|
59
|
+
end
|
60
|
+
|
55
61
|
private
|
56
62
|
|
57
63
|
def initialize_pages_array(api_response, initial_page_number)
|
data/lib/pillboxr/version.rb
CHANGED
@@ -19,6 +19,10 @@ class TestPillboxr < MiniTest::Unit::TestCase
|
|
19
19
|
@request_object = Pillboxr::Request.new(Pillboxr::Params.new([Pillboxr::Attributes::Shape.new(:round)]))
|
20
20
|
end
|
21
21
|
|
22
|
+
def teardown
|
23
|
+
Pillboxr.api_key = nil
|
24
|
+
end
|
25
|
+
|
22
26
|
def test_api_key
|
23
27
|
assert_raises(NoMethodError) { Pillboxr.api_key }
|
24
28
|
assert_raises(NoMethodError) do
|
@@ -2,8 +2,41 @@
|
|
2
2
|
require_relative 'test_helper'
|
3
3
|
|
4
4
|
class TestRequest < MiniTest::Unit::TestCase
|
5
|
-
def
|
5
|
+
def teardown
|
6
|
+
Pillboxr.api_key = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_passing_string_to_api_key
|
6
10
|
Pillboxr.api_key = "foo"
|
7
11
|
assert_equal("foo", Pillboxr::Request.send(:api_key))
|
8
12
|
end
|
13
|
+
|
14
|
+
def test_passing_pathname_to_api_key
|
15
|
+
Pillboxr.api_key = Pathname.new("./test/pillboxr/fixtures/api_key.yml")
|
16
|
+
assert_equal("foo", Pillboxr::Request.send(:api_key), "You probably need to create an api_key.yml file in the fixtures directory.")
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_passing_file_to_api_key
|
20
|
+
Pillboxr.api_key = File.open("./test/pillboxr/fixtures/api_key.yml", "r")
|
21
|
+
assert_equal("foo", Pillboxr::Request.send(:api_key), "You probably need to create an api_key.yml file in the fixtures directory.")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_passing_object_to_api_key
|
25
|
+
Pillboxr.api_key = Object.new.tap { |obj| obj.define_singleton_method(:key) { "foo" } }
|
26
|
+
assert_equal("foo", Pillboxr::Request.send(:api_key))
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_passing_no_argument_to_api_key
|
30
|
+
assert_equal(YAML.load_file("api_key.yml"), Pillboxr::Request.send(:api_key))
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_invalid_object
|
34
|
+
Pillboxr.api_key = Object.new
|
35
|
+
assert_raises(NoMethodError) { Pillboxr::Request.send(:api_key) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_passing_hash_to_api_key
|
39
|
+
Pillboxr.api_key = {}
|
40
|
+
assert_raises(ArgumentError) { Pillboxr::Request.send(:api_key) }
|
41
|
+
end
|
9
42
|
end
|