surveygizmo 0.0.1 → 0.0.2

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.
Files changed (48) hide show
  1. data/.gitignore +2 -0
  2. data/.rspec +1 -0
  3. data/Rakefile +7 -1
  4. data/lib/surveygizmo/client.rb +10 -2
  5. data/lib/surveygizmo/client/contact.rb +3 -3
  6. data/lib/surveygizmo/client/filter.rb +1 -1
  7. data/lib/surveygizmo/client/survey.rb +4 -4
  8. data/lib/surveygizmo/client/survey_question.rb +25 -0
  9. data/lib/surveygizmo/client/survey_response.rb +3 -3
  10. data/lib/surveygizmo/client/survey_statistic.rb +24 -0
  11. data/lib/surveygizmo/configurable.rb +27 -0
  12. data/lib/surveygizmo/configuration.rb +1 -1
  13. data/lib/surveygizmo/connection.rb +10 -3
  14. data/lib/surveygizmo/request.rb +0 -10
  15. data/lib/surveygizmo/version.rb +1 -1
  16. data/readme.textile +12 -12
  17. data/spec/fixtures/account.json +1 -0
  18. data/spec/fixtures/account_user.json +1 -0
  19. data/spec/fixtures/account_users.json +1 -0
  20. data/spec/fixtures/contact.json +1 -0
  21. data/spec/fixtures/contacts.json +1 -0
  22. data/spec/fixtures/create_account_user.json +1 -0
  23. data/spec/fixtures/delete_account_user.json +1 -0
  24. data/spec/fixtures/survey.json +1 -0
  25. data/spec/fixtures/survey_campaign.json +1 -0
  26. data/spec/fixtures/survey_campaigns.json +1 -0
  27. data/spec/fixtures/survey_question.json +33 -0
  28. data/spec/fixtures/survey_questions.json +195 -0
  29. data/spec/fixtures/survey_response.json +1 -0
  30. data/spec/fixtures/survey_responses.json +1 -0
  31. data/spec/fixtures/survey_statistic.json +7 -0
  32. data/spec/fixtures/survey_statistics.json +92 -0
  33. data/spec/fixtures/surveys.json +1 -0
  34. data/spec/fixtures/update_account_user.json +1 -0
  35. data/spec/helper.rb +51 -0
  36. data/spec/surveygizmo/client/account_spec.rb +19 -0
  37. data/spec/surveygizmo/client/account_user_spec.rb +83 -0
  38. data/spec/surveygizmo/client/contact_spec.rb +31 -0
  39. data/spec/surveygizmo/client/filter_spec.rb +22 -0
  40. data/spec/surveygizmo/client/survey_campaign_spec.rb +31 -0
  41. data/spec/surveygizmo/client/survey_question_spec.rb +31 -0
  42. data/spec/surveygizmo/client/survey_response_spec.rb +31 -0
  43. data/spec/surveygizmo/client/survey_spec.rb +45 -0
  44. data/spec/surveygizmo/client_spec.rb +67 -0
  45. data/spec/surveygizmo/survey_statistic_spec.rb +31 -0
  46. data/spec/surveygizmo_spec.rb +34 -0
  47. data/surveygizmo.gemspec +7 -2
  48. metadata +154 -10
@@ -0,0 +1 @@
1
+ {"result_ok":true,"data":{"id":"1","contact_id":"","status":"Complete","is_test_data":"1","date_submitted":"2012-09-03 23:47:47","sResponseComment":"","[question(2)]":"jamie@somewhere.com","[variable(\"STANDARD_IP\")]":"74.61.46.190","[variable(\"STANDARD_LONG\")]":"-122.564003","[variable(\"STANDARD_LAT\")]":"47.158298","[variable(\"STANDARD_GEOCOUNTRY\")]":"United States","[variable(\"STANDARD_GEOCITY\")]":"Lakewood","[variable(\"STANDARD_GEOREGION\")]":"WA","[variable(\"STANDARD_GEOPOSTAL\")]":"98498","[variable(\"STANDARD_RESPONSETIME\")]":"","[variable(\"STANDARD_COMMENTS\")]":"","[variable(\"STANDARD_GEODMA\")]":"0","[variable(\"1-shown\")]":"1","[variable(\"2-shown\")]":"1"}}
@@ -0,0 +1 @@
1
+ {"result_ok":true,"total_count":"2","page":1,"total_pages":1,"results_per_page":50,"data":[{"id":"1","contact_id":"","status":"Complete","is_test_data":"1","datesubmitted":"2012-09-03 23:47:47","sResponseComment":"","[question(2)]":"jamie@somewhere.com","[variable(\"STANDARD_IP\")]":"74.61.46.190","[variable(\"STANDARD_LONG\")]":"-122.564003","[variable(\"STANDARD_LAT\")]":"47.158298","[variable(\"STANDARD_GEOCOUNTRY\")]":"United States","[variable(\"STANDARD_GEOCITY\")]":"Lakewood","[variable(\"STANDARD_GEOREGION\")]":"WA","[variable(\"STANDARD_GEOPOSTAL\")]":"98498","[variable(\"STANDARD_RESPONSETIME\")]":"","[variable(\"STANDARD_COMMENTS\")]":"","[variable(\"STANDARD_GEODMA\")]":"0","[variable(\"1-shown\")]":"1","[variable(\"2-shown\")]":"1"},{"id":"2","contact_id":"","status":"Complete","is_test_data":"1","datesubmitted":"2012-09-03 23:50:42","sResponseComment":"","[question(2)]":"pickle@somewhere.com","[variable(\"STANDARD_IP\")]":"74.61.46.190","[variable(\"STANDARD_LONG\")]":"-122.564003","[variable(\"STANDARD_LAT\")]":"47.158298","[variable(\"STANDARD_GEOCOUNTRY\")]":"United States","[variable(\"STANDARD_GEOCITY\")]":"Lakewood","[variable(\"STANDARD_GEOREGION\")]":"WA","[variable(\"STANDARD_GEOPOSTAL\")]":"98498","[variable(\"STANDARD_RESPONSETIME\")]":"","[variable(\"STANDARD_COMMENTS\")]":"","[variable(\"STANDARD_GEODMA\")]":"0","[variable(\"1-shown\")]":"1","[variable(\"2-shown\")]":"1"}]}
@@ -0,0 +1,7 @@
1
+ {
2
+ "result_ok" : true,
3
+ "data" : { "_subtype" : "instructions",
4
+ "_type" : "SurveyStatistics",
5
+ "id" : "[question(3)]"
6
+ }
7
+ }
@@ -0,0 +1,92 @@
1
+ {
2
+ "page" : 1,
3
+ "result_ok" : true,
4
+ "results_per_page" : 126,
5
+ "total_count" : 126,
6
+ "total_pages" : 1,
7
+ "data" : [
8
+ { "_subtype" : "instructions",
9
+ "_type" : "SurveyDecorative",
10
+ "description" : [ ],
11
+ "has_showhide_deps" : null,
12
+ "id" : 3,
13
+ "options" : [ ],
14
+ "properties" : { "break_after" : false,
15
+ "custom_css" : "",
16
+ "disabled" : false,
17
+ "hidden" : false,
18
+ "hide_after_response" : false,
19
+ "labels_right" : false,
20
+ "map_key" : "instructions",
21
+ "messages" : { "inputmask" : [ ],
22
+ "l_extreme_label" : [ ],
23
+ "left_label" : [ ],
24
+ "r_extreme_label" : [ ],
25
+ "right_label" : [ ]
26
+ },
27
+ "question_description_above" : false,
28
+ "required" : false,
29
+ "show_title" : false,
30
+ "soft-required" : false
31
+ },
32
+ "shortname" : null,
33
+ "sub_question_skus" : null,
34
+ "title" : { "English" : "Directive" },
35
+ "varname" : null
36
+ },
37
+ { "_subtype" : "table",
38
+ "_type" : "SurveyQuestion",
39
+ "description" : [ ],
40
+ "has_showhide_deps" : false,
41
+ "id" : 106,
42
+ "options" : [ { "_type" : "SurveyOption",
43
+ "id" : 10031,
44
+ "properties" : [ ],
45
+ "title" : { "English" : "1" },
46
+ "value" : "1"
47
+ },
48
+ { "_type" : "SurveyOption",
49
+ "id" : 10032,
50
+ "properties" : [ ],
51
+ "title" : { "English" : "2" },
52
+ "value" : "2"
53
+ },
54
+ { "_type" : "SurveyOption",
55
+ "id" : 10033,
56
+ "properties" : [ ],
57
+ "title" : { "English" : "3" },
58
+ "value" : "3"
59
+ }
60
+ ],
61
+ "properties" : { "break_after" : false,
62
+ "custom_css" : "",
63
+ "disabled" : false,
64
+ "exclude_number" : "YES",
65
+ "hidden" : false,
66
+ "hide_after_response" : false,
67
+ "labels_right" : false,
68
+ "map_key" : "table-radio",
69
+ "messages" : { "inputmask" : [ ],
70
+ "l_extreme_label" : [ ],
71
+ "left_label" : [ ],
72
+ "r_extreme_label" : [ ],
73
+ "right_label" : [ ]
74
+ },
75
+ "question_description" : { "English" : "" },
76
+ "question_description_above" : false,
77
+ "required" : true,
78
+ "show_title" : false,
79
+ "soft-required" : false
80
+ },
81
+ "shortname" : "",
82
+ "sub_question_skus" : [ 107,
83
+ 108,
84
+ 109,
85
+ 110,
86
+ 111
87
+ ],
88
+ "title" : { "English" : " " },
89
+ "varname" : ""
90
+ }
91
+ ]
92
+ }
@@ -0,0 +1 @@
1
+ {"result_ok":true,"total_count":"1","page":1,"total_pages":1,"results_per_page":1,"data":[{"id":"101201","team":"4634","_type":"Survey","_subtype":"Standard Survey","status":"In Design","created_on":"2012-09-03 22:56:20","modified_on":"2012-09-03 22:56:21","title":"Movie Rating","statistics":null,"links":{"edit":"https:\/\/appv3.sgizmo.com\/login\/v1?authenticate=940a4c20c2d1917240e4956d4a78a0cf151d4592&account_user_id=2934&r=%2Fprojects%2Feditor%3Fid%3D1018301&signature=80a4f9","publish":"https:\/\/appv3.sgizmo.com\/login\/v1?authenticate=940a4c92c2d1917540e4956d4a78a0cf151d4592&account_user_id=231934&r=%2Fdistribute%2Fpromote%3Fid%3D1018301&signature=e421aa"}}]}
@@ -0,0 +1 @@
1
+ {"result_ok":true,"data":{"id":"183437","_type":"AccountUser","username":"Jon","email":"jon@gmail.com","status":"Active","last_login":"2012-07-05 18:24:02"}}
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ unless ENV['CI']
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_filter 'spec'
6
+ end
7
+ end
8
+
9
+ require 'surveygizmo'
10
+ require 'rspec'
11
+ require 'webmock/rspec'
12
+
13
+ def a_delete(path, endpoint='https://restapi.surveygizmo.com')
14
+ a_request(:delete, endpoint + path)
15
+ end
16
+
17
+ def a_get(path, endpoint='https://restapi.surveygizmo.com')
18
+ a_request(:get, endpoint + path)
19
+ end
20
+
21
+ def a_post(path, endpoint='https://restapi.surveygizmo.com')
22
+ a_request(:post, endpoint + path)
23
+ end
24
+
25
+ def a_put(path, endpoint='https://restapi.surveygizmo.com')
26
+ a_request(:put, endpoint + path)
27
+ end
28
+
29
+ def stub_delete(path, endpoint='https://restapi.surveygizmo.com')
30
+ stub_request(:delete, endpoint + path)
31
+ end
32
+
33
+ def stub_get(path, endpoint='https://restapi.surveygizmo.com')
34
+ stub_request(:get, endpoint + path)
35
+ end
36
+
37
+ def stub_post(path, endpoint='https://restapi.surveygizmo.com')
38
+ stub_request(:post, endpoint + path)
39
+ end
40
+
41
+ def stub_put(path, endpoint='https://restapi.surveygizmo.com')
42
+ stub_request(:put, endpoint + path)
43
+ end
44
+
45
+ def fixture_path
46
+ File.expand_path("../fixtures", __FILE__)
47
+ end
48
+
49
+ def fixture(file)
50
+ File.new(fixture_path + '/' + file)
51
+ end
@@ -0,0 +1,19 @@
1
+ require 'helper'
2
+
3
+ describe Surveygizmo::API do
4
+ before do
5
+ @client = Surveygizmo::Client.new
6
+ end
7
+
8
+ describe "#account" do
9
+ before do
10
+ stub_get("/v2/account").
11
+ to_return(:body => fixture("account.json"), :headers => {:content_type => "application/json; charset=utf-8"})
12
+ end
13
+ it "requests the correct resource" do
14
+ @client.account
15
+ a_get("/v2/account").
16
+ should have_been_made
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,83 @@
1
+ require 'helper'
2
+
3
+ describe Surveygizmo::API do
4
+ before do
5
+ @client = Surveygizmo::Client.new
6
+ end
7
+
8
+ describe "#account_users" do
9
+ before do
10
+ stub_get("/v2/accountuser").
11
+ to_return(:body => fixture("account_users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
12
+ end
13
+ it "requests the correct resource" do
14
+ @client.account_users
15
+ a_get("/v2/accountuser").
16
+ should have_been_made
17
+ end
18
+ end
19
+
20
+ describe "#account_user" do
21
+ before do
22
+ stub_get("/v2/accountuser/183437").
23
+ to_return(:body => fixture("account_user.json"), :headers => {:content_type => "application/json; charset=utf-8"})
24
+ end
25
+ it "requests the correct resource" do
26
+ @client.account_user(183437)
27
+ a_get("/v2/accountuser/183437").
28
+ should have_been_made
29
+ end
30
+ end
31
+
32
+ describe "#create_account_user" do
33
+ before do
34
+ stub_post("/v2/accountuser").
35
+ with(
36
+ :body => {:email => "jamie@somewhere.com", :username => "Jamie", :password => "hamsterdance"},
37
+ :query => {:_method => "PUT"}
38
+ ).
39
+ to_return(:body => fixture("create_account_user.json"), :headers => {:content_type => "application/json; charset=utf-8"})
40
+ end
41
+ it "requests the correct resource" do
42
+ @client.create_account_user({
43
+ :email => "jamie@somewhere.com",
44
+ :username => "Jamie",
45
+ :password => "hamsterdance"
46
+ })
47
+ a_post("/v2/accountuser").
48
+ with(
49
+ :body => {:email => "jamie@somewhere.com", :username => "Jamie", :password => "hamsterdance"},
50
+ :query => {:_method => "PUT"}
51
+ ).
52
+ should have_been_made
53
+ end
54
+ end
55
+
56
+ describe "#delete_account_user" do
57
+ before do
58
+ stub_post("/v2/accountuser/183437").
59
+ with(:query => {:_method => "DELETE"}).
60
+ to_return(:body => fixture("delete_account_user.json"), :headers => {:content_type => "application/json; charset=utf-8"})
61
+ end
62
+ it "requests the correct resource" do
63
+ @client.delete_account_user(183437)
64
+ a_post("/v2/accountuser/183437").
65
+ with(:query => {:_method => "DELETE"}).
66
+ should have_been_made
67
+ end
68
+ end
69
+
70
+ describe "#update_account_user" do
71
+ before do
72
+ stub_post("/v2/accountuser/183437").
73
+ with(:query => {:_method => "POST"}).
74
+ to_return(:body => fixture("update_account_user.json"), :headers => {:content_type => "application/json; charset=utf-8"})
75
+ end
76
+ it "requests the correct resource" do
77
+ @client.update_account_user(183437, {:email => "jon@gmail.com"})
78
+ a_post("/v2/accountuser/183437").
79
+ with(:query => {:_method => "POST"}).
80
+ should have_been_made
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,31 @@
1
+ require 'helper'
2
+
3
+ describe Surveygizmo::API do
4
+ before do
5
+ @client = Surveygizmo::Client.new
6
+ end
7
+
8
+ describe "#contacts" do
9
+ before do
10
+ stub_get("/v2/survey/1018301/surveycampaign/673550/contact").
11
+ to_return(:body => fixture("contacts.json"), :headers => {:content_type => "application/json; charset=utf-8"})
12
+ end
13
+ it "requests the correct resource" do
14
+ @client.contacts(1018301, 673550)
15
+ a_get("/v2/survey/1018301/surveycampaign/673550/contact").
16
+ should have_been_made
17
+ end
18
+ end
19
+
20
+ describe "#contact" do
21
+ before do
22
+ stub_get("/v2/survey/1018301/surveycampaign/673550/contact/1").
23
+ to_return(:body => fixture("contact.json"), :headers => {:content_type => "application/json; charset=utf-8"})
24
+ end
25
+ it "requests the correct resource" do
26
+ @client.contact(1018301, 673550, 1)
27
+ a_get("/v2/survey/1018301/surveycampaign/673550/contact/1").
28
+ should have_been_made
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ require 'helper'
2
+
3
+ describe Surveygizmo::API do
4
+ before do
5
+ @client = Surveygizmo::Client.new
6
+ end
7
+
8
+ describe "#formatted_filters" do
9
+ it "format filters for the request querystring" do
10
+ filters = @client.formatted_filters({
11
+ "field" => "status",
12
+ "operator" => "=",
13
+ "value" => "Active"
14
+ })
15
+ filters.should == {
16
+ "filter[field][0]"=>"status",
17
+ "filter[operator][0]"=>"=",
18
+ "filter[value][0]"=>"Active"
19
+ }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ require 'helper'
2
+
3
+ describe Surveygizmo::API do
4
+ before do
5
+ @client = Surveygizmo::Client.new
6
+ end
7
+
8
+ describe "#survey_campaigns" do
9
+ before do
10
+ stub_get("/v2/survey/1018301/surveycampaign").
11
+ to_return(:body => fixture("survey_campaigns.json"), :headers => {:content_type => "application/json; charset=utf-8"})
12
+ end
13
+ it "requests the correct resource" do
14
+ @client.survey_campaigns(1018301)
15
+ a_get("/v2/survey/1018301/surveycampaign").
16
+ should have_been_made
17
+ end
18
+ end
19
+
20
+ describe "#survey_campaign" do
21
+ before do
22
+ stub_get("/v2/survey/1018301/surveycampaign/673550").
23
+ to_return(:body => fixture("survey_campaign.json"), :headers => {:content_type => "application/json; charset=utf-8"})
24
+ end
25
+ it "requests the correct resource" do
26
+ @client.survey_campaign(1018301, 673550)
27
+ a_get("/v2/survey/1018301/surveycampaign/673550").
28
+ should have_been_made
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require 'helper'
2
+
3
+ describe Surveygizmo::API do
4
+ before do
5
+ @client = Surveygizmo::Client.new
6
+ end
7
+
8
+ describe "#survey_questions" do
9
+ before do
10
+ stub_get("/v2/survey/1018301/surveyquestion").
11
+ to_return(:body => fixture("survey_questions.json"), :headers => {:content_type => "application/json; charset=utf-8"})
12
+ end
13
+
14
+ it "requests the correct resource" do
15
+ @client.survey_questions(1018301)
16
+ a_get("/v2/survey/1018301/surveyquestion").should have_been_made
17
+ end
18
+ end
19
+
20
+ describe "#survey_question" do
21
+ before do
22
+ stub_get("/v2/survey/1018301/surveyquestion/1").
23
+ to_return(:body => fixture("survey_question.json"), :headers => {:content_type => "application/json; charset=utf-8"})
24
+ end
25
+ it "requests the correct resource" do
26
+ @client.survey_question(1018301, 1)
27
+ a_get("/v2/survey/1018301/surveyquestion/1").
28
+ should have_been_made
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require 'helper'
2
+
3
+ describe Surveygizmo::API do
4
+ before do
5
+ @client = Surveygizmo::Client.new
6
+ end
7
+
8
+ describe "#survey_responses" do
9
+ before do
10
+ stub_get("/v2/survey/1018301/surveyresponse").
11
+ to_return(:body => fixture("survey_responses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
12
+ end
13
+ it "requests the correct resource" do
14
+ @client.survey_responses(1018301)
15
+ a_get("/v2/survey/1018301/surveyresponse").
16
+ should have_been_made
17
+ end
18
+ end
19
+
20
+ describe "#survey_response" do
21
+ before do
22
+ stub_get("/v2/survey/1018301/surveyresponse/1").
23
+ to_return(:body => fixture("survey_response.json"), :headers => {:content_type => "application/json; charset=utf-8"})
24
+ end
25
+ it "requests the correct resource" do
26
+ @client.survey_response(1018301, 1)
27
+ a_get("/v2/survey/1018301/surveyresponse/1").
28
+ should have_been_made
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,45 @@
1
+ require 'helper'
2
+
3
+ describe Surveygizmo::API do
4
+ before do
5
+ @client = Surveygizmo::Client.new
6
+ end
7
+
8
+ describe "#surveys" do
9
+ before do
10
+ stub_get("/v2/survey").
11
+ to_return(:body => fixture("surveys.json"), :headers => {:content_type => "application/json; charset=utf-8"})
12
+ end
13
+ it "requests the correct resource" do
14
+ @client.surveys
15
+ a_get("/v2/survey").
16
+ should have_been_made
17
+ end
18
+ end
19
+
20
+ describe "#polls" do
21
+ before do
22
+ stub_get("/v2/survey").
23
+ to_return(:body => fixture("surveys.json"), :headers => {:content_type => "application/json; charset=utf-8"})
24
+ end
25
+ it "requests the correct resource" do
26
+ @client.polls
27
+ a_get("/v2/survey").
28
+ should have_been_made
29
+ end
30
+ end
31
+
32
+ describe "#survey" do
33
+ before do
34
+ stub_get("/v2/survey/1018301").
35
+ with(:query => {:metaonly=>"false"}).
36
+ to_return(:body => fixture("survey.json"), :headers => {:content_type => "application/json; charset=utf-8"})
37
+ end
38
+ it "requests the correct resource" do
39
+ @client.survey(1018301)
40
+ a_get("/v2/survey/1018301").
41
+ with(:query => {:metaonly=>"false"}).
42
+ should have_been_made
43
+ end
44
+ end
45
+ end