run_signup_api 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f0caebba99a7760a13cb70da2fa0c7edf4b59f95f5e4a6b8d472c1db359ce32
4
- data.tar.gz: 286a9eb781b7332aba38cf818ebd24162024e3fb1c2807ab50775b75c2481863
3
+ metadata.gz: 89bfa7ccc068c0fee63a861d9cc9d322a68b811aab3bcaf12bdd05ea3bcabcbc
4
+ data.tar.gz: f8936237dcba53debdf6d4390bb0b02acfa976619f3c30036aa7a5b3190fc05b
5
5
  SHA512:
6
- metadata.gz: 07ce4be4675c5c79ed2e050328ca37bed75bf6f6d26c87a3355d8405b5e7e3c139e4c438ceec56650b77ab3e65a30dce182c5e694cea05894b1942669fa92375
7
- data.tar.gz: 1f104cb19d93843807d35796740d7d962534040434218a069e6d33e3646fe175e0a983a77c76fee33a2afd46d69bf94abbb60b88a3d8a01404af6ef049a37bbb
6
+ metadata.gz: a3a18c3cd0b825341b436da78eaad7e9557f3baedabd0f52ed2897b09bf49a13235dfc9bb320aea558c3b579fa21de0acc9d0867775450b074d098faa77c2ea3
7
+ data.tar.gz: b94e57ab9e5711d41986c090542cfc21cf941a5b2ab38c0191416b7df7aaed78b874a0904b59f93873e87aeea1bf6b69b5b8b5e5de08187d75cf44ed238961a1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- run_signup_api (0.0.2)
4
+ run_signup_api (0.0.3)
5
5
  httparty
6
6
 
7
7
  GEM
@@ -1,33 +1,54 @@
1
+ # Mixins for coercing data to and from the API in expected formats
1
2
  module RunSignup
2
3
  module DataCoercion
3
- def coerce_hash_values hash
4
+ def coerce_from_api hash
4
5
  if hash
5
6
  hash.each do |k, v|
6
- hash[k] = coerce_value(v)
7
+ hash[k] = coerce_value_from_api v
8
+ if k == 'events'
9
+ hash[k] = hash[k].map { |event| RunSignup::Event.new(event) }
10
+ end
7
11
  end
8
12
  end
9
13
  hash
10
14
  end
11
15
 
12
- def coerce_value v
13
- if v.is_a?(Array)
14
- v.map { |v1| coerce_value(v1) }
15
- elsif v.is_a?(Hash)
16
- coerce_hash_values(v)
16
+ def coerce_value_from_api value
17
+ if value.is_a?(Array)
18
+ value.map { |v1| coerce_value_from_api(v1) }
19
+ elsif value.is_a?(Hash)
20
+ coerce_from_api(value)
17
21
  else
18
- case v
22
+ case value
19
23
  when 'T'
20
24
  true
21
25
  when 'F'
22
26
  false
23
27
  when /^\d{1,2}\/\d{1,2}\/\d{4} \d{2}:\d{2}$/
24
- DateTime.strptime(v, '%m/%d/%Y %H:%M').to_s
28
+ DateTime.strptime(value, '%m/%d/%Y %H:%M').to_s
25
29
  when /^\d{1,2}\/\d{1,2}\/\d{4}$/
26
- Date.strptime(v, '%m/%d/%Y').to_s
30
+ Date.strptime(value, '%m/%d/%Y').to_s
27
31
  else
28
- v
32
+ value
29
33
  end
30
34
  end
31
35
  end
36
+
37
+ def coerce_for_api hash
38
+ hash.each do |k, v|
39
+ hash[k] = coerce_value_for_api v
40
+ end
41
+ end
42
+
43
+ def coerce_value_for_api value
44
+ case value
45
+ when true
46
+ 'T'
47
+ when false
48
+ 'F'
49
+ else
50
+ value
51
+ end
52
+ end
32
53
  end
33
54
  end
@@ -7,7 +7,9 @@ module RunSignup
7
7
  include RunSignup::DataCoercion
8
8
 
9
9
  def initialize hash = nil
10
- super coerce_hash_values hash
10
+ super coerce_from_api hash
11
11
  end
12
12
  end
13
- end
13
+
14
+ class Event < OpenStruct; end;
15
+ end
@@ -1,3 +1,3 @@
1
1
  module RunSignupApi
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -3,6 +3,7 @@ require 'httparty'
3
3
  module RunSignupApi
4
4
  class Client
5
5
  include HTTParty
6
+ include RunSignup::DataCoercion
6
7
 
7
8
  BASE_URL = "https://runsignup.com/rest"
8
9
 
@@ -57,7 +58,10 @@ module RunSignupApi
57
58
  protected
58
59
 
59
60
  def call_api path, params = {}
60
- response = self.class.get("#{BASE_URL}/#{path}", query: default_params.merge(params))
61
+ response = self.class.get(
62
+ "#{BASE_URL}/#{path}",
63
+ query: default_params.merge(coerce_for_api params)
64
+ )
61
65
  if response.code == 200
62
66
  response = response.parsed_response
63
67
 
@@ -1,3 +1,3 @@
1
1
  module RunSignupApi
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: run_signup_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - dbwinger