electric_profile_ruby 1.0.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: c0e68350ef037ce05d8dcef7e9dd240c26c27d2f
4
+ data.tar.gz: aa04e0cc8dd0df26a336f18ab6257cd4e1076083
5
+ SHA512:
6
+ metadata.gz: ebc801572944f5f7a15e5b46399b23a7541e80ad877fadb8baa1b1fe21737127db78b34be14ac47527c4407fe4c2dc77208597bb0b325f61dfec544019e0fe98
7
+ data.tar.gz: f4f3c4486cf99b1f9bfa6ae7a55def56dc61fb1ae7c0d8a7998bdeae39df4b1c7f01765e400d2d2769c78393181ccc19d70c30e180de540b38eb6c1967e93fc7
data/.gitignore ADDED
@@ -0,0 +1,12 @@
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
12
+ .env
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
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 electric_profile_ruby.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ electric_profile_ruby (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.5.2)
10
+ public_suffix (>= 2.0.2, < 4.0)
11
+ crack (0.4.3)
12
+ safe_yaml (~> 1.0.0)
13
+ diff-lcs (1.3)
14
+ dotenv (2.2.1)
15
+ hashdiff (0.3.7)
16
+ public_suffix (3.0.2)
17
+ rake (10.5.0)
18
+ rspec (3.7.0)
19
+ rspec-core (~> 3.7.0)
20
+ rspec-expectations (~> 3.7.0)
21
+ rspec-mocks (~> 3.7.0)
22
+ rspec-core (3.7.1)
23
+ rspec-support (~> 3.7.0)
24
+ rspec-expectations (3.7.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.7.0)
27
+ rspec-mocks (3.7.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.7.0)
30
+ rspec-support (3.7.1)
31
+ safe_yaml (1.0.4)
32
+ webmock (3.3.0)
33
+ addressable (>= 2.3.6)
34
+ crack (>= 0.3.2)
35
+ hashdiff
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ bundler (~> 1.16)
42
+ dotenv
43
+ electric_profile_ruby!
44
+ rake (~> 10.0)
45
+ rspec (~> 3.0)
46
+ webmock
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 John Alston
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,39 @@
1
+ # ElectricProfileRuby
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/electric_profile_ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'electric_profile_ruby'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install electric_profile_ruby
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/electric_profile_ruby.
36
+
37
+ ## License
38
+
39
+ 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,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dotenv"
5
+ Dotenv.load!
6
+ require "electric_profile_ruby"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require "irb"
16
+ 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,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "electric_profile_ruby/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "electric_profile_ruby"
8
+ spec.version = ElectricProfile::VERSION
9
+ spec.authors = ["John Alston"]
10
+ spec.email = ["jalston@bovitzinc.com"]
11
+
12
+ spec.summary = "Official Ruby SDK for Electric Profile"
13
+ spec.description = "Official Ruby SDK for Electric Profile"
14
+ spec.homepage = "http://www.bovitzinc.com"
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 "webmock"
37
+ spec.add_development_dependency "dotenv"
38
+ end
@@ -0,0 +1,8 @@
1
+ require "electric_profile_ruby/version"
2
+ require "electric_profile_ruby/client"
3
+ require "electric_profile_ruby/question"
4
+ require "electric_profile_ruby/profiler"
5
+
6
+ module ElectricProfile
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,93 @@
1
+ module ElectricProfile
2
+ require 'net/http'
3
+ require 'net/https'
4
+ require 'json'
5
+
6
+ class Client
7
+ attr_reader :successful, :data, :error
8
+
9
+ def initialize
10
+ raise ArgumentError, 'Customer token is required' unless @customer_token = ENV['ELECTRIC_PROFILE_CUSTOMER_TOKEN']
11
+ raise ArgumentError, 'API URL is required' unless @api_url = ENV['ELECTRIC_PROFILE_API_URL']
12
+
13
+ @http_headers = {
14
+ 'Content-Type' => 'application/json',
15
+ 'Accept' => 'application/json',
16
+ 'Accept-Charset' => 'utf-8',
17
+ 'User-Agent' => 'electric_profile_ruby',
18
+ 'Profiling-Auth-Token' => @customer_token
19
+ }
20
+ end
21
+
22
+ def fetch_questions
23
+ uri = URI(@api_url + 'question')
24
+ http_request = Net::HTTP::Get.new uri, @http_headers
25
+ perform_request(uri, http_request)
26
+ end
27
+
28
+ def fetch_question(question_id)
29
+ uri = URI(@api_url + 'question?id=' + question_id)
30
+ http_request = Net::HTTP::Get.new uri, @http_headers
31
+ perform_request(uri, http_request)
32
+ end
33
+
34
+ def create_question(question_attributes)
35
+ uri = URI(@api_url + 'question')
36
+ http_request = Net::HTTP::Post.new uri, @http_headers
37
+ http_request.body = { "data" => question_attributes }.to_json
38
+ perform_request(uri, http_request)
39
+ end
40
+
41
+ def update_question(question_attributes)
42
+ uri = URI(@api_url + 'question')
43
+ http_request = Net::HTTP::Put.new uri, @http_headers
44
+ http_request.body = { "data" => question_attributes }.to_json
45
+ perform_request(uri, http_request)
46
+ end
47
+
48
+ def fetch_profilers
49
+ uri = URI(@api_url + 'profiler')
50
+ http_request = Net::HTTP::Get.new uri, @http_headers
51
+ perform_request(uri, http_request)
52
+ end
53
+
54
+ def fetch_profiler(profiler_id)
55
+ uri = URI(@api_url + 'profiler?id=' + profiler_id)
56
+ http_request = Net::HTTP::Get.new uri, @http_headers
57
+ perform_request(uri, http_request)
58
+ end
59
+
60
+ def create_profiler(profiler_attributes)
61
+ uri = URI(@api_url + 'profiler')
62
+ http_request = Net::HTTP::Post.new uri, @http_headers
63
+ http_request.body = { "data" => profiler_attributes }.to_json
64
+ perform_request(uri, http_request)
65
+ end
66
+
67
+ def update_profiler(profiler_attributes)
68
+ uri = URI(@api_url + 'profiler')
69
+ http_request = Net::HTTP::Put.new uri, @http_headers
70
+ http_request.body = { "data" => profiler_attributes }.to_json
71
+ perform_request(uri, http_request)
72
+ end
73
+
74
+ private
75
+ def perform_request(uri, http_request)
76
+ http_response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
77
+ http.request http_request
78
+ end
79
+
80
+ case http_response
81
+ when Net::HTTPSuccess, Net::HTTPRedirection
82
+ @data = JSON.parse http_response.body
83
+ @successful = true
84
+ else
85
+ @error = "#{http_response.code}: #{http_response.body}"
86
+ @successful = false
87
+ end
88
+
89
+ return @successful
90
+ end
91
+
92
+ end
93
+ end
@@ -0,0 +1,88 @@
1
+ module ElectricProfile
2
+
3
+ class Profiler
4
+ attr_accessor :id, :customerId, :name, :listQuestionsId, :introMessage, :exitMessage, :hideAnsweredQuestions, :callbackType, :error
5
+
6
+ def initialize(atts)
7
+ atts = atts.inject({}){ |memo, (k, v) | memo[k.to_sym] = v; memo }
8
+ @id = atts[:id]
9
+ @customerId = atts[:customerId]
10
+ @name = atts[:name]
11
+ @listQuestionsId = atts[:listQuestionsId] || []
12
+ @introMessage = atts[:introMessage]
13
+ @exitMessage = atts[:exitMessage]
14
+ @hideAnsweredQuestions = atts[:hideAnsweredQuestions] || "NO_ANSWERED"
15
+ @callbackType = atts[:callbackType]
16
+ end
17
+
18
+ def save
19
+ if @id
20
+ save_existing
21
+ else
22
+ save_new
23
+ end
24
+ end
25
+
26
+ def save_new
27
+ initialize_client
28
+ attributes = {
29
+ name: @name,
30
+ listQuestionsId: @listQuestionsId,
31
+ introMessage: @introMessage,
32
+ exitMessage: @exitMessage,
33
+ hideAnsweredQuestions: @hideAnsweredQuestions,
34
+ callbackType: @callbackType
35
+ }
36
+ if @client.create_profiler(attributes)
37
+ true
38
+ else
39
+ @error = @client.error
40
+ false
41
+ end
42
+ end
43
+
44
+ def save_existing
45
+ initialize_client
46
+ attributes = {
47
+ id: @id,
48
+ customerId: @customerId,
49
+ name: @name,
50
+ listQuestionsId: @listQuestionsId,
51
+ introMessage: @introMessage,
52
+ exitMessage: @exitMessage,
53
+ hideAnsweredQuestions: @hideAnsweredQuestions,
54
+ callbackType: @callbackType
55
+ }
56
+ if @client.update_profiler(attributes)
57
+ true
58
+ else
59
+ @error = @client.error
60
+ false
61
+ end
62
+ end
63
+
64
+ def self.find(id)
65
+ client = Client.new
66
+ if client.fetch_profiler(id)
67
+ new client.data["Items"].first
68
+ else
69
+ raise StandardError, client.error
70
+ end
71
+ end
72
+
73
+ def self.all
74
+ client = Client.new
75
+ if client.fetch_profilers
76
+ client.data["Items"].map { |atts| new atts }
77
+ else
78
+ raise StandardError, client.error
79
+ end
80
+ end
81
+
82
+ def initialize_client
83
+ @client ||= Client.new
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,88 @@
1
+ module ElectricProfile
2
+
3
+ class Question
4
+ attr_accessor :id, :customerId, :name, :prompt, :type, :answerOptions, :allowMultiple, :categories, :error
5
+
6
+ def initialize(atts)
7
+ atts = atts.inject({}){ |memo, (k, v) | memo[k.to_sym] = v; memo }
8
+ @id = atts[:id]
9
+ @customerId = atts[:customerId]
10
+ @name = atts[:name]
11
+ @prompt = atts[:prompt]
12
+ @type = atts[:type]
13
+ @answerOptions = atts[:answerOptions] || {}
14
+ @allowMultiple = atts[:allowMultiple] || false
15
+ @categories = atts[:categories] || []
16
+ end
17
+
18
+ def save
19
+ if @id
20
+ save_existing
21
+ else
22
+ save_new
23
+ end
24
+ end
25
+
26
+ def save_new
27
+ initialize_client
28
+ attributes = {
29
+ name: @name,
30
+ prompt: @prompt,
31
+ type: @type,
32
+ answerOptions: @answerOptions,
33
+ allowMultiple: @allowMultiple,
34
+ categories: @categories
35
+ }
36
+ if @client.create_question(attributes)
37
+ true
38
+ else
39
+ @error = @client.error
40
+ false
41
+ end
42
+ end
43
+
44
+ def save_existing
45
+ initialize_client
46
+ attributes = {
47
+ id: @id,
48
+ customerId: @customerId,
49
+ name: @name,
50
+ prompt: @prompt,
51
+ type: @type,
52
+ answerOptions: @answerOptions,
53
+ allowMultiple: @allowMultiple,
54
+ categories: @categories
55
+ }
56
+ if @client.update_question(attributes)
57
+ true
58
+ else
59
+ @error = @client.error
60
+ false
61
+ end
62
+ end
63
+
64
+ def self.find(id)
65
+ client = Client.new
66
+ if client.fetch_question(id)
67
+ new client.data
68
+ else
69
+ raise StandardError, client.error
70
+ end
71
+ end
72
+
73
+ def self.all
74
+ client = Client.new
75
+ if client.fetch_questions
76
+ client.data["Items"].map { |atts| new atts }
77
+ else
78
+ raise StandardError, client.error
79
+ end
80
+ end
81
+
82
+ def initialize_client
83
+ @client ||= Client.new
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,3 @@
1
+ module ElectricProfile
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: electric_profile_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - John Alston
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-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: webmock
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: dotenv
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
+ description: Official Ruby SDK for Electric Profile
84
+ email:
85
+ - jalston@bovitzinc.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".ruby-version"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - electric_profile_ruby.gemspec
102
+ - lib/electric_profile_ruby.rb
103
+ - lib/electric_profile_ruby/client.rb
104
+ - lib/electric_profile_ruby/profiler.rb
105
+ - lib/electric_profile_ruby/question.rb
106
+ - lib/electric_profile_ruby/version.rb
107
+ homepage: http://www.bovitzinc.com
108
+ licenses:
109
+ - MIT
110
+ metadata:
111
+ allowed_push_host: https://rubygems.org
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.6.11
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Official Ruby SDK for Electric Profile
132
+ test_files: []