osm 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ ## Version 0.1.7
2
+
3
+ * Ignore sections of type discount - assuming they're a strange symtom of how OSM handles discount codes
4
+
1
5
  ## Version 0.1.6
2
6
 
3
7
  * Internal changes due to OSM adding total rows in register and fexi record data (the total rows are ignored)
@@ -95,42 +95,44 @@ module Osm
95
95
  result = Array.new
96
96
  permissions = Hash.new
97
97
  data.each do |role_data|
98
- section_data = ActiveSupport::JSON.decode(role_data['sectionConfig'])
99
-
100
- # Make sense of flexi records
101
- fr_data = []
102
- flexi_records = []
103
- fr_data = section_data['extraRecords'] if section_data['extraRecords'].is_a?(Array)
104
- fr_data = section_data['extraRecords'].values if section_data['extraRecords'].is_a?(Hash)
105
- fr_data.each do |record_data|
106
- # Expect item to be: {:name=>String, :extraid=>Fixnum}
107
- # Sometimes get item as: [String, {"name"=>String, "extraid"=>Fixnum}]
108
- record_data = record_data[1] if record_data.is_a?(Array)
109
- flexi_records.push FlexiRecord.new(
110
- :id => Osm::to_i_or_nil(record_data['extraid']),
111
- :name => record_data['name'],
98
+ unless role_data['section'].eql?('discount') # It's not an actual section
99
+ section_data = ActiveSupport::JSON.decode(role_data['sectionConfig'])
100
+
101
+ # Make sense of flexi records
102
+ fr_data = []
103
+ flexi_records = []
104
+ fr_data = section_data['extraRecords'] if section_data['extraRecords'].is_a?(Array)
105
+ fr_data = section_data['extraRecords'].values if section_data['extraRecords'].is_a?(Hash)
106
+ fr_data.each do |record_data|
107
+ # Expect item to be: {:name=>String, :extraid=>Fixnum}
108
+ # Sometimes get item as: [String, {"name"=>String, "extraid"=>Fixnum}]
109
+ record_data = record_data[1] if record_data.is_a?(Array)
110
+ flexi_records.push FlexiRecord.new(
111
+ :id => Osm::to_i_or_nil(record_data['extraid']),
112
+ :name => record_data['name'],
113
+ )
114
+ end
115
+
116
+ section = new(
117
+ :id => Osm::to_i_or_nil(role_data['sectionid']),
118
+ :name => role_data['sectionname'],
119
+ :subscription_level => (subscription_levels[section_data['subscription_level']] || :unknown),
120
+ :subscription_expires => Osm::parse_date(section_data['subscription_expires']),
121
+ :type => !section_data['sectionType'].nil? ? section_data['sectionType'].to_sym : (!section_data['section'].nil? ? section_data['section'].to_sym : :unknown),
122
+ :num_scouts => section_data['numscouts'],
123
+ :column_names => section_data['columnNames'].is_a?(Hash) ? Osm::symbolize_hash(section_data['columnNames']) : {},
124
+ :fields => section_data['fields'].is_a?(Hash) ? Osm::symbolize_hash(section_data['fields']) : {},
125
+ :intouch_fields => section_data['intouch'].is_a?(Hash) ? Osm::symbolize_hash(section_data['intouch']) : {},
126
+ :mobile_fields => section_data['mobFields'].is_a?(Hash) ? Osm::symbolize_hash(section_data['mobFields']) : {},
127
+ :flexi_records => flexi_records.sort,
128
+ :group_id => role_data['groupid'],
129
+ :group_name => role_data['groupname'],
112
130
  )
113
- end
114
131
 
115
- section = new(
116
- :id => Osm::to_i_or_nil(role_data['sectionid']),
117
- :name => role_data['sectionname'],
118
- :subscription_level => (subscription_levels[section_data['subscription_level']] || :unknown),
119
- :subscription_expires => Osm::parse_date(section_data['subscription_expires']),
120
- :type => !section_data['sectionType'].nil? ? section_data['sectionType'].to_sym : :unknown,
121
- :num_scouts => section_data['numscouts'],
122
- :column_names => section_data['columnNames'].is_a?(Hash) ? Osm::symbolize_hash(section_data['columnNames']) : {},
123
- :fields => section_data['fields'].is_a?(Hash) ? Osm::symbolize_hash(section_data['fields']) : {},
124
- :intouch_fields => section_data['intouch'].is_a?(Hash) ? Osm::symbolize_hash(section_data['intouch']) : {},
125
- :mobile_fields => section_data['mobFields'].is_a?(Hash) ? Osm::symbolize_hash(section_data['mobFields']) : {},
126
- :flexi_records => flexi_records.sort,
127
- :group_id => role_data['groupid'],
128
- :group_name => role_data['groupname'],
129
- )
130
-
131
- result.push section
132
- cache_write(api, ['section', section.id], section)
133
- permissions.merge!(section.id => make_permissions_hash(role_data['permissions']))
132
+ result.push section
133
+ cache_write(api, ['section', section.id], section)
134
+ permissions.merge!(section.id => make_permissions_hash(role_data['permissions']))
135
+ end
134
136
  end
135
137
 
136
138
  set_user_permissions(api, get_user_permissions(api).merge(permissions))
@@ -178,7 +180,9 @@ module Osm
178
180
 
179
181
  all_permissions = Hash.new
180
182
  data.each do |item|
181
- all_permissions.merge!(Osm::to_i_or_nil(item['sectionid']) => make_permissions_hash(item['permissions']))
183
+ unless item['section'].eql?('discount') # It's not an actual section
184
+ all_permissions.merge!(Osm::to_i_or_nil(item['sectionid']) => make_permissions_hash(item['permissions']))
185
+ end
182
186
  end
183
187
  cache_write(api, cache_key, all_permissions)
184
188
  return all_permissions
@@ -295,4 +295,18 @@ describe "Online Scout Manager API Strangeness" do
295
295
  section.get_notepad(@api).should == ''
296
296
  end
297
297
 
298
+ it "handles skipping of a 'discount' section" do
299
+ body = [
300
+ {"sectionConfig"=>"{\"subscription_level\":1,\"subscription_expires\":\"2013-01-05\",\"sectionType\":\"beavers\",\"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\":[],\"wizard\":\"false\",\"fields\":{\"email1\":true,\"email2\":true,\"email3\":true,\"email4\":false,\"address\":true,\"address2\":false,\"phone1\":true,\"phone2\":true,\"phone3\":true,\"phone4\":true,\"school\":false,\"religion\":true,\"ethnicity\":true,\"medical\":true,\"patrol\":true,\"subs\":true,\"saved\":true},\"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"=>"3rd Somewhere", "groupid"=>"3", "groupNormalised"=>"1", "sectionid"=>"1", "sectionname"=>"Section 1", "section"=>"beavers", "isDefault"=>"1", "permissions"=>{"badge"=>100, "member"=>100, "user"=>100, "register"=>100, "contact"=>100, "programme"=>100, "originator"=>1, "events"=>100, "finance"=>100, "flexi"=>100}},
301
+ {"sectionConfig"=>"{\"code\":1,\"districts\":[\"Loddon\",\"Kennet\"]}","groupname"=>"Berkshire","groupid"=>"2","groupNormalised"=>"1","sectionid"=>"3","sectionname"=>"County Admin","section"=>"discount","isDefault"=>"0","permissions"=>{"districts"=>["Loddon"]}}
302
+ ]
303
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :body => body.to_json)
304
+
305
+ sections = Osm::Section.get_all(@api)
306
+ sections.size.should == 1
307
+ section = sections[0]
308
+ section.should_not be_nil
309
+ section.id.should == 1
310
+ end
311
+
298
312
  end
data/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Osm
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
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.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-11-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &78858770 !ruby/object:Gem::Requirement
16
+ requirement: &84367040 !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: *78858770
24
+ version_requirements: *84367040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &78858400 !ruby/object:Gem::Requirement
27
+ requirement: &84366580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.9'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *78858400
35
+ version_requirements: *84366580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: active_attr
38
- requirement: &78858050 !ruby/object:Gem::Requirement
38
+ requirement: &84365970 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.6'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *78858050
46
+ version_requirements: *84365970
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activemodel
49
- requirement: &78857710 !ruby/object:Gem::Requirement
49
+ requirement: &84365620 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '3.2'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *78857710
57
+ version_requirements: *84365620
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &78857360 !ruby/object:Gem::Requirement
60
+ requirement: &84365110 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '10.0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *78857360
68
+ version_requirements: *84365110
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &78857020 !ruby/object:Gem::Requirement
71
+ requirement: &84364610 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '2.11'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *78857020
79
+ version_requirements: *84364610
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: fakeweb
82
- requirement: &78856600 !ruby/object:Gem::Requirement
82
+ requirement: &84364270 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '1.3'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *78856600
90
+ version_requirements: *84364270
91
91
  description: Use the Online Scout Manager API (https://www.onlinescoutmanager.co.uk)
92
92
  to retrieve and save data.
93
93
  email: