buckybox-api 1.3.1 → 1.4.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 +4 -4
- data/buckybox-api.gemspec +1 -1
- data/lib/buckybox/api.rb +26 -3
- 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: 330e89a7ff831ac42be4151bd4d7cf8b23e9a53b
         | 
| 4 | 
            +
              data.tar.gz: 210061a10df2a9afec3443f4ff5928def4f360b0
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d1168bf5441e6c7a38f4de1b3701da726fb3dffe7b344eab4d8d29fe6b01fa02b8049e274fc11fcd749d8b81613bc146b8c66ca04fed58f8f62e1da6fd76e840
         | 
| 7 | 
            +
              data.tar.gz: c8106a1dec1774e6914ec7f03fcb42c681ae36e10209027b22c9f93b89842f49e6bf7e714181430a2f18352256a8c4505461c22c70443cecb6fac612e4a4ec8a
         | 
    
        data/buckybox-api.gemspec
    CHANGED
    
    | @@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | |
| 4 4 |  | 
| 5 5 | 
             
            Gem::Specification.new do |spec|
         | 
| 6 6 | 
             
              spec.name          = "buckybox-api"
         | 
| 7 | 
            -
              spec.version       = "1. | 
| 7 | 
            +
              spec.version       = "1.4.0"
         | 
| 8 8 | 
             
              spec.authors       = ["Cédric Félizard"]
         | 
| 9 9 | 
             
              spec.email         = ["cedric@felizard.fr"]
         | 
| 10 10 | 
             
              spec.summary       = %q{RubyGem wrapper for the Bucky Box API}
         | 
    
        data/lib/buckybox/api.rb
    CHANGED
    
    | @@ -8,6 +8,22 @@ module BuckyBox | |
| 8 8 | 
             
                ResponseError = Class.new(Exception) # generic error
         | 
| 9 9 | 
             
                NotFoundError = Class.new(Exception)
         | 
| 10 10 |  | 
| 11 | 
            +
                class CachedResponse
         | 
| 12 | 
            +
                  attr_reader :response, :cached_at
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  def initialize(response)
         | 
| 15 | 
            +
                    @response, @cached_at = response, epoch
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  def expired?
         | 
| 19 | 
            +
                    epoch - cached_at > 60 # NOTE: cache responses for 60 seconds
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  private def epoch
         | 
| 23 | 
            +
                    Time.now.utc.to_i
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 11 27 | 
             
                include HTTParty
         | 
| 12 28 | 
             
                format :json
         | 
| 13 29 | 
             
                base_uri "https://api.buckybox.com/v1"
         | 
| @@ -107,10 +123,17 @@ module BuckyBox | |
| 107 123 | 
             
                  }
         | 
| 108 124 |  | 
| 109 125 | 
             
                  if type == :get # NOTE: only cache GET method
         | 
| 110 | 
            -
                    cache_key = [self.class.headers.hash, uri, to_query(params)].join
         | 
| 111 | 
            -
             | 
| 112 126 | 
             
                    @cache ||= {}
         | 
| 113 | 
            -
                     | 
| 127 | 
            +
                    cache_key = [self.class.headers.hash, uri, to_query(params)].join
         | 
| 128 | 
            +
                    cached_response = @cache[cache_key]
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                    if cached_response && !cached_response.expired?
         | 
| 131 | 
            +
                      cached_response.response
         | 
| 132 | 
            +
                    else
         | 
| 133 | 
            +
                      response = query_fresh.call
         | 
| 134 | 
            +
                      @cache[cache_key] = CachedResponse.new(response)
         | 
| 135 | 
            +
                      response
         | 
| 136 | 
            +
                    end
         | 
| 114 137 | 
             
                  else
         | 
| 115 138 | 
             
                    query_fresh.call
         | 
| 116 139 | 
             
                  end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: buckybox-api
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1. | 
| 4 | 
            +
              version: 1.4.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Cédric Félizard
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015-04- | 
| 11 | 
            +
            date: 2015-04-07 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: httparty
         |