dmtd_vbmapp_data 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b6bc8d28e9e614d0e592527719a19c36f80aed6
4
+ data.tar.gz: ae285530bf3d1beab9b092645a645c858c7e2c1b
5
+ SHA512:
6
+ metadata.gz: aa6c9a4d8c78fab9c1a605fc0d03a82bae480832f302045adb381a0d3152823d7b4ee5336ae2372a8826b09aa194c1011e06927305405fa572a69cd6e9615114
7
+ data.tar.gz: 4d9df7246386e2e7a252e4370f93d3d8ef2fabfd6ab4e4f100d047153cd1c720ed50fa3332ec3e73b1586d592ad1fd1c3cecb9ac8db5ccf04a04b62ed062f59b
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1.0
5
+
6
+ env:
7
+ global:
8
+ - secure: gP248+snjbNPc0Uk6+rcTqRCVOrC7xsI9kFDQMnC+k04qkZ4B2ZJbz8ZFhws1XFAd0SNhEsmqnxVuTwAIUxdsJpe8eEqUFIYpNRWz6KNL58yADmQX84BjeNLBM4BxPIej4crr+1i++KxW9WVMV1SAA6/5NQ9wR0fCC39HyaVmgk=
9
+ - secure: Tv043DGoNh8bconcyqXVeWPnR81TrbLC2xwiUbdE6Utm9I5s34aqCjeiv1oV8Dd/OfqceHW9exQD9qBgD9VHsV+2VQhuamjwI4Oy4/PwHyyaMuSVKgvQsHfJRdxMNQbHNxfdYBhf4W6yYbSWquP8JzO3fnLtXEVEGDrDBxI3CRg=
10
+ - secure: GRXGSJG3ygT//t/ADWGLV8G9xYgAs2twmMV9vjP8qpCDn0ijlk3KpwrieqO+Ewz4ru1u1GS6ha5KFlTA5pWRdzc75u7N7xHFbMnLSMe74U54pU12xuAgwo5mGjGm9KcjCRlR5d2aKAcuI2geTz2dfWAZTrjak7mQcy1APUoBmxk=
11
+
12
+ before_install:
13
+ - gem install bundler --no-rdoc --no-ri --no-document --quiet
14
+
15
+ script:
16
+ - bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dmtd_vbmapp_data.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Data Makes the Difference, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # DmtdVbmapp
2
+
3
+ [![CI Status](http://img.shields.io/travis/foscomputerservices/dmtd_vbmapp_data.svg?style=flat)](https://travis-ci.org/foscomputerservices/dmtd_vbmapp_data)
4
+ [![Version](https://img.shields.io/gem/v/dmtd_vbmapp_data.svg?style=flat)](http://www.rubydoc.info/github/foscomputerservices/dmtd_vbmapp_data/master)
5
+ [![License](https://img.shields.io/gem/l/dmtd_vbmapp_data.svg?style=flat)](http://www.rubydoc.info/github/foscomputerservices/dmtd_vbmapp_data/master)
6
+ [![Platform](https://img.shields.io/gem/p/dmtd_vbmapp_data.svg?style=flat)](http://www.rubydoc.info/github/foscomputerservices/dmtd_vbmapp_data/master)
7
+
8
+ The gem is provided to ease access to DMTD's vbmappapp.com REST service.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'dmtd_vbmapp_data'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install dmtd_vbmapp_data
25
+
26
+ ## Configuration
27
+
28
+ Upon receiving an authorization token from Data Makes the Difference, add the following lines to your application's configuration:
29
+
30
+ ```ruby
31
+ DmtdVbmappData.configure server_url: 'your_assigned_web_service_url' # It can also be 'http://data-sandbox.vbmappapp.com' for testing purposes
32
+ DmtdVbmappData.configure auth_token: 'your_auth_token'
33
+ DmtdVbmappData.configure organization_id: your_organization_id
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( https://github.com/[my-github-username]/dmtd_vbmapp_data/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'dmtd_vbmapp_data'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dmtd_vbmapp_data/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'dmtd_vbmapp_data'
8
+ spec.version = DmtdVbmappData::VERSION
9
+ spec.authors = ['David Hunt']
10
+ spec.email = ['support@vbmappapp.com']
11
+
12
+ spec.summary = %q{Ruby gem to simplify access to DMTD's VB-MAPP REST service}
13
+ spec.description = %q{This gem provides a simplified Ruby API for DMTD customers accessing the vbmappapp.com REST service.}
14
+ spec.homepage = 'https://github.com/foscomputerservices/dmtd_vbmapp_data'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'psych', '~> 2.0'
23
+ spec.add_dependency 'json', '~> 1.8'
24
+ spec.add_dependency 'hashie', '~> 3.4'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.9'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+
29
+ spec.add_development_dependency 'rspec', '~> 3.2'
30
+ end
@@ -0,0 +1,52 @@
1
+ # External deps
2
+ require 'psych'
3
+ require 'json'
4
+ require 'hashie'
5
+
6
+ # Our classes
7
+ require 'dmtd_vbmapp_data/client'
8
+
9
+ require 'dmtd_vbmapp_data/guide'
10
+ require 'dmtd_vbmapp_data/guide_chapter'
11
+ require 'dmtd_vbmapp_data/guide_chapter_section'
12
+ require 'dmtd_vbmapp_data/guide_section_sub_section'
13
+
14
+ require 'dmtd_vbmapp_data/vbmapp'
15
+ require 'dmtd_vbmapp_data/vbmapp_area'
16
+ require 'dmtd_vbmapp_data/vbmapp_area_group'
17
+ require 'dmtd_vbmapp_data/vbmapp_area_question'
18
+ require 'dmtd_vbmapp_data/vbmapp_area_response'
19
+
20
+ require 'dmtd_vbmapp_data/version'
21
+
22
+ module DmtdVbmappData
23
+
24
+ @config = {
25
+ server_url: 'http://data-sandbox.vbmappapp.com',
26
+ auth_token: '',
27
+ organization_id: nil
28
+ }
29
+
30
+ @valid_config_keys = @config.keys
31
+
32
+ def self.configure(opts = {})
33
+ opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
34
+ end
35
+
36
+ def self.configure_with(path_to_yaml_file)
37
+ begin
38
+ config = Psych::load(IO.read(path_to_yaml_file))
39
+ rescue Errno::ENOENT
40
+ log(:warning, "YAML configuration file couldn't be found. Using defaults."); return
41
+ rescue Psych::SyntaxError
42
+ log(:warning, 'YAML configuration file contains invalid syntax. Using defaults.'); return
43
+ end
44
+
45
+ configure(config)
46
+ end
47
+
48
+ def self.config
49
+ @config
50
+ end
51
+
52
+ end
@@ -0,0 +1,132 @@
1
+ require 'dmtd_vbmapp_data/request_helpers'
2
+
3
+ module DmtdVbmappData
4
+
5
+ GENDER_MALE=1
6
+ GENDER_FEMALE=2
7
+
8
+ # Provides for the creating and retrieving of client instances in the VB-MAPP Data Server.
9
+ class Client
10
+
11
+ attr_reader :id
12
+ attr_reader :organization_id
13
+ attr_reader :code
14
+ attr_reader :date_of_birth
15
+ attr_reader :first_name
16
+ attr_reader :last_name
17
+ attr_reader :settings
18
+ attr_reader :created_at
19
+ attr_reader :updated_at
20
+ attr_reader :server_response_code
21
+
22
+ # Creates a new client on the VB-MAPP Data Server
23
+ #
24
+ # Note that +code+ may be specified as a key of the corresponding record in your database.
25
+ # This allows the client to be referred to later on via this key as opposed to the id
26
+ # generated by our system. Using this option means that your application data is not required
27
+ # to store a new id for the client, but can use your existing id (primary key).
28
+ #
29
+ # This operation blocks until it receives a response from the VB-MAPP Data Server.
30
+ #
31
+ # If +id+ is specified, then the instance will *not* be sent to the server, it is assumed to already be there.
32
+ #
33
+ # Params:
34
+ # +date_of_birth+:: the date of birth of the client as a ruby Date object
35
+ # +gender+:: the gender of the client, either +GENDER_MALE+ or +GENDER_FEMALE+
36
+ # +id+:: the vbmapp_data server's identifier for this client (may be nil)
37
+ # +organization_id+:: the organization identifier (may be nil, if so DmtdVbmappData.config['organization_id'] will be used)
38
+ # +code+:: a code that can be used to refer to the client; possibly a key in the customer's database (may be nil)
39
+ # +first_name+:: the first name of the client (may be nil)
40
+ # +last_name+:: the last name of the client (may be nil)
41
+ # +settings+:: a string value that can be associated with the client (may be nil)
42
+ def initialize(opts)
43
+ @date_of_birth = opts.fetch(:date_of_birth)
44
+ @gender = opts.fetch(:gender)
45
+ @id = opts.fetch(:id, nil)
46
+ @organization_id = opts.fetch(:organization_id, DmtdVbmappData.config[:organization_id])
47
+ @code = opts.fetch(:code, nil)
48
+ @first_name = opts.fetch(:first_name, nil)
49
+ @last_name = opts.fetch(:last_name, nil)
50
+ @settings = opts.fetch(:settings, nil)
51
+ @server_response_code = opts.fetch(:server_response_code, 200)
52
+
53
+ date = Time.now.utc.to_date
54
+ @created_at = opts.fetch(:created_at, date)
55
+ @updated_at = opts.fetch(:updated_at, date)
56
+
57
+ create_server_client if @id.nil?
58
+ end
59
+
60
+ # Retrieves all existing clients from the VB-MAPP Data Server
61
+ #
62
+ # This operation blocks until it receives a response from the VB-MAPP Data Server.
63
+ #
64
+ # Result:
65
+ # Array of DmtdVbmappData::Client instances or server http response code (integer) if an error was received
66
+ def self.retrieve_clients(opts = {})
67
+ retrieve_server_clients(opts)
68
+ end
69
+
70
+ # Retrieves the guide for the corresponding client instance
71
+ def guide
72
+ Guide.new(client: self)
73
+ end
74
+
75
+ # Retrieves the vbmapp for the corresponding client instance
76
+ def vbmapp
77
+ Vbmapp.new(client: self)
78
+ end
79
+
80
+ private
81
+
82
+ def self.end_point
83
+ '1/clients'
84
+ end
85
+
86
+ def create_server_client
87
+ params = { date_of_birth: @date_of_birth, gender: @gender, organization_id: @organization_id }
88
+ params[:code] = code unless code.nil?
89
+ params[:first_name] = first_name unless first_name.nil?
90
+ params[:last_name] = last_name unless last_name.nil?
91
+ params[:settings] = settings unless settings.nil?
92
+
93
+ proc_response = Client.process_response(RequestHelpers::post_authorized(end_point: Client::end_point, params: {object: params}))
94
+ json = proc_response[:json]
95
+ @server_response_code = proc_response[:code]
96
+
97
+ @id = json[:id] unless json.nil?
98
+ end
99
+
100
+ def self.retrieve_server_clients(opts)
101
+ result = nil
102
+ id = opts.fetch(:id, nil)
103
+ code = opts.fetch(:code, nil)
104
+ organization_id = opts.fetch(:organization_id, 1)
105
+
106
+ params = { organization_id: organization_id }
107
+
108
+ response = RequestHelpers::get_authorized(end_point: Client::end_point, params: params, client_id: id, client_code: code)
109
+ proc_response = process_response(response)
110
+ json_array = proc_response[:json]
111
+ server_response_code = proc_response[:code]
112
+
113
+ result = json_array.map {|json| json[:server_response_code] = server_response_code; Client.new(json) } unless json_array.nil?
114
+ result = server_response_code if json_array.nil?
115
+
116
+ result
117
+ end
118
+
119
+ def self.process_response(response)
120
+ json = nil
121
+ server_response_code = response.code.to_i
122
+
123
+ if server_response_code == 200
124
+ json_body = Hashie.symbolize_keys!(JSON.parse(response.body))
125
+ json = json_body[:response]
126
+ end
127
+
128
+ { json: json, code: server_response_code }
129
+ end
130
+ end
131
+
132
+ end
@@ -0,0 +1,65 @@
1
+ require 'dmtd_vbmapp_data/request_helpers'
2
+
3
+ module DmtdVbmappData
4
+
5
+ # Provides for the retrieving of VB-MAPP Guide content from the VB-MAPP Data Server.
6
+ class Guide
7
+
8
+ attr_reader :client
9
+
10
+ # Creates an accessor for the VB-MAPP Guide on the VB-MAPP Data Server
11
+ #
12
+ # This method does *not* block, simply creates an accessor and returns
13
+ #
14
+ # Params:
15
+ # +client+:: a client instance
16
+ def initialize(opts)
17
+ @client = opts.fetch(:client)
18
+ end
19
+
20
+ # Populates the internal VB-MAPP guide index
21
+ #
22
+ # This index is cached locally and expires once a day.
23
+ #
24
+ # The first call to this method with an expired cache will
25
+ # block until the cache is populated. All subsequent calls
26
+ # will load from the cache.
27
+ #
28
+ # Returns:
29
+ # Array as defined as the result of the 1/guide/index REST api
30
+ def index
31
+ if @guide_index.nil?
32
+ @guide_index = retrieve_guide_index
33
+ end
34
+
35
+ @guide_index
36
+ end
37
+
38
+ # Returns the VB-MAPP Guide chapters
39
+ #
40
+ # Note that this method calls +index+. See that method for
41
+ # its blocking characteristics.
42
+ def chapters
43
+ index.map.with_index {|chapter_json, chapter_num| GuideChapter.new(client: client, chapter_num: chapter_num, chapter_index_json: chapter_json)}
44
+ end
45
+
46
+ private
47
+
48
+ def self.end_point
49
+ '1/guide/index'
50
+ end
51
+
52
+ def retrieve_guide_index
53
+ response = RequestHelpers::get_authorized(end_point: Guide::end_point, params: nil, client_id: @client.id, client_code: @client.code)
54
+ proc_response = RequestHelpers::process_json_response(response)
55
+ json = proc_response[:json]
56
+ server_response_code = proc_response[:code]
57
+
58
+ result = json
59
+ result = server_response_code if json.nil?
60
+
61
+ result
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,74 @@
1
+ require 'dmtd_vbmapp_data/request_helpers'
2
+
3
+ module DmtdVbmappData
4
+
5
+ # Provides for the retrieving of VB-MAPP Guide chapters from the VB-MAPP Data Server.
6
+ class GuideChapter
7
+
8
+ attr_reader :client
9
+ attr_reader :chapter_num
10
+ attr_reader :chapter_title
11
+ attr_reader :chapter_short_title
12
+
13
+ # Creates an accessor for the VB-MAPP Guide Chapter on the VB-MAPP Data Server
14
+ #
15
+ # This method does *not* block, simply creates an accessor and returns
16
+ #
17
+ # Params:
18
+ # +client+:: a client instance
19
+ # +chapter_num+:: the number (index) of the chapter in the Guide's index array
20
+ # +chapter_index_json+:: the guide index json for the chapter
21
+ def initialize(opts)
22
+ @client = opts.fetch(:client)
23
+ @chapter_num = opts.fetch(:chapter_num)
24
+
25
+ index_json = opts.fetch(:chapter_index_json)
26
+ @chapter_title = index_json[:chapterTitle]
27
+ @chapter_short_title = index_json[:chapterShortTitle]
28
+ @sections_index = index_json[:sections]
29
+ end
30
+
31
+ # Returns the preamble of the Guide's chapter
32
+ #
33
+ # This method *does* block as the content is retrieved
34
+ def chapter_preamble
35
+ @chapter_preamble = retrieve_guide_chapter[:chapterPreamble] if @chapter_preamble.nil?
36
+
37
+ @chapter_preamble
38
+ end
39
+
40
+ # Returns the VB-MAPP Guide chapter sections
41
+ #
42
+ # This method does *not* block on server access
43
+ def sections
44
+ @sections = @sections_index.map.with_index { |section_index_json, section_num|
45
+ GuideChapterSection.new(client: client, chapter_num: chapter_num, section_num: section_num, section_index_json: section_index_json)
46
+ } if @sections.nil?
47
+
48
+ @sections
49
+ end
50
+
51
+ private
52
+
53
+ def self.end_point
54
+ '1/guide/chapter'
55
+ end
56
+
57
+ def retrieve_guide_chapter
58
+ params = {
59
+ chapter_num: chapter_num
60
+ }
61
+ response = RequestHelpers::get_authorized(end_point: GuideChapter::end_point, params: params, client_id: @client.id, client_code: @client.code)
62
+ proc_response = RequestHelpers::process_json_response(response)
63
+ json = proc_response[:json]
64
+ server_response_code = proc_response[:code]
65
+
66
+ result = json
67
+ result = server_response_code if json.nil?
68
+
69
+ result
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,75 @@
1
+ require 'dmtd_vbmapp_data/request_helpers'
2
+
3
+ module DmtdVbmappData
4
+
5
+ # Provides for the retrieving of VB-MAPP Guide chapter sections from the VB-MAPP Data Server.
6
+ class GuideChapterSection
7
+
8
+ attr_reader :client
9
+ attr_reader :chapter_num
10
+ attr_reader :section_num
11
+ attr_reader :section_title
12
+ attr_reader :section_short_title
13
+
14
+ # Creates an accessor for the VB-MAPP Guide Chapter Section on the VB-MAPP Data Server
15
+ #
16
+ # This method does *not* block, simply creates an accessor and returns
17
+ #
18
+ # Params:
19
+ # +client+:: a client instance
20
+ # +chapter_num+:: the number (index) of the chapter in the Guide's index array
21
+ # +section_num+:: the number (index) of the section in the chapter's sections array
22
+ # +section_index_json+:: the guide index json for the chapter
23
+ def initialize(opts)
24
+ @client = opts.fetch(:client)
25
+ @chapter_num = opts.fetch(:chapter_num)
26
+ @section_num = opts.fetch(:section_num)
27
+
28
+ index_json = opts.fetch(:section_index_json)
29
+ @section_title = index_json[:sectionTitle]
30
+ @section_short_title = index_json[:sectionShortTitle]
31
+ @subsection_count = index_json[:subsection_count]
32
+ end
33
+
34
+ # Returns the content of the Guide's chapter section
35
+ #
36
+ # This method *does* block as the content is retrieved
37
+ def section_content
38
+ @section_content = retrieve_guide_section[:sectionContent] if @section_content.nil?
39
+
40
+ @section_content
41
+ end
42
+
43
+ # Returns the VB-MAPP Guide section's sub_sections
44
+ def sub_sections
45
+ @sub_sections = (0..@subsection_count-1).map { |sub_section_num|
46
+ GuideSectionSubSection.new(client: client, chapter_num: chapter_num, section_num: section_num, sub_section_num: sub_section_num)
47
+ } if @sub_sections.nil?
48
+
49
+ @sub_sections
50
+ end
51
+
52
+ private
53
+
54
+ def self.end_point
55
+ '1/guide/section'
56
+ end
57
+
58
+ def retrieve_guide_section
59
+ params = {
60
+ chapter_num: chapter_num,
61
+ section_num: section_num
62
+ }
63
+ response = RequestHelpers::get_authorized(end_point: GuideChapterSection::end_point, params: params, client_id: @client.id, client_code: @client.code)
64
+ proc_response = RequestHelpers::process_json_response(response)
65
+ json = proc_response[:json]
66
+ server_response_code = proc_response[:code]
67
+
68
+ result = json
69
+ result = server_response_code if json.nil?
70
+
71
+ result
72
+ end
73
+ end
74
+
75
+ end
@@ -0,0 +1,70 @@
1
+ require 'dmtd_vbmapp_data/request_helpers'
2
+
3
+ module DmtdVbmappData
4
+
5
+ # Provides for the retrieving of VB-MAPP Guide section sub_sections from the VB-MAPP Data Server.
6
+ class GuideSectionSubSection
7
+
8
+ attr_reader :client
9
+ attr_reader :chapter_num
10
+ attr_reader :section_num
11
+ attr_reader :sub_section_num
12
+
13
+ # Creates an accessor for the VB-MAPP Guide Chapter Section on the VB-MAPP Data Server
14
+ #
15
+ # This method does *not* block, simply creates an accessor and returns
16
+ #
17
+ # Params:
18
+ # +client+:: a client instance
19
+ # +chapter_num+:: the number (index) of the chapter in the Guide's index array
20
+ # +section_num+:: the number (index) of the section in the chapter's sections array
21
+ # +sub_section_num+:: the number (index) of the sub_section in the range (0..subsection_count)
22
+ def initialize(opts)
23
+ @client = opts.fetch(:client)
24
+ @chapter_num = opts.fetch(:chapter_num)
25
+ @section_num = opts.fetch(:section_num)
26
+ @sub_section_num = opts.fetch(:sub_section_num)
27
+ end
28
+
29
+ def section_title
30
+ retrieve_guide_sub_section[:sectionTitle]
31
+ end
32
+
33
+ def section_short_title
34
+ retrieve_guide_sub_section[:sectionShortTitle]
35
+ end
36
+
37
+ # Returns the content of the Guide's chapter section
38
+ #
39
+ # This method *does* block as the content is retrieved
40
+ def section_content
41
+ retrieve_guide_sub_section[:sectionContent]
42
+ end
43
+
44
+ private
45
+
46
+ def self.end_point
47
+ '1/guide/sub_section'
48
+ end
49
+
50
+ def retrieve_guide_sub_section
51
+ if @guide_sub_section.nil?
52
+ params = {
53
+ chapter_num: chapter_num,
54
+ section_num: section_num,
55
+ sub_section_num: sub_section_num
56
+ }
57
+ response = RequestHelpers::get_authorized(end_point: GuideSectionSubSection::end_point, params: params, client_id: @client.id, client_code: @client.code)
58
+ proc_response = RequestHelpers::process_json_response(response)
59
+ json = proc_response[:json]
60
+ server_response_code = proc_response[:code]
61
+
62
+ @guide_sub_section = json
63
+ # result = server_response_code if json.nil?
64
+ end
65
+
66
+ @guide_sub_section
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,90 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module DmtdVbmappData
5
+
6
+ class RequestHelpers
7
+
8
+ # GET an authorized message from the vbmappdata server
9
+ #
10
+ # Params:
11
+ # +end_point+:: The end point to post
12
+ # +params+:: The parameters to send to the end point (may be nil)
13
+ # +client_id+:: The client id under which to record the post (may be nil)
14
+ # +client_code+:: The client code under which to record the post (maybe nil)
15
+ def self.get_authorized(opts = {})
16
+ end_point = opts.fetch(:end_point)
17
+ params = opts.fetch(:params, nil)
18
+ client_id = opts.fetch(:client_id, nil)
19
+ client_code = opts.fetch(:client_code, nil)
20
+
21
+ get url(end_point), params, client_id, client_code
22
+ end
23
+
24
+ # POST an authorized message to the vbmappdata server
25
+ #
26
+ # Params:
27
+ # +end_point+:: The end point to post
28
+ # +params+:: The parameters to send to the end point (may be nil)
29
+ # +client_id+:: The client id under which to record the post (may be nil)
30
+ # +client_code+:: The client code under which to record the post (maybe nil)
31
+ def self.post_authorized(opts = {})
32
+ end_point = opts.fetch(:end_point)
33
+ params = opts.fetch(:params, nil)
34
+ client_id = opts.fetch(:client_id, nil)
35
+ client_code = opts.fetch(:client_code, nil)
36
+
37
+ post url(end_point), params, client_id, client_code
38
+ end
39
+
40
+ # Process a JSON response from the server
41
+ #
42
+ # Returns:
43
+ # { json: <json>, code: <response.code.to_i> }
44
+ def self.process_json_response(response)
45
+ json = nil
46
+ server_response_code = response.code.to_i
47
+
48
+ if server_response_code == 200
49
+ json_body = Hashie.symbolize_keys!(JSON.parse(response.body))
50
+ json = json_body[:response]
51
+ end
52
+
53
+ { json: json, code: server_response_code }
54
+ end
55
+
56
+ private
57
+
58
+ def self.get(uri, params, client_id, client_code)
59
+ http = Net::HTTP.new(uri.host, uri.port)
60
+ request = Net::HTTP::Get.new(uri.request_uri)
61
+ add_auth(request, client_id, client_code)
62
+ request.set_form_data params unless params.nil?
63
+
64
+ http.request(request)
65
+ end
66
+
67
+ def self.post(uri, params, client_id, client_code)
68
+ http = Net::HTTP.new(uri.host, uri.port)
69
+ request = Net::HTTP::Post.new(uri.request_uri)
70
+ add_auth(request, client_id, client_code)
71
+ request.body = JSON(params)
72
+
73
+ http.request(request)
74
+ end
75
+
76
+ def self.url(end_point)
77
+ URI.parse("#{DmtdVbmappData.config[:server_url]}/#{end_point}")
78
+ end
79
+
80
+ def self.add_auth(request, client_id = nil, client_code = nil)
81
+ session_token = DmtdVbmappData.config[:auth_token]
82
+
83
+ request['Authorization'] = "Token token=\"#{session_token}\""
84
+ request['Accept'] = 'application/json'
85
+ request['Content-Type'] = 'application/json'
86
+ request['X-ClientId'] = client_id unless client_id.nil?
87
+ request['X-ClientCode'] = client_code unless client_code.nil?
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,68 @@
1
+ require 'dmtd_vbmapp_data/request_helpers'
2
+
3
+ module DmtdVbmappData
4
+
5
+ # Provides for the retrieving of VB-MAPP content from the VB-MAPP Data Server.
6
+ class Vbmapp
7
+
8
+ attr_reader :client
9
+
10
+ # Creates an accessor for the VB-MAPP content on the VB-MAPP Data Server
11
+ #
12
+ # This method does *not* block, simply creates an accessor and returns
13
+ #
14
+ # Params:
15
+ # +client+:: a client instance
16
+ def initialize(opts)
17
+ @client = opts.fetch(:client)
18
+ end
19
+
20
+ # Populates the internal VB-MAPP content index
21
+ #
22
+ # This index is cached locally and expires once a day.
23
+ #
24
+ # The first call to this method with an expired cache will
25
+ # block until the cache is populated. All subsequent calls
26
+ # will load from the cache.
27
+ #
28
+ # Returns:
29
+ # Array as defined as the result of the 1/guide/index REST api
30
+ def index
31
+ if @vbmapp_index.nil?
32
+ @vbmapp_index = retrieve_vbmapp_index
33
+ end
34
+
35
+ @vbmapp_index
36
+ end
37
+
38
+ # Returns the VB-MAPP Areas
39
+ #
40
+ # Note that this method calls +index+. See that method for
41
+ # its blocking characteristics.
42
+ def areas
43
+ @areas = index.map {|area_index_json| VbmappArea.new(client: client, area_index_json: area_index_json)} if @areas.nil?
44
+
45
+ @areas
46
+ end
47
+
48
+ private
49
+
50
+ def self.end_point
51
+ '1/vbmapp/index'
52
+ end
53
+
54
+ def retrieve_vbmapp_index
55
+ response = RequestHelpers::get_authorized(end_point: Vbmapp::end_point, params: nil, client_id: @client.id, client_code: @client.code)
56
+ proc_response = RequestHelpers::process_json_response(response)
57
+ json = proc_response[:json]
58
+ server_response_code = proc_response[:code]
59
+
60
+ result = json
61
+ result = server_response_code if json.nil?
62
+
63
+ result
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -0,0 +1,73 @@
1
+ require 'dmtd_vbmapp_data/request_helpers'
2
+
3
+ module DmtdVbmappData
4
+
5
+ # Provides for the retrieving of VB-MAPP area information from the VB-MAPP Data Server.
6
+ class VbmappArea
7
+
8
+ attr_reader :client
9
+ attr_reader :area
10
+
11
+ # Creates an accessor for the VB-MAPP Guide Chapter on the VB-MAPP Data Server
12
+ #
13
+ # This method does *not* block, simply creates an accessor and returns
14
+ #
15
+ # Params:
16
+ # +client+:: a client instance
17
+ # +area_index_json+:: the vbmapp area index json for the chapter
18
+ def initialize(opts)
19
+ @client = opts.fetch(:client)
20
+
21
+ index_json = opts.fetch(:area_index_json)
22
+ @area = index_json[:area]
23
+ @groups_index = index_json[:groups]
24
+ end
25
+
26
+ # Returns the VB-MAPP groups
27
+ #
28
+ # This method does *not* block on server access
29
+ def groups
30
+ @groups = @groups_index.map.with_index { |group_index_json, group_num|
31
+ VbmappAreaGroup.new(client: client, area: area, group_index_json: group_index_json)
32
+ } if @groups.nil?
33
+
34
+ @groups
35
+ end
36
+
37
+ # Returns the possible responses for all questions of this area
38
+ #
39
+ # This method *will* block on the first access to retrieve the
40
+ # data from the server
41
+ def responses
42
+ if @responses.nil?
43
+ responses_json = retrieve_responses_json || []
44
+ @responses = responses_json.map { |response_json| VbmappAreaResponse.new(area: area, response_json: response_json) }
45
+ end
46
+
47
+ @responses
48
+ end
49
+
50
+ private
51
+
52
+ def self.end_point
53
+ '1/vbmapp/area_responses'
54
+ end
55
+
56
+ def retrieve_responses_json
57
+ params = {
58
+ area: area
59
+ }
60
+ response = RequestHelpers::get_authorized(end_point: VbmappArea::end_point, params: params, client_id: @client.id, client_code: @client.code)
61
+ proc_response = RequestHelpers::process_json_response(response)
62
+ json = proc_response[:json]
63
+ server_response_code = proc_response[:code]
64
+
65
+ result = json
66
+ result = server_response_code if json.nil?
67
+
68
+ result
69
+ end
70
+
71
+ end
72
+
73
+ end
@@ -0,0 +1,91 @@
1
+ require 'dmtd_vbmapp_data/request_helpers'
2
+
3
+ module DmtdVbmappData
4
+
5
+ # Provides for the retrieving of VB-MAPP Guide chapter sections from the VB-MAPP Data Server.
6
+ class VbmappAreaGroup
7
+
8
+ attr_reader :client
9
+ attr_reader :area
10
+ attr_reader :group
11
+
12
+ # Creates an accessor for the VB-MAPP Area Group on the VB-MAPP Data Server
13
+ #
14
+ # This method does *not* block, simply creates an accessor and returns
15
+ #
16
+ # Params:
17
+ # +client+:: a client instance
18
+ # +area+:: the vbmapp area of the group
19
+ # +group_index_json+:: the vbmapp index json for the group
20
+ def initialize(opts)
21
+ @client = opts.fetch(:client)
22
+ @area = opts.fetch(:area)
23
+
24
+ index_json = opts.fetch(:group_index_json)
25
+ @group = index_json[:group]
26
+ @question_count = index_json[:question_count]
27
+ @levels = index_json[:levels]
28
+ end
29
+
30
+ # Returns the content of the Guide's chapter section
31
+ #
32
+ # This method *does* block as the content is retrieved
33
+ #
34
+ # +level+:: filters the questions to the given level (may be null)
35
+ def questions(opts = {})
36
+ level_name = opts.fetch(:level, nil)
37
+
38
+ if @questions.nil?
39
+ question_json = retrieve_question_json
40
+
41
+ @questions = question_json.map {|question_json|
42
+ VbmappAreaQuestion.new(client: client, area: area, group: group, question_json: question_json)
43
+ }
44
+ end
45
+
46
+ if level_name.nil?
47
+ result = @questions
48
+ else
49
+ level_desc = @levels.select {|level| level[:level] == level_name}[0]
50
+ start_num = level_desc[:start_question_num] + 1 # question_number is 1-based
51
+ end_num = start_num + level_desc[:question_count]
52
+
53
+ result = @questions.select {|question| question.question_number >= start_num && question.question_number <= end_num}
54
+ end
55
+
56
+ result
57
+ end
58
+
59
+ # Returns the VB-MAPP Guide section's sub_sections
60
+ def levels
61
+ @levels = @levels.map { |sub_section_num|
62
+ VbmappAreaLevel.new(client: client, area: area, group: section_num, sub_section_num: sub_section_num)
63
+ } if @levels.nil?
64
+
65
+ @levels
66
+ end
67
+
68
+ private
69
+
70
+ def self.end_point
71
+ '1/vbmapp/area_question'
72
+ end
73
+
74
+ def retrieve_question_json
75
+ params = {
76
+ area: area,
77
+ group: group
78
+ }
79
+ response = RequestHelpers::get_authorized(end_point: VbmappAreaGroup::end_point, params: params, client_id: @client.id, client_code: @client.code)
80
+ proc_response = RequestHelpers::process_json_response(response)
81
+ json = proc_response[:json]
82
+ server_response_code = proc_response[:code]
83
+
84
+ result = json
85
+ result = server_response_code if json.nil?
86
+
87
+ result
88
+ end
89
+ end
90
+
91
+ end
@@ -0,0 +1,62 @@
1
+ require 'dmtd_vbmapp_data/request_helpers'
2
+
3
+ module DmtdVbmappData
4
+
5
+ # Provides for the retrieving of VB-MAPP Guide chapter sections from the VB-MAPP Data Server.
6
+ class VbmappAreaQuestion
7
+
8
+ attr_reader :client
9
+ attr_reader :area
10
+ attr_reader :group
11
+ attr_reader :example
12
+ attr_reader :materials
13
+ attr_reader :question_number
14
+ attr_reader :question_text
15
+
16
+ # Creates an accessor for the VB-MAPP Area Question on the VB-MAPP Data Server
17
+ #
18
+ # This method does *not* block, simply creates an accessor and returns
19
+ #
20
+ # Params:
21
+ # +client+:: a client instance
22
+ # +area+:: the vbmapp area
23
+ # +group+:: the vbmapp area group name
24
+ # +question_json+:: The JSON that describes a VB-MAPP area question
25
+ def initialize(opts)
26
+ @client = opts.fetch(:client)
27
+ @area = opts.fetch(:area)
28
+ @group = opts.fetch(:group)
29
+
30
+ question_json = opts.fetch(:question_json)
31
+ @example = question_json[:example]
32
+ @guide_content = question_json[:guideContent]
33
+ @materials = question_json[:materials]
34
+ @question_number = question_json[:questionNumber]
35
+ @question_text = question_json[:questionText]
36
+ @responses_json_array = question_json[:responses]
37
+ end
38
+
39
+ # Returns the VB-MAPP question's possible responses.
40
+ def responses
41
+ if @responses.nil?
42
+
43
+ # If we don't have responses, get them from the area
44
+ if @responses_json_array.nil?
45
+ @responses = client.vbmapp.areas.select { |client_area| client_area.area == area}[0].responses
46
+ else
47
+ @responses = @responses_json_array.map { |response_json| VbmappAreaResponse.new(area: area, response_json: response_json) }
48
+ end
49
+ end
50
+
51
+ # @levels = @levels.map { |sub_section_num|
52
+ # GuideSectionSubSection.new(client: client, chapter_num: chapter_num, section_num: section_num, sub_section_num: sub_section_num)
53
+ # } if @levels.nil?
54
+ #
55
+ # @levels
56
+
57
+ @responses
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -0,0 +1,31 @@
1
+ require 'dmtd_vbmapp_data/request_helpers'
2
+
3
+ module DmtdVbmappData
4
+
5
+ # Provides for the retrieving of VB-MAPP Guide chapter sections from the VB-MAPP Data Server.
6
+ class VbmappAreaResponse
7
+
8
+ attr_reader :area
9
+ attr_reader :score
10
+ attr_reader :text
11
+ attr_reader :description
12
+
13
+ # Creates an accessor for the VB-MAPP Area Question on the VB-MAPP Data Server
14
+ #
15
+ # This method does *not* block, simply creates an accessor and returns
16
+ #
17
+ # Params:
18
+ # +area+:: the vbmapp area
19
+ # +response_json+:: the response's json
20
+ def initialize(opts)
21
+ @area = opts.fetch(:area)
22
+
23
+ response_json = opts.fetch(:response_json)
24
+ @score = response_json[:score]
25
+ @text = response_json[:text]
26
+ @description = response_json[:description]
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,3 @@
1
+ module DmtdVbmappData
2
+ VERSION = '1.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dmtd_vbmapp_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - David Hunt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: psych
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashie
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.2'
97
+ description: This gem provides a simplified Ruby API for DMTD customers accessing
98
+ the vbmappapp.com REST service.
99
+ email:
100
+ - support@vbmappapp.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - dmtd_vbmapp_data.gemspec
115
+ - lib/dmtd_vbmapp_data.rb
116
+ - lib/dmtd_vbmapp_data/client.rb
117
+ - lib/dmtd_vbmapp_data/guide.rb
118
+ - lib/dmtd_vbmapp_data/guide_chapter.rb
119
+ - lib/dmtd_vbmapp_data/guide_chapter_section.rb
120
+ - lib/dmtd_vbmapp_data/guide_section_sub_section.rb
121
+ - lib/dmtd_vbmapp_data/request_helpers.rb
122
+ - lib/dmtd_vbmapp_data/vbmapp.rb
123
+ - lib/dmtd_vbmapp_data/vbmapp_area.rb
124
+ - lib/dmtd_vbmapp_data/vbmapp_area_group.rb
125
+ - lib/dmtd_vbmapp_data/vbmapp_area_question.rb
126
+ - lib/dmtd_vbmapp_data/vbmapp_area_response.rb
127
+ - lib/dmtd_vbmapp_data/version.rb
128
+ homepage: https://github.com/foscomputerservices/dmtd_vbmapp_data
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.4.5
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Ruby gem to simplify access to DMTD's VB-MAPP REST service
152
+ test_files: []