isurvey 0.0.10 → 0.1.0

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
- Y2FhNTNkOWNmYTM3MjU1OTBlZTRkNzc3YzI3ODQ0NGU2ZWMzYWYzOA==
4
+ MWRjNmIxOTRhMTViNDk1NWQyMDRjZmE0OWFlMWYxYzM4YzIxYWI3ZA==
5
5
  data.tar.gz: !binary |-
6
- MzEzYjIzMDdhMTJhZDdlNWUyNDEyZDQ3ZTlkNmY0MDU1NDljYzdlOQ==
6
+ NjFjZDRhMmU1MmZjOTM4NDI3ODdmZGE5N2RjNzhlYWY3MTMwOTAwMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Mzg3MTdmNTA1NTZkYjBhMDNkZTY1ZWI2MTE1MGE4NDdiYWUxZTg1MmUxMzIz
10
- MTExZTU4Zjg3NjExNzA3OWE2NTQ3OTdmYWY1MWM4OTYzYmY1MDJjMTM1ODlh
11
- YjVjYTlhMmZkNWNhYjY3MWQ2ZjVlZWI2NjU4OGMwZTAyZTRhZGM=
9
+ OGEyM2VkOGFjNTdmYWViOTZkMDk3MzFmOGMzYzNmM2MyYTViOGZmOTVhYzRh
10
+ MDMxMDQ5NDExYTk5NWZlMWYzOTE3NDc2OGI3Njc4YTNmYzllMTdmNGZmN2Fj
11
+ OTY0OGRhNjk1OTIyNTkxMjFjNDAzNmE2YTRjYjFjMDcyN2VjZGI=
12
12
  data.tar.gz: !binary |-
13
- ZjQwYTdiNTkyZWQ0MjE2YTg2ZjAxZGFkMTc4NTE4MDU3M2NhMDcyMjZmOWY3
14
- YTZkMTg2YmEzNTU1NzRhNWE4ODM1YzY1YTgxYzk1NzBlMzY3ZDA4YTg3MWNk
15
- MzZhMzIyNDg3YzViYTljZjc4NjVmOWI3ZTQ4NTMyMmFhM2YyNjU=
13
+ MzI1NDk3MzY1YjYxMDZmNzEzYWVjNjMwNWM1YWQ3N2VjYzhjNzY4ODE2NDc0
14
+ MmY4MWE1NjgzYTI1MDlmYTFmNDZlZGUwMmRiNzM3N2FkOGVlNTZhYjNiY2Q2
15
+ MDIyNzNmZGNjZDFlYTI2YTU0MWJiNGZhYjE4ZGExODQ1NTk5MjY=
data/README.md CHANGED
@@ -21,6 +21,10 @@ You must set up your company identifier and survey password. Perhaps in config/
21
21
  Isurvey::Credentials.company_identifier = [cp]
22
22
  Isurvey::Credentials.survey_password = [sp]
23
23
 
24
+ Before being used, the API must be loaded. This can be done in your initialzer or in any other place you see fit.
25
+
26
+ Isurvey::API.load
27
+
24
28
  ## Usage
25
29
 
26
30
  There are questions and answers. Questions are available through Isurvey::Question and answers are available through Isurvey::Answer.
@@ -43,31 +47,30 @@ For answers, the available properties are:
43
47
 
44
48
  :screen_id, :question_id, :answer_id, :result_answer, :response_date
45
49
 
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
50
+ Any property can also be used to find on either questions or answers. For example:
51
51
 
52
- Get a list of the result ids:
52
+ Isurvey::Question.find_by_screen_id(:id)
53
+ Isurvey::Answer.find_by_question_id(:id)
53
54
 
54
- Isurvey::API.result_ids
55
+ You can query a question for its answers, or an answer for its questions.
55
56
 
56
- Get a list of the questions by screen id:
57
+ Isurvey::Question.answers
58
+ Isurvey::Answer.questions
57
59
 
58
- Isurvey::API.question_by_screen_id(screen_id)
60
+ You can also find answers by result id to a question.
59
61
 
60
- Get a list of the answers by screen id:
62
+ Isurvey::Question.answers_by_result_id(:id)
61
63
 
62
- Isurvey::API.answers_by_screen_id(screen_id)
64
+ Questions and Answers have shortcut methods that allow you to query for the first or some index:
63
65
 
64
- Get a list of the answers by result id:
66
+ Isurvey::Question.first
67
+ Isurvey::Answer[10]
65
68
 
66
- Isurvey::API.answers_by_result_id(result)
69
+ You can also get direct access to the API.
67
70
 
68
- Get a list of the answers by result id and screen id:
71
+ Get a list of the result ids:
69
72
 
70
- Isurvey::API.answer_by_screen_and_result_id(result_id: id, screen_id: id)
73
+ Isurvey::API.result_ids
71
74
 
72
75
  ## Contributing
73
76
 
@@ -2,5 +2,10 @@ module Isurvey
2
2
  class Answer
3
3
  include Base
4
4
  extend Collector
5
+ attr_accessor :result_id
6
+
7
+ def question
8
+ Question.find_by_screen_id(self.screen_id)
9
+ end
5
10
  end
6
11
  end
data/lib/isurvey/api.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  module Isurvey
2
2
  class API
3
+ def self.load
4
+ questions
5
+ answers
6
+ end
7
+
3
8
  def self.questions
4
9
  unless @questions
5
10
  @questions = []
@@ -20,32 +25,13 @@ module Isurvey
20
25
  @result_ids
21
26
  end
22
27
 
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)
28
+ def self.answers
45
29
  @answers = []
46
30
  survey_results.each do |result|
47
- result[:screen_results][:result].each do |question|
48
- @answers << question if question[:screen_id] == id
31
+ result[:screen_results][:result].each do |answer|
32
+ answer = Answer.new(hash: answer)
33
+ answer.result_id = result[:result_id]
34
+ @answers << answer
49
35
  end
50
36
  end
51
37
  @answers
@@ -1,7 +1,25 @@
1
1
  module Isurvey
2
2
  module Collector
3
+
4
+ def method_missing(method, *args, &block)
5
+ if method.to_s =~ /^find_by_(.+)$/
6
+ to_find = method.to_s.sub(/find_by_/, '')
7
+ all.select { |obj| obj.send(to_find.to_sym) == args.first }
8
+ else
9
+ super
10
+ end
11
+ end
12
+
3
13
  def all
4
- ObjectSpace.each_object(self).entries
14
+ ObjectSpace.each_object(self).entries
15
+ end
16
+
17
+ def first
18
+ all.first
19
+ end
20
+
21
+ def [](ind)
22
+ all[ind]
5
23
  end
6
24
  end
7
25
  end
@@ -2,5 +2,15 @@ module Isurvey
2
2
  class Question
3
3
  include Base
4
4
  extend Collector
5
+
6
+ def answers
7
+ Answer.find_by_screen_id(self.screen_id)
8
+ end
9
+
10
+ def answers_by_result_id(id)
11
+ answers.select do |answer|
12
+ answer.result_id == id
13
+ end
14
+ end
5
15
  end
6
16
  end
@@ -1,3 +1,3 @@
1
1
  module Isurvey
2
- VERSION = "0.0.10"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/isurvey.rb CHANGED
@@ -1,11 +1,11 @@
1
- require 'isurvey/version'
2
1
  require 'savon'
3
- require 'isurvey/soap_client'
4
- require 'isurvey/api'
5
- require 'isurvey/base'
6
- require 'isurvey/collector'
7
- require 'isurvey/question'
8
- require 'isurvey/answer'
2
+ require_relative './isurvey/version'
3
+ require_relative './isurvey/soap_client'
4
+ require_relative './isurvey/base'
5
+ require_relative './isurvey/collector'
6
+ require_relative './isurvey/api'
7
+ require_relative './isurvey/question'
8
+ require_relative './isurvey/answer'
9
9
 
10
10
  module Isurvey
11
11
  class Credentials
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.10
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Nipper