surveygizmo 0.0.1

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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Bobby Uhlenbrock
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,26 @@
1
+ require 'surveygizmo/api'
2
+ require 'surveygizmo/client'
3
+ require 'surveygizmo/configuration'
4
+
5
+ module Surveygizmo
6
+ extend Configuration
7
+ class << self
8
+ # Alias for Surveygizmo::Client.new
9
+ #
10
+ # @return [Surveygizmo::Client]
11
+ def new(options={})
12
+ Surveygizmo::Client.new(options)
13
+ end
14
+
15
+ # Delegate to Surveygizmo::Client
16
+ def method_missing(method, *args, &block)
17
+ return super unless new.respond_to?(method)
18
+ new.send(method, *args, &block)
19
+ end
20
+
21
+ def respond_to?(method, include_private = false)
22
+ new.respond_to?(method, include_private) || super(method, include_private)
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ require 'surveygizmo/configuration'
2
+ require 'surveygizmo/connection'
3
+ require 'surveygizmo/request'
4
+
5
+ module Surveygizmo
6
+ # @private
7
+ class API
8
+ include Connection
9
+ include Request
10
+
11
+ # @private
12
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
13
+
14
+ # Creates a new API
15
+ def initialize(options={})
16
+ options = Surveygizmo.options.merge(options)
17
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
18
+ send("#{key}=", options[key])
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ module Surveygizmo
2
+ # Wrapper for the Surveygizmo REST API
3
+ #
4
+ # @note All methods have been separated into modules and follow the same grouping used in {http://developer.surveygizmo.com/resources/rest-api-documentation-version-1-01/api-objects/ the Surveygizmo API Documentation}.
5
+ # @see http://developer.surveygizmo.com/resources/rest-api-documentation-version-1-01/
6
+ class Client < API
7
+ # Require client method modules after initializing the Client class in
8
+ # order to avoid a superclass mismatch error, allowing those modules to be
9
+ # Client-namespaced.
10
+ require 'surveygizmo/client/account'
11
+ require 'surveygizmo/client/account_user'
12
+ require 'surveygizmo/client/filter'
13
+ require 'surveygizmo/client/survey'
14
+ require 'surveygizmo/client/survey_campaign'
15
+ require 'surveygizmo/client/survey_response'
16
+
17
+ alias :api_endpoint :endpoint
18
+
19
+ include Surveygizmo::Client::Account
20
+ include Surveygizmo::Client::AccountUser
21
+ include Surveygizmo::Client::Filter
22
+ include Surveygizmo::Client::Survey
23
+ include Surveygizmo::Client::SurveyCampaign
24
+ include Surveygizmo::Client::SurveyResponse
25
+
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ module Surveygizmo
2
+ class Client
3
+ # Defines methods related to a SurveyGizmo account
4
+ # @see http://developer.surveygizmo.com/resources/rest-api-documentation-version-1-01/api-objects/account/
5
+ module Account
6
+
7
+ # Get details of authorized account
8
+ def account
9
+ get('account')
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,39 @@
1
+ module Surveygizmo
2
+ class Client
3
+ # Defines methods related to a SurveyGizmo account user (not to be confused with a {Contact})
4
+ # @see http://developer.surveygizmo.com/resources/rest-api-documentation-version-1-01/api-object-accountuser/
5
+ module AccountUser
6
+
7
+ # List all account users
8
+ def account_users
9
+ get('accountuser')
10
+ end
11
+
12
+ # Returns account user details for a given id
13
+ # @param id [Integer, String] A SurveyGizmo AccountUser ID
14
+ def account_user(id)
15
+ get("accountuser/#{id}")
16
+ end
17
+
18
+ # Create a new account user
19
+ # @param options [Hash] provide the :email, :username and :password
20
+ def create_account_user(options = {})
21
+ post('accountuser?_method=PUT', options)
22
+ end
23
+
24
+ # Remove an account user
25
+ # @param id [Integer, String] A SurveyGizmo AccountUser ID
26
+ def delete_account_user(id)
27
+ post("accountuser/#{id}?_method=DELETE")
28
+ end
29
+
30
+ # Change an account user
31
+ # @param id [Integer, String] A SurveyGizmo AccountUser ID
32
+ # @param options [Hash] provide the :email, :username and :password
33
+ def update_account_user(id, options = {})
34
+ post("accountuser/#{id}?_method=POST", options)
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ module Surveygizmo
2
+ class Client
3
+ # Defines methods related to a SurveyGizmo contact
4
+ # @see http://developer.surveygizmo.com/resources/rest-api-documentation-version-1-01/api-object-contact/
5
+ module Contact
6
+
7
+ # List all contacts
8
+ # @param survey_id [Integer, String] Specify the survey
9
+ # @param survey_campaign_id [Integer, String] Specify the campaign
10
+ def contacts(survey_id, survey_campaign_id)
11
+ get("survey/#{survey_id}/surveycampaign")
12
+ end
13
+
14
+ # Returns contact details for a given id
15
+ # @param survey_id [Integer, String] Specify the survey
16
+ # @param survey_campaign_id [Integer, String] Specify the campaign
17
+ # @param id [Integer, String] Specify the user
18
+ def contact(survey_id, survey_campaign_id, id)
19
+ get("survey/#{survey_id}/surveycampaign/#{id}")
20
+ end
21
+
22
+ # TODO: Create, Update, Delete
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ module Surveygizmo
2
+ class Client
3
+ # Defines methods related to filtering search results
4
+ # @see http://developer.surveygizmo.com/resources/filtering-and-browsing-results/
5
+ module Filter
6
+
7
+ # Format filters for the request querystring
8
+ # TODO: Not yet recursive
9
+ # @param filters [Hash] Filter(s) used to refine search
10
+ def formatted_filters(filters = {})
11
+ Hash[*filters.map{|key,value| ["filter[#{key}]", value]}.flatten]
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,30 @@
1
+ module Surveygizmo
2
+ class Client
3
+ # Defines methods related to a SurveyGizmo survey
4
+ # Polls, Quizzes, Forms, Registrations are all surveys with simple flags activated to change the behavior of the object
5
+ # @see http://developer.surveygizmo.com/resources/rest-api-documentation-version-1-01/api-object-survey/
6
+ module Survey
7
+
8
+ # List all surveys, optionally filtered
9
+ # @param filters [Hash] Filter(s) used to refine search
10
+ def surveys(filters = {})
11
+ get('survey', formatted_filters(filters))
12
+ end
13
+
14
+ # Temporary, until SG implements filtering by subtype
15
+ def polls
16
+ surveys.select { |s| s._subtype == 'Poll' }
17
+ end
18
+
19
+ # Returns survey details for a given id
20
+ # @param id [Integer, String] A SurveyGizmo AccountUser ID
21
+ # @param metaonly [Boolean] Return only meta data
22
+ def survey(id, metaonly = false)
23
+ get("survey/#{id}", :metaonly => metaonly)
24
+ end
25
+
26
+ # TODO: Create, Update, Delete
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ module Surveygizmo
2
+ class Client
3
+ # Defines methods related to a SurveyGizmo survey campaign
4
+ # @see http://developer.surveygizmo.com/resources/rest-api-documentation-version-1-01/api-object-surveycampaign/
5
+ module SurveyCampaign
6
+
7
+ # List all survey campaigns for a given survey
8
+ # @param survey_id [Integer, String] Specify the survey to the campaigns to get
9
+ def survey_campaigns(survey_id)
10
+ get("survey/#{survey_id}/surveycampaign")
11
+ end
12
+
13
+ # Returns survey campaign details for a given id
14
+ # @param survey_id [Integer, String] Specify the survey to the campaigns to get
15
+ # @param id [Integer, String] Specify the campaign to get
16
+ def survey_campaign(survey_id, id)
17
+ get("survey/#{survey_id}/surveycampaign/#{id}")
18
+ end
19
+
20
+ # TODO: Create, Update, Delete
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ module Surveygizmo
2
+ class Client
3
+ # Defines methods related to a SurveyGizmo survey response
4
+ # @see http://developer.surveygizmo.com/resources/rest-api-documentation-version-1-01/api-object-api-object-surveyresponse/
5
+ module SurveyResponse
6
+
7
+ # List all survey responses for a given survey
8
+ # @param survey_id [Integer, String] Specify the survey to the responses to get
9
+ def survey_responses(survey_id)
10
+ get("survey/#{survey_id}/surveyresponse")
11
+ end
12
+
13
+ # Returns survey response details for a given id
14
+ # @param survey_id [Integer, String] Specify the survey to the response to get
15
+ # @param id [Integer, String] Specify the response to get
16
+ def survey_response(survey_id, id)
17
+ get("survey/#{survey_id}/surveyresponse/#{id}")
18
+ end
19
+
20
+ # TODO: Create, Update, Delete
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,56 @@
1
+ require 'surveygizmo/version'
2
+
3
+ module Surveygizmo
4
+ # Defines constants and methods related to configuration
5
+ module Configuration
6
+
7
+ # An array of valid keys in the options hash when configuring a {Surveygizmo::API}
8
+ VALID_OPTIONS_KEYS = [
9
+ :username,
10
+ :password,
11
+ :endpoint,
12
+ :user_agent].freeze
13
+
14
+ # There is no default
15
+ DEFAULT_USERNAME = nil
16
+
17
+ # There is no default
18
+ DEFAULT_PASSWORD = nil
19
+
20
+ # The endpoint that will be used to connect if none is set
21
+ DEFAULT_ENDPOINT = 'https://restapi.surveygizmo.com/v1/'.freeze
22
+
23
+ # The value sent in the 'User-Agent' header if none is set
24
+ DEFAULT_USER_AGENT = "Surveygizmo Ruby Gem #{Surveygizmo::VERSION}".freeze
25
+
26
+ # @private
27
+ attr_accessor *VALID_OPTIONS_KEYS
28
+
29
+ # When this module is extended, set all configuration options to their default values
30
+ def self.extended(base)
31
+ base.reset
32
+ end
33
+
34
+ # Convenience method to allow configuration options to be set in a block
35
+ def configure
36
+ yield self
37
+ end
38
+
39
+ # Create a hash of options and their values
40
+ def options
41
+ options = {}
42
+ VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
43
+ options
44
+ end
45
+
46
+ # Reset all configuration options to defaults
47
+ def reset
48
+ self.endpoint = DEFAULT_ENDPOINT
49
+ self.username = DEFAULT_USERNAME
50
+ self.password = DEFAULT_PASSWORD
51
+ self.user_agent = DEFAULT_USER_AGENT
52
+ self
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,28 @@
1
+ require 'faraday_middleware'
2
+ require 'digest/md5'
3
+
4
+ module Surveygizmo
5
+ # @private
6
+ module Connection
7
+
8
+ private
9
+
10
+ def connection(temp_api_endpoint=nil)
11
+ options = {
12
+ :headers => { 'Accept' => 'application/json', 'User-Agent' => user_agent },
13
+ :ssl => { :verify => false },
14
+ :params => { :'user:md5' => "#{username}:#{Digest::MD5.hexdigest(password)}" }
15
+ }
16
+
17
+ options[:url] = temp_api_endpoint ? temp_api_endpoint : api_endpoint
18
+
19
+ Faraday.new(options) do |builder|
20
+ builder.use Faraday::Request::UrlEncoded
21
+ builder.use Faraday::Response::Mashify
22
+ builder.use Faraday::Response::ParseJson
23
+ builder.adapter(:net_http)
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,41 @@
1
+ module Surveygizmo
2
+ # Defines HTTP request methods
3
+ module Request
4
+
5
+ # Perform an HTTP GET request
6
+ def get(path, options={})
7
+ request(:get, path, options)
8
+ end
9
+
10
+ def post(path, options={}, temp_api_endpoint=nil)
11
+ request(:post, path, options, temp_api_endpoint)
12
+ end
13
+
14
+ # Perform an HTTP PUT request
15
+ def put(path, options={})
16
+ request(:put, path, options)
17
+ end
18
+
19
+ # Perform an HTTP DELETE request
20
+ def delete(path, options={})
21
+ request(:delete, path, options)
22
+ end
23
+
24
+ private
25
+
26
+ # Perform an HTTP request
27
+ def request(method, path, options, temp_api_endpoint=nil)
28
+ response = connection(temp_api_endpoint).send(method) do |request|
29
+ case method.to_sym
30
+ when :get, :delete
31
+ request.url(path, options)
32
+ when :post, :put
33
+ request.path = path
34
+ request.body = options unless options.empty?
35
+ end
36
+ end
37
+ response.body.data
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Surveygizmo
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,73 @@
1
+ h1. The SurveyGizmo Ruby Gem
2
+
3
+ A Ruby wrapper for the "SurveyGizmo REST API":http://developer.surveygizmo.com/resources/rest-api-documentation-version-1-01/
4
+
5
+ h2. Installation
6
+
7
+ @gem install surveygizmo@
8
+
9
+ h2. Documentation
10
+
11
+ http://rdoc.info/github/ample/surveygizmo
12
+
13
+ h2. Usage
14
+
15
+ <code>
16
+ # Configure your Surveygizmo client
17
+ Surveygizmo.configure do |config|
18
+ config.username = YOUR_USERNAME
19
+ config.password = YOUR_PASSWORD
20
+ end
21
+ </code>
22
+
23
+ h2. To Do List
24
+
25
+ This gem is very young, and not all endpoints have been implemented. Here's a brief overview of the progress so far (italics denotes lack of implementation):
26
+
27
+ * Account
28
+ ** Show
29
+ * Account User
30
+ ** Index
31
+ ** Show
32
+ ** Create
33
+ ** Update
34
+ ** Delete
35
+ * Contact
36
+ ** Index
37
+ ** Show
38
+ ** _Create_
39
+ ** _Update_
40
+ ** _Delete_
41
+ * Survey
42
+ ** Index
43
+ ** Show
44
+ ** _Create_
45
+ ** _Update_
46
+ ** _Delete_
47
+ * Survey Campaign
48
+ ** Index
49
+ ** Show
50
+ ** _Create_
51
+ ** _Update_
52
+ ** _Delete_
53
+ * Survey Response
54
+ ** Index
55
+ ** Show
56
+ ** _Create_
57
+ ** _Update_
58
+ ** _Delete_
59
+ * _Survey Option_
60
+ * _Survey Question_
61
+ * _Survey Page_
62
+ * _Survey Statistics_
63
+ * _Email Message_
64
+
65
+ Also, there aren't any tests yet. This is high on the priority list and should be coming soon.
66
+
67
+ h2. Thanks
68
+
69
+ This gem is heavily inspired by the Twitter gem and John Nunemaker's hard work.
70
+
71
+ h2. Copyright
72
+
73
+ Copyright (c) 2011 Bobby Uhlenbrock. See LICENSE for details.
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'surveygizmo/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'surveygizmo'
7
+ s.version = Surveygizmo::VERSION
8
+ s.authors = ['Bobby Uhlenbrock']
9
+ s.email = ['developers@helloample.com']
10
+ s.homepage = 'http://github.com/ample/surveygizmo'
11
+ s.summary = %q{A Ruby wrapper for the SurveyGizmo REST API}
12
+ s.description = %q{A Ruby wrapper for the SurveyGizmo REST API}
13
+ s.rubyforge_project = 'surveygizmo'
14
+
15
+ # Development Gems
16
+ # s.add_development_dependency 'rspec'
17
+ # Gems
18
+ s.add_dependency 'hashie', '~> 1.1.0'
19
+ s.add_dependency 'faraday', '~> 0.7.4'
20
+ s.add_dependency 'faraday_middleware', '~> 0.7.0'
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ['lib']
26
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: surveygizmo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bobby Uhlenbrock
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hashie
16
+ requirement: &70230798285560 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70230798285560
25
+ - !ruby/object:Gem::Dependency
26
+ name: faraday
27
+ requirement: &70230798284520 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.7.4
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70230798284520
36
+ - !ruby/object:Gem::Dependency
37
+ name: faraday_middleware
38
+ requirement: &70230798283660 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.7.0
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70230798283660
47
+ description: A Ruby wrapper for the SurveyGizmo REST API
48
+ email:
49
+ - developers@helloample.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - Rakefile
58
+ - lib/surveygizmo.rb
59
+ - lib/surveygizmo/api.rb
60
+ - lib/surveygizmo/client.rb
61
+ - lib/surveygizmo/client/account.rb
62
+ - lib/surveygizmo/client/account_user.rb
63
+ - lib/surveygizmo/client/contact.rb
64
+ - lib/surveygizmo/client/filter.rb
65
+ - lib/surveygizmo/client/survey.rb
66
+ - lib/surveygizmo/client/survey_campaign.rb
67
+ - lib/surveygizmo/client/survey_response.rb
68
+ - lib/surveygizmo/configuration.rb
69
+ - lib/surveygizmo/connection.rb
70
+ - lib/surveygizmo/request.rb
71
+ - lib/surveygizmo/version.rb
72
+ - readme.textile
73
+ - surveygizmo.gemspec
74
+ homepage: http://github.com/ample/surveygizmo
75
+ licenses: []
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project: surveygizmo
94
+ rubygems_version: 1.8.11
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: A Ruby wrapper for the SurveyGizmo REST API
98
+ test_files: []