scoreoid 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,6 +1,11 @@
1
1
  Scoreoid Ruby Change Log
2
2
  ========================
3
3
 
4
+ 2012-11-25 *v1.1.0*
5
+ -------------------
6
+
7
+ - Allow passing date parameters (`:start_date` or `:end_date`) in natural language, such as "1 year ago". You can still pass a Date or Time object instead.
8
+
4
9
  2012-11-25 *v1.0.0*
5
10
  -------------------
6
11
 
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  Scoreoid Ruby
2
2
  =============
3
3
 
4
- Scoreoid Ruby is a wrapper for the Scoreoid API. It is in the early development stages,
5
- with plans to support all Scoreoid API methods.
4
+ Summary
5
+ -------
6
+
7
+ Scoreoid Ruby is a wrapper for the [Scoreoid](https://www.scoreoid.com/) API.
6
8
 
7
9
  Installation
8
10
  ------------
@@ -22,6 +24,8 @@ Or install it yourself as:
22
24
  Usage
23
25
  -----
24
26
 
27
+ Full documentation is [available online](http://rubydoc.info/gems/scoreoid/frames).
28
+
25
29
  To get started, configure Scoreoid Ruby with your API key and game ID:
26
30
 
27
31
  require 'scoreoid'
data/Rakefile CHANGED
@@ -6,3 +6,8 @@ RSpec::Core::RakeTask.new(:spec)
6
6
  YARD::Rake::YardocTask.new(:yard)
7
7
 
8
8
  task default: :spec
9
+
10
+ desc 'Start an IRB session in the context of the current bundle'
11
+ task :irb do
12
+ sh 'bundle console'
13
+ end
data/lib/scoreoid/api.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'date'
2
-
1
+ require 'chronic'
3
2
  require 'multi_json'
4
3
  require 'rest_client'
5
4
 
@@ -12,6 +11,10 @@ module Scoreoid
12
11
  class << self
13
12
  # Query a given Scoreoid API method and return the repsonse as a string.
14
13
  #
14
+ # Supplied parameters will be prepared with {.prepare_params} before sending.
15
+ # This is so that you can, for example, supply a Date object for :start_date
16
+ # even though the Scoreoid API expects it to be a string formatted as "YYYY-MM-DD".
17
+ #
15
18
  # @param [String] api_method The Scoreoid API method to query
16
19
  # @param [Hash] params Parameters to include in the API request
17
20
  #
@@ -36,7 +39,6 @@ module Scoreoid
36
39
  # @return [Hash] The Scoreoid API response parsed into a Hash.
37
40
  #
38
41
  # @see .query
39
- # @see .prepare_params
40
42
  def query_and_parse(api_method, params={})
41
43
  params = params.merge(response: 'json')
42
44
 
@@ -50,16 +52,25 @@ module Scoreoid
50
52
 
51
53
  # Attempt to coerce parameters into formats that the Scoreoid API expects.
52
54
  #
55
+ # Date parameters will be parsed with Chronic, so you can supply dates in
56
+ # natural language such as "may 5th 2012" or "1 year ago".
57
+ #
53
58
  # @param [Hash] params A hash of any parameters you wish to format.
54
59
  #
55
- # @option params [Date, Time, String] :start_date
56
- # @option params [Date, Time, String] :end_date
60
+ # @option params [#to_s, #strftime] :start_date
61
+ # @option params [#to_s, #strftime] :end_date
57
62
  #
58
63
  # @return [Hash] The formatted parameters, ready to use in an API query.
59
64
  def prepare_params(params)
60
- params.each do |key, value|
61
- if [:start_date, :end_date].include?(key) and value.respond_to?(:strftime)
62
- params[key] = value.strftime '%Y-%m-%d'
65
+ params.each do |key, _|
66
+ if [:start_date, :end_date].include?(key)
67
+ if params[key].respond_to? :to_s
68
+ params[key] = Chronic.parse(params[key].to_s, context: :past)
69
+ end
70
+
71
+ if params[key].respond_to? :strftime
72
+ params[key] = params[key].strftime '%Y-%m-%d'
73
+ end
63
74
  end
64
75
  end
65
76
  params
@@ -1,4 +1,4 @@
1
1
  module Scoreoid
2
2
  # The currently loaded Scoreoid Ruby version.
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.0'
4
4
  end
data/scoreoid.gemspec CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.license = 'MIT'
13
13
 
14
14
  gem.required_ruby_version = '1.9.2'
15
+ gem.add_runtime_dependency 'chronic', '~> 0.8.0'
15
16
  gem.add_runtime_dependency 'multi_json', '~> 1.3'
16
17
  gem.add_runtime_dependency 'rest-client', '~> 1.6'
17
18
 
data/spec/api_spec.rb CHANGED
@@ -34,8 +34,8 @@ describe Scoreoid::API do
34
34
 
35
35
  it 'should format the parameters before sending' do
36
36
  example_response = %q({"players": 7})
37
- given_params = {start_date: Date.new(2010, 1, 1), end_date: Date.new(2012, 2, 3).to_time}
38
- formatted_params = {start_date: '2010-01-01', end_date: '2012-02-03'}
37
+ given_params = {start_date: Date.new(2010, 1, 1), end_date: 'december 3rd 2011'}
38
+ formatted_params = {start_date: '2010-01-01', end_date: '2011-12-03'}
39
39
 
40
40
  RestClient.stub(:post).and_return(example_response)
41
41
  RestClient.should_receive(:post).with('https://www.scoreoid.com/api/playerCount', formatted_params)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scoreoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-25 00:00:00.000000000 Z
12
+ date: 2012-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: chronic
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.8.0
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: multi_json
16
32
  requirement: !ruby/object:Gem::Requirement