survey_monkey 0.2.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c6ff1c896073faa5c2f32aa2410c0d74d46086d
4
- data.tar.gz: 208f9ee34f065f9c5b87c5d5906d95d39badea19
3
+ metadata.gz: 125097a806ade2658f50ab46a3fac7fc954da771
4
+ data.tar.gz: dd25f4b0540f416285a04a24ca34c5e553a9b987
5
5
  SHA512:
6
- metadata.gz: 306f74acec296051f7b1ad0b0d67109e3cdb99002af433846799cddb50826af44d2980d2b8f1c45d528682ef57c769bee5a990ff0e3e571bdb536bd96e14bffc
7
- data.tar.gz: 7f926d813786aeb7856138e3e678e8037fc5eed345de37bb53eccf4dcfe49f15aebf06db3492a556b00d65263fcd0b4a120c3dbfdca1fc0ee0343e685547c599
6
+ metadata.gz: a4cf4f96c0c90543d2bb4dc3d34669bc85b41916af9619572da7c2c543dd9ab8276e87d10f061c73a91f2fd59a69f38c8adc9c27b5e8f244c329063237881d43
7
+ data.tar.gz: 55defc012c0dcb8462dd1c080747dc03cb58dc66c691dcbbcc9e2d8ffe8ac9109ac81f2b7ea5a43f8a97e131c051f7bcb0a4b626ff81443f74f282dbd74a51c2
data/README.md CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
18
18
 
19
19
  To Authenticate, you have two options:
20
20
 
21
- 1. Use ENV Variables:
21
+ Option 1: Use ENV Variables:
22
22
 
23
23
  ```ruby
24
24
  # Set the following variables ( the gem is configured to use dotenv.
@@ -32,14 +32,14 @@ ENV['SURVEY_MONKEY_CLIENT_SECRET']
32
32
  ENV['SURVEY_MONKEY_CLIENT_ID']
33
33
  ```
34
34
 
35
- 2. Create an instance of SurveyMonkey::Auth
35
+ Option 2: Create an instance of SurveyMonkey::Auth with the credentials.
36
36
 
37
37
  ```ruby
38
38
  api_credentials = {
39
- access_token: 'accesstoken',
40
- api_key: 'apikey',
41
- client_secret: 'clientsecret',
42
- client_id: 'clientid'
39
+ access_token: 'accesstoken',
40
+ api_key: 'apikey',
41
+ client_secret: 'clientsecret',
42
+ client_id: 'clientid'
43
43
  }
44
44
  auth = SurveyMonkey::Auth.new(api_credentials)
45
45
 
@@ -58,15 +58,16 @@ Make the request:
58
58
  ```ruby
59
59
  # Create the request
60
60
  # if ENV vars were used, auth can be excluded from options hash
61
+ # params can be excluded or nil to set with set_params method and a block
61
62
 
62
- options = {api_method: api_method, auth: auth}
63
+ options = {api_method: api_method, auth: auth, params: nil}
63
64
  api_request = SurveyMonkey::Request.new(api_method)
64
65
 
65
66
  # Set the parameters
66
67
  api_request.set_parameters do |p|
67
68
  p.page = 1
68
69
  p.page_size = 10
69
- p.order_ac = 'true'
70
+ p.order_asc = 'true'
70
71
  end
71
72
 
72
73
  # Run the request
@@ -79,10 +80,24 @@ result = api_request.result
79
80
 
80
81
  ## Quick Requests
81
82
  ```ruby
83
+ # A shortcut for specifying params is to use a hash instead of the block.
84
+ # The params_hash is passed in the options hash under the :params key
85
+ # e.g.
86
+ params_hash = {page_size: 10, page: 1, order_asc: 'true'}
87
+ options = {params: params_hash}
88
+
82
89
  # A shortcut for making requests using default options is to simply call
83
90
  # SurveyMonkey.method where method is the name of the API method you wish to call
84
91
  # e.g.
85
- request = SurveyMonkey.get_survey_list
92
+
93
+ api_request = SurveyMonkey.get_survey_list options
94
+
95
+ # Run the request
96
+ api_request.run_request
97
+
98
+ # View the result
99
+ result = api_request.result
100
+
86
101
  ```
87
102
 
88
103
  ## TODO
@@ -73,7 +73,7 @@ create_flow:
73
73
  parameters:
74
74
  survey:
75
75
  template_id: optional
76
- form_survey_id: optional
76
+ from_survey_id: optional
77
77
  survey_title: optional
78
78
  collector:
79
79
  type: conditionally_required
@@ -1,5 +1,8 @@
1
1
  require 'survey_monkey/recipients'
2
2
  require 'survey_monkey/recipient'
3
+ require "active_support"
4
+ require "active_support/core_ext/string"
5
+ require "active_support/core_ext/object"
3
6
 
4
7
  module SurveyMonkey
5
8
  class Parameters
@@ -18,23 +21,35 @@ module SurveyMonkey
18
21
  def to_hash
19
22
  converted_hash = Hash.new
20
23
  method_parameters.keys.each do |root|
21
- if method_parameters[root].is_a? Hash ## has child
24
+ if method_parameters[root].is_a? Hash ## The parameter has children
22
25
  converted_hash[root] = Hash.new
23
26
  method_parameters[root].keys.each do |child|
24
27
  if method_parameters[root][child].is_a? Hash ## has grand_child
25
28
  method_parameters[root].keys.each do |grand_child|
26
- converted_hash[root][child][grand_child] = self.send("#{root}_#{child}_#{grand_child}") ## GrandChild
29
+ # save the value for each grand_child into the hash
30
+ converted_hash[root][child][grand_child] = self.send("#{root}_#{child}_#{grand_child}")
27
31
  end
32
+ # Delete any nil grand_child keys
33
+ converted_hash[root][child].delete_if{ |k, v| v.nil? } if converted_hash[root].has_key?(child)
28
34
  elsif method_parameters[root][child].is_a? Array
29
- converted_hash[root][child] = self.send("#{root}_#{child}").to_hash ## Child Array
35
+ # child is an array. elements of array to hash
36
+ value = self.send("#{root}_#{child}")
37
+ unless value.empty?
38
+ converted_hash[root][child] = value
39
+ converted_hash[root][child].map{ |e| e.to_hash }
40
+ end
30
41
  else
31
- converted_hash[root][child] = self.send("#{root}_#{child}") ## Child
42
+ value = self.send("#{root}_#{child}")
43
+ converted_hash[root][child] = value unless value.nil? ## save value for child (dont assign nil values)
32
44
  end
45
+ # Delete any root keys with nil values
46
+ converted_hash[root] = converted_hash[root].delete_if{ |k, v| v.nil? } if converted_hash.has_key?(root)
33
47
  end
34
48
  elsif method_parameters[root].is_a? Array
35
- converted_hash[root] = self.send("#{root}").to_hash ## root Array
49
+ converted_hash[root] = self.send("#{root}").to_hash.delete_if{ |k, v| v.nil? } ## root Array
36
50
  else
37
- converted_hash[root] = self.send("#{root}") ## No children
51
+ value = self.send("#{root}") ## No children
52
+ converted_hash[root] = value unless value.nil?
38
53
  end
39
54
  end
40
55
  converted_hash
@@ -2,17 +2,21 @@ module SurveyMonkey
2
2
  class Recipient
3
3
  attr_accessor :email, :first_name, :last_name, :custom_id
4
4
 
5
- def intialize(options = {})
6
- email = options[:email]
7
- first_name = options[:first_name]
8
- first_name = options[:first_name]
9
- last_name = options[:last_name]
10
- custom_id = options[:custom_id]
11
-
5
+ def initialize(options = {})
6
+ @email = options[:email]
7
+ @first_name = options[:first_name]
8
+ @last_name = options[:last_name]
9
+ @custom_id = options[:custom_id]
12
10
  raise "Email Required for Recipient" if email.nil?
13
11
  end
12
+
14
13
  def to_hash
15
- { email: email, name: name, last_name: last_name, custom_id: custom_id }
14
+ hash = Hash.new
15
+ hash["email"] = email unless email.nil?
16
+ hash["first_name"] = first_name unless first_name.nil?
17
+ hash["last_name"] = last_name unless last_name.nil?
18
+ hash["custom_id"] = custom_id unless custom_id.nil?
19
+ hash
16
20
  end
17
21
  end
18
22
  end
@@ -17,7 +17,11 @@ module SurveyMonkey
17
17
  end
18
18
 
19
19
  def to_hash
20
- map { |e| e.as_json }
20
+ map { |e| e.to_hash }
21
+ end
22
+
23
+ def empty?
24
+ count == 0
21
25
  end
22
26
  end
23
27
  end
@@ -71,6 +71,7 @@ module SurveyMonkey
71
71
  end
72
72
  end
73
73
  request.run
74
+ self
74
75
  end
75
76
 
76
77
  def set_on_complete_response
@@ -93,6 +94,11 @@ module SurveyMonkey
93
94
  JSON.parse @response.body
94
95
  end
95
96
 
97
+ def submit
98
+ run_request
99
+ result
100
+ end
101
+
96
102
  private
97
103
  def api_key
98
104
  @api_key
@@ -1,3 +1,3 @@
1
1
  module SurveyMonkey
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.2"
3
3
  end
data/lib/survey_monkey.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require "dotenv"
2
+ require "json"
2
3
  require "active_record"
3
4
  require "active_support"
4
- require "json"
5
+ require "active_support/all"
5
6
  require "typhoeus"
6
7
  require "yaml"
7
8
  require "survey_monkey/config"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: survey_monkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Dawson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-07 00:00:00.000000000 Z
11
+ date: 2015-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus