chimpanzee 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/Guardfile +25 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/chimpanzee.gemspec +32 -0
- data/lib/chimpanzee.rb +26 -0
- data/lib/chimpanzee/api2.rb +32 -0
- data/lib/chimpanzee/api2/api_caller.rb +76 -0
- data/lib/chimpanzee/api2/collectors.rb +8 -0
- data/lib/chimpanzee/api2/missing_method.rb +10 -0
- data/lib/chimpanzee/api2/surveys.rb +124 -0
- data/lib/chimpanzee/api2/user.rb +7 -0
- data/lib/chimpanzee/configuration.rb +11 -0
- data/lib/chimpanzee/exceptions.rb +4 -0
- data/lib/chimpanzee/version.rb +3 -0
- data/test/chimpanzee/api2/api_caller_test.rb +45 -0
- data/test/chimpanzee/api2/collectors_test.rb +21 -0
- data/test/chimpanzee/api2/surveys_test.rb +28 -0
- data/test/chimpanzee/api2/user_test.rb +20 -0
- data/test/chimpanzee/api2_test.rb +23 -0
- data/test/chimpanzee/configuration_test.rb +18 -0
- data/test/chimpanzee_test.rb +30 -0
- data/test/support/configure_chimpanzee.rb +9 -0
- data/test/test_helper.rb +19 -0
- metadata +219 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b0516672dd2273303e50c721922002b9756129fc
|
4
|
+
data.tar.gz: 5fe6722aa270e72388e0c217fd3722a115e54058
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: adf84d6e7c1bc695f88d1596a40fc273a8153cc906b87a58e9f70ecb70c661c072ca9b8b8e4796a2af36d2bec2d6989a9b8f4c20a2dd9cd490d7837a2fed6586
|
7
|
+
data.tar.gz: 981c7d1b70385dc340fe2c0433bc794180a3418c57a254c01a08b2f6f281d5bc57bb0aeb318dcdda0a7543bcd16775da90504da241e25ffab2a1faa275f985ac
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
guard :minitest do
|
2
|
+
# with Minitest::Unit
|
3
|
+
watch(%r{^test/(.*)\/?(.*)_test\.rb$})
|
4
|
+
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
|
5
|
+
watch(%r{^test/test_helper\.rb$}) { 'test' }
|
6
|
+
|
7
|
+
# with Minitest::Spec
|
8
|
+
# watch(%r{^spec/(.*)_spec\.rb$})
|
9
|
+
# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
10
|
+
# watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
|
11
|
+
|
12
|
+
# Rails 4
|
13
|
+
# watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
|
14
|
+
# watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' }
|
15
|
+
# watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
|
16
|
+
# watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
|
17
|
+
# watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
|
18
|
+
# watch(%r{^test/.+_test\.rb$})
|
19
|
+
# watch(%r{^test/test_helper\.rb$}) { 'test' }
|
20
|
+
|
21
|
+
# Rails < 4
|
22
|
+
# watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
|
23
|
+
# watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" }
|
24
|
+
# watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
|
25
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Maciej Litwiniuk
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Chimpanzee
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'chimpanzee'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install chimpanzee
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/chimpanzee/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/chimpanzee.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chimpanzee/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "chimpanzee"
|
8
|
+
spec.version = Chimpanzee::VERSION
|
9
|
+
spec.authors = ["Maciej Litwiniuk"]
|
10
|
+
spec.email = ["maciej@litwiniuk.net"]
|
11
|
+
spec.summary = %q{API wrapper for surveymonkey.net}
|
12
|
+
spec.description = %q{Simple API wrapper for surveymonkey.net API version 2.0}
|
13
|
+
spec.homepage = "https://github.com/prograils/chimpanzee"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "minitest"
|
24
|
+
spec.add_development_dependency "guard"
|
25
|
+
spec.add_development_dependency "guard-minitest"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "pry-remote"
|
28
|
+
spec.add_development_dependency "pry-nav"
|
29
|
+
spec.add_development_dependency "fakeweb", ["~> 1.3"]
|
30
|
+
spec.add_runtime_dependency "httparty", ["~> 0.13.0"]
|
31
|
+
|
32
|
+
end
|
data/lib/chimpanzee.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "chimpanzee/api2"
|
2
|
+
require "chimpanzee/configuration"
|
3
|
+
require "chimpanzee/exceptions"
|
4
|
+
require "chimpanzee/version"
|
5
|
+
|
6
|
+
module Chimpanzee
|
7
|
+
class << self
|
8
|
+
attr_writer :configuration
|
9
|
+
attr_writer :api
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configuration
|
13
|
+
return @configuration if @configuration
|
14
|
+
self.configuration = Configuration.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure
|
18
|
+
yield(configuration)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.api
|
22
|
+
return @api if @api
|
23
|
+
self.api = Chimpanzee::Api2
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Chimpanzee
|
2
|
+
module Api2
|
3
|
+
autoload :ApiCaller, 'chimpanzee/api2/api_caller'
|
4
|
+
autoload :Collectors, 'chimpanzee/api2/collectors'
|
5
|
+
autoload :MissingMethod, 'chimpanzee/api2/missing_method'
|
6
|
+
autoload :Surveys, 'chimpanzee/api2/surveys'
|
7
|
+
autoload :User, 'chimpanzee/api2/user'
|
8
|
+
class << self
|
9
|
+
attr_writer :api_caller
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def self.surveys
|
14
|
+
@surveys ||= Api2::Surveys.new
|
15
|
+
end
|
16
|
+
def self.user
|
17
|
+
@user ||= Api2::User.new
|
18
|
+
end
|
19
|
+
def self.collectors
|
20
|
+
@collectors ||= Api2::Collectors.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.api_caller
|
24
|
+
return @api_caller if @api_caller
|
25
|
+
self.api_caller = ApiCaller.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.get_api_caller(*args)
|
29
|
+
self.api_caller.get_api_caller(*args)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
module Chimpanzee
|
3
|
+
module Api2
|
4
|
+
class ApiCaller
|
5
|
+
include HTTParty
|
6
|
+
base_uri Chimpanzee.configuration.surveymonkey_host
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
config = Chimpanzee.configuration
|
10
|
+
if not config.api_key
|
11
|
+
raise Chimpanzee::InvalidConfigException
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(method, *args, &block)
|
16
|
+
response = nil
|
17
|
+
response = build_query(method, *args)
|
18
|
+
begin
|
19
|
+
JSON.parse(response.body)
|
20
|
+
rescue
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_access_token(client_id, client_secret, redirect_uri, code)
|
26
|
+
opts = {
|
27
|
+
body: {
|
28
|
+
client_secret: client_secret,
|
29
|
+
code: code,
|
30
|
+
client_id: client_id,
|
31
|
+
grant_type: 'authorization_code',
|
32
|
+
redirect_uri: redirect_uri
|
33
|
+
},
|
34
|
+
query: {
|
35
|
+
api_key: Chimpanzee.configuration.api_key
|
36
|
+
}
|
37
|
+
}
|
38
|
+
response = self.class.post '/oauth/token', opts
|
39
|
+
Rails.logger.info response
|
40
|
+
Rails.logger.info response.body
|
41
|
+
begin
|
42
|
+
JSON.parse(response.body)
|
43
|
+
rescue
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def build_query(method, *args)
|
50
|
+
url = build_url(method)
|
51
|
+
options = build_options(args.is_a?(Array) && args.first.is_a?(Hash) ? args.first : {})
|
52
|
+
self.class.post url, options
|
53
|
+
end
|
54
|
+
|
55
|
+
def build_options(args={})
|
56
|
+
{
|
57
|
+
headers: {
|
58
|
+
'Content-Type'=> 'application/json',
|
59
|
+
'Authorization'=> "bearer #{Chimpanzee.configuration.access_token}"
|
60
|
+
},
|
61
|
+
query: {
|
62
|
+
api_key: Chimpanzee.configuration.api_key
|
63
|
+
}.merge(args),
|
64
|
+
body: {
|
65
|
+
}.merge(args).to_json
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def build_url(method)
|
70
|
+
url = ['/v2']
|
71
|
+
url << method.to_s.split('_', 2)
|
72
|
+
url.flatten.join('/')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Chimpanzee
|
2
|
+
module Api2
|
3
|
+
class Surveys
|
4
|
+
|
5
|
+
include MissingMethod
|
6
|
+
|
7
|
+
def export_survey_responses_to_csv_array(survey_id, survey=nil)
|
8
|
+
survey_id = survey_id.to_s
|
9
|
+
survey ||= get_survey_details survey_id: survey_id
|
10
|
+
respondents = get_respondent_list survey_id: survey_id,
|
11
|
+
fields: ['date_start', 'date_modified']
|
12
|
+
respondents = extract_respondents(respondents)
|
13
|
+
questions = map_questions(survey)
|
14
|
+
answers = map_answers(survey)
|
15
|
+
responses = get_responses_in_batches(survey_id, respondents.keys)
|
16
|
+
responses = map_responses(responses, answers)
|
17
|
+
build_csv_array(questions, answers, responses, respondents)
|
18
|
+
end
|
19
|
+
|
20
|
+
## builds CSV array ready to be exported to ie. Excel
|
21
|
+
## First row acts as title row
|
22
|
+
def build_csv_array(questions, answers, responses, respondents)
|
23
|
+
csv_array = []
|
24
|
+
if questions
|
25
|
+
title_row = []
|
26
|
+
respondents_order = []
|
27
|
+
respondents_fields = respondents.values.first
|
28
|
+
if respondents_fields && !respondents_fields.empty?
|
29
|
+
respondents_fields.keys.each{|k| respondents_order << k }
|
30
|
+
questions_order = []
|
31
|
+
title_row.concat respondents_order
|
32
|
+
questions.each.each do |key, q|
|
33
|
+
title_row << q
|
34
|
+
questions_order << key
|
35
|
+
end
|
36
|
+
csv_array << title_row
|
37
|
+
responses.each do |key, response|
|
38
|
+
row = []
|
39
|
+
respondents_order.each do |k|
|
40
|
+
row << respondents[key][k]
|
41
|
+
end
|
42
|
+
questions_order.each do |qid|
|
43
|
+
row << (response[qid] || []).join(", ")
|
44
|
+
end
|
45
|
+
csv_array << row
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
csv_array
|
50
|
+
end
|
51
|
+
|
52
|
+
## Create more readable structure with responses
|
53
|
+
## Hash - key -> respondent id, value: hash with key of question_id
|
54
|
+
## Anwers are array of texts
|
55
|
+
def map_responses(responses_raw, answers)
|
56
|
+
responses = {}
|
57
|
+
if responses_raw && responses_raw['data'].present?
|
58
|
+
responses_raw['data'].each do |response|
|
59
|
+
if response && response['questions']
|
60
|
+
response_hash = {}
|
61
|
+
response['questions'].each do |question|
|
62
|
+
answer_array = []
|
63
|
+
question['answers'].each do |answer|
|
64
|
+
answer_array << (answer['text'] || answers[answer['col']])
|
65
|
+
end
|
66
|
+
response_hash[question['question_id']] = answer_array
|
67
|
+
end
|
68
|
+
responses[response['respondent_id']] = response_hash
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
responses
|
73
|
+
end
|
74
|
+
|
75
|
+
def extract_respondents(respondents)
|
76
|
+
respondents_hash = {}
|
77
|
+
if respondents && respondents['data'].present? && respondents['data']['respondents'].present?
|
78
|
+
respondents['data']['respondents'].each do |respondent|
|
79
|
+
respondents_hash[respondent['respondent_id']] = respondent
|
80
|
+
end
|
81
|
+
end
|
82
|
+
respondents_hash
|
83
|
+
end
|
84
|
+
|
85
|
+
def map_questions(survey)
|
86
|
+
questions = {}
|
87
|
+
if survey && survey['data'].present? && survey['data']['pages'].present?
|
88
|
+
survey['data']['pages'].each do |page|
|
89
|
+
page['questions'].each do |question|
|
90
|
+
questions[question['question_id']] = question['heading']
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
questions
|
95
|
+
end
|
96
|
+
|
97
|
+
def map_answers(survey)
|
98
|
+
answers = {}
|
99
|
+
if survey && survey['data'].present? && survey['data']['pages'].present?
|
100
|
+
survey['data']['pages'].each do |page|
|
101
|
+
page['questions'].each do |question|
|
102
|
+
question['answers'].each do |answer|
|
103
|
+
answers[answer['answer_id']] = answer['weight'] || answer['text']
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
answers
|
109
|
+
end
|
110
|
+
|
111
|
+
## SurveyMonkey API allows fetching max of 100 responses per request
|
112
|
+
def get_responses_in_batches(survey_id, respondent_ids)
|
113
|
+
ret = { 'data' => [] }
|
114
|
+
while respondent_ids.count > 0
|
115
|
+
respondent_ids_batch = respondent_ids.shift(100)
|
116
|
+
responses = get_responses survey_id: survey_id,
|
117
|
+
respondent_ids: respondent_ids_batch
|
118
|
+
ret['data'].concat responses['data'] if responses
|
119
|
+
end
|
120
|
+
ret
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Chimpanzee
|
4
|
+
module Api2
|
5
|
+
describe ApiCaller do
|
6
|
+
describe ".initialize" do
|
7
|
+
it "should raise error if api_key is not set" do
|
8
|
+
old = Chimpanzee.configuration.api_key
|
9
|
+
Chimpanzee.configuration.api_key = nil
|
10
|
+
Proc.new do
|
11
|
+
ApiCaller.new
|
12
|
+
end.must_raise Chimpanzee::InvalidConfigException
|
13
|
+
Chimpanzee.configuration.api_key = old
|
14
|
+
end
|
15
|
+
it "should raise error if access_token is not set" do
|
16
|
+
old = Chimpanzee.configuration.access_token
|
17
|
+
Chimpanzee.configuration.access_token = nil
|
18
|
+
Proc.new do
|
19
|
+
ApiCaller.new
|
20
|
+
end.must_raise Chimpanzee::InvalidConfigException
|
21
|
+
Chimpanzee.configuration.access_token = old
|
22
|
+
end
|
23
|
+
end
|
24
|
+
describe "with valid api key" do
|
25
|
+
before do
|
26
|
+
configure_chimpanzee
|
27
|
+
end
|
28
|
+
|
29
|
+
it "build url with given parameters" do
|
30
|
+
a = ApiCaller.new
|
31
|
+
url = a.build_url 'surveys_get_survey_list'
|
32
|
+
url.must_equal "/v2/surveys/get_survey_list"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "calls get_survey_list and gets the result" do
|
36
|
+
FakeWeb.register_uri(:post, "https://api.surveymonkey.net/v2/surveys/get_survey_list?api_key=#{Chimpanzee.configuration.api_key}", body: '{"status":0,"data":{"surveys":[{"survey_id":"123456"}],"page":1,"page_size":1000}}')
|
37
|
+
a = ApiCaller.new
|
38
|
+
resp = a.surveys_get_survey_list
|
39
|
+
resp.is_a?(Hash).must_equal true
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Chimpanzee
|
4
|
+
module Api2
|
5
|
+
describe Collectors do
|
6
|
+
before do
|
7
|
+
configure_chimpanzee
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should transfer method call to Api2 class" do
|
11
|
+
mock_obj = Minitest::Mock.new
|
12
|
+
@api.api_caller = mock_obj
|
13
|
+
mock_obj.expect('user_get_user_details', [])
|
14
|
+
@api.user.get_user_details
|
15
|
+
mock_obj.verify
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Chimpanzee
|
4
|
+
module Api2
|
5
|
+
describe Surveys do
|
6
|
+
before do
|
7
|
+
configure_chimpanzee
|
8
|
+
@api.api_caller = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
@api.api_caller = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "must transfer method call to Api2 class" do
|
16
|
+
mock_obj = Minitest::Mock.new
|
17
|
+
@api.api_caller = mock_obj
|
18
|
+
mock_obj.expect('surveys_get_survey_list', [])
|
19
|
+
@api.surveys.get_survey_list
|
20
|
+
mock_obj.verify
|
21
|
+
end
|
22
|
+
|
23
|
+
it "must export survey to array" do
|
24
|
+
s = Surveys.new
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Chimpanzee
|
4
|
+
module Api2
|
5
|
+
describe User do
|
6
|
+
before do
|
7
|
+
configure_chimpanzee
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should transfer method call to Api2 class" do
|
11
|
+
mock_obj = Minitest::Mock.new
|
12
|
+
@api.api_caller = mock_obj
|
13
|
+
mock_obj.expect('user_get_user_details', [])
|
14
|
+
@api.user.get_user_details
|
15
|
+
mock_obj.verify
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Chimpanzee
|
4
|
+
describe Api2 do
|
5
|
+
describe "with valid api key" do
|
6
|
+
before do
|
7
|
+
configure_chimpanzee
|
8
|
+
end
|
9
|
+
it "should return surveys object" do
|
10
|
+
Chimpanzee::Api2.surveys.class.must_equal Api2::Surveys
|
11
|
+
end
|
12
|
+
it "should return user object" do
|
13
|
+
Chimpanzee::Api2.user.class.must_equal Api2::User
|
14
|
+
end
|
15
|
+
it "should return collectors object" do
|
16
|
+
Chimpanzee::Api2.collectors.class.must_equal Api2::Collectors
|
17
|
+
end
|
18
|
+
it "should return api_caller object" do
|
19
|
+
Chimpanzee::Api2.api_caller.class.must_equal Api2::ApiCaller
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Chimpanzee
|
4
|
+
describe Configuration do
|
5
|
+
it "should has surveymonkes host already set" do
|
6
|
+
configuration = Configuration.new
|
7
|
+
configuration.surveymonkey_host.must_equal 'https://api.surveymonkey.net'
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should allow changing config values" do
|
11
|
+
configuration = Configuration.new
|
12
|
+
configuration.surveymonkey_host = 'http://google.com'
|
13
|
+
configuration.api_key = 'foobar'
|
14
|
+
configuration.surveymonkey_host.must_equal 'http://google.com'
|
15
|
+
configuration.api_key.must_equal 'foobar'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe Chimpanzee do
|
4
|
+
describe "#configuration" do
|
5
|
+
it 'should return configuration' do
|
6
|
+
c = Chimpanzee.configuration
|
7
|
+
c.class.must_equal Chimpanzee::Configuration
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#configure" do
|
12
|
+
before do
|
13
|
+
Chimpanzee.configure do |c|
|
14
|
+
c.api_key = 'test'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should properly set values in block' do
|
19
|
+
config = Chimpanzee.configuration
|
20
|
+
config.api_key.must_equal 'test'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#api" do
|
25
|
+
it 'should return api object' do
|
26
|
+
c = Chimpanzee.api
|
27
|
+
c.must_equal Chimpanzee::Api2
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module ConfigureChimpanzee
|
2
|
+
def configure_chimpanzee
|
3
|
+
Chimpanzee.configure do |c|
|
4
|
+
c.api_key = ENV['CHIMPANZEE_API_KEY'] || ENV['API_KEY'] || "test"
|
5
|
+
c.access_token = ENV['CHIMPANZEE_ACCESS_TOKEN'] || ENV['ACCESS_TOKEN'] || "test"
|
6
|
+
end
|
7
|
+
@api = Chimpanzee.api
|
8
|
+
end
|
9
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/unit'
|
3
|
+
require 'minitest/pride'
|
4
|
+
|
5
|
+
require 'chimpanzee'
|
6
|
+
require 'fakeweb'
|
7
|
+
|
8
|
+
## support files
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
10
|
+
|
11
|
+
class MiniTest::Spec
|
12
|
+
include ConfigureChimpanzee
|
13
|
+
before do
|
14
|
+
FakeWeb.clean_registry
|
15
|
+
end
|
16
|
+
after do
|
17
|
+
FakeWeb.clean_registry
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,219 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chimpanzee
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maciej Litwiniuk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-11 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-remote
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-nav
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: fakeweb
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.3'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.3'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: httparty
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.13.0
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.13.0
|
153
|
+
description: Simple API wrapper for surveymonkey.net API version 2.0
|
154
|
+
email:
|
155
|
+
- maciej@litwiniuk.net
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".gitignore"
|
161
|
+
- Gemfile
|
162
|
+
- Guardfile
|
163
|
+
- LICENSE.txt
|
164
|
+
- README.md
|
165
|
+
- Rakefile
|
166
|
+
- chimpanzee.gemspec
|
167
|
+
- lib/chimpanzee.rb
|
168
|
+
- lib/chimpanzee/api2.rb
|
169
|
+
- lib/chimpanzee/api2/api_caller.rb
|
170
|
+
- lib/chimpanzee/api2/collectors.rb
|
171
|
+
- lib/chimpanzee/api2/missing_method.rb
|
172
|
+
- lib/chimpanzee/api2/surveys.rb
|
173
|
+
- lib/chimpanzee/api2/user.rb
|
174
|
+
- lib/chimpanzee/configuration.rb
|
175
|
+
- lib/chimpanzee/exceptions.rb
|
176
|
+
- lib/chimpanzee/version.rb
|
177
|
+
- test/chimpanzee/api2/api_caller_test.rb
|
178
|
+
- test/chimpanzee/api2/collectors_test.rb
|
179
|
+
- test/chimpanzee/api2/surveys_test.rb
|
180
|
+
- test/chimpanzee/api2/user_test.rb
|
181
|
+
- test/chimpanzee/api2_test.rb
|
182
|
+
- test/chimpanzee/configuration_test.rb
|
183
|
+
- test/chimpanzee_test.rb
|
184
|
+
- test/support/configure_chimpanzee.rb
|
185
|
+
- test/test_helper.rb
|
186
|
+
homepage: https://github.com/prograils/chimpanzee
|
187
|
+
licenses:
|
188
|
+
- MIT
|
189
|
+
metadata: {}
|
190
|
+
post_install_message:
|
191
|
+
rdoc_options: []
|
192
|
+
require_paths:
|
193
|
+
- lib
|
194
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '0'
|
199
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - ">="
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0'
|
204
|
+
requirements: []
|
205
|
+
rubyforge_project:
|
206
|
+
rubygems_version: 2.4.5
|
207
|
+
signing_key:
|
208
|
+
specification_version: 4
|
209
|
+
summary: API wrapper for surveymonkey.net
|
210
|
+
test_files:
|
211
|
+
- test/chimpanzee/api2/api_caller_test.rb
|
212
|
+
- test/chimpanzee/api2/collectors_test.rb
|
213
|
+
- test/chimpanzee/api2/surveys_test.rb
|
214
|
+
- test/chimpanzee/api2/user_test.rb
|
215
|
+
- test/chimpanzee/api2_test.rb
|
216
|
+
- test/chimpanzee/configuration_test.rb
|
217
|
+
- test/chimpanzee_test.rb
|
218
|
+
- test/support/configure_chimpanzee.rb
|
219
|
+
- test/test_helper.rb
|