surveymonkey 0.2.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0c1572387413d53da2a0a44985440a8ea47270f
4
- data.tar.gz: 692049f25149f4e8794f099be218fa76fc75b130
3
+ metadata.gz: 0016ceeb8fa3c8895b7b465a24f4f6e3df95861f
4
+ data.tar.gz: c3a701a37149d2c21653683e7fa30b21affffb59
5
5
  SHA512:
6
- metadata.gz: cd15fc54ca2937595c44f09a12c96f2fbf1ed5c14c3842f1a8bf4563267cb7d502e5cc74172628920fb93e68eb672c08c0bf28f2ac82d8ca324b6e6cff6068b2
7
- data.tar.gz: 7f05a0f14e09ff41e7c68b57b038141ffffba22ffe30c7832e1fe327c71ec140623692e50dd85e9351930226bc8fb78865b541c778e53d98dedd3a28402ee13a
6
+ metadata.gz: abc80f434fdcce9004c57845d154f1cce4e9569772d4137a590b558f4c1e9fe45a9a9df656a574f88d4aa80c4dad107943b54f4bb77af73f07045915653f40fa
7
+ data.tar.gz: e477655cec24b311616023d00215c41a6f1a829c95488631a078847493f9dab58e2a9b602774e04ff74631ea5bad050f942d2583f39387a99f1c32708a6ae035
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  /_yardoc/
4
4
  /coverage/
5
5
  /doc/
6
+ /html/
6
7
  /pkg/
7
8
  /spec/reports/
8
9
  /tmp/
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
  require "rubygems/tasks"
4
+ require "rdoc/task"
4
5
 
5
6
  # Default directory to look in is `/specs`
6
7
  # Run with `rake spec`
@@ -14,3 +15,9 @@ task :default => :spec
14
15
  Gem::Tasks.new do |tasks|
15
16
  tasks.console.command = "pry"
16
17
  end
18
+
19
+ # RDoc tasks
20
+ RDoc::Task.new do |rdoc|
21
+ rdoc.main = "README.rdoc"
22
+ rdoc.rdoc_files.include("README.md", "lib/*/*.rb", "lib/*/*/*.rb", "lib/*/*/*/*.rb")
23
+ end
data/lib/surveymonkey.rb CHANGED
@@ -4,12 +4,21 @@ require "surveymonkey/version"
4
4
  require "surveymonkey/logging"
5
5
  require "surveymonkey/request"
6
6
 
7
+ ##
8
+ # Top-level module, holds the user-facing methods
9
+
7
10
  module Surveymonkey
8
11
 
9
12
  class << self
10
13
  # Constants
11
14
 
12
15
  # Public methods
16
+
17
+ ##
18
+ # Catch-all method; matches SurveyMonkey API method names. Call like so:
19
+ #
20
+ # Surveymonkey.get_user_details({'method_params' => {'foo' => 'bar'}})
21
+
13
22
  def method_missing(method_name, *args)
14
23
  begin
15
24
  $log.debug(sprintf("%s: %s\n", __method__, 'enter'))
@@ -1,11 +1,17 @@
1
1
  require 'surveymonkey/logging'
2
2
  require 'json'
3
3
 
4
+ ##
5
+ # Object representing the SurveyMonkey API.
6
+
4
7
  class Surveymonkey::API
5
8
  autoload :Method, 'surveymonkey/api/method'
6
9
 
7
10
  # constants
8
11
 
12
+ ##
13
+ # Hash defining the methods in the SurveyMonkey API. Current as of 2015-05-05.
14
+
9
15
  Api_methods = {
10
16
  'create_flow' => {
11
17
  'path' => '/v2/batch/create_flow',
@@ -45,6 +51,9 @@ class Surveymonkey::API
45
51
  # public methods
46
52
  attr_reader :api_methods
47
53
 
54
+ ##
55
+ # Look up a SurveyMonkey API method and return its path and associated HTTP method.
56
+
48
57
  def api_method(key, api_methods = self.api_methods)
49
58
  begin
50
59
  $log.debug(sprintf("%s: api methods: %s\n", __method__, api_methods.inspect))
@@ -69,6 +78,11 @@ class Surveymonkey::API
69
78
  end
70
79
  end
71
80
 
81
+ ##
82
+ # SurveyMonkey API method params need to be a JSON-encoded string; this
83
+ # method passes through a string and tries to turn another data type into
84
+ # JSON.
85
+
72
86
  def api_method_params(method_params)
73
87
  begin
74
88
  # TODO validate params against API spec
@@ -85,6 +99,11 @@ class Surveymonkey::API
85
99
  end
86
100
  end
87
101
 
102
+ ##
103
+ # Create a new Surveymonkey::API object. The only parameter is an
104
+ # api_methods hash (use this if you want to override the definition of the
105
+ # SurveyMonkey API, I guess?)
106
+
88
107
  def initialize
89
108
  begin
90
109
  @api_methods = Api_methods
@@ -1,8 +1,15 @@
1
1
  require 'surveymonkey/logging'
2
2
 
3
+ ##
4
+ # Object representing a SurveyMonkey API method.
5
+
3
6
  class Surveymonkey::API::Method
4
7
  attr_reader :path, :http_method
5
8
 
9
+ ##
10
+ # Create a new method. Does some input validation to make sure the
11
+ # associated HTTP method is valid.
12
+
6
13
  def initialize(path, http_method = 'post')
7
14
  begin
8
15
  $log.debug(sprintf("%s: enter", __method__))
@@ -3,6 +3,9 @@ require "json"
3
3
 
4
4
  require "surveymonkey/logging"
5
5
 
6
+ ##
7
+ # Class encapsulating the HTTParty client used to communicate with the SurveyMonkey API.
8
+
6
9
  class Surveymonkey::Client
7
10
  include HTTParty
8
11
 
@@ -13,6 +16,12 @@ class Surveymonkey::Client
13
16
  # public methods
14
17
  attr_reader :baseuri, :api_key, :access_token
15
18
 
19
+ ##
20
+ # Create a new Surveymonkey::Client object. Requires the following parameters:
21
+ # * baseuri
22
+ # * access_token
23
+ # * api_key
24
+
16
25
  def initialize(baseuri, access_token, api_key)
17
26
  begin
18
27
  @baseuri = baseuri
@@ -37,7 +46,7 @@ class Surveymonkey::Client
37
46
  # private methods
38
47
  private
39
48
 
40
- def _http_headers(token)
49
+ def _http_headers(token) #:nodoc:
41
50
  begin
42
51
  $log.debug(sprintf("%s: constructing http headers with token '%s'\n", __method__, token))
43
52
  http_headers = {
@@ -1,3 +1,13 @@
1
+ ##
2
+ # Implement logging for Surveymonkey via the Logging library.
3
+ #
4
+ # Logging configuration happens at runtime and is drawn from the
5
+ # **SURVEYMONKEY_LOGLEVEL** environment variable. Set this variable to one of
6
+ # the standard syslog levels (debug, info, warning, error, fatal) to enable
7
+ # more or less logging. At present Surveymonkey logs a lot of debug messages,
8
+ # and other than that just emits errors and fatals if it encounters problems.
9
+ # The default loglevel is error.
10
+
1
11
  module Surveymonkey::Logging
2
12
  # initialize logging
3
13
  if ENV.member?('SURVEYMONKEY_LOGLEVEL')
@@ -2,6 +2,9 @@ require 'surveymonkey/logging'
2
2
  require 'surveymonkey/api'
3
3
  require 'surveymonkey/client'
4
4
 
5
+ ##
6
+ # Object representing a request to the SurveyMonkey API. Parameters should all be populated automatically.
7
+
5
8
  class Surveymonkey::Request
6
9
 
7
10
  begin
@@ -13,6 +16,13 @@ class Surveymonkey::Request
13
16
  Baseuri = 'https://api.surveymonkey.net'
14
17
 
15
18
  # public methods
19
+
20
+ ##
21
+ # Send the HTTP request to the SurveyMonkey API and parse the response.
22
+ # This is an opportunity to override defaults, _e.g._ if you want to use
23
+ # different credentials for a specific request, or if you're sending the
24
+ # same request repeatedly with different parameters.
25
+
16
26
  def execute(method_params = self.method_params, api_method = self.api_method, api_key = self.api_key, access_token = self.access_token)
17
27
  begin
18
28
  $log.debug(sprintf("%s: enter\n", __method__))
@@ -44,6 +54,14 @@ class Surveymonkey::Request
44
54
  end
45
55
  end
46
56
 
57
+ ##
58
+ # Create a new Surveymonkey::Request object. Takes a string representing the API method name and a hash of parameters; the relevant parameters are the following:
59
+ #
60
+ # * baseuri
61
+ # * method_params
62
+ # * access_token
63
+ # * api_key
64
+
47
65
  def initialize(api_method, *args)
48
66
  begin
49
67
  $log.debug(sprintf("%s: enter\n", __method__))
@@ -75,7 +93,7 @@ class Surveymonkey::Request
75
93
  # private methods
76
94
  private
77
95
 
78
- def _client
96
+ def _client #:nodoc:
79
97
  begin
80
98
  @client = Surveymonkey::Client.new()
81
99
  rescue StandardError => e
@@ -85,7 +103,7 @@ class Surveymonkey::Request
85
103
  end
86
104
  end
87
105
 
88
- def _api
106
+ def _api #:nodoc:
89
107
  begin
90
108
  @api = Surveymonkey::API.new()
91
109
  rescue StandardError => e
@@ -95,7 +113,7 @@ class Surveymonkey::Request
95
113
  end
96
114
  end
97
115
 
98
- def _http_headers(token)
116
+ def _http_headers(token) #:nodoc:
99
117
  begin
100
118
  $log.debug(sprintf("%s: constructing http headers with token '%s'\n", __method__, token))
101
119
  http_headers = {
@@ -111,7 +129,7 @@ class Surveymonkey::Request
111
129
  end
112
130
  end
113
131
 
114
- def _from_env(key)
132
+ def _from_env(key) #:nodoc:
115
133
  begin
116
134
  $log.debug(sprintf("%s: fetching '%s' from environment\n", __method__, key))
117
135
  value = ENV.fetch(key)
@@ -126,7 +144,7 @@ class Surveymonkey::Request
126
144
  end
127
145
  end
128
146
 
129
- def _request_uri(path, api_key)
147
+ def _request_uri(path, api_key) #:nodoc:
130
148
  begin
131
149
  $log.debug(sprintf("%s: generating request uri fragment from '%s' and '%s'\n", __method__, path, api_key))
132
150
  request_uri = sprintf("%s?api_key=%s", path, api_key)
@@ -1,3 +1,6 @@
1
+ ##
2
+ # Specify the version of the surveymonkey gem.
3
+
1
4
  module Surveymonkey
2
- VERSION = "0.2.0"
5
+ VERSION = "0.2.1"
3
6
  end
data/surveymonkey.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{Client for SurveyMonkey REST API}
13
13
  spec.description = %q{Interact with SurveyMonkey's REST API. Requires an API token.}
14
- spec.homepage = "http://developer.surveymonkey.com/"
14
+ spec.homepage = "https://github.com/hakamadare/rubygem-surveymonkey/"
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler", ">= 1.7"
25
25
  spec.add_development_dependency "pry", "~> 0.10"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rdoc", "~> 4"
27
28
  spec.add_development_dependency "rspec", "~> 2.4"
28
29
  spec.add_development_dependency "rubygems-tasks", "~> 0.2"
29
30
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: surveymonkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Huff
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-04 00:00:00.000000000 Z
11
+ date: 2015-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '4'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -144,12 +158,11 @@ files:
144
158
  - lib/surveymonkey/api.rb
145
159
  - lib/surveymonkey/api/method.rb
146
160
  - lib/surveymonkey/client.rb
147
- - lib/surveymonkey/config.rb
148
161
  - lib/surveymonkey/logging.rb
149
162
  - lib/surveymonkey/request.rb
150
163
  - lib/surveymonkey/version.rb
151
164
  - surveymonkey.gemspec
152
- homepage: http://developer.surveymonkey.com/
165
+ homepage: https://github.com/hakamadare/rubygem-surveymonkey/
153
166
  licenses:
154
167
  - MIT
155
168
  metadata: {}
@@ -1,10 +0,0 @@
1
- class Surveymonkey::Config
2
- attr_accessor :apiversion, :baseurl
3
-
4
- def initialize(baseurl = 'https://api.surveymonkey.net', apiversion = '2')
5
- @baseurl = baseurl
6
- @apiversion = apiversion
7
-
8
- @apiurl = "#{baseurl}/v#{apiversion}"
9
- end
10
- end