surveymonkey_api 0.2.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8c3549682e84998718c2eea98d0839b7727b1eab
4
+ data.tar.gz: '09d30690b5b4a76e1833b6caa6fad9257c364510'
5
+ SHA512:
6
+ metadata.gz: 03b30f0816910d19494260cdedf7a1f716b8349c43cdcb640254a69bbd18e9481bb8fbe136ca8eca201dade41d45a7e5d17a3ce09b57e502f89f98c7f04bb1ed
7
+ data.tar.gz: ef651b3962ac6ecbcd4610cc70904cd5d25cbfc8b4e3f82ad6a9f23abfe1dd2ddc1c48d81791c560a3401efb0c04cf3a7fe2245c5c5325482b6f235c449c32fd
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in surveymonkey_api.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ surveymonkey_api (0.1.0)
5
+ httparty (~> 0.13)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (10.0.2)
11
+ coderay (1.1.2)
12
+ diff-lcs (1.3)
13
+ httparty (0.16.2)
14
+ multi_xml (>= 0.5.2)
15
+ method_source (0.9.0)
16
+ multi_xml (0.6.0)
17
+ pry (0.11.3)
18
+ coderay (~> 1.1.0)
19
+ method_source (~> 0.9.0)
20
+ pry-byebug (3.6.0)
21
+ byebug (~> 10.0)
22
+ pry (~> 0.10)
23
+ rake (10.4.2)
24
+ rspec (3.7.0)
25
+ rspec-core (~> 3.7.0)
26
+ rspec-expectations (~> 3.7.0)
27
+ rspec-mocks (~> 3.7.0)
28
+ rspec-core (3.7.1)
29
+ rspec-support (~> 3.7.0)
30
+ rspec-expectations (3.7.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.7.0)
33
+ rspec-mocks (3.7.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.7.0)
36
+ rspec-support (3.7.1)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ bundler (~> 1.16)
43
+ pry-byebug (~> 3.1)
44
+ rake (~> 10.0)
45
+ rspec (~> 3.0)
46
+ surveymonkey_api!
47
+
48
+ BUNDLED WITH
49
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Carlos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # SurveymonkeyApi
2
+
3
+ Easily interact with the SurveyMonkey API v3. Access matched questions and answers.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'surveymonkey_api'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install surveymonkey_api
21
+
22
+ ## Usage
23
+
24
+ Access a survey:
25
+ ```ruby
26
+ Surveymonkey::Survey.new('survey_id')
27
+ ```
28
+
29
+ Access a survey responses:
30
+ ```ruby
31
+ survey = _
32
+ survey.responses
33
+ responses = _
34
+ ```
35
+
36
+ Access the first response, and go through each page, question and answer and print the titles:
37
+ ```ruby
38
+ responses.first.pages.each do |page|
39
+ puts page.title
40
+ page.questions.each do |question|
41
+ puts question.title
42
+ question.answers.each do |answer|
43
+ puts answer.title
44
+ end
45
+ end
46
+ end
47
+ ```
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/chdezmar/surveymonkey_api.
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "surveymonkey_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,15 @@
1
+ require 'httparty'
2
+ require 'uri'
3
+ require "surveymonkey_api/version"
4
+ require 'surveymonkey_api/client/survey'
5
+ require 'surveymonkey_api/client'
6
+ require 'surveymonkey_api/survey'
7
+ require 'surveymonkey_api/response'
8
+ require 'surveymonkey_api/response/page'
9
+ require 'surveymonkey_api/response/question'
10
+ require 'surveymonkey_api/response/answer'
11
+ require 'pry-byebug'
12
+
13
+ # Top-level module
14
+ module SurveymonkeyApi
15
+ end
@@ -0,0 +1,14 @@
1
+ module Surveymonkey
2
+ # Client
3
+ class Client
4
+ include HTTParty
5
+ include Surveymonkey::Client::Survey
6
+ base_uri 'https://api.surveymonkey.net/v3'
7
+ format :json
8
+
9
+ def initialize(access_token = nil)
10
+ @access_token = access_token || ENV['SURVEYMONKEY_API_TOKEN']
11
+ self.class.default_options.merge!(headers: { 'Authorization' => "bearer #{@access_token}" })
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ module Surveymonkey
2
+ class Client
3
+ # Survey endpoints
4
+ module Survey
5
+
6
+ # Return all surveys
7
+ def surveys(options = {})
8
+ response = self.class.get('/surveys', { query: options })
9
+ response.parsed_response
10
+ end
11
+
12
+ # Return survey folders
13
+ def survey_folders(options = {})
14
+ response = self.class.get("/survey_folders", { query: options })
15
+ response.parsed_response
16
+ end
17
+
18
+ # Return survey details (survey structure)
19
+ def survey_details(survey_id, options = {})
20
+ response = self.class.get("/surveys/#{survey_id}/details", { query: options })
21
+ response.parsed_response
22
+ end
23
+
24
+ # Return all survey responses
25
+ def survey_responses(survey_id, options = {})
26
+ response = self.class.get("/surveys/#{survey_id}/responses/bulk", { query: options })
27
+ response.parsed_response
28
+ end
29
+
30
+ # Return survey responses
31
+ def survey_response(survey_id, response_id, options = {})
32
+ response = self.class.get("/surveys/#{survey_id}/responses/#{response_id}/details", { query: options })
33
+ response.parsed_response
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,34 @@
1
+ module Surveymonkey
2
+ # Response
3
+ class Response
4
+ extend Forwardable
5
+ attr_reader :survey_id, :id, :survey_structure
6
+
7
+ def initialize(survey_id, id)
8
+ @survey_id = survey_id
9
+ @id = id
10
+ @survey_structure = Surveymonkey::Survey.new(survey_id)
11
+ end
12
+
13
+ def raw_details(options = {})
14
+ client.survey_response(survey_id, id, options)
15
+ end
16
+
17
+ def pages(options = {})
18
+ @pages ||= client.survey_response(survey_id, id, options)['pages'].each_with_object([]) do |page, arr|
19
+ if !page['questions'].empty?
20
+ page_structure = details['pages'].detect{|p| p['id'] == page['id']}
21
+ arr << Surveymonkey::Response::Page.new(page, page_structure)
22
+ end
23
+ end
24
+ end
25
+
26
+ def_delegators :@survey_structure, :details
27
+
28
+ private
29
+
30
+ def client
31
+ @client ||= Surveymonkey::Client.new
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,21 @@
1
+ module Surveymonkey
2
+ # Response Answer
3
+ class Response::Question::Answer
4
+ attr_reader :id, :raw_data, :answer_structure
5
+
6
+ def initialize(raw_data, answer_structure)
7
+ @raw_data = raw_data
8
+ @id = raw_data['choice_id'] || raw_data['other_id']
9
+ @answer_structure = answer_structure
10
+ end
11
+
12
+ # Match answer title
13
+ def title
14
+ @title ||= if raw_data['text']
15
+ raw_data['text']
16
+ else
17
+ answer_structure['choices'].detect {|c| c['id'] == id}['text']
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ module Surveymonkey
2
+ # Response Page
3
+ class Response::Page
4
+ attr_reader :id, :raw_data, :page_structure
5
+
6
+ def initialize(raw_data, page_structure)
7
+ @raw_data = raw_data
8
+ @id = raw_data['id']
9
+ @page_structure = page_structure
10
+ end
11
+
12
+ # Match page title
13
+ def title
14
+ @title ||= page_structure['title']
15
+ end
16
+
17
+ def questions
18
+ @questions ||= raw_data['questions'].each_with_object([]) do |question, arr|
19
+ question_structure = page_structure['questions'].detect{|q| q['id'] == question['id']}
20
+ arr << Surveymonkey::Response::Question.new(question, question_structure)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ module Surveymonkey
2
+ # Response Question
3
+ class Response::Question
4
+ attr_reader :id, :raw_data, :question_structure
5
+
6
+ def initialize(raw_data, question_structure)
7
+ @raw_data = raw_data
8
+ @id = raw_data['id']
9
+ @question_structure = question_structure
10
+ end
11
+
12
+ # Match response title
13
+ def title
14
+ @title ||= question_structure['headings'].first['heading']
15
+ end
16
+
17
+ def answers
18
+ @answers ||= raw_data['answers'].each_with_object([]) do |answer, arr|
19
+ answer_structure = question_structure['answers']
20
+ arr << Surveymonkey::Response::Question::Answer.new(answer, answer_structure)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ module Surveymonkey
2
+ # Survey
3
+ class Survey
4
+ attr_reader :id
5
+
6
+ def initialize(id)
7
+ @id = id
8
+ end
9
+
10
+ def details(options = {})
11
+ @details ||= client.survey_details(id, options)
12
+ end
13
+
14
+ def raw_responses(options = {})
15
+ client.survey_responses(id, options)
16
+ end
17
+
18
+ def responses(options = {})
19
+ @responses ||= client.survey_responses(id, options)['data'].each_with_object([]) do |response, arr|
20
+ arr << Surveymonkey::Response.new(id, response['id'])
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def client
27
+ @client ||= Surveymonkey::Client.new
28
+ end
29
+ end
30
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ module SurveymonkeyApi
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "surveymonkey_api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "surveymonkey_api"
8
+ spec.version = SurveymonkeyApi::VERSION
9
+ spec.authors = ["Carlos"]
10
+ spec.email = ["chdezmar@gmail.com"]
11
+
12
+ spec.summary = %q{.}
13
+ spec.description = %q{.}
14
+ spec.homepage = "https://github.com/chdezmar/surveymonkey_api"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency 'bundler', '~> 1.16'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rspec', '~> 3.0'
36
+ spec.add_development_dependency 'pry-byebug', "~> 3.1"
37
+ spec.add_dependency 'httparty', '~> 0.13'
38
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: surveymonkey_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Carlos
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.13'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.13'
83
+ description: "."
84
+ email:
85
+ - chdezmar@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/surveymonkey_api.rb
101
+ - lib/surveymonkey_api/client.rb
102
+ - lib/surveymonkey_api/client/survey.rb
103
+ - lib/surveymonkey_api/response.rb
104
+ - lib/surveymonkey_api/response/answer.rb
105
+ - lib/surveymonkey_api/response/page.rb
106
+ - lib/surveymonkey_api/response/question.rb
107
+ - lib/surveymonkey_api/survey.rb
108
+ - lib/surveymonkey_api/survey/page.rb
109
+ - lib/surveymonkey_api/version.rb
110
+ - surveymonkey_api.gemspec
111
+ homepage: https://github.com/chdezmar/surveymonkey_api
112
+ licenses:
113
+ - MIT
114
+ metadata:
115
+ allowed_push_host: https://rubygems.org
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.6.13
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: "."
136
+ test_files: []