osm 0.0.9 → 0.0.10
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.
- data/CHANGELOG.md +5 -0
- data/lib/osm/activity.rb +4 -4
- data/lib/osm/api.rb +15 -11
- data/lib/osm/api_access.rb +1 -1
- data/lib/osm/due_badges.rb +3 -3
- data/lib/osm/role.rb +1 -1
- data/lib/osm/section.rb +5 -5
- data/spec/osm/api_strangeness_spec.rb +8 -0
- data/version.rb +1 -1
- metadata +11 -11
data/CHANGELOG.md
CHANGED
data/lib/osm/activity.rb
CHANGED
@@ -64,10 +64,10 @@ module Osm
|
|
64
64
|
@deletable = data['deletable'] ? true : false
|
65
65
|
@used = data['used'].to_i
|
66
66
|
@versions = data['versions']
|
67
|
-
@sections = Osm::make_array_of_symbols(data['sections']
|
68
|
-
@tags = data['tags']
|
69
|
-
@files = data['files']
|
70
|
-
@badges = data['badges']
|
67
|
+
@sections = data['sections'].is_a?(Array) ? Osm::make_array_of_symbols(data['sections']) : []
|
68
|
+
@tags = data['tags'].is_a?(Array) ? data['tags'] : []
|
69
|
+
@files = data['files'].is_a?(Array) ? data['files'] : []
|
70
|
+
@badges = data['badges'].is_a?(Array) ? data['badges'] : []
|
71
71
|
|
72
72
|
# Clean versions hashes
|
73
73
|
@versions.each do |version|
|
data/lib/osm/api.rb
CHANGED
@@ -269,7 +269,7 @@ module Osm
|
|
269
269
|
# @return [Array<Osm::Evening>]
|
270
270
|
def get_programme(section, term, options={}, api_data={})
|
271
271
|
section_id = id_for_section(section)
|
272
|
-
term_id = id_for_term(term)
|
272
|
+
term_id = id_for_term(term, section)
|
273
273
|
|
274
274
|
if !options[:no_cache] && cache_exist?("programme-#{section_id}-#{term_id}") && self.user_can_access?(:programme, section_id, api_data)
|
275
275
|
return cache_read("programme-#{section_id}-#{term_id}")
|
@@ -329,7 +329,7 @@ module Osm
|
|
329
329
|
# @return [Array<Osm::Member>]
|
330
330
|
def get_members(section, term=nil, options={}, api_data={})
|
331
331
|
section_id = id_for_section(section)
|
332
|
-
term_id = id_for_term(term)
|
332
|
+
term_id = id_for_term(term, section)
|
333
333
|
|
334
334
|
if !options[:no_cache] && cache_exist?("members-#{section_id}-#{term_id}") && self.user_can_access?(:member, section_id, api_data)
|
335
335
|
return cache_read("members-#{section_id}-#{term_id}")
|
@@ -428,7 +428,7 @@ module Osm
|
|
428
428
|
# @return [Osm::DueBadges]
|
429
429
|
def get_due_badges(section, term=nil, options={}, api_data={})
|
430
430
|
section_id = id_for_section(section)
|
431
|
-
term_id = id_for_term(term)
|
431
|
+
term_id = id_for_term(term, section)
|
432
432
|
|
433
433
|
if !options[:no_cache] && cache_exist?("due_badges-#{section_id}-#{term_id}") && self.user_can_access?(:badge, section_id, api_data)
|
434
434
|
return cache_read("due_badges-#{section_id}-#{term_id}")
|
@@ -452,7 +452,7 @@ module Osm
|
|
452
452
|
# @return [Array<Hash>] representing the rows of the register
|
453
453
|
def get_register_structure(section, term=nil, options={}, api_data={})
|
454
454
|
section_id = id_for_section(section)
|
455
|
-
term_id = id_for_term(term)
|
455
|
+
term_id = id_for_term(term, section)
|
456
456
|
|
457
457
|
if !options[:no_cache] && cache_exist?("register_structure-#{section_id}-#{term_id}") && self.user_can_access?(:register, section_id, api_data)
|
458
458
|
return cache_read("register_structure-#{section_id}-#{term_id}")
|
@@ -480,7 +480,7 @@ module Osm
|
|
480
480
|
# @return [Array<Hash>] representing the attendance of each member
|
481
481
|
def get_register(section, term=nil, options={}, api_data={})
|
482
482
|
section_id = id_for_section(section)
|
483
|
-
term_id = id_for_term(term)
|
483
|
+
term_id = id_for_term(term, section)
|
484
484
|
|
485
485
|
if !options[:no_cache] && cache_exist?("register-#{section_id}-#{term_id}") && self.user_can_access?(:register, section_id, api_data)
|
486
486
|
return cache_read("register-#{section_id}-#{term_id}")
|
@@ -651,17 +651,21 @@ module Osm
|
|
651
651
|
# @param [String, Symbol] id_method the method to call on cl to get the ID
|
652
652
|
# @return [Fixnum] the ID
|
653
653
|
def id_for(cl, value, error_name, id_method=:id)
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
654
|
+
if value.is_a?(cl)
|
655
|
+
value = value.send(id_method)
|
656
|
+
else
|
657
|
+
raise(ArgumentError, "Invalid type for #{error_name}") unless value.is_a?(Fixnum)
|
658
|
+
end
|
659
|
+
|
660
|
+
raise(ArgumentError, "Invalid #{error_name} ID") unless value > 0
|
661
|
+
return value
|
658
662
|
end
|
659
663
|
|
660
664
|
def id_for_section(section)
|
661
665
|
id_for(Osm::Section, section, 'section')
|
662
666
|
end
|
663
|
-
def id_for_term(term)
|
664
|
-
return term.nil? ? Osm::find_current_term_id(self,
|
667
|
+
def id_for_term(term, section)
|
668
|
+
return term.nil? ? Osm::find_current_term_id(self, id_for_section(section), api_data) : id_for(Osm::Term, term, 'term')
|
665
669
|
end
|
666
670
|
|
667
671
|
end
|
data/lib/osm/api_access.rb
CHANGED
@@ -15,7 +15,7 @@ module Osm
|
|
15
15
|
def initialize(data)
|
16
16
|
@id = data['apiid'].to_i
|
17
17
|
@name = data['name']
|
18
|
-
@permissions = data['permissions']
|
18
|
+
@permissions = data['permissions'].is_a?(Hash) ? data['permissions'] : {}
|
19
19
|
|
20
20
|
# Rubyfy permissions hash
|
21
21
|
@permissions.keys.each do |key|
|
data/lib/osm/due_badges.rb
CHANGED
@@ -8,15 +8,15 @@ module Osm
|
|
8
8
|
# @!attribute [r] by_member
|
9
9
|
# @return [Hash] the due badges grouped by member
|
10
10
|
# @!attribute [r] totals
|
11
|
-
# @return [Hash] the total number of each
|
11
|
+
# @return [Hash] the total number of each badge which is due
|
12
12
|
|
13
13
|
# Initialize a new Event using the hash returned by the API call
|
14
14
|
# @param data the hash of data for the object returned by the API
|
15
15
|
def initialize(data)
|
16
16
|
data = {} unless data.is_a?(Hash)
|
17
17
|
|
18
|
-
@pending = Osm::symbolize_hash(data['pending']
|
19
|
-
@descriptions = Osm::symbolize_hash(data['description']
|
18
|
+
@pending = data['pending'].is_a?(Hash) ? Osm::symbolize_hash(data['pending']) : {}
|
19
|
+
@descriptions = data['description'].is_a?(Hash) ? Osm::symbolize_hash(data['description']) : {}
|
20
20
|
|
21
21
|
@pending.each_key do |key|
|
22
22
|
@pending[key].each_with_index do |item, index|
|
data/lib/osm/role.rb
CHANGED
@@ -18,7 +18,7 @@ module Osm
|
|
18
18
|
@section = Osm::Section.new(data['sectionid'], data['sectionname'], ActiveSupport::JSON.decode(data['sectionConfig']), self)
|
19
19
|
@group_name = data['groupname']
|
20
20
|
@group_id = Osm::to_i_or_nil(data['groupid'])
|
21
|
-
@permissions = Osm::symbolize_hash(data['permissions']
|
21
|
+
@permissions = data['permissions'].is_a?(Hash) ? Osm::symbolize_hash(data['permissions']) : {}
|
22
22
|
|
23
23
|
# Convert permission values to a number
|
24
24
|
@permissions.each_key do |key|
|
data/lib/osm/section.rb
CHANGED
@@ -44,11 +44,11 @@ module Osm
|
|
44
44
|
@subscription_expires = data['subscription_expires'] ? Date.parse(data['subscription_expires'], 'yyyy-mm-dd') : nil
|
45
45
|
@type = !data['sectionType'].nil? ? data['sectionType'].to_sym : :unknown
|
46
46
|
@num_scouts = data['numscouts']
|
47
|
-
@column_names = Osm::symbolize_hash(data['columnNames']
|
48
|
-
@fields = Osm::symbolize_hash(data['fields']
|
49
|
-
@intouch_fields = Osm::symbolize_hash(data['intouch']
|
50
|
-
@mobile_fields = Osm::symbolize_hash(data['mobFields']
|
51
|
-
@extra_records = data['extraRecords']
|
47
|
+
@column_names = data['columnNames'].is_a?(Hash) ? Osm::symbolize_hash(data['columnNames']) : {}
|
48
|
+
@fields = data['fields'].is_a?(Hash) ? Osm::symbolize_hash(data['fields']) : {}
|
49
|
+
@intouch_fields = data['intouch'].is_a?(Hash) ? Osm::symbolize_hash(data['intouch']) : {}
|
50
|
+
@mobile_fields = data['mobFields'].is_a?(Hash) ? Osm::symbolize_hash(data['mobFields']) : {}
|
51
|
+
@extra_records = data['extraRecords'].is_a?(Array) ? data['extraRecords'] : []
|
52
52
|
@role = role
|
53
53
|
|
54
54
|
# Symbolise the keys in each hash of the extra_records array
|
@@ -45,4 +45,12 @@ describe "Online Scout Manager API Strangeness" do
|
|
45
45
|
@api.get_events(1).should == []
|
46
46
|
end
|
47
47
|
|
48
|
+
|
49
|
+
it "handles a section config where fields is an empty array" do
|
50
|
+
body = '[{"sectionConfig":"{\"subscription_level\":3,\"subscription_expires\":\"2013-01-05\",\"columnNames\":{\"phone1\":\"Home Phone\",\"phone2\":\"Parent 1 Phone\",\"address\":\"Member\'s Address\",\"phone3\":\"Parent 2 Phone\",\"address2\":\"Address 2\",\"phone4\":\"Alternate Contact Phone\",\"subs\":\"Gender\",\"email1\":\"Parent 1 Email\",\"medical\":\"Medical / Dietary\",\"email2\":\"Parent 2 Email\",\"ethnicity\":\"Gift Aid\",\"email3\":\"Member\'s Email\",\"religion\":\"Religion\",\"email4\":\"Email 4\",\"school\":\"School\"},\"numscouts\":10,\"hasUsedBadgeRecords\":true,\"hasProgramme\":true,\"extraRecords\":[{\"name\":\"Subs\",\"extraid\":\"529\"}],\"wizard\":\"false\",\"fields\":[],\"intouch\":{\"address\":true,\"address2\":false,\"email1\":false,\"email2\":false,\"email3\":false,\"email4\":false,\"phone1\":true,\"phone2\":true,\"phone3\":true,\"phone4\":true,\"medical\":false},\"mobFields\":{\"email1\":false,\"email2\":false,\"email3\":false,\"email4\":false,\"address\":true,\"address2\":false,\"phone1\":true,\"phone2\":true,\"phone3\":true,\"phone4\":true,\"school\":false,\"religion\":false,\"ethnicity\":true,\"medical\":true,\"patrol\":true,\"subs\":false}}","groupname":"1st Somewhere","groupid":"1","groupNormalised":"1","sectionid":"1","sectionname":"Section 1","section":"cubs","isDefault":"1","permissions":{"badge":100,"member":100,"user":100,"register":100,"contact":100,"programme":100,"originator":1,"events":100,"finance":100,"flexi":100}}]'
|
51
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :body => body)
|
52
|
+
|
53
|
+
@api.get_section(1).fields.should == {}
|
54
|
+
|
55
|
+
end
|
48
56
|
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.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-08-19 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &81097930 !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: *81097930
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: httparty
|
27
|
-
requirement: &
|
27
|
+
requirement: &81097720 !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: *81097720
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &81097480 !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: *81097480
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &81097190 !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: *81097190
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: fakeweb
|
60
|
-
requirement: &
|
60
|
+
requirement: &81083410 !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: *81083410
|
69
69
|
description: Use the Online Scout Manager API (https://www.onlinescoutmanager.co.uk)
|
70
70
|
to retrieve and save data.
|
71
71
|
email:
|