pillboxr 0.8.0 → 0.8.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.
- data/README.md +10 -1
- data/lib/pillboxr.rb +4 -2
- data/lib/pillboxr/request.rb +29 -8
- data/lib/pillboxr/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -16,7 +16,16 @@ Getting started is fairly easy:
|
|
16
16
|
|
17
17
|
$ gem install pillboxr
|
18
18
|
|
19
|
-
Next obtain an API key
|
19
|
+
Next obtain an API key. See below for directions on obtaining an API key. There are several ways to tell Pillboxr about your API key. All of the following are valid:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
Pillboxr.api_key = "Your API key as a string." # simple string
|
23
|
+
Pillboxr.api_key = Pathname.new("/path/to/yaml/or/text/file/containing/only/api/key/as/string") # absolute or relative path
|
24
|
+
Pillboxr.api_key = File.new("/path/to/yaml/or/text/file/containing/only/api/key/as/string", "r") # file descriptor object
|
25
|
+
Pillboxr.api_key = Object.new.tap { |obj| obj.define_singleton_method(:key) { "Your API key string" } } # object that responds to 'key' method
|
26
|
+
```
|
27
|
+
|
28
|
+
If you do not specify a key Pillboxr will try to find an api_key.yml in the current working directory and load the key from that file.
|
20
29
|
|
21
30
|
Finally:
|
22
31
|
|
data/lib/pillboxr.rb
CHANGED
@@ -8,8 +8,10 @@ require_relative 'pillboxr/request'
|
|
8
8
|
|
9
9
|
module Pillboxr
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
# Assign an api_key to this session. Delegates to Request#api_key=
|
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
|
+
def api_key=(arg)
|
14
|
+
Request.api_key = arg
|
13
15
|
end
|
14
16
|
|
15
17
|
# Search API for pages of pills. Also accepts a block that yields pages for iterating through.
|
data/lib/pillboxr/request.rb
CHANGED
@@ -43,18 +43,39 @@ module Pillboxr
|
|
43
43
|
|
44
44
|
# Assign an API key to this session.
|
45
45
|
# @param [String] your API key in string format.
|
46
|
-
def self.api_key=(
|
47
|
-
@api_key =
|
46
|
+
def self.api_key=(arg)
|
47
|
+
@api_key = arg
|
48
48
|
end
|
49
49
|
|
50
50
|
private
|
51
51
|
def self.api_key
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
case @api_key
|
53
|
+
when String
|
54
|
+
return @api_key
|
55
|
+
when Pathname
|
56
|
+
if @api_key.absolute?
|
57
|
+
return YAML.load_file(@api_key)
|
58
|
+
else
|
59
|
+
return YAML.load_file(@api_key.realpath)
|
60
|
+
end
|
61
|
+
when File
|
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
|
+
when nil
|
70
|
+
begin
|
71
|
+
return YAML.load_file(File.expand_path("api_key.yml"))
|
72
|
+
rescue Errno::ENOENT => e
|
73
|
+
raise e, "API key not found. Please create an api_key.yml file in the current working directory of the project or pass the key as an argument."
|
74
|
+
rescue TypeError => e
|
75
|
+
raise e, "The api_key.yml in this directory does not contain an appropriate key."
|
76
|
+
end
|
77
|
+
else
|
78
|
+
raise ArgumentError, "api_key must be one of 'String', 'Pathname', 'File', or an object that responds to the 'key' method."
|
58
79
|
end
|
59
80
|
end
|
60
81
|
|
data/lib/pillboxr/version.rb
CHANGED
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.8.
|
4
|
+
version: 0.8.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-09-
|
14
|
+
date: 2012-09-12 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: httparty
|