halo-api 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/halo-api/api_response.rb +7 -5
- data/lib/halo-api/client.rb +0 -8
- data/lib/halo-api/configuration.rb +3 -3
- data/lib/halo-api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac6683a4f6b77b466d74763747790e755a27d5dd
|
4
|
+
data.tar.gz: 306f987da2c11c26ea94a0ce0a53ec68596be007
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a0e6ebeb64625c5fabedf95a8a18731b0fac70c2a859eb0ac261c99ca9d33763045c9d6112a40d93f3fbe85e1baf38624036c3ee8682da5100292c088a371ba
|
7
|
+
data.tar.gz: f5b0459e581a3ea4e8f01f497558245ce34803bd58099f959d35c5349f8086765aa5275970d9ad831e87c12fe788b754e28ecb7dcaa36d6dac0d1db3d0a326df
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'addressable/uri'
|
3
|
+
require 'redis'
|
3
4
|
|
4
5
|
module Halo
|
5
6
|
class InvalidCacheStore < StandardError; end
|
@@ -10,7 +11,7 @@ module Halo
|
|
10
11
|
def initialize(options = {})
|
11
12
|
client = options.delete(:client)
|
12
13
|
@api_key = client.api_key
|
13
|
-
@region = client.region
|
14
|
+
@region = client.region || Halo::Configuration::DEFAULT_REGION
|
14
15
|
@cache_store = client.cache_store || {}
|
15
16
|
|
16
17
|
raise InvalidCacheStore if cached? && !redis_store.is_a?(Redis)
|
@@ -19,20 +20,21 @@ module Halo
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def get_data(path, options = {})
|
23
|
+
store_key = "#{path}#{options}#{@region}"
|
22
24
|
if cached?
|
23
|
-
result = redis_store.get(
|
25
|
+
result = redis_store.get(store_key)
|
24
26
|
return JSON.parse(result) if result
|
25
27
|
end
|
26
28
|
response = perform_uncached_request(:get, path, options)
|
27
|
-
redis_store.setex
|
29
|
+
redis_store.setex(store_key, ttl, response.to_json) if cached?
|
28
30
|
response
|
29
31
|
end
|
30
32
|
|
31
33
|
def perform_uncached_request(verb, path, params = {})
|
32
34
|
options = {}
|
33
35
|
headers = {
|
34
|
-
'Ocp-Apim-Subscription-Key'
|
35
|
-
'Accept-Language'
|
36
|
+
'Ocp-Apim-Subscription-Key': @api_key,
|
37
|
+
'Accept-Language': @region
|
36
38
|
}
|
37
39
|
|
38
40
|
options[:headers] = headers unless headers.empty?
|
data/lib/halo-api/client.rb
CHANGED
@@ -4,9 +4,9 @@ module Halo
|
|
4
4
|
OPTIONS = %i[api_key region redis ttl].freeze
|
5
5
|
|
6
6
|
DEFAULT_API_KEY = nil
|
7
|
-
DEFAULT_REGION = 'en'
|
8
|
-
DEFAULT_REDIS = 'redis://localhost:6379'
|
9
|
-
DEFAULT_TTL = 1800
|
7
|
+
DEFAULT_REGION = 'en'.freeze
|
8
|
+
DEFAULT_REDIS = 'redis://localhost:6379'.freeze
|
9
|
+
DEFAULT_TTL = 1800 # 30m
|
10
10
|
|
11
11
|
attr_accessor(*OPTIONS)
|
12
12
|
|
data/lib/halo-api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: halo-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|