zenps-ruby 0.0.0 → 0.0.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
  SHA256:
3
- metadata.gz: 5e271f0e89ea5c2b50ee41b4b32341089ad9c806adcf65083de65fe04e01fa72
4
- data.tar.gz: 0a5adda8c8afecc4f5f24ef3eb9f29623c9f749ebcb6db2ddfa6694bd2b05337
3
+ metadata.gz: 931e2368e823cda7839fa93c039c78c1c8100abe3946b43ef5823e87b8145e32
4
+ data.tar.gz: c316c9c3acaabda72b797ecd47bc5017f6491e64055ff1b51f720606c64c5c28
5
5
  SHA512:
6
- metadata.gz: f23b98117c2e18c3a8944dca873571a7b91a0eed744814c2ac6d11ab33d1e8c0d9e4a543b9fc89f206448f788f4435bc1dfac4dd0aa10ac27ec36f262db6d34d
7
- data.tar.gz: ae19e9a9a630523b87eb3a0195ae5c4ffe70ff2ce43b2d6a0d799fb6b1a629531ed2bd5278bd39a798ec22308d3c3e74b034328aadc8133d5d18a65b011a59bd
6
+ metadata.gz: 32cab1857eecb8c81e3fce35cf1d9ff2fe07e394441987f8df03a2be7032c3137d7e8a8fad7f6f0b21197ecbfd95fcc40e6bea12c84151d3647a7fcb90d99d9c
7
+ data.tar.gz: ecfbe289ddf70293b10bb8a1d50647da99e0d24f91ead8bffd783bf80ed656804b8d53a623bd2b38eff446094f2cb8339cdcfc227404a878d60f02557944e885
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://badge.fury.io/rb/zenps-ruby.svg)](https://badge.fury.io/rb/zenps-ruby)
1
2
  [![Codeship Status for aphilippartd/zenps-ruby](https://app.codeship.com/projects/beb50360-2413-0137-0f16-0e0a32caa97a/status?branch=master)](https://app.codeship.com/projects/330078)
2
3
  [![Maintainability](https://api.codeclimate.com/v1/badges/065b707a3ccd884c40d6/maintainability)](https://codeclimate.com/github/aphilippartd/zenps-ruby/maintainability)
3
4
  [![Test Coverage](https://api.codeclimate.com/v1/badges/065b707a3ccd884c40d6/test_coverage)](https://codeclimate.com/github/aphilippartd/zenps-ruby/test_coverage)
@@ -37,13 +38,13 @@ Zenps.configure_with('path/to/your/configuration/file.yml')
37
38
  This wrapper allows you to send NPS surveys to your user in batch...
38
39
 
39
40
  ```ruby
40
- Zenps::Survey.call([user_1, user_2])
41
+ Zenps::Survey.call([user_1, user_2], event: 'sign_up')
41
42
  ```
42
43
 
43
44
  ...or on a per-user basis
44
45
 
45
46
  ```ruby
46
- Zenps::Survey.call(user)
47
+ Zenps::Survey.call(user, event: 'sign_up')
47
48
  ```
48
49
 
49
50
  A user subject can either be:
@@ -59,20 +60,22 @@ A user subject can either be:
59
60
  This allows for the gem to be used eg. in a rails application with User models that respond to the email method (and/or locale) as follows
60
61
 
61
62
  ```ruby
62
- Zenps::Survey.call(User.limit(10))
63
+ Zenps::Survey.call(User.limit(10), event: 'sign_up')
63
64
  ```
64
65
 
65
66
  but also in a more simple way as follows
66
67
 
67
68
  ```ruby
68
- Zenps::Survey.call('john.doe@acme.com')
69
+ Zenps::Survey.call('john.doe@acme.com', event: 'sign_up')
69
70
  ```
70
71
 
71
72
  The following options are available on the Survey call method:
72
73
 
73
- - locale (String) - Overwrites the user's AND default locale
74
- - event (String) - Typically the event triggering the NPS survey
75
- - tags (Array) - Tags giving you granularity in your analytics
74
+ | Options | Type | Mandatory | Description |
75
+ | --------|:---------------:| :--------:|------------------------------------------------:|
76
+ | locale | String | false | Overwrites the user's AND default locale |
77
+ | event | String | true | Typically the event triggering the NPS survey |
78
+ | tags | Array\[String\] | false | Tags giving you granularity in your analytics |
76
79
 
77
80
  Example:
78
81
 
data/lib/zenps-ruby.rb CHANGED
@@ -1,9 +1,9 @@
1
-
2
1
  require 'yaml'
3
2
  require 'logger'
4
- require 'zenps/client.rb'
5
- require 'zenps/payload.rb'
6
- require 'zenps/survey.rb'
3
+ require_relative 'zenps/client.rb'
4
+ require_relative 'zenps/payload.rb'
5
+ require_relative 'zenps/survey.rb'
6
+ # Zenps ruby wrapper
7
7
  module Zenps
8
8
  # Configuration defaults
9
9
  @config = {
@@ -16,13 +16,13 @@ module Zenps
16
16
 
17
17
  # Configure through hash
18
18
  def self.configure(options = {})
19
- options.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
19
+ options.each { |k, v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym }
20
20
  end
21
21
 
22
22
  # Configure through yaml file
23
23
  def self.configure_with(path_to_yaml_file)
24
24
  begin
25
- config = YAML::load(IO.read(path_to_yaml_file))
25
+ config = YAML.safe_load(IO.read(path_to_yaml_file))
26
26
  rescue Errno::ENOENT
27
27
  raise ConfigurationPathError
28
28
  end
@@ -33,14 +33,16 @@ module Zenps
33
33
  @config
34
34
  end
35
35
 
36
+ # Missing ZENPS key error
36
37
  class KeyMissingError < StandardError
37
- def initialize(msg="Zenps configuration key missing")
38
+ def initialize(msg = 'Zenps configuration key missing')
38
39
  super
39
40
  end
40
41
  end
41
42
 
43
+ # Wrong configuration path error
42
44
  class ConfigurationPathError < StandardError
43
- def initialize(msg="YAML configuration file couldn't be found.")
45
+ def initialize(msg = "YAML configuration file couldn't be found.")
44
46
  super
45
47
  end
46
48
  end
data/lib/zenps/client.rb CHANGED
@@ -3,13 +3,13 @@ require 'uri'
3
3
  require 'json'
4
4
 
5
5
  module Zenps
6
+ # Api client for Zenps
6
7
  class Client
7
-
8
8
  def initialize
9
9
  check_configuration
10
10
  end
11
11
 
12
- def call(options={})
12
+ def call(options = {})
13
13
  @options = options
14
14
  perform_request
15
15
  expose_response
@@ -26,7 +26,7 @@ module Zenps
26
26
  def perform_request
27
27
  request = Net::HTTP::Post.new(uri, header)
28
28
  request.body = body
29
- @response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) {|http| http.request request}
29
+ @response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request request }
30
30
  end
31
31
 
32
32
  def expose_response
@@ -40,7 +40,7 @@ module Zenps
40
40
  def body
41
41
  {
42
42
  to: {
43
- email: email,
43
+ email: email
44
44
  },
45
45
  locale: locale,
46
46
  event: event,
@@ -74,6 +74,7 @@ module Zenps
74
74
  def tags
75
75
  (options['tags'] || options[:tags] || []).join(', ')
76
76
  rescue NoMethodError
77
+ nil
77
78
  end
78
79
 
79
80
  def end_point
data/lib/zenps/payload.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  module Zenps
2
+ # Class for structuring subjects into array of hashes from:
3
+ # - (array of) string(s)
4
+ # - (array of) hash(es)
5
+ # - (array of) object(s)
2
6
  class Payload
3
- # Returns array of hashes from:
4
- # - (array of) string(s)
5
- # - (array of) hash(es)
6
- # - (array of) object(s)
7
7
  def get(subjects)
8
8
  @subjects = subjects
9
- return payload
9
+ payload
10
10
  end
11
11
 
12
12
  private
@@ -15,11 +15,11 @@ module Zenps
15
15
 
16
16
  def payload
17
17
  @subjects = [subjects] unless array_but_not_hash?
18
- return get_payload
18
+ build_payload
19
19
  end
20
20
 
21
- def get_payload
22
- return subjects.map do |subject|
21
+ def build_payload
22
+ subjects.map do |subject|
23
23
  {
24
24
  email: get_email(subject),
25
25
  locale: get_locale(subject)
data/lib/zenps/survey.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  module Zenps
2
+ # Takes list of subjects and sends NPS survey to all subjects
2
3
  class Survey
3
- # Takes list of subjects and sends NPS survey to all subjects
4
- def self.call(subjects, options={})
4
+ def self.call(subjects, options = {})
5
5
  new.call(subjects, options)
6
6
  end
7
7
 
8
- def call(subjects, options={})
8
+ def call(subjects, options = {})
9
9
  @subjects = subjects
10
10
  @options = options
11
11
  perform_requests
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zenps-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Philippart de Foy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-08 00:00:00.000000000 Z
11
+ date: 2019-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
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'
111
125
  description: Ruby wrapper for Zenps
112
126
  email: alexis.philippartdefoy@gmail.com
113
127
  executables: []