nike_v2 0.2.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,18 @@
1
1
  require 'httparty'
2
+ require 'httparty_sober'
2
3
  module NikeV2
3
4
  class Resource < Base
4
5
  include HTTParty
6
+ include HTTParty::Sober
5
7
 
6
8
  base_uri 'https://api.nike.com'
7
9
 
8
10
  RESP_MSG_INVALID_TOKEN = 'invalid_token'
9
11
 
12
+ if NikeV2.configuration.cache
13
+ cache NikeV2.configuration.cache
14
+ end
15
+
10
16
  def initialize(attributes={})
11
17
  super(attributes)
12
18
  end
@@ -23,7 +29,7 @@ module NikeV2
23
29
 
24
30
  def get(*args, &block)
25
31
  build_options(args)
26
- self.class.get(*args, &block)
32
+ self.class.send(get_method, *args, &block)
27
33
  end
28
34
 
29
35
  private
@@ -51,5 +57,13 @@ module NikeV2
51
57
  def api_url
52
58
  self.class.const_get('API_URL')
53
59
  end
60
+
61
+ def get_method
62
+ if NikeV2.configuration.cache
63
+ 'get_with_caching'
64
+ else
65
+ 'get'
66
+ end
67
+ end
54
68
  end
55
69
  end
@@ -25,12 +25,15 @@ module NikeV2
25
25
  summary_data['summaries'].each do |data|
26
26
  initialization_data[data['experienceType'].downcase] = {}
27
27
  data['records'].each do |record|
28
- initialization_data[data['experienceType'].downcase][record['recordType']] = record['recordValue']
28
+ if record.is_a?(Hash)
29
+ initialization_data[data['experienceType'].downcase][record['recordType']] = record['recordValue']
30
+ else
31
+ initialization_data[data['experienceType'].downcase][record[0]] = record[1]
32
+ end
29
33
  end
30
34
  end
31
35
  end
32
36
  end
33
-
34
37
  initialization_data
35
38
  end
36
39
  end
@@ -1,3 +1,3 @@
1
1
  module NikeV2
2
- VERSION = '0.2.8'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/nike_v2.rb CHANGED
@@ -2,6 +2,24 @@ require 'alchemist'
2
2
  require 'forwardable'
3
3
  require 'ext/core_ext'
4
4
 
5
+ module NikeV2
6
+ def self.configuration
7
+ @configuration ||= Configuration.new
8
+ end
9
+
10
+ def self.configure
11
+ yield(configuration) if block_given?
12
+ end
13
+
14
+ class Configuration
15
+ attr_accessor :cache
16
+
17
+ def initialize
18
+ @cache = false
19
+ end
20
+ end
21
+ end
22
+
5
23
  require 'nike_v2/base'
6
24
  require 'nike_v2/metric'
7
25
  require 'nike_v2/metrics'
@@ -11,4 +29,4 @@ require 'nike_v2/person'
11
29
  require 'nike_v2/activity'
12
30
  require 'nike_v2/activities'
13
31
  require 'nike_v2/summary'
14
- require 'nike_v2/gps_data'
32
+ require 'nike_v2/gps_data'
data/nike_v2.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.require_paths = ['lib']
17
17
 
18
18
  s.add_runtime_dependency 'httparty', '>= 0.10.0'
19
+ s.add_runtime_dependency "httparty_sober", "~> 0.2.1"
19
20
  s.add_runtime_dependency 'alchemist', '>= 0.1.3'
20
21
 
21
22
  s.add_development_dependency 'factory_girl', '~> 4.2.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nike_v2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-11 00:00:00.000000000 Z
12
+ date: 2013-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.10.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: httparty_sober
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.2.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.2.1
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: alchemist
32
48
  requirement: !ruby/object:Gem::Requirement