Skip to content

Commit

Permalink
added ttl support and changed README
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni Intini committed Mar 29, 2014
1 parent dda6400 commit 7b8a3b1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ Or install it yourself as:
```ruby
require 'lol'

# defaults to euw
client = Lol::Client.new "my_api_key"
client = Lol::Client.new "my_api_key", "euw"
# => <Lol::Client:0x007fd09d1abb00 @api_key="my_api_key", @region="euw">

# na
na_client = Lol::Client.new "my_api_key", :region => "na"
# => <Lol::Client:0x007fd09d1abb00 @api_key="my_api_key", @region="na">
# NEW! You can cache requests using Redis now
# ttl defaults to 900
client = Lol::Client.new "my_api_key", "euw", {redis: "redis://localhost:6379", ttl: 900}

# Available Requests
client.champion
Expand Down Expand Up @@ -119,8 +118,8 @@ client.static.champion.get(champData: 'lore')
5. Create new Pull Request

## Changelog

- 0.9.7 Updated LeagueReqeust to API v2.3
- 0.9.11 Added caching support via REDIS
- 0.9.7 Updated LeagueRequest to API v2.3
- 0.9.6 Updated SummonerRequest and GameRequest to API v1.3
- 0.9.5 Fixed documentation
- 0.9.4 Completed support for updated API
Expand Down
6 changes: 3 additions & 3 deletions lib/lol/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ def static
def initialize api_key, options = {}
@api_key = api_key
@region = options.delete(:region) || "euw"
set_up_cache(options.delete(:redis))
set_up_cache(options.delete(:redis), options.delete(:ttl))
end

def set_up_cache(redis_url)
def set_up_cache(redis_url, ttl)
return @cached = false unless redis_url

@ttl = 900
@ttl = ttl || 900
@cached = true
@redis = Redis.new :url => redis_url
end
Expand Down
5 changes: 5 additions & 0 deletions spec/lol/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
expect(client.ttl).to eq(15*60)
end

it "accepts a custom ttl" do
client = Client.new "foo", redis: "redis://dummy-url", ttl: 10
expect(client.ttl).to eq(10)
end

it "instantiates a redis client if redis is in the options" do
client = Client.new "foo", redis: "redis://localhost:6379"
expect(client.instance_variable_get(:@redis)).to be_a(Redis)
Expand Down

0 comments on commit 7b8a3b1

Please sign in to comment.