isurvey 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2RjMjU3NGRlZjVjODgyMjMwYWE2OTA3NTg4MGU4Yzg2Y2I2ZTRhMg==
4
+ MjE2NmJkYjlhNWMzMjg5ZmU0MGNmODkzNmM5ODYxOTUwOWJlNDEzMQ==
5
5
  data.tar.gz: !binary |-
6
- MmJmNWI0ZThjMjNjZjkzOTZlZmYzN2Q2NWUxN2EyZjRmZDc0Njg4OA==
6
+ MjlhMjVkOTFlMTU3M2ZkNDAzZjNiMWY1Y2RiY2M5ODMwMWU0MTYzNg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZWU4MGMzMGQ1MzY0NTY3NDJlOTg3NTg3ZWMwYWIyNGFjNDU2NWYxNjVhN2Mx
10
- ZmUxY2FhOGYwZGU5NWQ2MTViOTNiYWMwMmE5YTc3YTgzMjJmNzkwYzA0ZDM2
11
- MzczZDQwNmZiZTczM2RjMjVhMTIxNDMxNGY4MDU4NmU0NmNmODg=
9
+ ZTYyNDczMWI0N2EwNzhiNzg3ZjcwOTNlNmRlZTdjOGFiN2U5NGYwZTJlN2I2
10
+ MGU5M2VjMGY1ZjJhMzAyYjExN2NiNTc5NTlmYzBlMjFjNGE1MjBmYzQ3NGQw
11
+ MTFhMTE4YWMwNWFiNzE2MTRkNTY1MGI3ZWIwOGRjY2Y0NDlkZjc=
12
12
  data.tar.gz: !binary |-
13
- NTEwNWJkYjllZTEzNDU5MTRjYzZkNDY5YzNjZDA3YzQ1ZWNjZjE1NDAzNDdk
14
- NWJiMTY2MTI3ZWYyYWNlYmQwMGFmMWM2MzVlYTFjY2M3MGMyNDFmN2UwZjUz
15
- MTQzMGY2MzBkOWVmZWYzZmU5OTg5N2JlNjhjYmQxZDEyYmY1ODY=
13
+ YmNjYTU3OTBjYzZmYTVkZGQwZDZjNTI3ZTAxZjBmOTQ2MzU5ZGRlZTc2ZDc0
14
+ YTJmZTI1MzNiYWFkZGM3Mjk2YTUxZTUyYzk0NTljNTExMzY2YzEwYjAyY2M2
15
+ OThlY2ZlYTU3NDRjYmQ4ZWEyM2YwOWUzNTJhMGFjYTEzMTI2ZjM=
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Isurvey
2
2
 
3
- TODO: Write a gem description
3
+ Gem for interacting with iSurvey's SOAP api.
4
4
 
5
5
  ## Installation
6
6
 
@@ -16,9 +16,58 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install isurvey
18
18
 
19
+ You must set up your company identifier and survey password. Perhaps in config/initiaizers/isurvey.rb if you are using Rails.
20
+
21
+ Isurvey::Credentials.company_identifier = [cp]
22
+ Isurvey::Credentials.survey_password = [sp]
23
+
19
24
  ## Usage
20
25
 
21
- TODO: Write usage instructions here
26
+ There are questions and answers. Questions are available through Isurvey::Question and answers are available through Isurvey::Answer.
27
+
28
+ To get a list of all questions:
29
+
30
+ Isurvey::Question.all
31
+
32
+ To get a list of all answers:
33
+
34
+ Isurvey::Answer.all
35
+
36
+ All of the properties available through the iSurvye API are also available through the gem. You obtain a property value by calling for it on the appropriate class; for example, Isurvey::Answer.all.first.screen_id would give you the screen_id of the first Answer.
37
+
38
+ For questions, the available properties are:
39
+
40
+ :screen_id, :question_number, :screen_id_next, :show_labels, :selectable_images, :screen_text, :screen_instructions, :theme_class_id, :screen_options, :answers, :questions
41
+
42
+ For answers, the available properties are:
43
+
44
+ :screen_id, :question_id, :answer_id, :result_answer, :response_date
45
+
46
+ You can also get direct access to the API. I do not recommend relying on any of these methods since they are being phased out.
47
+
48
+ Get a list of the questions:
49
+
50
+ Isurvey::API.questions
51
+
52
+ Get a list of the result ids:
53
+
54
+ Isurvey::API.result_ids
55
+
56
+ Get a list of the questions by screen id:
57
+
58
+ Isurvey::API.question_by_screen_id(screen_id)
59
+
60
+ Get a list of the answers by screen id:
61
+
62
+ Isurvey::API.answers_by_screen_id(screen_id)
63
+
64
+ Get a list of the answers by result id:
65
+
66
+ Isurvey::API.answers_by_result_id(result)
67
+
68
+ Get a list of the answers by result id and screen id:
69
+
70
+ Isurvey::API.answer_by_screen_and_result_id(result_id: id, screen_id: id)
22
71
 
23
72
  ## Contributing
24
73
 
data/isurvey.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "savon", "~> 2.0"
25
+ spec.add_development_dependency "rspec"
25
26
  spec.add_development_dependency "rake"
26
27
 
27
28
  end
@@ -0,0 +1,6 @@
1
+ module Isurvey
2
+ class Answer
3
+ include Base
4
+ extend Collector
5
+ end
6
+ end
@@ -0,0 +1,66 @@
1
+ module Isurvey
2
+ class API
3
+ def self.questions
4
+ unless @questions
5
+ @questions = []
6
+ self.screens.each do |question|
7
+ @questions << Question.new(hash: question)
8
+ end
9
+ end
10
+ @questions
11
+ end
12
+
13
+ def self.result_ids
14
+ unless @result_ids
15
+ @result_ids = []
16
+ survey_results.each do |result|
17
+ @result_ids << result[:result_id]
18
+ end
19
+ end
20
+ @result_ids
21
+ end
22
+
23
+
24
+ def self.question_by_screen_id(id)
25
+ self.screens.each do |question|
26
+ if question[:screen_id] == id
27
+ return question[:screen_text]
28
+ end
29
+ end
30
+ end
31
+
32
+ def self.answer_by_screen_and_result_id(options)
33
+ answers_by_result_id(options[:result_id]) & answers_by_screen_id(options[:screen_id])
34
+ end
35
+
36
+ def self.answers_by_result_id(id)
37
+ survey_results.each do |result|
38
+ if result[:result_id] == id
39
+ return result[:screen_results][:result]
40
+ end
41
+ end
42
+ end
43
+
44
+ def self.answers_by_screen_id(id)
45
+ @answers = []
46
+ survey_results.each do |result|
47
+ result[:screen_results][:result].each do |question|
48
+ @answers << question if question[:screen_id] == id
49
+ end
50
+ end
51
+ @answers
52
+
53
+ private
54
+ def self.survey
55
+ SOAPClient.export_survey.body[:export_survey_response][:export_survey_result]
56
+ end
57
+
58
+ def self.survey_results
59
+ SOAPClient.export_survey_results.body[:export_survey_results_response][:export_survey_results_result][:survey_result]
60
+ end
61
+
62
+ def self.screens
63
+ survey[:screens][:screen]
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,17 @@
1
+ module Isurvey
2
+ module Base
3
+ attr_reader :hash
4
+
5
+ def initialize(options)
6
+ @hash = options[:hash]
7
+ end
8
+
9
+ def method_missing(method, *args, &block)
10
+ if hash.has_key? method
11
+ @hash[method]
12
+ else
13
+ super
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module Isurvey
2
+ module Collector
3
+ def all
4
+ ObjectSpace.each_object(self).entries
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module Isurvey
2
+ class Question
3
+ include Base
4
+ extend Collector
5
+ end
6
+ end
@@ -0,0 +1,28 @@
1
+ module Isurvey
2
+ class SOAPClient
3
+ def self.savon_client
4
+ @savon_client ||= Savon.client(
5
+ wsdl: "https://isurveysoft.com/servicesv3/exportservice.asmx?WSDL"
6
+ )
7
+ end
8
+
9
+ def self.savon_call(operation)
10
+ self.savon_client.call(
11
+ operation,
12
+ message:
13
+ {
14
+ cp: Credentials.company_identifier,
15
+ sp: Credentials.survey_password
16
+ }
17
+ )
18
+ end
19
+
20
+ def self.export_survey
21
+ @export_survey ||= self.savon_call(:export_survey)
22
+ end
23
+
24
+ def self.export_survey_results
25
+ @export_survey_results ||= self.savon_call(:export_survey_results)
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Isurvey
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/isurvey.rb CHANGED
@@ -1,101 +1,16 @@
1
- require "isurvey/version"
2
- require "savon"
1
+ require 'isurvey/version'
2
+ require 'savon'
3
+ require 'isurvey/base'
4
+ require 'isurvey/collector'
5
+ require 'isurvey/soap_client'
6
+ require 'isurvey/api'
7
+ require 'isurvey/question'
8
+ require 'isurvey/answer'
3
9
 
4
10
  module Isurvey
5
- class SOAPClient
11
+ class Credentials
6
12
  class << self
7
13
  attr_accessor :company_identifier, :survey_password
8
14
  end
9
-
10
- def self.savon_client
11
- @savon_client ||= Savon.client(
12
- wsdl: "https://isurveysoft.com/servicesv3/exportservice.asmx?WSDL"
13
- )
14
- end
15
-
16
- def self.savon_call(operation)
17
- self.savon_client.call(
18
- operation,
19
- message:
20
- {
21
- cp: company_identifier,
22
- sp: survey_password
23
- }
24
- )
25
- end
26
-
27
- def self.export_survey
28
- @export_survey ||= self.savon_call(:export_survey)
29
- end
30
-
31
- def self.export_survey_results
32
- @export_survey_results ||= self.savon_call(:export_survey_results)
33
- end
34
- end
35
-
36
- class API
37
- def self.questions
38
- unless @questions
39
- @questions = []
40
- self.screens.each do |question|
41
- @questions << question
42
- end
43
- end
44
- @questions
45
- end
46
-
47
- def self.result_ids
48
- unless @result_ids
49
- @result_ids = []
50
- survey_results.each do |result|
51
- @result_ids << result[:result_id]
52
- end
53
- end
54
- @result_ids
55
- end
56
-
57
-
58
- def self.question_by_screen_id(id)
59
- self.screens.each do |question|
60
- if question[:screen_id] == id
61
- return question[:screen_text]
62
- end
63
- end
64
- end
65
-
66
- def self.answer_by_screen_and_result_id(options)
67
- answers_by_result_id(options[:result_id]) & answers_by_screen_id(options[:screen_id])
68
- end
69
-
70
- def self.answers_by_result_id(id)
71
- survey_results.each do |result|
72
- if result[:result_id] == id
73
- return result[:screen_results][:result]
74
- end
75
- end
76
- end
77
-
78
- def self.answers_by_screen_id(id)
79
- @answers = []
80
- survey_results.each do |result|
81
- result[:screen_results][:result].each do |question|
82
- @answers << question if question[:screen_id] == id
83
- end
84
- end
85
- @answers
86
- end
87
-
88
- private
89
- def self.survey
90
- SOAPClient.export_survey.body[:export_survey_response][:export_survey_result]
91
- end
92
-
93
- def self.survey_results
94
- SOAPClient.export_survey_results.body[:export_survey_results_response][:export_survey_results_result][:survey_result]
95
- end
96
-
97
- def self.screens
98
- survey[:screens][:screen]
99
- end
100
15
  end
101
16
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Isurvey::Answer do
4
+
5
+ before :all do
6
+ @answer1 = Isurvey::Answer.new(hash: {:screen_id=>"431583", :question_id=>nil, :answer_id=>nil, :result_answer=>"9", :response_date=>"2013-06-14 19:34:58"})
7
+ @answer2 = Isurvey::Answer.new(hash: {:screen_id=>"431583", :question_id=>nil, :answer_id=>nil, :result_answer=>"9", :response_date=>"2013-06-14 19:34:58"})
8
+ end
9
+
10
+ it "should return the correct screen_id" do
11
+ @answer1.screen_id.should == '431583'
12
+ end
13
+
14
+ it "should return the correct result_answer" do
15
+ @answer1.result_answer.should == '9'
16
+ end
17
+
18
+ it "should return all questions for all" do
19
+ Isurvey::Answer.all.length.should == 2
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Isurvey::Question do
4
+
5
+ before :all do
6
+ @question1 = Isurvey::Question.new(hash: {:screen_id=>"431424", :question_number=>"0", :screen_id_next=>"431426", :show_labels=>true, :selectable_images=>false, :screen_text=>"This is the Week in the Life Daily Survey. ", :screen_instruction=>nil, :theme_class_id=>"59786", :screen_options=>{:screen_option=>[{:screen_option_ref_code=>"DisplayImageAboveText", :screen_option_value_text=>"False"}, {:screen_option_ref_code=>"SelectableImages", :screen_option_value_text=>false}, {:screen_option_ref_code=>"ShowLabels", :screen_option_value_text=>true}]}, :answers=>nil, :questions=>nil, :@type=>"information", :@next_screen_is_linked=>"false"})
7
+ @question2 = Isurvey::Question.new(hash: {:screen_id=>"431424", :question_number=>"0", :screen_id_next=>"431426", :show_labels=>true, :selectable_images=>false, :screen_text=>"This is the Week in the Life Daily Survey. ", :screen_instruction=>nil, :theme_class_id=>"59786", :screen_options=>{:screen_option=>[{:screen_option_ref_code=>"DisplayImageAboveText", :screen_option_value_text=>"False"}, {:screen_option_ref_code=>"SelectableImages", :screen_option_value_text=>false}, {:screen_option_ref_code=>"ShowLabels", :screen_option_value_text=>true}]}, :answers=>nil, :questions=>nil, :@type=>"information", :@next_screen_is_linked=>"false"})
8
+ end
9
+
10
+ it "should return the correct screen_id" do
11
+ @question1.screen_id.should == '431424'
12
+ end
13
+
14
+ it "should return the correct screen_text" do
15
+ @question1.screen_text.should == 'This is the Week in the Life Daily Survey. '
16
+ end
17
+
18
+ it "should return all questions for all" do
19
+ Isurvey::Question.all.length.should == 2
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ require_relative '../lib/isurvey/base.rb'
2
+ require_relative '../lib/isurvey/collector.rb'
3
+ require_relative '../lib/isurvey/question.rb'
4
+ require_relative '../lib/isurvey/answer.rb'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isurvey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Nipper
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +94,16 @@ files:
80
94
  - Rakefile
81
95
  - isurvey.gemspec
82
96
  - lib/isurvey.rb
97
+ - lib/isurvey/answer.rb
98
+ - lib/isurvey/api.rb
99
+ - lib/isurvey/base.rb
100
+ - lib/isurvey/collector.rb
101
+ - lib/isurvey/question.rb
102
+ - lib/isurvey/soap_client.rb
83
103
  - lib/isurvey/version.rb
104
+ - spec/answer_spec.rb
105
+ - spec/question_spec.rb
106
+ - spec/spec_helper.rb
84
107
  homepage: http://github.com/mnipper/isurvey
85
108
  licenses:
86
109
  - MIT
@@ -105,4 +128,7 @@ rubygems_version: 2.0.3
105
128
  signing_key:
106
129
  specification_version: 4
107
130
  summary: Communicate with the iSurvey SOAP api.
108
- test_files: []
131
+ test_files:
132
+ - spec/answer_spec.rb
133
+ - spec/question_spec.rb
134
+ - spec/spec_helper.rb