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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d241a3a1fe1f27c5cb995fafd2d02b4a9d861a9e
4
- data.tar.gz: 2f16787de453f9975aba2c683ef74b4cebc9ab14
3
+ metadata.gz: ac6683a4f6b77b466d74763747790e755a27d5dd
4
+ data.tar.gz: 306f987da2c11c26ea94a0ce0a53ec68596be007
5
5
  SHA512:
6
- metadata.gz: 98e71bf3bb6b85f0d9386ed8c9e83615e11a5a2abdb4228817af018557c4aebfd596d0c48a4a173b0acacbfa4e8efdbc3edfb27ee5e9fa1cd808504283cfbc82
7
- data.tar.gz: b9d1cc843c195d556b896ccc87fb7d7e3656ca46ac40a68103102ac37914e6853b6e0dc54bc618d6f27aa0ce7373a78865c7b79ae723fb8fca8a0e64fc4da511
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("#{path}#{options}")
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 "#{path}#{options}", ttl, response.to_json if cached?
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' => @api_key,
35
- 'Accept-Language' => @region
36
+ 'Ocp-Apim-Subscription-Key': @api_key,
37
+ 'Accept-Language': @region
36
38
  }
37
39
 
38
40
  options[:headers] = headers unless headers.empty?
@@ -1,13 +1,5 @@
1
- require 'halo-api/version'
2
- require 'halo-api/api_response'
3
- require 'halo-api/configuration'
4
-
5
- require 'redis'
6
-
7
-
8
1
  module Halo
9
2
  class Client
10
- include HTTParty
11
3
 
12
4
  attr_accessor(*Configuration::OPTIONS)
13
5
 
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module Halo
2
- VERSION = '0.4.1'.freeze
2
+ VERSION = '0.4.2'.freeze
3
3
  end
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.1
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-26 00:00:00.000000000 Z
11
+ date: 2017-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty