pillboxr 0.7.6 → 0.8.0
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 +12 -3
 - data/lib/pillboxr.rb +5 -1
 - data/lib/pillboxr/params.rb +6 -1
 - data/lib/pillboxr/request.rb +3 -3
 - data/lib/pillboxr/version.rb +1 -1
 - data/test/pillboxr/params_test.rb +2 -2
 - data/test/pillboxr/pill_test.rb +2 -2
 - data/test/pillboxr/pillboxr_test.rb +18 -11
 - metadata +2 -2
 
    
        data/README.md
    CHANGED
    
    | 
         @@ -33,14 +33,14 @@ result.pages.current.pills # An array with the retrieved pill objects. 
     | 
|
| 
       33 
33 
     | 
    
         
             
            ```ruby
         
     | 
| 
       34 
34 
     | 
    
         
             
            require 'pillboxr'
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
            result = Pillboxr.color(:blue).image(true). 
     | 
| 
      
 36 
     | 
    
         
            +
            result = Pillboxr.color(:blue).image(true).get # Get result of object with one page of blue pills with images associated.
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
            result.pages.current.pills # an array with the retrieved pill objects.
         
     | 
| 
       39 
39 
     | 
    
         
             
            ```
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
            ***
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
            **Important:** *When chaining query methods you must add the ` 
     | 
| 
      
 43 
     | 
    
         
            +
            **Important:** *When chaining query methods you must add the `get` method on the end of the query chain, similar to working with `ActiveRelation` in Rails (where the `all` method indicates completion of the query), so the request can be lazily evaluated.*
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
       45 
45 
     | 
    
         
             
            ***
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
         @@ -66,7 +66,7 @@ all_blue_pills.flatten! # all_blue_pills is now an array of all 2059 blue pills. 
     | 
|
| 
       66 
66 
     | 
    
         
             
            ```ruby
         
     | 
| 
       67 
67 
     | 
    
         
             
            require 'pillboxr'
         
     | 
| 
       68 
68 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
            result = Pillboxr.color(:blue). 
     | 
| 
      
 69 
     | 
    
         
            +
            result = Pillboxr.color(:blue).get do |r|
         
     | 
| 
       70 
70 
     | 
    
         
             
              r.pages.each do |page|
         
     | 
| 
       71 
71 
     | 
    
         
             
                page.get # won't retrieve a page that is already retrieved.
         
     | 
| 
       72 
72 
     | 
    
         
             
              end
         
     | 
| 
         @@ -77,6 +77,15 @@ result.pages.each { |page| all_blue_pills << page.pills } 
     | 
|
| 
       77 
77 
     | 
    
         | 
| 
       78 
78 
     | 
    
         
             
            all_blue_pills.flatten! # all_blue_pills is now an array of all 2059 blue pills.
         
     | 
| 
       79 
79 
     | 
    
         
             
            ```
         
     | 
| 
      
 80 
     | 
    
         
            +
            You can also pass an additional options hash to the `get` method to explicitly specify the page of results you want.
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 83 
     | 
    
         
            +
            require 'pillboxr'
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
            result = Pillboxr.color(:blue).get(page: 3) # pages are zero indexed.
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
            result.pages.current.pills # an array of the fourth page of blue pill results.
         
     | 
| 
      
 88 
     | 
    
         
            +
            ```
         
     | 
| 
       80 
89 
     | 
    
         | 
| 
       81 
90 
     | 
    
         
             
            You can run the tests by typing `rake` in the library directory.  You may have to install some development gems prior to running the tests by running `bundle install` in the library directory.
         
     | 
| 
       82 
91 
     | 
    
         | 
    
        data/lib/pillboxr.rb
    CHANGED
    
    | 
         @@ -51,7 +51,11 @@ module Pillboxr 
     | 
|
| 
       51 
51 
     | 
    
         
             
              end
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
       53 
53 
     | 
    
         
             
              def complete(params = @params, &block) # :nodoc:
         
     | 
| 
       54 
     | 
    
         
            -
                 
     | 
| 
      
 54 
     | 
    
         
            +
                begin
         
     | 
| 
      
 55 
     | 
    
         
            +
                  return Result.new(Request.new(params).perform, &block)
         
     | 
| 
      
 56 
     | 
    
         
            +
                ensure
         
     | 
| 
      
 57 
     | 
    
         
            +
                  @params = Params.new(self)
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
       55 
59 
     | 
    
         
             
              end
         
     | 
| 
       56 
60 
     | 
    
         | 
| 
       57 
61 
     | 
    
         
             
              private
         
     | 
    
        data/lib/pillboxr/params.rb
    CHANGED
    
    | 
         @@ -11,7 +11,12 @@ module Pillboxr 
     | 
|
| 
       11 
11 
     | 
    
         
             
                  self.collect(&:to_param).join
         
     | 
| 
       12 
12 
     | 
    
         
             
                end
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
                 
     | 
| 
      
 14 
     | 
    
         
            +
                # finalize the query and request the results
         
     | 
| 
      
 15 
     | 
    
         
            +
                # @param [Hash] options for which page to fetch
         
     | 
| 
      
 16 
     | 
    
         
            +
                def get(options = {}, &block)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  if options[:page]
         
     | 
| 
      
 18 
     | 
    
         
            +
                    self << Pillboxr::Attributes::Lowerlimit.new(options.fetch(:page) * RECORDS_PER_PAGE)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
       15 
20 
     | 
    
         
             
                  @module_name.send(:complete, self, &block)
         
     | 
| 
       16 
21 
     | 
    
         
             
                end
         
     | 
| 
       17 
22 
     | 
    
         | 
    
        data/lib/pillboxr/request.rb
    CHANGED
    
    | 
         @@ -28,15 +28,15 @@ module Pillboxr 
     | 
|
| 
       28 
28 
     | 
    
         | 
| 
       29 
29 
     | 
    
         
             
                attr_reader :full_path, :params, :api_response
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
                def initialize( 
     | 
| 
       32 
     | 
    
         
            -
                  @full_path =  
     | 
| 
      
 31 
     | 
    
         
            +
                def initialize(path = default_path, api_params)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  @full_path = path + api_params.concatenate
         
     | 
| 
       33 
33 
     | 
    
         
             
                  @params = api_params
         
     | 
| 
       34 
34 
     | 
    
         
             
                  @api_response = Pillboxr::Response.new
         
     | 
| 
       35 
35 
     | 
    
         
             
                  @api_response.query = self
         
     | 
| 
       36 
36 
     | 
    
         
             
                end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
                def perform
         
     | 
| 
       39 
     | 
    
         
            -
                  puts "path = #{ 
     | 
| 
      
 39 
     | 
    
         
            +
                  puts "path = #{full_path}"
         
     | 
| 
       40 
40 
     | 
    
         
             
                  @api_response.body = self.class.get(full_path)
         
     | 
| 
       41 
41 
     | 
    
         
             
                  return self.api_response
         
     | 
| 
       42 
42 
     | 
    
         
             
                end
         
     | 
    
        data/lib/pillboxr/version.rb
    CHANGED
    
    
| 
         @@ -23,12 +23,12 @@ class TestParams < MiniTest::Unit::TestCase 
     | 
|
| 
       23 
23 
     | 
    
         
             
                assert_equal(300, @params.limit)
         
     | 
| 
       24 
24 
     | 
    
         
             
              end
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
              def  
     | 
| 
      
 26 
     | 
    
         
            +
              def test_get_method
         
     | 
| 
       27 
27 
     | 
    
         
             
                pillboxr = MiniTest::Mock.new
         
     | 
| 
       28 
28 
     | 
    
         
             
                result = MiniTest::Mock.new
         
     | 
| 
       29 
29 
     | 
    
         
             
                p = Pillboxr::Params.new(pillboxr)
         
     | 
| 
       30 
30 
     | 
    
         
             
                pillboxr.expect(:send,  result, [:complete, @params])
         
     | 
| 
       31 
     | 
    
         
            -
                p. 
     | 
| 
      
 31 
     | 
    
         
            +
                p.get
         
     | 
| 
       32 
32 
     | 
    
         
             
                pillboxr.verify
         
     | 
| 
       33 
33 
     | 
    
         
             
              end
         
     | 
| 
       34 
34 
     | 
    
         | 
    
        data/test/pillboxr/pill_test.rb
    CHANGED
    
    | 
         @@ -3,8 +3,8 @@ require_relative 'test_helper' 
     | 
|
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            class TestPill < MiniTest::Unit::TestCase
         
     | 
| 
       5 
5 
     | 
    
         
             
              def setup
         
     | 
| 
       6 
     | 
    
         
            -
                @blue_pills = Pillboxr.color(:blue).image(true). 
     | 
| 
       7 
     | 
    
         
            -
                @scored_pills = Pillboxr.score(3). 
     | 
| 
      
 6 
     | 
    
         
            +
                @blue_pills = Pillboxr.color(:blue).image(true).get.pages.current.pills
         
     | 
| 
      
 7 
     | 
    
         
            +
                @scored_pills = Pillboxr.score(3).get.pages.current.pills
         
     | 
| 
       8 
8 
     | 
    
         
             
              end
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              def test_accessor_methods
         
     | 
| 
         @@ -96,13 +96,13 @@ class TestPillboxr < MiniTest::Unit::TestCase 
     | 
|
| 
       96 
96 
     | 
    
         | 
| 
       97 
97 
     | 
    
         
             
              def test_method_missing_with_shape
         
     | 
| 
       98 
98 
     | 
    
         
             
                VCR.use_cassette(:method_missing_shape) do
         
     | 
| 
       99 
     | 
    
         
            -
                  assert_equal(@num_round_shape_records, Pillboxr.shape(:round). 
     | 
| 
      
 99 
     | 
    
         
            +
                  assert_equal(@num_round_shape_records, Pillboxr.shape(:round).get.record_count)
         
     | 
| 
       100 
100 
     | 
    
         
             
                end
         
     | 
| 
       101 
101 
     | 
    
         
             
              end
         
     | 
| 
       102 
102 
     | 
    
         | 
| 
       103 
103 
     | 
    
         
             
              def test_method_missing_with_image
         
     | 
| 
       104 
104 
     | 
    
         
             
                VCR.use_cassette(:method_missing_has_image) do
         
     | 
| 
       105 
     | 
    
         
            -
                  @result = Pillboxr.image(true). 
     | 
| 
      
 105 
     | 
    
         
            +
                  @result = Pillboxr.image(true).get
         
     | 
| 
       106 
106 
     | 
    
         
             
                end
         
     | 
| 
       107 
107 
     | 
    
         | 
| 
       108 
108 
     | 
    
         
             
                @result.pages.first.pills.each do |pill|
         
     | 
| 
         @@ -113,32 +113,32 @@ class TestPillboxr < MiniTest::Unit::TestCase 
     | 
|
| 
       113 
113 
     | 
    
         | 
| 
       114 
114 
     | 
    
         
             
              def test_method_missing_with_color
         
     | 
| 
       115 
115 
     | 
    
         
             
                VCR.use_cassette(:method_missing_color) do
         
     | 
| 
       116 
     | 
    
         
            -
                  assert_equal(@num_blue_color_records, Pillboxr.color(:blue). 
     | 
| 
      
 116 
     | 
    
         
            +
                  assert_equal(@num_blue_color_records, Pillboxr.color(:blue).get.record_count)
         
     | 
| 
       117 
117 
     | 
    
         
             
                end
         
     | 
| 
       118 
118 
     | 
    
         
             
              end
         
     | 
| 
       119 
119 
     | 
    
         | 
| 
       120 
120 
     | 
    
         
             
              # def test_method_missing_with_imprint # Broken currently
         
     | 
| 
       121 
121 
     | 
    
         
             
              #   VCR.use_cassette(:method_missing_imprint) do
         
     | 
| 
       122 
     | 
    
         
            -
              #     assert_equal(@num_imprint_23_records, Pillboxr.imprint(23). 
     | 
| 
      
 122 
     | 
    
         
            +
              #     assert_equal(@num_imprint_23_records, Pillboxr.imprint(23).get.record_count)
         
     | 
| 
       123 
123 
     | 
    
         
             
              #   end
         
     | 
| 
       124 
124 
     | 
    
         
             
              # end
         
     | 
| 
       125 
125 
     | 
    
         | 
| 
       126 
126 
     | 
    
         
             
              def test_method_missing_with_size
         
     | 
| 
       127 
     | 
    
         
            -
                VCR.use_cassette(:method_missing_size, :allow_playback_repeats => true) do
         
     | 
| 
       128 
     | 
    
         
            -
                  assert_equal(@num_5_mm_records, Pillboxr.size(5). 
     | 
| 
       129 
     | 
    
         
            -
                  assert_equal(@num_5_mm_records, Pillboxr.size("5"). 
     | 
| 
      
 127 
     | 
    
         
            +
                VCR.use_cassette(:method_missing_size, :match_requests_on => [:body], :allow_playback_repeats => true) do
         
     | 
| 
      
 128 
     | 
    
         
            +
                  assert_equal(@num_5_mm_records, Pillboxr.size(5).get.record_count)
         
     | 
| 
      
 129 
     | 
    
         
            +
                  assert_equal(@num_5_mm_records, Pillboxr.size("5").get.record_count)
         
     | 
| 
       130 
130 
     | 
    
         
             
                end
         
     | 
| 
       131 
131 
     | 
    
         
             
              end
         
     | 
| 
       132 
132 
     | 
    
         | 
| 
       133 
133 
     | 
    
         
             
              def test_method_missing_with_author
         
     | 
| 
       134 
134 
     | 
    
         
             
                VCR.use_cassette(:method_missing_author) do
         
     | 
| 
       135 
     | 
    
         
            -
                  assert_equal(@num_mylan_records, Pillboxr.author("Mylan Pharmaceuticals Inc."). 
     | 
| 
      
 135 
     | 
    
         
            +
                  assert_equal(@num_mylan_records, Pillboxr.author("Mylan Pharmaceuticals Inc.").get.record_count)
         
     | 
| 
       136 
136 
     | 
    
         
             
                end
         
     | 
| 
       137 
137 
     | 
    
         
             
              end
         
     | 
| 
       138 
138 
     | 
    
         | 
| 
       139 
139 
     | 
    
         
             
              def test_method_missing_with_lower_limit
         
     | 
| 
       140 
140 
     | 
    
         
             
                VCR.use_cassette(:method_missing_with_lower_limit, :allow_playback_repeats => true) do
         
     | 
| 
       141 
     | 
    
         
            -
                  assert_equal(201, Pillboxr.shape(:round).lower_limit(202). 
     | 
| 
      
 141 
     | 
    
         
            +
                  assert_equal(201, Pillboxr.shape(:round).lower_limit(202).get.pages.current.pills.size)
         
     | 
| 
       142 
142 
     | 
    
         
             
                end
         
     | 
| 
       143 
143 
     | 
    
         
             
              end
         
     | 
| 
       144 
144 
     | 
    
         | 
| 
         @@ -153,13 +153,13 @@ class TestPillboxr < MiniTest::Unit::TestCase 
     | 
|
| 
       153 
153 
     | 
    
         | 
| 
       154 
154 
     | 
    
         
             
              def test_method_chaining
         
     | 
| 
       155 
155 
     | 
    
         
             
                VCR.use_cassette(:method_chaining) do
         
     | 
| 
       156 
     | 
    
         
            -
                  assert_equal(@num_blue_records_with_image, Pillboxr.color(:blue).image(true). 
     | 
| 
      
 156 
     | 
    
         
            +
                  assert_equal(@num_blue_records_with_image, Pillboxr.color(:blue).image(true).get.record_count)
         
     | 
| 
       157 
157 
     | 
    
         
             
                end
         
     | 
| 
       158 
158 
     | 
    
         
             
              end
         
     | 
| 
       159 
159 
     | 
    
         | 
| 
       160 
160 
     | 
    
         
             
              def test_method_missing_with_a_block
         
     | 
| 
       161 
161 
     | 
    
         
             
                VCR.use_cassette(:method_missing_with_a_block) do
         
     | 
| 
       162 
     | 
    
         
            -
                  @result = Pillboxr.image(true). 
     | 
| 
      
 162 
     | 
    
         
            +
                  @result = Pillboxr.image(true).get do |r|
         
     | 
| 
       163 
163 
     | 
    
         
             
                    r.pages.each do |page|
         
     | 
| 
       164 
164 
     | 
    
         
             
                      page.get unless page.retrieved?
         
     | 
| 
       165 
165 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -168,4 +168,11 @@ class TestPillboxr < MiniTest::Unit::TestCase 
     | 
|
| 
       168 
168 
     | 
    
         
             
                @result.pages.each { |page| assert page.retrieved? }
         
     | 
| 
       169 
169 
     | 
    
         
             
                assert_equal(@num_image_records, @result.pages.inject(0) { |sum, page| sum + page.pills.size })
         
     | 
| 
       170 
170 
     | 
    
         
             
              end
         
     | 
| 
      
 171 
     | 
    
         
            +
             
     | 
| 
      
 172 
     | 
    
         
            +
              def test_get_method_with_options
         
     | 
| 
      
 173 
     | 
    
         
            +
                VCR.use_cassette(:get_method_with_options) do
         
     | 
| 
      
 174 
     | 
    
         
            +
                  @result = Pillboxr.image(true).get(page: 3)
         
     | 
| 
      
 175 
     | 
    
         
            +
                  assert_equal(3, @result.pages.current.number)
         
     | 
| 
      
 176 
     | 
    
         
            +
                end
         
     | 
| 
      
 177 
     | 
    
         
            +
              end
         
     | 
| 
       171 
178 
     | 
    
         
             
            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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.8.0
         
     | 
| 
       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-11 00:00:00.000000000 Z
         
     | 
| 
       15 
15 
     | 
    
         
             
            dependencies:
         
     | 
| 
       16 
16 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       17 
17 
     | 
    
         
             
              name: httparty
         
     |