faraday_api_cache 0.0.2 → 0.0.3

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
- ---
2
- SHA1:
3
- metadata.gz: 29f3996cccec51cb7f8d257c5194f2bc4d9af93e
4
- data.tar.gz: ea48eaaa543a0bffdcf8482446859cdd0da04eed
5
- SHA512:
6
- metadata.gz: b7ab9be166de1f3a223cecb2a8fdedd493efbf2d702559e2ee34ecc393e06ad365086c41ba30ea3ae03c443667331b8ac57adc45d21f1eaa9cf56a9f774ced1f
7
- data.tar.gz: f57693702599b18fe6ea6cf131125455b442dc3bbfba2c8ab3d37aeb96a1d305df63ed68087fe17d927755b8f01c0da8de3c0fb8ba8b4832bd7afeeb759f504f
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a9f6a6340b3bc149aadf515cccc280b84d6a9e79
4
+ data.tar.gz: 6861ca429409c65a74c8d458cdcff67e7a33d24a
5
+ SHA512:
6
+ metadata.gz: a4f64dd8c6d4a4bb2aaab518820135eb6c9e741c6a4ce561eb80a09e6e7150383dfaf773a5c77ba7a898d796370d53a13de2367e1243a9a402695e68c795dd17
7
+ data.tar.gz: 249c213aab1079bac16474e2b31c6deb4dc33a6044a3297bf3221729714cf6bb709ee30562a5c58b1be7bfd16bbffb9f61ea599e92c754940a9b7ace24864d03
data/README.md CHANGED
@@ -1,29 +1,36 @@
1
- # FaradayApiCache
1
+ # Faraday API Cache
2
2
 
3
- TODO: Write a gem description
3
+ This is a [faraday](https://github.com/lostisland/faraday) middleware that integrates [API Cache](https://github.com/mloughran/api_cache) into the faraday middleware stack. Using Faraday API Cache, GET requests using Faraday will be cached automatically.
4
4
 
5
- ## Installation
5
+ ## Usage
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Make sure you have required the Faraday API Cache gem, or included it in your Gemfile. Then add Faraday API Cache as a request middleware:
8
8
 
9
- gem 'faraday_api_cache'
9
+ ~~~ruby
10
+ farcon = Faraday.new(url: 'http://example.com') do |c|
11
+ c.request :api_cache
12
+ # more config goes here...
13
+ end
14
+ ~~~
10
15
 
11
- And then execute:
16
+ That's it!
12
17
 
13
- $ bundle
18
+ Faraday API Cache passes any hash arguments to API Cache - see the [API Cache documentation](https://github.com/mloughran/api_cache) for more details (but the `cache` parameter especially is useful).
14
19
 
15
- Or install it yourself as:
20
+ Faraday API Cache also provides helper methods to change the logger and cache store used by API Cache:
16
21
 
17
- $ gem install faraday_api_cache
22
+ ~~~ruby
23
+ FaradayAPICache.logger = Rails.logger
24
+ FaradayAPICache.store = Moneta.new(:Memcached)
25
+ ~~~
18
26
 
19
- ## Usage
27
+ ## Why use Faraday API Cache?
28
+
29
+ There are already good middleware for caching in Faraday:
20
30
 
21
- TODO: Write usage instructions here
31
+ * [faraday-http-cache](https://github.com/plataformatec/faraday-http-cache) takes cache settings from the expiry and modified response headers, whereas Faraday API Cache lets the developer set the cache expiry.
32
+ * The caching middleware in [faraday_middleware](https://github.com/lostisland/faraday_middleware) is equivelent to Faraday API Cache, but if you're already using API Cache then it might make more sense to use Faraday API Cache.
22
33
 
23
- ## Contributing
34
+ ## Credits
24
35
 
25
- 1. Fork it ( https://github.com/[my-github-username]/faraday_api_cache/fork )
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create a new Pull Request
36
+ Faraday API Cache was originally written by [Ismael Celis](https://github.com/ismasan), but was open sourced and is now maintained by [Iain Beeston](https://github.com/iainbeeston).
@@ -1,4 +1,16 @@
1
1
  require 'faraday_api_cache/version'
2
2
  require 'faraday_api_cache/middleware'
3
3
 
4
+ module FaradayAPICache
5
+ class << self
6
+ def logger=(logger)
7
+ APICache.logger = logger
8
+ end
9
+
10
+ def store=(store)
11
+ APICache.store = store
12
+ end
13
+ end
14
+ end
15
+
4
16
  Faraday::Request.register_middleware api_cache: FaradayAPICache::Middleware
@@ -5,31 +5,17 @@ module FaradayAPICache
5
5
  class Middleware < Faraday::Middleware
6
6
  def initialize(app, options = {})
7
7
  super(app)
8
- @options = options.to_hash
8
+ @options = { period: 0, timeout: 0 }.merge(options.to_hash)
9
9
  end
10
10
 
11
11
  def call(env)
12
12
  if env[:method] == :get
13
13
  APICache.get(env[:url].to_s, @options) do
14
- APICache.logger.debug 'FaradayAPICache cache miss... Caching.'
15
14
  @app.call(env)
16
15
  end
17
16
  else
18
- APICache.logger.debug 'FaradayAPICache cache hit.'
19
17
  @app.call(env)
20
18
  end
21
19
  end
22
-
23
- def self.clear
24
- self.store = APICache::MemoryStore.new
25
- end
26
-
27
- def self.logger=(logger)
28
- APICache.logger = logger
29
- end
30
-
31
- def self.store=(store)
32
- APICache.store = store
33
- end
34
20
  end
35
21
  end
@@ -1,3 +1,3 @@
1
1
  module FaradayAPICache
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,80 +1,65 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: faraday_api_cache
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Ismael Celis
8
8
  - Iain Beeston
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-16 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2014-07-19 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: faraday
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - '>='
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :runtime
22
17
  prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - '>='
26
- - !ruby/object:Gem::Version
27
- version: '0'
28
- - !ruby/object:Gem::Dependency
29
- name: api_cache
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - '>='
33
- - !ruby/object:Gem::Version
34
- version: '0'
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - &id002
21
+ - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
35
24
  type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: api_cache
36
28
  prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - '>='
40
- - !ruby/object:Gem::Version
41
- version: '0'
42
- - !ruby/object:Gem::Dependency
29
+ requirement: &id003 !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - *id002
32
+ type: :runtime
33
+ version_requirements: *id003
34
+ - !ruby/object:Gem::Dependency
43
35
  name: bundler
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ~>
47
- - !ruby/object:Gem::Version
48
- version: '1.6'
49
- type: :development
50
36
  prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
37
+ requirement: &id004 !ruby/object:Gem::Requirement
38
+ requirements:
53
39
  - - ~>
54
- - !ruby/object:Gem::Version
55
- version: '1.6'
56
- - !ruby/object:Gem::Dependency
57
- name: rake
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - '>='
61
- - !ruby/object:Gem::Version
62
- version: '0'
40
+ - !ruby/object:Gem::Version
41
+ version: "1.6"
63
42
  type: :development
43
+ version_requirements: *id004
44
+ - !ruby/object:Gem::Dependency
45
+ name: rake
64
46
  prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
47
+ requirement: &id005 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - *id002
50
+ type: :development
51
+ version_requirements: *id005
70
52
  description:
71
- email:
53
+ email:
72
54
  - ismaelct@gmail.com
73
55
  - iain.beeston@gmail.com
74
56
  executables: []
57
+
75
58
  extensions: []
59
+
76
60
  extra_rdoc_files: []
77
- files:
61
+
62
+ files:
78
63
  - .gitignore
79
64
  - Gemfile
80
65
  - LICENSE.txt
@@ -85,27 +70,29 @@ files:
85
70
  - lib/faraday_api_cache/middleware.rb
86
71
  - lib/faraday_api_cache/version.rb
87
72
  homepage:
88
- licenses:
73
+ licenses:
89
74
  - MIT
90
75
  metadata: {}
76
+
91
77
  post_install_message:
92
78
  rdoc_options: []
93
- require_paths:
79
+
80
+ require_paths:
94
81
  - lib
95
- required_ruby_version: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - '>='
98
- - !ruby/object:Gem::Version
99
- version: '1.9'
100
- required_rubygems_version: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - '>='
103
- - !ruby/object:Gem::Version
104
- version: '0'
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "1.9"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - *id002
105
90
  requirements: []
91
+
106
92
  rubyforge_project:
107
93
  rubygems_version: 2.2.2
108
94
  signing_key:
109
95
  specification_version: 4
110
96
  summary: A faraday middleware that uses API Cache to transparently cache requests
111
97
  test_files: []
98
+