everlog 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 605ddffeb6d60d16b12a0799b042c5c00267824d
4
- data.tar.gz: 518eb8103899b7fa4781cbbf49a4a04e2973af5d
3
+ metadata.gz: cdeac73e0c2896ab2a4a419211ed244304801ac4
4
+ data.tar.gz: e6e220f0d5a333b4e23089b1aebc8f6d4eb80b4d
5
5
  SHA512:
6
- metadata.gz: 31139ea009529f3ff56712a69381ab39b6c24d47658b7b905f684f0f010388b31c2326a80998cb212b924a1d1ce2022db24415813c19653c873078e29993d4bf
7
- data.tar.gz: 9feec3bfe84591bdc8ec690d9fcc83c0d408300996ec68446827fa0890b042f7de998a66e5a06ddf4a0c69b7ddc99122a295e36fb3c5054be7f15adafe25983d
6
+ metadata.gz: 4ce875a255ece257cf37bb70a3fa2528c08f407cf6e0618283796b31ec20c73131952ec8a9852454b736d70784a34e4a8a8f2ae6252448de762592bec1f2db15
7
+ data.tar.gz: 8f55770e57d40f4f2fc2dd4b5dc5a48b7323c32f1ec7c840aba5321569be23502ace4f0dbfc0735b9a2f8e8e65bdb56c7a88ed3d772d655f993563f1c01ecc79
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ test/version_tmp
17
17
  tmp
18
18
  spec/.env.test
19
19
  .idea/
20
+ lib/everlog/inf/cache/data
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency 'hatena-bookmark'
26
26
  spec.add_dependency 'octokit'
27
27
  spec.add_dependency 'wunderground'
28
+ spec.add_dependency 'LocalFileCache'
28
29
  spec.add_development_dependency "rspec"
29
30
  spec.add_development_dependency "guard-rspec"
30
31
  spec.add_development_dependency "dotenv"
@@ -1,5 +1,6 @@
1
1
  class Everlog
2
2
  class Inf
3
+ require 'everlog/inf/cache'
3
4
  require 'everlog/inf/api'
4
5
  end
5
6
  end
@@ -2,12 +2,20 @@ class Everlog
2
2
  class Inf::Api::Wunderground < Inf::Api
3
3
  require 'wunderground'
4
4
 
5
+ def initialize config
6
+ super(config)
7
+ @cache = Inf::Cache::File::Wunderground.new
8
+ end
9
+
5
10
  def client
6
11
  @client ||= ::Wunderground.new(@config.access_token, throws_exceptions: true)
7
12
  end
8
13
 
9
14
  def yesterday place
10
- client.yesterday_for(place)['history']
15
+ @cache.delete((Date.today - 2).to_s)
16
+ @cache.get_and_save((Date.today - 1).to_s, { place: place, client: client}) do |args|
17
+ args[:client].yesterday_for(args[:place])['history']
18
+ end
11
19
  rescue => e
12
20
  raise InfrastructureWeatherError, "yesterday error / #{e.message}"
13
21
  end
@@ -0,0 +1,5 @@
1
+ class Everlog
2
+ class Inf::Cache < Inf
3
+ require 'everlog/inf/cache/file'
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ class Everlog
2
+ class Inf::Cache::File < Inf::Cache
3
+ require 'LocalFileCache'
4
+ require 'everlog/inf/cache/file/wunderground'
5
+ require 'pry'
6
+
7
+ def initialize
8
+ service = self.class.name.split('::').last.downcase
9
+ @cache = LocalFileCache.new("#{::File.dirname(__FILE__)}/data/#{service}")
10
+ end
11
+
12
+ def get_and_save(date, proc_args = {}, &api_proc)
13
+ return @cache.get(date) if @cache.has?(date)
14
+ data = api_proc.call(proc_args)
15
+ @cache.set(date, data)
16
+ data
17
+ end
18
+
19
+ def delete key
20
+ @cache.delete key
21
+ end
22
+
23
+ def flush
24
+ @cache.flush
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ class Everlog
2
+ class Inf::Cache::File::Wunderground < Inf::Cache::File
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  class Everlog
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -7,5 +7,15 @@ describe Everlog::Inf::Api::Wunderground do
7
7
 
8
8
  describe '#yesterday' do
9
9
  it { expect { instance.yesterday('Tokyo') }.not_to raise_error }
10
+ it 'read from cache' do
11
+ LocalFileCache.any_instance.should_receive(:get).once.and_return('sunny')
12
+
13
+ # 一度目はcacheにセットされる
14
+ expect { instance.yesterday('Tokyo').not_to raise_error }
15
+ # 二度目はcacheからデータを取る
16
+ expect(instance.yesterday('Tokyo')).to eq 'sunny'
17
+ # キャッシュ消す
18
+ instance.instance_eval { @cache.flush }
19
+ end
10
20
  end
11
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: everlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - gong023
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-08 00:00:00.000000000 Z
11
+ date: 2014-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evernote_oauth
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: LocalFileCache
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rspec
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -240,6 +254,9 @@ files:
240
254
  - lib/everlog/inf/api/moves.rb
241
255
  - lib/everlog/inf/api/twitter.rb
242
256
  - lib/everlog/inf/api/wunderground.rb
257
+ - lib/everlog/inf/cache.rb
258
+ - lib/everlog/inf/cache/file.rb
259
+ - lib/everlog/inf/cache/file/wunderground.rb
243
260
  - lib/everlog/version.rb
244
261
  - spec/fixtures/animetick/list_ticket_response.json
245
262
  - spec/fixtures/hatena/feed_response.json