zenps-ruby 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +9 -5
- data/lib/zenps/client.rb +17 -19
- data/lib/zenps/payload.rb +9 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cdf4ec564f1ea34c3123c569c756457ba9ad61b49a836efe2dacde0513317a2
|
4
|
+
data.tar.gz: 4163d373e87d92f495a53bb614420a989b4a9c48bdd95c7fbc07a172410d8e9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
-
|
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
|
-
-
|
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
|
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
|
-
*
|
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
|
|
data/lib/zenps/client.rb
CHANGED
@@ -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
|
63
|
-
|
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
|
67
|
-
|
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
|
71
|
-
options[
|
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
|
-
(
|
73
|
+
get_attribute('tags', default: []).join(', ')
|
76
74
|
rescue NoMethodError
|
77
75
|
nil
|
78
76
|
end
|
data/lib/zenps/payload.rb
CHANGED
@@ -22,21 +22,21 @@ module Zenps
|
|
22
22
|
subjects.map do |subject|
|
23
23
|
{
|
24
24
|
email: get_email(subject),
|
25
|
-
|
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(
|
31
|
-
|
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
|
37
|
-
return if
|
38
|
-
return
|
39
|
-
return
|
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?
|