qualtrics_api 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9b596ee7f98f076fd177905c54611c0884181a7
4
- data.tar.gz: ab95a05e5eb6b293d5fa6f92a2989cc27477695b
3
+ metadata.gz: f99dbc6dfa6842ea514f22148e7c87fb8b183414
4
+ data.tar.gz: d6778d2aadd24c5ed9bb93e7b2de9f829228bbf8
5
5
  SHA512:
6
- metadata.gz: 4f3af6fe953f4d57bdc69e2968205464e2e9089c221bb79f888b797063d8ca83f00d4e43d223d18ec68ed537fbbf16057c36d143fcf42f741153970913aeec86
7
- data.tar.gz: d38eb7ff62912c5ac57337f366200ba436306284483814e745b31edea564ccf5ad645bfab084deb0e0bb18410b218255f26344be40e292b1f3e61ad9cbeeead4
6
+ metadata.gz: b706a1e3f81b142307c87b7cf650c6a58797831451abc67609ded2fa0f9db158688348d0adc4ba678e60db265caee228d42364265fdc857d0bde6054fa8d139b
7
+ data.tar.gz: 096263c96a01bc162753b1c4bed1c1122c789f9efd795348b415850500cf2160e54b1dc7a7f599f2b3806a3061981356f52fb5d09bcbb285e0388c08452edc5f
data/lib/qualtrics_api.rb CHANGED
@@ -10,6 +10,12 @@ require "qualtrics_api/request_error_handler"
10
10
 
11
11
  require "qualtrics_api/configurable"
12
12
  require "qualtrics_api/client"
13
+
14
+ require "qualtrics_api/extensions/serializable_model"
15
+ require "qualtrics_api/extensions/serializable_collection"
16
+
17
+ require "qualtrics_api/base_model"
18
+
13
19
  require "qualtrics_api/survey"
14
20
  require "qualtrics_api/survey_collection"
15
21
  require "qualtrics_api/response_export"
@@ -0,0 +1,20 @@
1
+ module QualtricsAPI
2
+ class BaseModel
3
+ include Virtus.value_object
4
+ include QualtricsAPI::Extensions::SerializableModel
5
+
6
+ def initialize(options = {})
7
+ attributes_mappings.each do |key, qualtrics_key|
8
+ instance_variable_set "@#{key}", options[qualtrics_key]
9
+ end
10
+ super
11
+ end
12
+
13
+ private
14
+
15
+ def attributes_mappings
16
+ {}
17
+ end
18
+
19
+ end
20
+ end
@@ -4,6 +4,7 @@ module QualtricsAPI
4
4
 
5
5
  def configure
6
6
  yield self
7
+ self
7
8
  end
8
9
  end
9
10
  end
@@ -0,0 +1,15 @@
1
+ module QualtricsAPI
2
+ module Extensions
3
+ module SerializableCollection
4
+ def as_json(options = {})
5
+ @all.map do |model|
6
+ model.as_json(options)
7
+ end
8
+ end
9
+
10
+ def to_json(options = {})
11
+ as_json.to_json(options)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module QualtricsAPI
2
+ module Extensions
3
+ module SerializableModel
4
+ def as_json(_options = {})
5
+ attributes
6
+ end
7
+
8
+ def to_json(options = {})
9
+ attributes.to_json(options)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,19 +1,11 @@
1
1
  module QualtricsAPI
2
- class Panel
3
- include Virtus.value_object
2
+ class Panel < BaseModel
4
3
 
5
4
  attribute :id, String
6
5
  attribute :library_id, String
7
6
  attribute :name, String
8
7
  attribute :category, String
9
8
 
10
- def initialize(options = {})
11
- attributes_mappings.each do |key, qualtrics_key|
12
- instance_variable_set "@#{key}", options[qualtrics_key]
13
- end
14
- super
15
- end
16
-
17
9
  def members(options = {})
18
10
  @members ||= QualtricsAPI::PanelMemberCollection.new(options.merge(id: id))
19
11
  end
@@ -3,6 +3,7 @@ module QualtricsAPI
3
3
  extend Forwardable
4
4
  include Enumerable
5
5
  include Virtus.value_object
6
+ include QualtricsAPI::Extensions::SerializableCollection
6
7
 
7
8
  attribute :all, Array, :default => []
8
9
 
@@ -1,7 +1,5 @@
1
1
  module QualtricsAPI
2
- class PanelMember
3
- include Virtus.value_object
4
-
2
+ class PanelMember < BaseModel
5
3
  attribute :id, String
6
4
  attribute :first_name, String
7
5
  attribute :last_name, String
@@ -11,23 +9,18 @@ module QualtricsAPI
11
9
  attribute :external_data_reference, String
12
10
  attribute :embeded_data, Hash
13
11
 
14
- def initialize(options = {})
15
- attributes_mappings.each do |key, qualtrics_key|
16
- instance_variable_set "@#{key}", options[qualtrics_key]
17
- end
18
- super
19
- end
20
-
21
12
  def to_json(_options = {})
22
- serialized_attributes.to_json
13
+ attributes.to_json
23
14
  end
24
15
 
25
- private
16
+ alias_method :super_attributes, :attributes
26
17
 
27
- def serialized_attributes
28
- Hash[attributes.map { |k, v| [mapped_and_uppercased_attribute(k), v] }].delete_if { |_k, v| v.nil? }
18
+ def attributes
19
+ Hash[super_attributes.map { |k, v| [mapped_and_uppercased_attribute(k), v] }].delete_if { |_k, v| v.nil? }
29
20
  end
30
21
 
22
+ private
23
+
31
24
  def mapped_and_uppercased_attribute(attribute)
32
25
  (attributes_mappings[attribute] || attribute).to_s.tap do |a|
33
26
  a[0] = a[0].upcase
@@ -1,6 +1,5 @@
1
1
  module QualtricsAPI
2
- class Survey
3
- include Virtus.value_object
2
+ class Survey < BaseModel
4
3
 
5
4
  attribute :id, String
6
5
  attribute :name, String
@@ -9,13 +8,6 @@ module QualtricsAPI
9
8
  attribute :created_at, String
10
9
  attribute :status, String
11
10
 
12
- def initialize(options = {})
13
- attributes_mappings.each do |key, qualtrics_key|
14
- instance_variable_set "@#{key}", options[qualtrics_key]
15
- end
16
- super
17
- end
18
-
19
11
  def export_responses(export_options = {})
20
12
  QualtricsAPI::Services::ResponseExportService.new(export_options.merge(survey_id: id))
21
13
  end
@@ -32,7 +32,7 @@ module QualtricsAPI
32
32
  def [](survey_id)
33
33
  find(survey_id)
34
34
  end
35
-
35
+
36
36
  def find(survey_id)
37
37
  @all.detect do |survey|
38
38
  survey.id == survey_id
@@ -1,3 +1,3 @@
1
1
  module QualtricsAPI
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qualtrics_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yurui Zhang
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-07-21 00:00:00.000000000 Z
13
+ date: 2015-07-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -170,8 +170,11 @@ files:
170
170
  - fixtures/vcr_cassettes/survey_collection_fetch_sucess.yml
171
171
  - fixtures/vcr_cassettes/survey_collection_fetch_with_scopeId_success.yml
172
172
  - lib/qualtrics_api.rb
173
+ - lib/qualtrics_api/base_model.rb
173
174
  - lib/qualtrics_api/client.rb
174
175
  - lib/qualtrics_api/configurable.rb
176
+ - lib/qualtrics_api/extensions/serializable_collection.rb
177
+ - lib/qualtrics_api/extensions/serializable_model.rb
175
178
  - lib/qualtrics_api/panel.rb
176
179
  - lib/qualtrics_api/panel_collection.rb
177
180
  - lib/qualtrics_api/panel_import.rb