api-model 2.2.3 → 2.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67b49931f63da3d0513936563bbd57b3d0d748d1
4
- data.tar.gz: 35ac10fb3187252443df74c7e5d36efdb31ffdc4
3
+ metadata.gz: 52cac4da2cc85c6c496d340cb4cca2c4b6662de2
4
+ data.tar.gz: 6009b3cf582247c64c7f34b5b3eec4f4405a23b0
5
5
  SHA512:
6
- metadata.gz: 593efe9fb7d5b3411400ac81269938bcffe17515c185f9c7724483d79195f1cb0401e6ff86b95a6157c19afe8863dbab55d446a0e312ad53b8083c5215ba946b
7
- data.tar.gz: 8970ca96cb6f76534fe2d5a312c9e9aed4c49f784ec6c8fcfb631dfa303ceb704d95848ddad43b58e32aa648e55c69664eab5e60be2192a1f16ca87b92fc5fa0
6
+ metadata.gz: 5acbe5cfb9066089acdb1cccf1b663062052196287b28d7f04eae7f16fd47b94b37799b8160a525da52cddd02f42c234e4b9aff3ebb86fae0dd350ab9894cb84
7
+ data.tar.gz: d3da9f0ec5bd00b6114fae65cc8fee7cc7f0a6c0707f98815f85e556187a74fa344e8f47d20eab5ecf39c63125aafe2ee6058cc83f25b9dbb5c9af8dc73c23b0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- api-model (2.2.3)
4
+ api-model (2.3.0)
5
5
  activemodel (~> 4.1)
6
6
  activesupport (~> 4.1)
7
7
  hash-pipe (~> 0.0)
@@ -12,10 +12,10 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activemodel (4.1.7)
16
- activesupport (= 4.1.7)
15
+ activemodel (4.1.8)
16
+ activesupport (= 4.1.8)
17
17
  builder (~> 3.1)
18
- activesupport (4.1.7)
18
+ activesupport (4.1.8)
19
19
  i18n (~> 0.6, >= 0.6.9)
20
20
  json (~> 1.7, >= 1.7.7)
21
21
  minitest (~> 5.1)
data/README.md CHANGED
@@ -215,6 +215,13 @@ something like this:
215
215
  end
216
216
  ```
217
217
 
218
+ By default, the unique id for the cache store/fetch will be a combination of the path and parameters. If you want to override
219
+ this, you can either redefine the `cache_id` method, or set the cache_id when making requests:
220
+
221
+ ```ruby
222
+ MyModel.get_json "/foo", { some_param: "bar" }, cache_id: "whatever!"
223
+ ```
224
+
218
225
  ### Headers
219
226
 
220
227
  ```ruby
data/api-model.gemspec CHANGED
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "api-model"
5
- s.version = "2.2.3"
5
+ s.version = "2.3.0"
6
6
  s.authors = ["Damien Timewell", "Erik Rothoff Andersson"]
7
7
  s.email = ["mail@damientimewell.com", "erik.rothoff@gmail.com"]
8
8
  s.licenses = ['MIT']
@@ -1,7 +1,6 @@
1
1
  module ApiModel
2
2
  module ClassMethods
3
3
 
4
- # TODO - try to think of a more memorable name for this...
5
4
  def attribute_synonym(primary_method_name, *alternate_names)
6
5
  alternate_names.each do |alternate_name|
7
6
  alias_method "#{alternate_name}=".to_sym, "#{primary_method_name}=".to_sym
@@ -26,7 +25,7 @@ module ApiModel
26
25
  end
27
26
 
28
27
  def call_api(method, path, options={})
29
- cache cache_id(path, options) do
28
+ cache options.delete(:cache_id) || cache_id(path, options) do
30
29
  request = HttpRequest.new path: path, method: method, config: api_model_configuration
31
30
  request.builder = options.delete(:builder) || api_model_configuration.builder || self
32
31
  request.options.deep_merge! options
@@ -35,7 +34,6 @@ module ApiModel
35
34
  end
36
35
 
37
36
  def cache_id(path, options={})
38
- return @cache_id if @cache_id
39
37
  p = (options[:params] || {}).collect{ |k,v| "#{k}#{v}" }.join("")
40
38
  "#{path}#{p}"
41
39
  end
@@ -296,10 +296,21 @@ describe ApiModel do
296
296
  end
297
297
  end
298
298
 
299
- describe "cache_id" do
300
- it 'should use options and the request path to create an identifier for the cache' do
299
+ describe "caching" do
300
+ it 'should use options and the request path to create an identifier for the cache_id' do
301
301
  BlogPost.cache_id("/box", params: { foo: "bar" }).should eq "/boxfoobar"
302
302
  end
303
+
304
+ it 'should use a custom cache key instead of the cache_id if it is present' do
305
+ BlogPost.should_not_receive :cache_id
306
+ VCR.use_cassette('posts') { BlogPost.get_json "http://api-model-specs.com/single_post", {}, cache_id: "custom_key" }
307
+ end
308
+
309
+ it 'should not pass custom cache_ids onto api requests' do
310
+ expect {
311
+ VCR.use_cassette('posts') { BlogPost.get_json "http://api-model-specs.com/single_post", {}, cache_id: "custom_key" }
312
+ }.to_not raise_error(Ethon::Errors::InvalidOption)
313
+ end
303
314
  end
304
315
 
305
316
  describe "successful?" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Timewell
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-18 00:00:00.000000000 Z
12
+ date: 2014-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport