pillboxr 0.7.5 → 0.7.6

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.
@@ -8,13 +8,19 @@ require_relative 'pillboxr/request'
8
8
 
9
9
  module Pillboxr
10
10
 
11
+ def api_key=(str)
12
+ Request.api_key = str
13
+ end
14
+
11
15
  # Search API for pages of pills. Also accepts a block that yields pages for iterating through.
12
16
  # @param [Hash] search parameters, see {Pillboxr::Attributes} for accepted parameters.
13
17
  # @return [Result] a {Pillboxr::Result} object that has pages of data that can be iterated through.
14
- def with(query_hash, &block)
18
+ def with(options, &block)
15
19
  @params ||= Params.new(self)
16
20
 
17
- query_hash.each do |k,v|
21
+ self.api_key = options.delete(:api_key)
22
+
23
+ options.each do |k,v|
18
24
  if attributes.keys.include?(k)
19
25
  @params << symbol_to_instance(k,v)
20
26
  elsif api_attributes.keys.include?(k)
@@ -18,7 +18,7 @@ module Pillboxr
18
18
  result = {'Pills' => {'pill' => [], 'record_count' => 0 }}
19
19
  return result
20
20
  elsif e.message == API_KEY_ERROR_MESSAGE
21
- raise "Invalid api_key.yml. Check format and try again."
21
+ raise "Invalid api_key. Check format and try again."
22
22
  else
23
23
  raise
24
24
  end
@@ -41,8 +41,14 @@ module Pillboxr
41
41
  return self.api_response
42
42
  end
43
43
 
44
+ # Assign an API key to this session.
45
+ # @param [String] your API key in string format.
46
+ def self.api_key=(str)
47
+ @api_key = str
48
+ end
49
+
44
50
  private
45
- def api_key
51
+ def self.api_key
46
52
  begin
47
53
  @api_key ||= YAML.load_file(File.expand_path("api_key.yml"))
48
54
  rescue Errno::ENOENT => e
@@ -53,7 +59,7 @@ module Pillboxr
53
59
  end
54
60
 
55
61
  def default_path
56
- "/PHP/pillboxAPIService.php?key=#{api_key}"
62
+ "/PHP/pillboxAPIService.php?key=#{self.class.api_key}"
57
63
  end
58
64
  end
59
65
  end
@@ -1,4 +1,4 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  module Pillboxr
3
- VERSION = "0.7.5"
3
+ VERSION = "0.7.6"
4
4
  end
@@ -2,7 +2,6 @@
2
2
  require_relative 'test_helper'
3
3
  require 'vcr'
4
4
 
5
-
6
5
  VCR.configure do |c|
7
6
  c.cassette_library_dir = 'test/pillboxr/fixtures/vcr_cassettes'
8
7
  c.hook_into :webmock
@@ -21,15 +20,19 @@ class TestPillboxr < MiniTest::Unit::TestCase
21
20
  end
22
21
 
23
22
  def test_api_key
24
- assert_raises(NoMethodError) { Pillboxr::Request.api_key }
23
+ assert_raises(NoMethodError) { Pillboxr.api_key }
25
24
  assert_raises(NoMethodError) do
26
25
  @request_object.api_key
27
26
  end
27
+ Pillboxr.api_key = "foo"
28
+ assert_equal("foo", Pillboxr::Request.send(:api_key))
29
+ assert_raises(RuntimeError) { Pillboxr.with({:api_key => 'bar', :color => :blue}) }
30
+ assert_equal("bar", Pillboxr::Request.send(:api_key))
28
31
  end
29
32
 
30
33
  def test_returns_the_correct_default_path
31
34
  assert_raises(NoMethodError) { @request_object.default_path }
32
- assert_equal("/PHP/pillboxAPIService.php?key=#{@request_object.send(:api_key)}", @request_object.send(:default_path))
35
+ assert_equal("/PHP/pillboxAPIService.php?key=#{@request_object.class.send(:api_key)}", @request_object.send(:default_path))
33
36
  end
34
37
 
35
38
  def test_returns_number_of_records
@@ -0,0 +1,9 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require_relative 'test_helper'
3
+
4
+ class TestRequest < MiniTest::Unit::TestCase
5
+ def test_setting_api_key
6
+ Pillboxr.api_key = "foo"
7
+ assert_equal("foo", Pillboxr::Request.send(:api_key))
8
+ end
9
+ 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.7.5
4
+ version: 0.7.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -146,6 +146,7 @@ files:
146
146
  - test/pillboxr/params_test.rb
147
147
  - test/pillboxr/pill_test.rb
148
148
  - test/pillboxr/pillboxr_test.rb
149
+ - test/pillboxr/request_test.rb
149
150
  - test/pillboxr/response_test.rb
150
151
  - test/pillboxr/test_helper.rb
151
152
  homepage: http://rubygems.org/gems/pillboxr