zenps-ruby 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 931e2368e823cda7839fa93c039c78c1c8100abe3946b43ef5823e87b8145e32
4
- data.tar.gz: c316c9c3acaabda72b797ecd47bc5017f6491e64055ff1b51f720606c64c5c28
3
+ metadata.gz: 2cdf4ec564f1ea34c3123c569c756457ba9ad61b49a836efe2dacde0513317a2
4
+ data.tar.gz: 4163d373e87d92f495a53bb614420a989b4a9c48bdd95c7fbc07a172410d8e9b
5
5
  SHA512:
6
- metadata.gz: 32cab1857eecb8c81e3fce35cf1d9ff2fe07e394441987f8df03a2be7032c3137d7e8a8fad7f6f0b21197ecbfd95fcc40e6bea12c84151d3647a7fcb90d99d9c
7
- data.tar.gz: ecfbe289ddf70293b10bb8a1d50647da99e0d24f91ead8bffd783bf80ed656804b8d53a623bd2b38eff446094f2cb8339cdcfc227404a878d60f02557944e885
6
+ metadata.gz: cd93e3b6d9bbefac6129db2d240e1ab4d0d15c2f4c22ff5ec07d3476074146f9f45298341f59f6c630187b91b39e4b9ea8a682d6fb7c344a6f3135a6fa88a8ab
7
+ data.tar.gz: 96d7bc60e3a96b15b11f60ba7c6b2bca5e573d4a14b772a0616b15626b76764ae15bccb9c89d3b2ce192879c3e823f3f743cec73d0cab80f69bbc84c78d17267
data/README.md CHANGED
@@ -52,10 +52,14 @@ A user subject can either be:
52
52
  - A string (email of user to be surveyed)
53
53
  - A hash containing the following keys:
54
54
  - email (compulsory)
55
- - locale (optional --> defaults to `en`)
55
+ - first_name (optional)
56
+ - last_name (optional)
57
+ - locale (optional --> defaults to `en` unless overwritten in general call)
56
58
  - An object that responds to
57
59
  - email method (compulsory)
58
- - locale (optional --> defaults to `en`)
60
+ - first_name method (optional)
61
+ - last_name method (optional)
62
+ - locale (optional --> defaults to `en` unless overwritten in general call)
59
63
 
60
64
  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
61
65
 
@@ -84,15 +88,15 @@ Zenps::Survey.call(user, locale: 'fr', event: 'sign_up', tags: ['man', 'facebook
84
88
  ```
85
89
 
86
90
 
87
- ## Contributing to pipedrive-ruby
91
+ ## Contributing to zenps-ruby
88
92
 
89
93
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
90
94
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
91
95
  * Fork the project.
92
96
  * Start a feature/bugfix branch.
93
97
  * Commit and push until you are happy with your contribution.
94
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
95
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
98
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. Coverage should remain as high as possible.
99
+ * Make sure all tests pass as well as rubocop checks.
96
100
 
97
101
  ## License
98
102
 
@@ -31,23 +31,12 @@ module Zenps
31
31
 
32
32
  def expose_response
33
33
  {
34
- email: email,
34
+ email: get_attribute(:email),
35
35
  code: response.code.to_i,
36
36
  body: response.body
37
37
  }
38
38
  end
39
39
 
40
- def body
41
- {
42
- to: {
43
- email: email
44
- },
45
- locale: locale,
46
- event: event,
47
- tags: tags
48
- }.compact.to_json
49
- end
50
-
51
40
  def uri
52
41
  @uri ||= URI.parse(end_point)
53
42
  end
@@ -59,20 +48,29 @@ module Zenps
59
48
  }
60
49
  end
61
50
 
62
- def email
63
- options[:email]
51
+ def body
52
+ {
53
+ to: to,
54
+ locale: get_attribute(:locale, default: 'en'),
55
+ event: get_attribute(:event),
56
+ tags: tags
57
+ }.compact.to_json
64
58
  end
65
59
 
66
- def locale
67
- options['locale'] || options[:locale] || 'en'
60
+ def to
61
+ {
62
+ email: get_attribute(:email),
63
+ first_name: get_attribute(:first_name),
64
+ last_name: get_attribute(:last_name)
65
+ }.compact
68
66
  end
69
67
 
70
- def event
71
- options['event'] || options[:event]
68
+ def get_attribute(attribute, params = {})
69
+ options[attribute.to_s] || options[attribute] || params[:default]
72
70
  end
73
71
 
74
72
  def tags
75
- (options['tags'] || options[:tags] || []).join(', ')
73
+ get_attribute('tags', default: []).join(', ')
76
74
  rescue NoMethodError
77
75
  nil
78
76
  end
@@ -22,21 +22,21 @@ module Zenps
22
22
  subjects.map do |subject|
23
23
  {
24
24
  email: get_email(subject),
25
- locale: get_locale(subject)
25
+ first_name: get_attribute(subject, :first_name),
26
+ last_name: get_attribute(subject, :last_name),
27
+ locale: get_attribute(subject, :locale)
26
28
  }.compact
27
29
  end
28
30
  end
29
31
 
30
- def get_email(object)
31
- return object if object.class == String
32
- return object[:email] || object['email'] if object.class == Hash
33
- return object.email if object.respond_to? :email
32
+ def get_email(subject)
33
+ subject.class == String ? subject : get_attribute(subject, :email)
34
34
  end
35
35
 
36
- def get_locale(object)
37
- return if object.class == String
38
- return object[:locale] || object['locale'] if object.class == Hash
39
- return object.locale if object.respond_to? :locale
36
+ def get_attribute(subject, attribute)
37
+ return if subject.class == String
38
+ return subject[attribute.to_s] || subject[attribute] if subject.class == Hash
39
+ return subject.send(attribute) if subject.respond_to?(attribute)
40
40
  end
41
41
 
42
42
  def array_but_not_hash?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zenps-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Philippart de Foy