survey-gizmo-ruby 1.0.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/Gemfile +1 -2
- data/README.md +88 -50
- data/Rakefile +2 -1
- data/lib/survey-gizmo-ruby.rb +1 -1
- data/lib/survey_gizmo/api/contact.rb +3 -3
- data/lib/survey_gizmo/api/option.rb +3 -4
- data/lib/survey_gizmo/api/page.rb +9 -5
- data/lib/survey_gizmo/api/question.rb +31 -17
- data/lib/survey_gizmo/api/response.rb +8 -9
- data/lib/survey_gizmo/api/survey.rb +21 -6
- data/lib/survey_gizmo/resource.rb +114 -214
- data/lib/survey_gizmo/rest_response.rb +82 -0
- data/lib/survey_gizmo/survey_gizmo.rb +27 -22
- data/spec/resource_spec.rb +81 -55
- data/spec/support/methods.rb +7 -4
- data/spec/support/spec_shared_api_object.rb +25 -71
- data/spec/support/spec_shared_object_with_errors.rb +6 -8
- data/spec/support/test_resource_classes.rb +4 -21
- data/spec/survey-gizmo-ruby_spec.rb +8 -98
- data/survey-gizmo-ruby.gemspec +22 -17
- metadata +68 -11
- data/lib/survey_gizmo/collection.rb +0 -72
@@ -1,35 +1,33 @@
|
|
1
1
|
shared_examples_for 'an object with errors' do
|
2
2
|
before(:each) do
|
3
|
-
SurveyGizmo.setup(:
|
3
|
+
SurveyGizmo.setup(user: 'test@test.com', password: 'password')
|
4
4
|
stub_request(:any, /#{@base}/).to_return(json_response(false, 'There was an error!'))
|
5
5
|
end
|
6
|
-
|
7
|
-
it "should be in zombie state if requests fail"
|
8
6
|
|
9
7
|
context "class methods" do
|
10
8
|
it { described_class.first(get_attributes).should be_nil }
|
11
|
-
it { described_class.all(get_attributes).should be_empty }
|
9
|
+
it { described_class.all(get_attributes).should be_empty }
|
12
10
|
end
|
13
11
|
|
14
12
|
context "instance methods" do
|
15
13
|
before(:each) do
|
16
14
|
@obj = described_class.new(create_attributes)
|
17
15
|
end
|
18
|
-
|
16
|
+
|
19
17
|
it "should have an errors array" do
|
20
18
|
@obj.errors.should == []
|
21
19
|
end
|
22
|
-
|
20
|
+
|
23
21
|
it "should add errors on failed requests" do
|
24
22
|
@obj.save.should == false
|
25
23
|
@obj.errors.should include('There was an error!')
|
26
24
|
end
|
27
|
-
|
25
|
+
|
28
26
|
it "should empty the errors array if object gets saved" do
|
29
27
|
stub_request(:any, /#{@base}/).to_return(json_response(false, 'There was an error!'), json_response(true, get_attributes))
|
30
28
|
@obj.save.should == false
|
31
29
|
@obj.errors.should_not be_empty
|
32
|
-
@obj.save.should ==
|
30
|
+
@obj.save.id.nil?.should == false
|
33
31
|
@obj.errors.should be_empty
|
34
32
|
end
|
35
33
|
end
|
@@ -1,42 +1,25 @@
|
|
1
1
|
module SurveyGizmoSpec
|
2
2
|
class ResourceTest
|
3
3
|
include SurveyGizmo::Resource
|
4
|
-
|
4
|
+
|
5
5
|
attribute :id, Integer
|
6
6
|
attribute :title, String
|
7
7
|
attribute :test_id, Integer
|
8
|
-
|
8
|
+
|
9
9
|
# routes
|
10
10
|
route '/test/:id', :via => :get
|
11
11
|
route '/test/:test_id/resource', :via => :create
|
12
12
|
route '/test/:test_id/resource/:id', :via => [:update, :delete]
|
13
|
-
|
14
|
-
def to_param_options
|
15
|
-
{:id => self.id, :test_id => self.test_id}
|
16
|
-
end
|
17
|
-
end
|
18
13
|
|
19
|
-
class CollectionTest
|
20
|
-
include SurveyGizmo::Resource
|
21
|
-
|
22
|
-
attribute :id, Integer
|
23
|
-
attribute :title, String
|
24
|
-
|
25
|
-
# routes
|
26
|
-
route '/test/:id', :via => :get
|
27
|
-
route '/test/collection', :via => :create
|
28
|
-
route '/test/collection/:id', :via => [:update, :delete]
|
29
|
-
|
30
14
|
def to_param_options
|
31
|
-
{:
|
15
|
+
{id: self.id, test_id: self.test_id}
|
32
16
|
end
|
33
17
|
end
|
34
18
|
|
35
19
|
class GenericResource
|
36
20
|
include SurveyGizmo::Resource
|
37
|
-
|
21
|
+
|
38
22
|
attribute :id, Integer
|
39
23
|
attribute :title, String
|
40
|
-
|
41
24
|
end
|
42
25
|
end
|
@@ -1,107 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
it
|
3
|
+
describe SurveyGizmo do
|
4
|
+
it 'should have a base uri' do
|
5
5
|
SurveyGizmo.base_uri.should == 'https://restapi.surveygizmo.com/v3'
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
9
|
-
SurveyGizmo.
|
10
|
-
SurveyGizmo.
|
8
|
+
it 'should raise an error if auth isn\'t configured' do
|
9
|
+
#SurveyGizmo.reset
|
10
|
+
#expect(SurveyGizmo::API::Survey.all).to raise_exception
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
|
15
|
-
|
16
|
-
before(:each) do
|
17
|
-
@array = [
|
18
|
-
{:id => 1, :title => 'Test 1'},
|
19
|
-
{:id => 2, :title => 'Test 2'},
|
20
|
-
{:id => 3, :title => 'Test 3'},
|
21
|
-
{:id => 4, :title => 'Test 4'}
|
22
|
-
]
|
23
|
-
|
24
|
-
SurveyGizmo::Collection.send :public, *SurveyGizmo::Collection.private_instance_methods
|
25
|
-
end
|
26
|
-
|
27
|
-
let(:described_class) { SurveyGizmoSpec::CollectionTest }
|
28
|
-
|
29
|
-
context "class" do
|
30
|
-
before(:each) do
|
31
|
-
described_class.collection :generic_resources
|
32
|
-
end
|
33
|
-
|
34
|
-
subject { SurveyGizmo::Collection.new(described_class, :generic_resources, @array) }
|
35
|
-
|
36
|
-
it { should_not be_loaded }
|
37
|
-
|
38
|
-
it "should set the options in the collections property" do
|
39
|
-
described_class.collections.should == {:generic_resources => {:parent => described_class, :target => :generic_resources}}
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should load objects using the given class" do
|
43
|
-
subject.first.should be_instance_of(SurveyGizmoSpec::GenericResource)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should be loaded before iteration" do
|
47
|
-
subject.should_not be_loaded
|
48
|
-
subject.each
|
49
|
-
subject.should be_loaded
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context '#collection' do
|
54
|
-
before(:each) do
|
55
|
-
described_class.collection(:resources, 'ResourceTest')
|
56
|
-
end
|
57
|
-
|
58
|
-
it { lambda{ described_class.collection :resources, 'ResourceTest'}.should_not raise_error }
|
59
|
-
|
60
|
-
it "should have an accessor for the collection" do
|
61
|
-
described_class.new.should respond_to('resources')
|
62
|
-
described_class.new.should respond_to('resources=')
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should set an empty collection" do
|
66
|
-
described_class.collection(:resources, 'ResourceTest')
|
67
|
-
obj = described_class.new()
|
68
|
-
obj.resources.should be_empty
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should set a collection" do
|
72
|
-
described_class.collection(:resources, 'ResourceTest')
|
73
|
-
obj = described_class.new()
|
74
|
-
obj.resources = @array
|
75
|
-
obj.resources.should be_instance_of(SurveyGizmo::Collection)
|
76
|
-
obj.resources.length.should == @array.length
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should set a collection from a hash" do
|
80
|
-
obj = described_class.new(:id => 1, :resources => @array)
|
81
|
-
obj.resources.should be_instance_of(SurveyGizmo::Collection)
|
82
|
-
obj.resources.length.should == @array.length
|
83
|
-
end
|
84
|
-
|
85
|
-
it "can handle multiple collections" do
|
86
|
-
described_class.collection(:generic_resources)
|
87
|
-
described_class.new.should respond_to('resources')
|
88
|
-
described_class.new.should respond_to('generic_resources')
|
89
|
-
end
|
90
|
-
|
91
|
-
it "can handle nested collections" do
|
92
|
-
pending("Needs to be changed to work with suite. Right now it only passes in isolation.")
|
93
|
-
SurveyGizmoSpec::ResourceTest.collection :generic_resources
|
94
|
-
@generic_resource_list = [
|
95
|
-
{:id => 1, :title => 'Generic Test 5'},
|
96
|
-
{:id => 2, :title => 'Generic Test 6'},
|
97
|
-
{:id => 3, :title => 'Generic Test 7'}
|
98
|
-
]
|
99
|
-
|
100
|
-
@array << {:id => 99, :generic_resources => @generic_resource_list}
|
101
|
-
obj = described_class.new(:id => 1, :resources => @array)
|
102
|
-
obj.resources.first.should be_instance_of(SurveyGizmoSpec::ResourceTest)
|
103
|
-
obj.resources.detect{|r| r.id == 99 }.generic_resources.first.should be_instance_of(SurveyGizmoSpec::GenericResource)
|
104
|
-
end
|
105
|
-
end
|
13
|
+
it 'should allow basic authentication configuration' do
|
14
|
+
SurveyGizmo.setup(user: 'test@test.com', password: 'password')
|
15
|
+
SurveyGizmo.default_options[:default_params].should == {'user:md5' => 'test@test.com:5f4dcc3b5aa765d61d8327deb882cf99'}
|
106
16
|
end
|
107
17
|
end
|
data/survey-gizmo-ruby.gemspec
CHANGED
@@ -3,27 +3,32 @@ lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
|
-
gem.name =
|
7
|
-
gem.version =
|
8
|
-
gem.authors = [
|
9
|
-
gem.email = [
|
10
|
-
gem.description =
|
11
|
-
gem.summary =
|
12
|
-
gem.homepage =
|
13
|
-
gem.licenses = [
|
6
|
+
gem.name = 'survey-gizmo-ruby'
|
7
|
+
gem.version = '2.0.0'
|
8
|
+
gem.authors = ['Kabari Hendrick', 'Chris Horn', 'Adrien Jarthon', 'Lumos Labs, Inc.']
|
9
|
+
gem.email = ['adrien.jarthon@dimelo.com']
|
10
|
+
gem.description = 'Gem to use the SurveyGizmo.com REST API, v3+'
|
11
|
+
gem.summary = 'Gem to use the SurveyGizmo.com REST API, v3+'
|
12
|
+
gem.homepage = 'http://github.com/RipTheJacker/survey-gizmo-ruby'
|
13
|
+
gem.licenses = ['MIT']
|
14
|
+
gem.required_ruby_version = '>= 1.9'
|
14
15
|
|
15
|
-
gem.add_dependency 'activesupport',
|
16
|
-
gem.add_dependency 'i18n'
|
17
|
-
gem.add_dependency 'virtus', ">= 1.0.0"
|
18
|
-
gem.add_dependency 'httparty'
|
16
|
+
gem.add_dependency 'activesupport', '>= 3.0'
|
19
17
|
gem.add_dependency 'addressable'
|
20
|
-
gem.
|
21
|
-
gem.
|
18
|
+
gem.add_dependency 'awesome_print'
|
19
|
+
gem.add_dependency 'httparty'
|
20
|
+
gem.add_dependency 'i18n'
|
21
|
+
gem.add_dependency 'virtus', '>= 1.0.0'
|
22
|
+
|
23
|
+
gem.add_development_dependency 'bluecloth'
|
24
|
+
gem.add_development_dependency 'net-http-spy'
|
25
|
+
gem.add_development_dependency 'rspec', '~> 2.11.0'
|
22
26
|
gem.add_development_dependency 'rake'
|
27
|
+
gem.add_development_dependency 'webmock'
|
28
|
+
gem.add_development_dependency 'yard'
|
23
29
|
|
24
30
|
gem.files = `git ls-files`.split($/)
|
25
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
31
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
26
32
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
27
|
-
gem.require_paths = [
|
33
|
+
gem.require_paths = ['lib']
|
28
34
|
end
|
29
|
-
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: survey-gizmo-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kabari Hendrick
|
8
8
|
- Chris Horn
|
9
9
|
- Adrien Jarthon
|
10
|
+
- Lumos Labs, Inc.
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2015-
|
14
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: activesupport
|
@@ -27,7 +28,7 @@ dependencies:
|
|
27
28
|
- !ruby/object:Gem::Version
|
28
29
|
version: '3.0'
|
29
30
|
- !ruby/object:Gem::Dependency
|
30
|
-
name:
|
31
|
+
name: addressable
|
31
32
|
requirement: !ruby/object:Gem::Requirement
|
32
33
|
requirements:
|
33
34
|
- - ">="
|
@@ -41,19 +42,19 @@ dependencies:
|
|
41
42
|
- !ruby/object:Gem::Version
|
42
43
|
version: '0'
|
43
44
|
- !ruby/object:Gem::Dependency
|
44
|
-
name:
|
45
|
+
name: awesome_print
|
45
46
|
requirement: !ruby/object:Gem::Requirement
|
46
47
|
requirements:
|
47
48
|
- - ">="
|
48
49
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
50
|
+
version: '0'
|
50
51
|
type: :runtime
|
51
52
|
prerelease: false
|
52
53
|
version_requirements: !ruby/object:Gem::Requirement
|
53
54
|
requirements:
|
54
55
|
- - ">="
|
55
56
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
57
|
+
version: '0'
|
57
58
|
- !ruby/object:Gem::Dependency
|
58
59
|
name: httparty
|
59
60
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,7 +70,7 @@ dependencies:
|
|
69
70
|
- !ruby/object:Gem::Version
|
70
71
|
version: '0'
|
71
72
|
- !ruby/object:Gem::Dependency
|
72
|
-
name:
|
73
|
+
name: i18n
|
73
74
|
requirement: !ruby/object:Gem::Requirement
|
74
75
|
requirements:
|
75
76
|
- - ">="
|
@@ -83,7 +84,35 @@ dependencies:
|
|
83
84
|
- !ruby/object:Gem::Version
|
84
85
|
version: '0'
|
85
86
|
- !ruby/object:Gem::Dependency
|
86
|
-
name:
|
87
|
+
name: virtus
|
88
|
+
requirement: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 1.0.0
|
93
|
+
type: :runtime
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 1.0.0
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
name: bluecloth
|
102
|
+
requirement: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
type: :development
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: net-http-spy
|
87
116
|
requirement: !ruby/object:Gem::Requirement
|
88
117
|
requirements:
|
89
118
|
- - ">="
|
@@ -124,6 +153,34 @@ dependencies:
|
|
124
153
|
- - ">="
|
125
154
|
- !ruby/object:Gem::Version
|
126
155
|
version: '0'
|
156
|
+
- !ruby/object:Gem::Dependency
|
157
|
+
name: webmock
|
158
|
+
requirement: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
type: :development
|
164
|
+
prerelease: false
|
165
|
+
version_requirements: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
- !ruby/object:Gem::Dependency
|
171
|
+
name: yard
|
172
|
+
requirement: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
type: :development
|
178
|
+
prerelease: false
|
179
|
+
version_requirements: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
127
184
|
description: Gem to use the SurveyGizmo.com REST API, v3+
|
128
185
|
email:
|
129
186
|
- adrien.jarthon@dimelo.com
|
@@ -147,8 +204,8 @@ files:
|
|
147
204
|
- lib/survey_gizmo/api/response.rb
|
148
205
|
- lib/survey_gizmo/api/survey.rb
|
149
206
|
- lib/survey_gizmo/api/survey_campaign.rb
|
150
|
-
- lib/survey_gizmo/collection.rb
|
151
207
|
- lib/survey_gizmo/resource.rb
|
208
|
+
- lib/survey_gizmo/rest_response.rb
|
152
209
|
- lib/survey_gizmo/survey_gizmo.rb
|
153
210
|
- spec/resource_spec.rb
|
154
211
|
- spec/spec_helper.rb
|
@@ -173,7 +230,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
173
230
|
requirements:
|
174
231
|
- - ">="
|
175
232
|
- !ruby/object:Gem::Version
|
176
|
-
version: '
|
233
|
+
version: '1.9'
|
177
234
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
235
|
requirements:
|
179
236
|
- - ">="
|
@@ -181,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
238
|
version: '0'
|
182
239
|
requirements: []
|
183
240
|
rubyforge_project:
|
184
|
-
rubygems_version: 2.
|
241
|
+
rubygems_version: 2.2.2
|
185
242
|
signing_key:
|
186
243
|
specification_version: 4
|
187
244
|
summary: Gem to use the SurveyGizmo.com REST API, v3+
|
@@ -1,72 +0,0 @@
|
|
1
|
-
module SurveyGizmo
|
2
|
-
class Collection
|
3
|
-
|
4
|
-
private
|
5
|
-
# @param [Class] resource
|
6
|
-
# @param [Symbol] name
|
7
|
-
# @param [Array] values in hashes
|
8
|
-
def initialize(resource, name, values)
|
9
|
-
@array = Array(values)
|
10
|
-
@collection = []
|
11
|
-
@loaded = false
|
12
|
-
@options = resource.collections[name]
|
13
|
-
end
|
14
|
-
|
15
|
-
public
|
16
|
-
|
17
|
-
# @private
|
18
|
-
def length
|
19
|
-
@array.length
|
20
|
-
end
|
21
|
-
|
22
|
-
# @private
|
23
|
-
def each
|
24
|
-
lazy_load
|
25
|
-
if block_given?
|
26
|
-
@collection.each{ |o| yield(o) }
|
27
|
-
else
|
28
|
-
@collection.each
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# @private
|
33
|
-
def method_missing(meth, *args, &blk)
|
34
|
-
lazy_load
|
35
|
-
@collection.send(meth, *args, &blk)
|
36
|
-
end
|
37
|
-
|
38
|
-
# @private
|
39
|
-
def model
|
40
|
-
return @model if defined?(@model)
|
41
|
-
return (@model = options[:target]) if options[:target].is_a?(Class)
|
42
|
-
name_string = options[:target].is_a?(Symbol) ? ActiveSupport::Inflector.classify(options[:target]) : options[:target]
|
43
|
-
@model = name_string[/::/] ? Object.const_get?(name_string) : Resource.descendants.detect{ |d| ActiveSupport::Inflector.demodulize(d.name) == name_string }
|
44
|
-
raise NameError, "#{name_string} is not a descendant of SurveyGizmo::Resource" unless @model
|
45
|
-
@model
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
protected
|
50
|
-
attr_accessor :options
|
51
|
-
|
52
|
-
def lazy_load
|
53
|
-
return if loaded?
|
54
|
-
@collection = @array.map{|hash| load_object(hash) }
|
55
|
-
mark_loaded
|
56
|
-
end
|
57
|
-
|
58
|
-
def load_object(obj_or_attributes)
|
59
|
-
return obj_or_attributes if loaded?
|
60
|
-
obj_or_attributes.is_a?(Hash) ? model.load(obj_or_attributes) : obj_or_attributes
|
61
|
-
end
|
62
|
-
|
63
|
-
def mark_loaded
|
64
|
-
@loaded = true
|
65
|
-
end
|
66
|
-
|
67
|
-
def loaded?
|
68
|
-
@loaded
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|