osm 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/lib/osm/api.rb +16 -2
- data/lib/osm/member.rb +2 -1
- data/lib/osm/register_data.rb +2 -1
- data/lib/osm/section.rb +2 -1
- data/version.rb +1 -1
- metadata +12 -12
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## Version 0.0.14
|
2
|
+
|
3
|
+
* Add :debug option to Api.configure
|
4
|
+
* -2 is a valid grouping\_id value
|
5
|
+
* Fix Api.get_register\_data\ returning wrong object
|
6
|
+
* Fix check of :num\_scouts in Section.initalize
|
7
|
+
|
1
8
|
## Version 0.0.13
|
2
9
|
|
3
10
|
* Fix bug - invalid grouping\_leader in member incorrectly risen for -1
|
data/lib/osm/api.rb
CHANGED
@@ -20,6 +20,7 @@ module Osm
|
|
20
20
|
@@user_access = Hash.new
|
21
21
|
@@cache_prepend_to_key = 'OSMAPI'
|
22
22
|
@@cache = nil
|
23
|
+
@@debug = false
|
23
24
|
|
24
25
|
# Initialize a new API connection
|
25
26
|
# If passing user details then both must be passed
|
@@ -47,6 +48,7 @@ module Osm
|
|
47
48
|
# @option options [Class] :cache (optional) An instance of a cache class, must provide the methods (exist?, delete, write, read), for details see Rails.cache. Whilst this is optional you should remember that caching is required to use the OSM API.
|
48
49
|
# @option options [Fixnum] :default_cache_ttl (optional, default = 30.minutes) The default TTL value for the cache, note that some items are cached for twice this time and others are cached for half this time (in seconds)
|
49
50
|
# @option options [String] :cache_prepend_to_key (optional, default = 'OSMAPI') Text to prepend to the key used to store data in the cache
|
51
|
+
# @option options [Boolean] :debug if true debugging info is output (options, default = false)
|
50
52
|
# @return nil
|
51
53
|
def self.configure(options)
|
52
54
|
raise ArgumentError, ':api_id does not exist in options hash' if options[:api_id].nil?
|
@@ -67,6 +69,7 @@ module Osm
|
|
67
69
|
@@default_cache_ttl = options[:default_cache_ttl].to_i unless options[:default_cache_ttl].nil?
|
68
70
|
@@cache_prepend_to_key = options[:cache_prepend_to_key].to_s unless options[:cache_prepend_to_key].nil?
|
69
71
|
@@cache = options[:cache]
|
72
|
+
@@debug = !!options[:debug]
|
70
73
|
nil
|
71
74
|
end
|
72
75
|
|
@@ -489,12 +492,13 @@ module Osm
|
|
489
492
|
data = perform_query("users.php?action=register§ionid=#{section_id}&termid=#{term_id}", api_data)
|
490
493
|
|
491
494
|
data = data['items']
|
495
|
+
to_return = []
|
492
496
|
data.each do |item|
|
493
|
-
|
497
|
+
to_return.push Osm::RegisterData.from_api(item)
|
494
498
|
end
|
495
499
|
self.user_can_access :register, section_id, api_data
|
496
500
|
cache_write("register-#{section_id}-#{term_id}", data, :expires_in => @@default_cache_ttl/2)
|
497
|
-
return
|
501
|
+
return to_return
|
498
502
|
end
|
499
503
|
|
500
504
|
# Create an evening in OSM
|
@@ -595,6 +599,11 @@ module Osm
|
|
595
599
|
end
|
596
600
|
end
|
597
601
|
|
602
|
+
if @@debug
|
603
|
+
puts "Making OSM API request to #{url}"
|
604
|
+
puts api_data.to_s
|
605
|
+
end
|
606
|
+
|
598
607
|
begin
|
599
608
|
result = HTTParty.post("#{@base_url}/#{url}", {:body => api_data})
|
600
609
|
rescue SocketError, TimeoutError, OpenSSL::SSL::SSLError
|
@@ -602,6 +611,11 @@ module Osm
|
|
602
611
|
end
|
603
612
|
raise ConnectionError, "HTTP Status code was #{result.response.code}" if !result.response.code.eql?('200')
|
604
613
|
|
614
|
+
if @@debug
|
615
|
+
puts "Result from OSM request to #{url}"
|
616
|
+
puts result.response.body
|
617
|
+
end
|
618
|
+
|
605
619
|
raise Error, result.response.body unless looks_like_json?(result.response.body)
|
606
620
|
decoded = ActiveSupport::JSON.decode(result.response.body)
|
607
621
|
osm_error = get_osm_error(decoded)
|
data/lib/osm/member.rb
CHANGED
@@ -68,9 +68,10 @@ module Osm
|
|
68
68
|
# Initialize a new Member
|
69
69
|
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
70
70
|
def initialize(attributes={})
|
71
|
-
[:id, :section_id
|
71
|
+
[:id, :section_id].each do |attribute|
|
72
72
|
raise ArgumentError, ":#{attribute} must be nil or a Fixnum > 0" unless attributes[attribute].nil? || (attributes[attribute].is_a?(Fixnum) && attributes[attribute] > 0)
|
73
73
|
end
|
74
|
+
raise ArgumentError, ':grouping_id must be nil or a Fixnum >= -2' unless attributes[:grouping_id].nil? || (attributes[:grouping_id].is_a?(Fixnum) && attributes[:grouping_id] >= -2)
|
74
75
|
[:joined_years, :grouping_leader].each do |attribute|
|
75
76
|
raise ArgumentError, ":#{attribute} must be nil or a Fixnum >= -1" unless attributes[attribute].nil? || (attributes[attribute].is_a?(Fixnum) && attributes[attribute] >= -1)
|
76
77
|
end
|
data/lib/osm/register_data.rb
CHANGED
@@ -21,9 +21,10 @@ module Osm
|
|
21
21
|
# Initialize a new RegisterData
|
22
22
|
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
23
23
|
def initialize(attributes={})
|
24
|
-
[:member_id, :
|
24
|
+
[:member_id, :section_id].each do |attribute|
|
25
25
|
raise ArgumentError, ":#{attribute} must be nil or a Fixnum > 0" unless attributes[attribute].nil? || (attributes[attribute].is_a?(Fixnum) && attributes[attribute] > 0)
|
26
26
|
end
|
27
|
+
raise ArgumentError, ':grouping_id must be nil or a Fixnum >= -2' unless attributes[:grouping_id].nil? || (attributes[:grouping_id].is_a?(Fixnum) && attributes[:grouping_id] >= -2)
|
27
28
|
raise ArgumentError, ':total must be a Fixnum >= 0' unless (attributes[:total].is_a?(Fixnum) && attributes[:total] >= 0)
|
28
29
|
[:first_name, :last_name].each do |attribute|
|
29
30
|
raise ArgumentError, "#{attribute} must be nil or a String" unless attributes[attribute].nil? || attributes[attribute].is_a?(String)
|
data/lib/osm/section.rb
CHANGED
@@ -32,9 +32,10 @@ module Osm
|
|
32
32
|
# Initialize a new Section
|
33
33
|
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
34
34
|
def initialize(attributes={})
|
35
|
+
puts ":num_scouts = #{attributes[:num_scouts].inspect}"
|
35
36
|
raise ArgumentError, ':id must be nil or a Fixnum > 0' unless attributes[:id].nil? || (attributes[:id].is_a?(Fixnum) && attributes[:id] > 0)
|
36
37
|
raise ArgumentError, ':section_name must be nil or a String' unless attributes[:section_name].nil? || attributes[:section_name].is_a?(String)
|
37
|
-
raise ArgumentError, ':num_scouts must be nil or a Fixnum >= 0' unless attributes[:num_scouts].nil? || (attributes[:num_scouts].is_a?(Fixnum) && attributes[:num_scouts]
|
38
|
+
raise ArgumentError, ':num_scouts must be nil or a Fixnum >= 0' unless attributes[:num_scouts].nil? || (attributes[:num_scouts].is_a?(Fixnum) && attributes[:num_scouts] >= 0)
|
38
39
|
[:column_names, :fields, :intouch_fields, :mobile_fields].each do |attribute|
|
39
40
|
raise ArgumentError, ":#{attribute} must be nil or a Hash" unless attributes[attribute].nil? || attributes[attribute].is_a?(Hash)
|
40
41
|
end
|
data/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-30 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &87769510 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *87769510
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: httparty
|
27
|
-
requirement: &
|
27
|
+
requirement: &87769250 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *87769250
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &87768850 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *87768850
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &87768490 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *87768490
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: fakeweb
|
60
|
-
requirement: &
|
60
|
+
requirement: &87768140 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *87768140
|
69
69
|
description: Use the Online Scout Manager API (https://www.onlinescoutmanager.co.uk)
|
70
70
|
to retrieve and save data.
|
71
71
|
email:
|